HTML ondurationchange Event Attribute

Description

The event attribute ondurationchange occurs when the length of a media file changes (that is, when the duration attribute changes).

When a media file is loaded, its duration changes from the Nan value to the actual duration.

Video upload triggers the following events:

Syntax

<element ondurationchange="script">

Values

  • scriptThe name of the script to use when the event has been triggered.

Example

<!DOCTYPE HTML>
<html>
<head>
</head>
<body>

<audio id="myAudio" controls ondurationchange="myFunction(this)">  
  <source src="audio.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>

<script>
function myFunction(x) {
    alert("Duration of this audio file: " + x.duration + " seconds");
}
</script> 

<p>This example shows how to use the ondurationchange event in an AUDIO element.</p>
<p><strong>Note:</strong>When the audio is downloaded, the “ondurationchange” event will occur, it changes from “NaN” to the actual file duration.</p>

</body>
</html>

Supported Tags

<audio> and <video>

Browser Support

Desktop
Explorer Edge Chrome Firefox Opera Safari
XXYes3.5XX
Tablets / Mobile
Android Chrome Firefox Opera Safari Samsung
YesYes4XXX