Set time position to 5 seconds:
document.getElementById("myVideo").currentTime = 5;
<!DOCTYPE html> <html> <body> <p id="demo"></p> <video id="myVideo" width="100" height="100" controls> <source src="video.mp4" type="video/mp4"> <source src="video.ogg" type="video/ogg"> Your browser does not support the video tag. </video><br> <button onclick="getCurTime()" type="button">Get current time position</button> <button onclick="setCurTime()" type="button">Set time position to 5 seconds</button> <script> var x = document.getElementById("myVideo"); function getCurTime() {// w w w. j av a2 s. c o m document.getElementById("demo").innerHTML = x.currentTime; } function setCurTime() { x.currentTime = 5; } </script> </body> </html>
The currentTime
property sets or gets the current position in seconds of the video playback.
When setting this property, the playback will jump to the specified position.
Property Values
Value | Description |
---|---|
seconds | Specifies the position for the playback of the video, in seconds |
The currentTime
property returns a Number representing the current playback time in seconds.