2015-10-16 110 views
0

我有這個代碼爲我的YouTube視頻創建iframe 但我不太確定如何顯示縮略圖,因爲現在它只是 顯示一個黑盒子和之後我點擊視頻開始播放。YouTube IFrame播放器API縮略圖沒有顯示

我試過player.cueVideoById('eJSik6ejkr0',0,'highres')但仍然沒有。

任何想法我能做些什麼來使縮略圖可見?

感謝

 player = new YT.Player('player', { 
 
      height: '475', 
 
      width: '100%', 
 
      videoId: 'eJSik6ejkr0', 
 
\t \t playerVars: { 'rel': 0, 'modestbranding': 1, 'autoplay': 1, 'controls': 0 }, 
 
      events: { 
 
      'onStateChange': onPlayerStateChange 
 
      } 
 
     });

+0

當我在下面的答案中使用你的代碼片段時,我得到了'這包含了來自VEVO的內容。它在某些網站上播放受到限制。這解釋了爲什麼你不能得到拇指指甲。 – Jaco

回答

0

這是Youtube Player API給出的例子和正確地顯示縮略圖。但是,某些內容提供商會限制播放某些網站,因此您可能會收到縮略圖。用你的視頻ID,我得到一個黑盒子,在中間這條消息:This contains content from VEVO. It is restricted from playback on certain sites

< !DOCTYPE html> 
 
    < html> 
 
    < body> 
 
     <!-- 1. The <iframe> (and video player) will replace this <div> tag. --> 
 
     < div id="player"> 
 
     < /div> 
 

 
      <script> 
 
      // 
 
      2.This code loads the IFrame Player API code asynchronously. 
 
      var tag = document.createElement('script'); 
 

 
      tag.src = "https://www.youtube.com/iframe_api"; 
 
      var firstScriptTag = document.getElementsByTagName('script')[0]; 
 
      firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); 
 

 
      // 3. This function creates an <iframe> (and YouTube player) 
 
      // after the API code downloads. 
 
      var player; 
 

 
      function onYouTubeIframeAPIReady() { 
 
       player = new YT.Player('player', { 
 
       height: '390', 
 
       width: '640', 
 
       videoId: 'M7lc1UVf-VE', 
 
       events: { 
 
        'onReady': onPlayerReady, 
 
        'onStateChange': onPlayerStateChange 
 
       } 
 
       }); 
 
      } 
 

 
      // 4. The API will call this function when the video player is ready. 
 
      function onPlayerReady(event) { 
 
       event.target.playVideo(); 
 
      } 
 

 
      // 5. The API calls this function when the player's state changes. 
 
      // The function indicates that when playing a video (state=1), 
 
      // the player should play for six seconds and then stop. 
 
      var done = false; 
 

 
      function onPlayerStateChange(event) { 
 
       if (event.data == YT.PlayerState.PLAYING && !done) { 
 
       setTimeout(stopVideo, 6000); 
 
       done = true; 
 
       } 
 
      } 
 

 
      function stopVideo() { 
 
       player.stopVideo(); 
 
       } < /script> 
 
    </body > 
 
       < /html>

0

好,我管理它...

的VEVO只是一個例子(壞的) ...我在頁面上有5個視頻(主要的1個和4個小視頻),並且在主視頻運行之後,我在所有4個小視頻中使用了pausedVideo方法,因此它們全部變爲「黑色」。

現在很好,謝謝你的幫助!

相關問題