Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MediaElement.js stop all players

I've been playing around with MediaElement.js for a while now and have a new application that uses 20 players on a single page. I'd like to be able to have the songs stop when another one is played - and not to overlap the tracks when they are playing. I can't seem to find an easy way to hack this - perhaps someone knows of a way?

Thanks.

like image 763
David Avatar asked Dec 07 '22 23:12

David


2 Answers

In jQuery, you could do

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

Let me know if that works.

like image 127
John Dyer Avatar answered Dec 09 '22 12:12

John Dyer


A quick and dirty one ;)

$(".mejs-play").live('click',function(){
  $(".mejs-pause").trigger('click');                              
});
like image 36
Olivier Avatar answered Dec 09 '22 11:12

Olivier