Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I stop all currently playing MediaElement players?

I'm wondering how to stop all the MediaElement players currently in the DOM. I've tried this:

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

Let me know if that works.

A quick and dirty one, but neither work.

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

Tried to do my homework on this one but can't seem to find a response anymore.

like image 343
David Avatar asked Feb 25 '11 00:02

David


2 Answers

Try this...

$('video, audio').each(function() {
      $(this)[0].pause();
});
like image 91
alex Avatar answered Sep 25 '22 02:09

alex


Here's a simple way to do a "stop all".

When first creating your MediaElement players, create them each explicity (as opposed to using $('video,audio').mediaelementplayer()):

var mediaElementPlayers = [];
$('video,audio').each(function(){
    mediaElementPlayers.push(new MediaElementPlayer(this));
});

And then, when you want to stop them:

for (var i=0; i<mediaElementPlayers.length; i++){
    mediaElementPlayers[i].pause(); // pause
    if (mediaElementPlayers[i].getCurrentTime()){
        mediaElementPlayers[i].setCurrentTime(0); // rewind
    }
}
like image 42
Bart Avatar answered Sep 22 '22 02:09

Bart