2015-10-16 108 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方法,因此它们全部变为“黑色”。

现在很好,谢谢你的帮助!

相关问题