Thursday, 15 April 2021

youtube player api for list does always play initial video

I want to switch playlist with https://jsfiddle.net/g1xfh7rd/ but it does always reload the same initial playlist. I tried all solutions suggested YouTube Player API list with videos and it didn't work

    <div id="ytplayer"></div>
    <div onClick="loadPlaylist()">load another</div>


    <script async src="https://www.youtube.com/iframe_api"></script>


    <script>
    // 1. ytplayer code: https://developers.google.com/youtube/player_parameters#IFrame_Player_API

    var tag = document.createElement('script');
    tag.src = "https://www.youtube.com/player_api";
    var firstScriptTag = document.getElementsByTagName('script')[0];
    firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
    var player;


    function onYouTubePlayerAPIReady() 
    {
            player = new YT.Player('ytplayer', 
            {
              height: '390',
              width: '640',
              playerVars: 
              {
                listType:'playlist',
                list: 'RDEMe12_MlgO8mGFdeeftZ2nOQ'
              }
            });
    }


    function loadPlaylist() {
      player.loadPlaylist('PLuvQYuQ7n4rAtqY1dDvhts08zBoisI8xA');
    }



     </script>
     


from youtube player api for list does always play initial video

No comments:

Post a Comment