Good on a page with
You just have to pass the id
of audio
that you want to pause and ready friend
var audio = document.getElementById("myAudio");
function playAudio() {
audio.play();
}
function pauseAudio() {
audio.pause();
}
There is an event that allows you to detect when a video / audio is playing. For simplicity I give you an example with jQuery how to stop the rest of the videos:
$('audio').on('play', function () { //cuando un audio empieza a reproducirse
var current=this;
$('audio').each(function() {
if (this!== current) { //todos los demás
this.pause(); //los pausamos
}
});
});
Making the audio do not stop when loading another page is impossible, since it is part of the page you are leaving. The most you can do is detect when the user leaves the page, save the playback time (attribute currentTime
) in the localStorage and try to play from that moment on the new page, which must load the same resource. But anyway there will be a pause between both events.