Horje

How to Run "myFunction" when the audio is ready to start playing - HTML ondurationchange Attribute

Audio Example. This example demonstrates how to use the "ondurationchange" attribute on an AUDIO element. Note: When the audio is loaded, the "ondurationchange" event will occur, it changes from "NaN" to the actual duration of the audioclip.
index.html
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>




Type:
html
Category:
Web Tutorial
Sub Category:
HTML Attribute
Uploaded by:
Admin