I am trying to add multiple videos to a playlist, but only one video is added to the playlist. I can successful create a playlist and insert a video to the playlist, but can
One solution is to add delays for every insert into a playlist. I'm not entirely sure why a delay is needed though.
I am using a custom loop too with setTimeout();
.
Example implementation using delays:
// Global array holds links and a global counter variable
var links = [
"wtLJPvx7-ys",
"K3meJyiYWFw",
"3TtVsy98ces"
]
var counter = 0;
function addVideosToPlaylist() {
myLoop(links[0]);
}
function myLoop() {
addToPlaylist(video_id);
setTimeout(function() {
counter++;
if (counter < links.length)
myLoop(links[counter]);
}, 3000);
}