HTML Audio/Video DOMdurationchangeEvents

HTML Audio/Video DOM Reference Manual

Example

The duration of the prompt video has changed:

myVid=document.getElementById("video1");
myVid.ondurationchange=alert("The video duration has changed");

Try it Yourself »

Definition and Usage

When the duration data of the specified audio/video changes, the durationchange event occurs.

After the audio/video is loaded, the duration will change from "NaN" to the actual duration of the audio/video.

During the loading process of the audio/video, the following events will occur in sequence:

  1. loadstart
  2. durationchange
  3. loadedmetadata
  4. loadeddata
  5. progress
  6. canplay
  7. canplaythrough

Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the durationchange event.

Note:Internet Explorer 8 and earlier versions do not support this event.


Syntax

In HTML:

<audio|video ondurationchange="SomeJavaScriptCode">

In JavaScript:

audio|video.ondurationchange=SomeJavaScriptCode;

Using addEventListener():

audio|video.addEventListener("durationchange", function()
  {
  //SomeJavaScriptCode
  }
);

Technical Details

The following HTML tags are supported: <audio>, <video>
The following JavaScript objects are supported: Audio, Video


实例

More Examples

Using the ondurationchange attribute on HTML elements

Use addEventListener() to listen for the durationchange event


HTML Audio/Video DOM Reference Manualother extensions