Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML Audio/Video DOM timeupdate Event

HTML Audio/Video DOM timeupdate Event

HTML audio/video Tag Reference HTML Audio/Video DOM Reference

Example

When the video's playback position has changed, display the current playback position (in seconds):

// Get the element with id="myVideo"

var vid = document.getElementById("myVideo");

// Add a ratechange event to the

vid.ontimeupdate = function() {myFunction()};

function myFunction() {

// Display the element with id="demo"

the playback position of the video in the element

    document.getElementById("demo").innerHTML = vid.currentTime;

}

Try it »

The bottom of this article contains more examples.


Definition and Usage

The timeupdate event is triggered when the playback position of the audio/video changes.

This event can be triggered in the following situations:

Tip: The timeupdate event is usually used together with the Audio/Video object's currentTime property, which returns the playback position of the audio/video (in seconds).


Browser support

The numbers in the table indicate the version number of the first browser to support the event.

Events
timeupdate Yes 9.0 Yes Yes Yes

Syntax

In HTML:

<

audio|video

ontimeupdate="

myScript

">

Try it

In JavaScript:

audio|video

.ontimeupdate=function(){

myScript

};

Try it

In JavaScript, use the addEventListener() method:

audio|video

.addEventListener("timeupdate",

myScript

);

Try it

Note: Internet Explorer 8 and earlier IE versions do not support addEventListener() method.


Technical Details

Supported HTML tags:
Supported JavaScript objects: Audio, Video

More examples

Example

When the audio's playback position changes, display the current playback position of the audio (in seconds):

// Get the element with id="myVideo"

var aud = document.getElementById("myVideo");

// Add a seeked event to the

aud.ontimeupdate = function() {myFunction()};

function myFunction() {

// Display the element with id="demo"

the playback position of the audio in the element

    document.getElementById("demo").innerHTML = aud.currentTime;

}

Try it »

Example

Use the currentTime property to set the playback position to 5 seconds:

document.getElementById("myVideo").currentTime = 5;

Try it »


HTML audio/video Tag Reference HTML Audio/Video DOM Reference