Skip to content Skip to sidebar Skip to footer

How Do You Detect When Html5 Audio Has Finished Playing (more Than Once)?

I am having a problem detecting when an tag is finished playing an mp3. When I do something like this: myAudio.addEventListener('ended', function() { alert('e

Solution 1:

The ended event is created based on .currentTime attribute. http://w3c.github.io/html/semantics-embedded-content.html#eventdef-media-ended

So, all you have to do is set the .currentTime to zero again.

myAudio.addEventListener("ended", function(){
     myAudio.currentTime = 0;
     console.log("ended");
});

Post a Comment for "How Do You Detect When Html5 Audio Has Finished Playing (more Than Once)?"