【问题标题】:Confusion with iframe api [duplicate]与iframe api混淆[重复]
【发布时间】:2017-02-28 22:45:34
【问题描述】:

大家好!

我是 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,以便我可以使用它在结束后在同一起点重新加载视频。因为它现在重新加载并从头开始。

提前致谢, 杰伦

【问题讨论】:

    标签: javascript iframe youtube-api


    【解决方案1】:

    如何在您的视频对象中包含 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(seconds:Number, allowSeekAhead:Boolean):Void

    【讨论】:

      猜你喜欢
      • 2012-12-16
      • 1970-01-01
      • 1970-01-01
      • 2016-02-24
      • 2023-03-12
      • 2014-08-23
      • 1970-01-01
      • 2015-04-24
      • 2012-08-12
      相关资源
      最近更新 更多