Javascript DOM onloadedmetadata Event on <audio>

Introduction

Execute a JavaScript when meta data for an audio is loaded:

View in separate window

<!DOCTYPE html>
<html>
<body>

<audio controls onloadedmetadata="myFunction()">
  <source src="sound.ogg" type="audio/ogg">
  <source src="sound.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>//  w w  w.  j  ava2  s  . c  om

<p id="demo"></p>



<script>
function myFunction() {
  document.getElementById("demo").innerHTML = "Meta data for audio loaded";
}
</script>

</body>
</html>



PreviousNext

Related