Javascript DOM onplaying Event on <audio> element

Introduction

Execute a JavaScript when an audio is ready to start after having been paused:

This example demonstrates how to assign an "onplaying" event to an audio element.

View in separate window

<!DOCTYPE html>
<html>
<body>
<p>Play, pause and then play the audio again.</p>

<audio controls onplaying="myFunction()">
  <source src="sound.ogg" type="audio/ogg">
  <source src="sound.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>//from w w w .j  a  v a2  s.co  m

<p id="demo"></p>
<script>
function myFunction() {
  document.getElementById("demo").innerHTML = "The audio is now playing";
}
</script>

</body>
</html>



PreviousNext

Related