I need to call a function when an HTML5 audio element stops playing. Specifically the function will reset the seek bar and change the pause icon to a play icon.
Here's my JavaScript:
var audio = document.getElementById('audio');
audio.addEventListener('ended', stopAudio);
function stopAudio() {
audio.stop();
$('.play-pause .play').show();
$('.play-pause .pause').hide();
}
.. only the code inside is not executing once called. The audio is playing successfully and ending successfully, it's just not calling my function. What am I missing?
<audio>
element actually haveid="audio"
? Otherwise it looks fine --ended
is the correct event name. whatwg.org/specs/web-apps/current-work/#htmlaudioelement look for "Event handler" - leftclickben