Skip to content

Instantly share code, notes, and snippets.

@monkeycycle
Forked from coreyworrell/gist:1313678
Last active April 27, 2017 23:54
Show Gist options
  • Save monkeycycle/1395867 to your computer and use it in GitHub Desktop.
Save monkeycycle/1395867 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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment