English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML Reference Manual

HTML Tag Directory

HTML Audio/Video DOM durationchange event

The durationchange event is triggered when the duration attribute is updated.

 HTML Audio/Video DOM Reference Manual

Online Example

Tip: The video duration has changed:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>HTML Audio/Using the video durationchange event-Basic Tutorial(oldtoolbag.com)</<title>
</<head>
<body>
<video id="video1" controls="controls">
  <source src="movie.mp4" type="video/mp4">
  <source src="movie.ogg" type="video/ogg">
  Your browser does not support HTML5 video tag.
</video>
<script>
myVid=document.getElementById("video1");
myVid.ondurationchange=alert("The video duration has changed");
</script> 
</body>
</html>
Test and see ‹/›

Definition and usage

When changing the specified audio/The durationchange event occurs when the video duration data is loaded.
Note: When loading audio/After the video, the duration will change from 'NaN' to audio/Actual duration of the video.

When the audio/The following events will occur in sequence when the video is in the process of loading:

Browser compatibility

IEFirefoxOperaChromeSafari

All mainstream 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;

Use addEventListener():

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

Technical Details

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

More Examples

Use the ondurationchange attribute on HTML elements

Use addEventListener() to listen to the durationchange event

 HTML Audio/Video DOM Reference Manual