有没有办法将referer设置为youtube-iframe-api?

问题描述 投票:8回答:1

我正在开发Chrome扩展程序,我正在使用youtube-iframe-api

由以下代码制作的播放器可以播放除vevo等有限(?)视频之外的任何视频。

function onYouTubeIframeAPIReady() { 
  player = new YT.Player('player', {
  height: '300px',
  width: '800px',
  videoId: 'RhU9MZ98jxo', 
  playerVars: {
    'origin': 'https://www.youtube.com',
    'wmode': 'opaque'
  },
  events: {
    'onReady': onPlayerReady,
    'onStateChange': onPlayerStateChange
  }
});
};

我在wmode中添加了原点和playerVars,因为我找到了一些可以解决问题的答案。但他们没有工作。

我想知道可以用嵌入youtube播放器(iframe)播放vevo视频

javascript iframe youtube youtube-iframe-api
1个回答
5
投票

我使用youtube API文档中提供的示例设法在w3schools的“Try it yourself”中播放了一个vevo视频:

<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: 'tWQPbHXyoFQ',
          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>

当您尝试播放vevo视频时会发生什么?你得到什么错误或消息?

作为youtube上传者,您可以选择拒绝将视频嵌入除youtube之外的其他网站中,在这些情况下,您无法真正做任何事情。

© www.soinside.com 2019 - 2024. All rights reserved.