Answer the question
In order to leave comments, you need to log in
How to make a looped playlist of videos from YouTube and Vimeo using js?
Interested in the question of how it is possible to technically implement a looped playlist of videos from YouTube and Vimeo. Specifically, how can the following scheme be implemented: The page has loaded, the playback of video clips has begun. 2 when one video ends, the next video starts and so on in a circle. How to implement this? Perhaps there are some libraries?
Answer the question
In order to leave comments, you need to log in
For example, we create an array of video IDs, create api download functions and the following video:
var playlist=["0Bmhjf0rKe8","jQZtk-fCWQ4","5wosC9QLQTM"];
var whonext=0;
var player;
function onYouTubePlayerAPIReady() {
player = new YT.Player('player', {
height: '390',
width: '640',
videoId: playlist[0],
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
whonext++;
}
function playNext(){
if(whonext>playlist.length-1){whonext=0}
player.loadVideoById({'videoId': playlist[whonext]});
whonext++;
}
function onPlayerReady(event) {
event.target.playVideo();
}
function onPlayerStateChange(event) {
if(event.data === 0) {
playNext();
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question