3

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

例子:

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

请,建议!

4

1 回答 1

0

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

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

于 2013-07-15T12:25:39.507 回答