Confusion with iframe api



heyo伙计们!

我是JavaScript的新手,有点菜鸟,这就是为什么我尝试使用尽可能少的JS,但在这部分中我确实需要它。

我有一个全屏视频,它第一次播放正确,但是我希望它在重新加载时再次使用嵌入式URL。所以我做了这个JS。

        function onYouTubeIframeAPIReady() {
          var player;
          player = new YT.Player('video', {
            videoId: 'A3rvUNcueFg', // YouTube Video ID
            playerVars: {
              autoplay: 1,        // Auto-play the video on load
              controls: 0,        // Show pause/play buttons in player
              showinfo: 0,        // Hide the video title
              loop: 1,            // Run the video in a loop
              fs: 1,              // Hide the full screen button
              cc_load_policty: 0, // Hide closed captions
              iv_load_policy: 3,  // Hide the Video Annotations
              autohide: 1,         // Hide video controls when playing
              start: 13,
              end: 295,
              rel: 0,
              playlist: 'A3rvUNcueFg'
            },
            events: {
              onReady: function(e) {
                e.target.mute();
                var Embed = e.target.getVideoEmbedCode();
              }
            }
          });
          YT.PlayerState.ENDED: function(e) {
            var player;
            player = new YT.Player(Embed)
         }

所以我想做什么,我希望它静音(该部分有效)。然后获取嵌入URL,这样我就可以使用它在结束后在同一起点重新加载视频。因为现在它重新加载并从头开始。

预先感谢Jeroen

如何在视频对象中包含seekto选项。您可以将它传递给要跳过以启动视频的秒数。

function onYouTubeIframeAPIReady() {
      var player;
      var time = //whatever time you want it to start from each loop; NEW CODE
      player = new YT.Player('video', {
        videoId: 'A3rvUNcueFg', // YouTube Video ID
        playerVars: {
          autoplay: 1,        // Auto-play the video on load
          controls: 0,        // Show pause/play buttons in player
          showinfo: 0,        // Hide the video title
          loop: 1,            // Run the video in a loop
          fs: 1,   // Hide the full screen button
          cc_load_policty: 0, // Hide closed captions
          iv_load_policy: 3,  // Hide the Video Annotations
          autohide: 1,         // Hide video controls when playing
          start: 13,
          end: 295,
          rel: 0,
          playlist: 'A3rvUNcueFg'
        },
        events: {
          onReady: function(e) {
            e.target.mute();
            var Embed = e.target.getVideoEmbedCode();
          }
        }
      });
      YT.PlayerState.ENDED: function(e) {
        var player;
        player = new YT.Player(Embed);
        player.seekTo(time);  //NEW CODE
     }

参考:https://developers.google.com/youtube/iframe_api_reference#playback_controls

player.seekto(秒:编号,允许Seekahead:boolean):void

相关内容

  • 没有找到相关文章

最新更新