Created
October 25, 2011 18:06
-
-
Save coreyworrell/1313678 to your computer and use it in GitHub Desktop.
JW Player - Stop other videos when playing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($) { | |
/** | |
* We have to get a collection of id's because the HTML5 player moves the DOM | |
* around and returns different elements when caching the selectors. | |
*/ | |
var elements = $('.video-player > div, .video-player object'), | |
playerIds = []; | |
elements.each(function(i, player) { | |
playerIds.push(player.id); | |
}); | |
$.each(playerIds, function(i, id) { | |
jwplayer(id).onPlay(function() { | |
$.each(playerIds, function(x, pid) { | |
if (id === pid) | |
return true; | |
jwplayer(pid).stop(); | |
}); | |
}); | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sorry I am pretty new to JS. Where should I put this code?
Thank you.
Tse