Execute a JavaScript when the current playback position has changed:
In this example, we assign an "ontimeupdate" event to a video element.
When the user starts to play the video, or skips to a new position in the video, a function is triggered.
It will display the current position in seconds of the video playback.
<!DOCTYPE html> <html> <body> <video controls ontimeupdate="myFunction(this)"> <source src="video.mp4" type="video/mp4"> <source src="video.ogg" type="video/ogg"> Your browser does not support HTML5 video. </video>/*from w w w .j a v a 2s . c o m*/ <p>Playback position: <span id="demo"></span></p> <script> function myFunction(event) { // The currentTime property returns the current position of the audio/video playback document.getElementById("demo").innerHTML = event.currentTime; } </script> </body> </html>
The ontimeupdate event occurs when the playing position of an audio/video has changed.
Bubbles: | No |
---|---|
Cancelable: | No |
Event type: | Event |
Supported HTML tags: | <audio> and <video> |