Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

commented Nov 8, 2013

Thanks man. Its saved my day.

@tsegaa

This comment has been minimized.

Copy link

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
You can’t perform that action at this time.