I have been absolutely everywhere (I think) and cannot find a way to trigger a stop event in the html5 audio controller. My audio controller has a playlist in which each track will play when it is selected, or cycle through each track to the next. The following button also works there.
My play / pause button is as follows:
` function playPause() {
var audioPlayer = document.getElementsByTagName('audio')[0];
if(audioPlayer!=undefined) {
if (audioPlayer.paused) {
audioPlayer.play();
} else {
audioPlayer.pause();
}
} else {
loadPlayer();
}
}
`
I need a βStopβ button that stops the sound and returns to the beginning of the currently playing track. I was thinking about using the current playback position somehow, but I can't get around this.
I also tried this (adapted by advice here in another question), to no avail:
` function stop() {
var audioPlayer = document.getElementsByTagName('audio');
addEventListener('loadedmetadata', function() {
this.currentTime = 0;
}, false);
}
`
Any ideas?
source