Execute a JavaScript when an audio has started to play: - Javascript DOM Event

Javascript examples for DOM Event:onplay

Description

Execute a JavaScript when an audio has started to play:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<audio controls onplay="myFunction()">
  <source src="your.ogg" type="audio/ogg">
  <source src="your.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>/*from   w w w .ja  v a 2  s . c o  m*/

<script>
function myFunction() {
    console.log("The audio started to play");
}
</script>

</body>
</html>

Related Tutorials