![]() |
Definition and UsageThe 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:
Applies toThe ondurationchange attribute is part of the Event Attributes, and can be used on the following elements:
Browser SupportThe |
Example:
HTML
<audio id="myAudio" controls ondurationchange="myFunction(this)">
<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>
<script>
function myFunction(x) {
alert("The duration of this audioclip is : " + x.duration + " seconds");
}
</script>
Example:
HTML
<video id="myVideo" width="320" height="176" controls ondurationchange="myFunction(this)">
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_5mb.mp4" type="video/mp4">
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_5mb.mp4" type="video/ogg">
Your browser does not support HTML5 video.
</video>
<script>
function myFunction(x) {
alert("The duration of this video is : " + x.duration + " seconds");
}
</script>
html ondurationchange |
How to Run "myFunction" when the audio is ready to start playing - HTML ondurationchange Attribute | HTML Attribute |
How to Run "myFunction" when the video is ready to start playing - | HTML Attribute |
Read Full: | HTML Attribute |
Type: | Develop |
Category: | Web Tutorial |
Sub Category: | HTML Attribute |
Uploaded by: | Admin |
Views: | 101 |
Reffered: https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_att_ondurationchange