![]() |
The HTML ondurationchange Attribute is an event attribute that occurs when the audio/video duration is changed. The duration of the audio/video is changed from “NaN” to the actual duration of the audio/video when it loads.
|
<!DOCTYPE html>
<html>
<body>
<script>
function myFunction() { alert("The audio duration has changed");
}
</script>
<video controls ondurationchange="myFunction()"> <source src="https://download.samplelib.com/mp3/sample-3s.mp3" type="video/mp4"> <source src="https://download.samplelib.com/mp3/sample-3s.mp3" type="video/ogg"> Your browser does not support HTML5 video.
</video>
<p>Video courtesy of <a href="https://www.bigbuckbunny.org/" target="_blank">Big Buck Bunny</a>.</p>
</body>
</html>
The durationchange event occurs when the duration data of the specified audio/video is changed.
Note: When an audio/video is loaded, the duration will change from "NaN" to the actual duration of the audio/video.
During the loading process of an audio/video, the following events occur, in this order:
The numbers in the table specify the first browser version that fully supports the event.
< element ondurationchange=" script ">
Value | Description |
---|---|
script | The script to be run on duration change |
Supported HTML tags: | <audio> and <video> |
---|---|
Supported JavaScript objects: | Audio, Video |
The audio duration has changed in this code.
<!DOCTYPE html>
<html>
<body>
<script>
function myFunction() { alert("The audio duration has changed");
}
</script>
<video controls ondurationchange="myFunction()"> <source src="https://download.samplelib.com/mp3/sample-3s.mp3" type="video/mp4"> <source src="https://download.samplelib.com/mp3/sample-3s.mp3" type="video/ogg"> Your browser does not support HTML5 video.
</video>
<p>Video courtesy of <a href="https://www.bigbuckbunny.org/" target="_blank">Big Buck Bunny</a>.</p>
</body>
</html>
The audio duration has changed.
<!DOCTYPE html>
<html>
<body>
<script>
function myFunction() { alert("The audio duration has changed");
}
</script>
<audio controls ondurationchange="myFunction()"> <source src="https://download.samplelib.com/mp3/sample-3s.mp3" type="audio/ogg"> <source src="https://download.samplelib.com/mp3/sample-3s.mp3" type="audio/mpeg"> Your browser does not support the audio element.
</audio>
</body>
</html>
html event attributes |
Type
: |
Develop |
Category
: |
Web Tutorial |
Sub Category
: |
HTML Media Events Attribute |
Uploaded by
: |
Admin |
Read Article https://horje.com/learn/1434/reference