Find out if the audio has ended:
var x = document.getElementById("myAudio").ended;
Click the button to find out if the audio has ended.
<!DOCTYPE html> <html> <body> <audio id="myAudio" controls> <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 a v a 2 s.com <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { var x = document.getElementById("myAudio").ended; document.getElementById("demo").innerHTML = x; } </script> </body> </html>
The ended
property returns whether the audio has ended playing.
This property is read-only.
It returns a boolean.
It returns true if the playback has ended, otherwise it returns false.