Search code examples
javascriptyoutubeyoutube-apiplaylist

How to add start time to a YouTube playlist that uses listType


As seen working here: https://jsfiddle.net/spqf729t/

This is the embed player, works here

<iframe width="442" height="261" src="https://www.youtube.com/embed?listType=playlist&list=TLGG9A81gaxbq3wwODEwMjAyMw&start=200" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>

image

How do I have it work here? https://jsfiddle.net/n0rxfzag/

This is the javascript player, it's not working.

 function addPlayer(video) {
const options = {
  height: 360,
  host: "https://www.youtube-nocookie.com",
  width: 640,
  start:200
};
options.playerVars = {
  autoplay: 0,
  cc_load_policy: 0,
  controls: 1,
  disablekb: 1,
  fs: 0,
  iv_load_policy: 3,
  listType: "playlist",
  list: "TLGG9A81gaxbq3wwODEwMjAyMw",
};
options.events = {
  "onReady": onPlayerReady
};

image

I added start:200 to the javascript


Solution

  • start: 200 should add to playerVars:

        options.playerVars = {
          autoplay: 0,
          cc_load_policy: 0,
          controls: 1,
          disablekb: 1,
          fs: 0,
          iv_load_policy: 3,
          listType: "playlist",
          list: "TLGG9A81gaxbq3wwODEwMjAyMw",
          start: 200,
        };
    

    In function shufflePlaylist:

      function shufflePlaylist(player) {
        player.setShuffle(true);
        //player.playVideoAt(0);
        //player.pauseVideo();
      }
    

    Aslo you can try function seekTo