impregnable fiend impregnable fiend - 5 months ago 14
Javascript Question

How to catch 'stop' event in HTML5 audio and then do something?

I'am beginner in HTML5 and not even middle in JS, but I'am trying to figure out how to correctly use

and smth else... so i've got this question... my html:

<i class='some_icon' onclick='play();'>
<audio src='some_mp3.mp3' id='player'></audio>

Now when I click on the icon I want some mp3 file play and it works because I wrote this js:

function play() {
var my = document.getElementById('player');
if (my.paused) {;
} else {
my.currentTime = 0

BUT, besides, I want to change my icon WHEN that mp3 file ENDS... how can I do that? Any help will be greatly appreciated :)


Here is the code to trigger some code when your audio ( or video ) ends:

var my = document.getElementById('player');

my.addEventListener("ended", function(e){
  // here goes your code to change the icon
}, false);