2017-02-28 124 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:布爾值):無效