Youtube API https协议

问题描述:

当我使用 onYouTubeIframeAPIReady 创建iframe播放器API时,使用 http 协议创建链接

When I create an iframe player API using the onYouTubeIframeAPIReady, the link is created with the http protocol

示例:

  // 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。

Does anyone know how to do the video to be created with the https protocol? Need to install the api on a platform.

请建议!

如果直接在html中创建iframe元素,则可以指定https,而不是使用稍后替换的div。如果需要,您可以动态创建iframe标记。请查看此部分的底部,其中详细说明了如何执行此操作。

You can specify https if you create the iframe element directly in your html, rather than using the div which gets replaced later on. You can create the iframe tag dynamically if you need to. Look at the bottom of this section, which spells out how to do it.

注意 - 即使您通过https加载播放器,实际视频流也可以通过http提供。这似乎导致Chrome中的混合模式警告,但不是其他浏览器(根据我去年的经验;它可能已经改变)。请参阅此官方博客文章,其中解释了播放器可以通过https加载,但警告视频仍然不一定以这种方式提供。

Beware — even if you load the player over https, the actual video stream may be served over http. That seems to cause a mixed-mode warning in Chrome, though not other browsers (in my experience last year; it may have since changed). See this official blog post, which explains that the player can be loaded over https but warns that the video still won't necessarily be served that way.