Multiple players playing simultaneously #285

Closed
ghost opened this Issue Oct 31, 2011 · 4 comments

Projects

None yet

3 participants

@ghost
ghost commented Oct 31, 2011

Hi,
thanks for the great plugin. However, I have a small problem.
I have several video elements on the same page. If I click play on one video and then click play on another and so on, all videos are playing simultaneously. How can I automatically pause current player if another one is clicked?

Thanks!

@mtomasz
mtomasz commented Nov 10, 2011

I have same problem and looking for solution too. Any ideas?

@johndyer
Owner

This might be a nice feature to implement. Anyone want to take it on?

@ecurtis
ecurtis commented Nov 21, 2011

I found the basis for this on stackoverflow and hacked it until it worked:

/ make an array for the mediaelement players
mediaElementPlayers = new Array();

jQuery('audio,video').mediaelementplayer(
{
    audioWidth: 25,
    audioHeight: 25,
    startVolume: 0.8,
    features: ['playpause'],
    success: function (mediaElement, domObject) {

          // add this mediaelement to the mediaElementPlayers array
          mediaElementPlayers.push(mediaElement);

          // bind the play event to the pauseAllPlayers function
          mediaElement.addEventListener('play', function(e) {
              pauseAllPlayers(e.target); }, false); }
});



// iterate through the mediaElementPlayers array, pause all players except the one that triggered the event.
function pauseAllPlayers(currentPlayer){
for(i=0; i<mediaElementPlayers.length; i++){
    if(mediaElementPlayers[i] != currentPlayer){
        mediaElementPlayers[i].pause();
    }
}
}
@johndyer
Owner
johndyer commented Dec 6, 2011

This will be in 2.4.2

@johndyer johndyer closed this Dec 6, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment