Home >Web Front-end >H5 Tutorial >H5 sets or returns the currentTime property of the current position (in seconds) of audio/video playback
Example
Set the time position to 5 seconds:
myVid=document.getElementById("video1"); myVid.currentTime=5;
Definition and usage
currentTime property sets or returnsAudio/ The current position of video in seconds.
When this property is set, playback will jump to the specified position.
Browser support
All major browsers support the currentTime attribute.
Note: This attribute is not supported in Internet Explorer 8 or earlier browsers.
Syntax
Set currentTime attribute:
audio|video.currentTime="seconds"
Return currentTime attribute:
audio|video.currentTime
Attribute value
Value | Description |
seconds | Indicates the current position of audio/video playback in seconds. |
Technical details
Return value | Numeric value, representing seconds |
Example
Set the time position to 5 seconds:
<!DOCTYPE html> <html> <body> <p> <button onclick="getCurTime()" type="button">获得当前时间的位置</button> <button onclick="setCurTime()" type="button">把时间位置设置为 5 秒</button> </p> <video id="video1" controls="controls"> <source src="/kf51/demo/mov_bbb.mp4" type="video/mp4"> <source src="/kf51/demo/mov_bbb.ogg" type="video/ogg"> 您的浏览器不支持 video 标签。 </video> <script> var myVid = document.getElementById("video1"); function getCurTime() { alert(myVid.currentTime); } function setCurTime() { myVid.currentTime = 5; } </script> </body> </html>
The above is the detailed content of H5 sets or returns the currentTime property of the current position (in seconds) of audio/video playback. For more information, please follow other related articles on the PHP Chinese website!