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

multiple players


I have a single page which has to have multiple players

The first player is static content so it can use bespoke "workarround" code if needed

the other players are generated by a content management system and so they all have to use the same code without work arrounds for each one

the html for the video areas of the page will look something like this

<div id="main_video"></div>

<div class="other_video" id="vid_1"></div>
<div class="other_video" id="vid_2"></div>
<div class="other_video" id="vid_3"></div>
<div class="other_video" id="vid_4"></div>

the "other_video" s will all have the exact same settings the only difference being the content being played

My plan was to have a single jwplayer('.other_video').setting() declaration to setup all the players
and the target the IDs of each video to change the content.

However i cant make this work
when i try to use a classname with jwplayer() it does not work

how can i make this work

3 Community Answers

Todd

JW Player Support Agent  
0 rated :

If the only thing different in each player is the video URL, you do not have to have a separate class. And you have to have one setup() call for each div, as there is no way to combine all of them into one.

<div id="main_video"></div>

<div class="other_video" id="vid_1"></div>
<div class="other_video" id="vid_2"></div>
<div class="other_video" id="vid_3"></div>
<div class="other_video" id="vid_4"></div>

<script>
jwplayer('main_video').setup({
  file: 'main_video.mp4'
});

jwplayer('vid_1').setup({
  file: 'vid_1.mp4'
});

jwplayer('vid_2').setup({
  file: 'vid_2.mp4'
});

//other jwplayer().setup() calls here...
</script>

samcoppock

User  
0 rated :

ok
since all of the need to have seperate IDs is there any wya to call functions such as pause mute ect on all of the players?

Todd

JW Player Support Agent  
0 rated :

Check out the code example I wrote for a different forum thread: https://support.jwplayer.com/customer/portal/questions/16245906-stop-rest-players-and-play-the-current-one-when-multiple-players

<div id="player1"></div><br><br>
<div id="player2"></div><br><br>
<div id="player3"></div><br><br>
<div id="player4"></div><br><br>
<script>	
jwplayer('player1').setup({
	file: 'bunny.mp4',
	image: 'bunny.jpg'
});
jwplayer('player2').setup({
	file: 'tears.mp4',
	image: 'tears.jpg'
});
jwplayer('player3').setup({
	file: 'sintel.mp4',
	image: 'sintel.jpg'
});
jwplayer('player4').setup({
	file: 'tears.mp4',
	image: 'tears.jpg'
});

jwplayer('player1').on('play',function(){
	playOnlyOne('player1');
});
jwplayer('player2').on('play',function(){
	playOnlyOne('player2');
});
jwplayer('player3').on('play',function(){
	playOnlyOne('player3');
});
jwplayer('player4').on('play',function(){
	playOnlyOne('player4');
});

function playOnlyOne(playThis) {
	for (i=0; i<document.getElementsByClassName('jwplayer').length;i++) { 
		if (document.getElementsByClassName('jwplayer')[i].id != playThis) {
			jwplayer(document.getElementsByClassName('jwplayer')[i]).play(false);		
		}
	}
}
</script>

This question has received the maximum number of answers.