MediaElement.js stops all players

I have been playing with MediaElement.js for a long time and have a new application that uses 20 players on one page. I would like the songs to stop when the other played, and so that they do not overlap the tracks during the game. I can't find an easy way to hack this - maybe someone knows about the way?

Thank.

+4
source share
4 answers

In jQuery you can do

$('video,audio').each(function() {
      $(this)[0].pause();
});

Let me know if this works.

+6
source

Quick and dirty;)

$(".mejs-play").live('click',function(){
  $(".mejs-pause").trigger('click');                              
});
+3
source

MediaElement.js "mejs", "", , . mep_0, mep_1 ..

/lodash, -

_.each(mejs.players, function(player) {
    player.media.stop();
});

js, ""

for (var player in mejs.players) {
    mejs.players[player].media.stop();
}
+3
source

The easiest one I found with jQuery:

$('video,audio').trigger('pause');

One liner to win! It also avoids JS errorssince it does not directly target elements, thanks to jQuery.

+3
source

Source: https://habr.com/ru/post/1790200/


All Articles