1

I have a checkbox that plays audio when it's checked and stops playing audio when unchecked. But the audio stops at a point if you keep it checked because of the length of the audio. When the audio ends I want to set the checkbox to unchecked. How do I check if the audio has stopped in javascript.

Sorry if I used the word check too many times.

Chris Rohit Brendan
  • 893
  • 1
  • 9
  • 20
  • Possible duplicate of - http://stackoverflow.com/questions/9437228/html5-check-if-audio-is-playing – Wez Feb 25 '13 at 13:03

1 Answers1

2

Add a event like this:

var audio = document.getElementById("#audio");

audio.addEventListener("ended", function() { 

   var checkbox = document.getElementById("#checkbox1");
   checkbox.checked = false;

}, true);

Also you can check if the browser supports onended event using:

audio.hasOwnProperty('ended')

letiagoalves
  • 11,224
  • 4
  • 40
  • 66