This question might be asked before. I have an array of videos. What I want to loop this playlist when it's end.
My code works fine and it loop through all the video one by one and play but the problem is when it plays last video after this it stop. I want to start over again from first video. I will appreciate any help.
Here is the code
var videoList = [..]
var curVideo = 0;
var videoPlayer = document.getElementById('videoPlayer');
videoPlayer.onended = function(){
curVideo++;
if(curVideo < videoList.length){
videoPlayer.src = videoList[curVideo];
} else if (curVideo == videoList.length){
console.log("list is finished");
}
}
Change your if
statement to while
and then when curVideo
reaches the end, set curVideo
back to 0. That should create an infinite loop.
You would of course need to change your else if
to an if
to check to see if it's at the end.
It works for me. I figured it out. This is the code maybe someone can benefit from it.
var videoList = [..]
var curVideo = 0;
var videoPlayer = document.getElementById('videoPlayer');
videoPlayer.onended = function(){
curVideo++;
if(curVideo < videoList.length){
videoPlayer.src = videoList[curVideo];
// return;
}
if (curVideo == videoList.length){
curVideo=0;
videoPlayer.src = videoList[curVideo];
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.