Created
December 3, 2014 19:19
-
-
Save dmlap/58cbfcecec7c435b4655 to your computer and use it in GitHub Desktop.
Loading videos in a sequence.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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