Skip to content

Instantly share code, notes, and snippets.

@alexmahan
Last active January 4, 2016 18:49
Show Gist options
  • Save alexmahan/8663168 to your computer and use it in GitHub Desktop.
Save alexmahan/8663168 to your computer and use it in GitHub Desktop.
Loops through a bunch of videos (however many you want) and plays them infinitely. You can set the first one to "autoplay" in the markup if you wish. This uses jQuery but could be (should be) vanilla JavaScript easily enough. Doesn't work in IE8 or under (duh) because it uses addEventListener and uses the <video> element with no flash fallback.
vidLooper = function() {
var allVids = $('.vid');
$.each(allVids, function(index, value) {
if (index < allVids.length-1) {
value.addEventListener('ended', function() {
var nextVid = allVids.eq(index+1);
nextVid[0].play();
});
} else if (index === allVids.length-1) {
value.addEventListener('ended', function() {
var firstVid = allVids[0];
firstVid.play();
});
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment