2017-02-28 116 views
0

Heyo伙计们!与iframe api混淆

我是新来的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) 
     } 

所以我希望它做什么,我希望它静音(该部分工程)。 然后获取嵌入网址,以便在结束后在相同的起始点重新加载视频。因为它现在重新加载并从头开始。

由于提前, 吉荣

回答

0

如何,包括您的视频对象的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(秒:数字,allowSeekAhead:布尔值):无效