Skip to content

Instantly share code, notes, and snippets.

@danemacaulay
Last active August 29, 2015 13:57
Show Gist options
  • Save danemacaulay/9844272 to your computer and use it in GitHub Desktop.
Save danemacaulay/9844272 to your computer and use it in GitHub Desktop.
video.js Event Controller
(function ($) {
$(document).ready(function() {
bindVideoListeners();
});
function bindVideoListeners(){
$('video').each(function() {
var id = $(this).attr('id');
videojs(id).on('play', function(){
stopOtherPlayers(id);
});
videojs(id).on('ended', function(){
this.currentTime(0);
this.posterImage.show();
});
});
}
function stopOtherPlayers(playerID){
var $otherVideos = $('video').not('#' + playerID + ' video');
$otherVideos.each(function() {
videojs($(this).attr('id')).pause();
});
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment