Skip to content

Instantly share code, notes, and snippets.

@coreyworrell
Created October 25, 2011 18:06
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save coreyworrell/1313678 to your computer and use it in GitHub Desktop.
Save coreyworrell/1313678 to your computer and use it in GitHub Desktop.
JW Player - Stop other videos when playing
(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);
@crazyrohila
Copy link

Thanks man. Its saved my day.

@tsegaa
Copy link

tsegaa commented Aug 30, 2017

Sorry I am pretty new to JS. Where should I put this code?

Thank you.
Tse

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment