Can not insert multiple videos into a playlist - YouTube API v3

前端 未结 3 1896
小鲜肉
小鲜肉 2021-01-13 13:55

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

3条回答
  •  无人及你
    2021-01-13 14:41

    In addition to Rohan's answer, the function call at the bottom should be:

    function myLoop(video_id) {
        addToPlaylist(video_id);
        setTimeout(function() {
            counter++;
            if(counter < links.length)
                myLoop(links[counter]);
        }, 3000);
    }
    

    It lacked "video_id" as a parameter.

    It worked good for me.

    The whole, working code is:

    // 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(video_id) {
        addToPlaylist(video_id);
        setTimeout(function() {
            counter++;
            if(counter < links.length)
                myLoop(links[counter]);
        }, 3000);
    }
    

提交回复
热议问题