YouTube API - 在设置的开始和结束时间之间循环播放视频

问题描述 投票:4回答:2

我设法启动视频并在我需要的时候结束视频,但有没有办法循环这个?循环选项似乎没有做太多。

小提琴:https://jsfiddle.net/u7nkz292/

码:

<div id="ytplayer"></div>



<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: '360',
      width: '640',
      videoId: 'M7lc1UVf-VE', 
          playerVars: {
      autoplay: 1,        // Auto-play the video on load
      controls: 0,        // Show pause/play buttons in player
      showinfo: 0,        // Hide the video title
      modestbranding: 1,  // Hide the Youtube Logo
      fs: 1,              // Hide the full screen button
      cc_load_policy: 0, // Hide closed captions
      iv_load_policy: 3,  // Hide the Video Annotations
      start: 36,
      end: 45,
      loop: 1,            // Run the video in a loop
      autohide: 0         // Hide video controls when playing
    },
    });
  }
</script>
javascript youtube youtube-api youtube-javascript-api
2个回答
3
投票

迭代Bertrand Martel上面的伟大的answer

如果你循环播放同一个视频,我发现你可以通过调用player.seekTo(startSeconds)instead of player.loadVideoById(...)来最小化循环之间的延迟。 Here是比较两种方法的表现的小提琴。

© www.soinside.com 2019 - 2024. All rights reserved.