mediaelement/mediaelement

Multiple players playing simultaneously

Opened this issue · 5 comments

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!

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

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

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();
    }
}
}

This will be in 2.4.2

Hi, I want to be able to play all players at the same time. I want to create an app where you can select which hls stream I want to display on the screen.
How can I play multiple HLS streams on the same page?

Rgds,
F