2013-07-15 137 views
2

当我创建使用onYouTubeIframeAPIReady的iframe播放器API,该链接与http协议创建的Youtube API HTTPS协议

实施例:

// 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', { 
      width: '560', 
      height: '600', 
      videoId: '7j8B_r4OfAw', 
      events: { 
      'onReady': onPlayerReady, 
      'onStateChange': onPlayerStateChange 
      } 
     }); 
     } 

iframe中结果:

<iframe id="player" frameborder="0" allowfullscreen="1" title="YouTube video player" width="560" height="600" src="http://www.youtube.com/embed/7j8B_r4OfAw?enablejsapi=1"></iframe> 

不任何人都知道如何使用https协议创建视频?需要在平台上安装api。

请建议!

回答

0

如果您直接在您的html中创建iframe元素,而不是使用稍后替换的div,则可以指定https。如果需要,您可以动态创建iframe标记。看看this section的底部,它说明了如何去做。

请注意 - 即使您通过https加载播放器,实际的视频流也可能通过http提供。这似乎在Chrome中导致混合模式警告,但不是其他浏览器(以我去年的经验,可能已经改变)。请参阅this official blog post,其中解释说可以通过https加载播放器,但会警告视频不一定会以这种方式提供。