【问题标题】:errors in youtube javascript apiyoutube javascript api中的错误
【发布时间】:2015-05-31 15:34:42
【问题描述】:

我在使用 YouTube 播放器工具 - Iframe API 播放视频时遇到一些错误。我在浏览器的控制台窗口中遇到这 6 个错误

1.在“DOMWindow”上执行“postMessage”失败:提供的目标原点(“https://www.youtube.com”)与接收窗口的原点(“http://127.0.0.1”)不匹配。
2.GET chrome-extension://boadgeojelhgndaghljhdcfkmllpafd/cast_sender.js net::ERR_FAILED
3.GET chrome-extension://dliochdbjfkdbacpmhlcpmleaejidimm/cast_sender.js net::ERR_FAILED
4.GET chrome-extension://hfaagokkkhdbgiakmmlclaapfelnkoah/cast_sender.js net::ERR_FAILED
5.GET chrome-extension://fmfcbgogabcbclcofgocippekhfcmgfj/cast_sender.js net::ERR_FAILED
6.GET chrome-extension://enhhojjnijigcajfphajepfemndkmdlo/cast_sender.js net::ERR_FAILED

我的 index.php 是

<html>
<head>
</head>
<body>

<div id='player'></div>
<!--iframe id="player" type="text/html" width="640" height="390"
  src="https://www.youtube.com/embed/M7lc1UVf-VE?enablejsapi=1&origin=http://example.com"
  frameborder="0"></iframe-->

  <script>

      var tag = document.createElement('script');
      tag.src = "http://www.youtube.com/iframe_api";
      var firstScriptTag = document.getElementsByTagName('script')[0];
      firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
      // 2. This code loads the IFrame Player API code asynchronously.
      // 3. This function creates an <iframe> (and YouTube player)
      //    after the API code downloads.
      var player;
      function onYouTubeIframeAPIReady() {
        player = new YT.Player('player', {
          height: '500',
          width: '500',
          videoId: 'wbLBHYAd0kE',//videos[currentid],
          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, 10000);
          done = true;
        }
      }
      function stopVideo() {
          alert();
        player.stopVideo();
      }

</script>
</body>
</html>

我需要做些什么来消除这些错误?

【问题讨论】:

    标签: php youtube-api youtube-javascript-api


    【解决方案1】:

    第一个错误:

    tag.src = "http://www.youtube.com/iframe_api";
    

    进入

    tag.src = "https://www.youtube.com/iframe_api";
    

    错误 2-6: 这是官方 Chromecast JavaScript 库的一个已知错误。它不会静默失败,而是将这些错误消息转储到所有非 Chrome 浏览器以及不存在 Chromecast 扩展程序的 Chrome 浏览器中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-05-02
      • 2023-03-22
      • 1970-01-01
      • 2014-04-24
      • 1970-01-01
      • 2019-02-04
      • 2011-07-13
      相关资源
      最近更新 更多