Name is required.
Email address is required.
Invalid email address
Answer is required.
Exceeding max length of 5KB

Stop any other player on page from playing when playing a video


I know of the events: onPlay - feature to stop other players on the page from playing, but is there a way to do it without knowing the ids of those other players or how many other players there are? So it stops any other player except (this) player? I feel like there must be a way without listing out all the other players and telling each of them to stop. Thanks in advance!

4 Community Answers

jherrieven

Best Answer 

Something like this:

function pauseAllOthers(currentId){
var jwcount = 0;
while(jwplayer(jwcount) && jwplayer(jwcount).container && jwplayer(jwcount).getState()){
var jwp = jwplayer(jwcount);
if(jwp && jwp.id != currentId){
jwp.pause(true);
}
jwcount++;
}
}

James Herrieven

View in conversation

jherrieven

Best Answer  User  
0 rated :

Something like this:

function pauseAllOthers(currentId){
var jwcount = 0;
while(jwplayer(jwcount) && jwplayer(jwcount).container && jwplayer(jwcount).getState()){
var jwp = jwplayer(jwcount);
if(jwp && jwp.id != currentId){
jwp.pause(true);
}
jwcount++;
}
}

James Herrieven

klainez

User  
0 rated :

Would you run the function on the onplay event within a current player setup embed? so

<script>
jwplayer("player1").setup({
file: 'xyz.mp4',
autostart: false,
width: '100%',
aspectratio: '16:9',
stretching: 'exactfit',
events:{
onPlay: pauseAllOthers(player1);
}
});


</script>

or somewhere else?

jherrieven

User  
1 rated :

Yeah, more or less. The JW6 event syntax would be as follows:

<script>
jwplayer("player1").setup({
file: 'xyz.mp4',
autostart: false,
width: '100%',
aspectratio: '16:9',
stretching: 'exactfit'
});
jwplayer("player1").onBeforePlay(function(){
pauseAllOthers("player1");
});

// Pause All Others
function pauseAllOthers(currentId){
...
}
</script>

I'd actually pause all the other players *before* the current one begins playing.

James

klainez

User  
0 rated :

I see - thanks!!

This question has received the maximum number of answers.