1
votes

I want to know how to add selected YouTube videos to a temporary playlist / playing queue?
I have an option where user have to select what all videos to be included in the playing queue.

Click on the ADD icon (black background box) and that selected video will be displayed in the purple background and it also has to be included in the playlist/Queue.

I am able to add the videos in the purple box but unable to add them in the queue.

I tried using this code

player.cuePlaylist({
    list:  ["83uA6kS_6LE", "RVYU9Be2RtA", "DkQRcjKTqiU", "5NUZtQRgLSQ"]  //array of videos ID
});

After that when currently playing video ends I tried to play next video using

function onPlayerStateChange(event) {
if(event.data==0){     //when video ends event.data becomes 0 
      player.nextVideo();
}

But it neither do anything nor shows any error in the console. I even tried replacing player.nextVideo(); with player.playVideo(); then instead of starting next video it re-plays the current one.

I tried looking for it in the YouTube documentation but couldn't find anything https://developers.google.com/youtube/js_api_reference#Queueing_Functions

EDIT 1
TRIED with
cueVideoById(); loadVideoById(); But not working.
I would really appreciate if you guys can provide me an answer or a way to reach the correct audience for this question.

1
Can you provide the error logs?abielita
@abielita its not showing any error in the consoleAyush Katoch

1 Answers

0
votes

I think the issue is that you have a typo in your call to cuePlaylist. The argument is "playlist" and not "list". Try this:

player.cuePlaylist({
    playlist:  ["83uA6kS_6LE", "RVYU9Be2RtA", "DkQRcjKTqiU", "5NUZtQRgLSQ"]
});