Skip to content

Instantly share code, notes, and snippets.

@dmlap
Created December 3, 2014 19:19
Show Gist options
  • Save dmlap/58cbfcecec7c435b4655 to your computer and use it in GitHub Desktop.
Save dmlap/58cbfcecec7c435b4655 to your computer and use it in GitHub Desktop.
Loading videos in a sequence.
var videoIds = [1, 2, 3, 4];
// get the first video
player.catalog.getVideo(videoIds[0], function(error, video) {
if (error) {
return alert(error);
}
videoIds.shift();
// load it into the player so it's ready when the user hits "play"
player.catalog.load(video);
// wait until the video ends and then load up the next video
player.on('ended', function() {
// figure out what the next video ID is
var nextVideoId = videoIds.shift();
// do nothing if all the videos are over
if (!nextVideoId) {
return;
}
// fetch the next video from the catalog
player.catalog.getVideo(nextVideoId, function(error, video) {
if (error) {
return alert(error);
}
// load it into the player and start playback
player.catalog.load(video);
player.play();
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment