Youtube player api with loop

后端 未结 7 1024
伪装坚强ぢ
伪装坚强ぢ 2020-12-31 02:24

I am struggling with setting up the loop for youtube videos using youtube player api.

The problem is that the video is not running under a loop.

Here is my c

相关标签:
7条回答
  • 2020-12-31 03:19

    This is what I have used for the API IFrame video loop. I noticed that you must include "playlist:VIDEO_ID" parameter. and it works. This is my example

    <script>
      // Load the IFrame Player API code asynchronously.
      var tag = document.createElement('script');
      tag.src = "https://www.youtube.com/player_api";
      var firstScriptTag = document.getElementsByTagName('script')[0];
      firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
    
      // Replace the 'ytplayer' element with an <iframe> and
      // YouTube player after the API code downloads.
      var player;
    
      function onYouTubePlayerAPIReady() {
        player = new YT.Player('ytplayer', {
          height: '390',
          width: '640',
          videoId: 'VIDEO_ID',
          playerVars: {
            playlist: 'VIDEO_ID',
            loop: 1
          }
        });
      }
    </script>

    0 讨论(0)
提交回复
热议问题