user2260237
user2260237

Reputation:

html5 play only one file at a time and stop others? with jquery?

I have multiple audio files and i want to make it pause/stop all others if one plays.

This is how it looks like and i have jquery if that ease the solution:

<audio controls="">
<source type="audio/ogg" src="asdf.ogg"></source>
<source type="audio/mpeg" src="asdf.mp3"></source>
</audio>

<audio controls="">
<source type="audio/ogg" src="asdf.ogg"></source>
<source type="audio/mpeg" src="asdf.mp3"></source>
</audio>

<audio controls="">
<source type="audio/ogg" src="asdf.ogg"></source>
<source type="audio/mpeg" src="asdf.mp3"></source>
</audio>

Upvotes: 0

Views: 1706

Answers (1)

reyaner
reyaner

Reputation: 2819

Hi in jQuery like this:

$("audio").on("play", function(){
    var _this = $(this);
    $("audio").each(function(i,el){
        if(!$(el).is(_this))
            $(el).get(0).pause();
    });
});

now you could try it your self in JS, and post it, to show that you tried something yourself!

Upvotes: 2

Related Questions