Cordova / Phonegap YouTube iframe_api错误:XMLHttpRequest无法加载chrome-extension仅支持HTTP的交叉源请求

时间:2014-11-03 21:45:09

标签: android cordova youtube youtube-iframe-api

我正在尝试将a YouTube iframe API与我的cordova-android项目一起使用。当我在我的计算机上的浏览器中运行代码时它运行得很好,但是当我构建我的应用程序并在我的手机上运行时,包含iframe的页面将无法加载,并且我在我的控制台中收到以下错误:

  

XMLHttpRequest无法加载chrome-extension://boadgeojelhgndaghljhdicfkmllpafd/cast_sender.js。仅支持HTTP

的跨源请求

这是我的代码:

 <div class='ui-body ui-body-a'>
       <!-- 1. The <iframe> (and video player) will replace this <div> tag. -->
       <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: 'M7lc1UVf-VE',
                   events: {
                       'onReady': onPlayerReady,
                       'onStateChange': onPlayerStateChange
                   }
               });
           }

           // 4. The API will call this function when the video player is ready.
           function onPlayerReady(event) {
               console.log('Loaded Video)
           }

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

提前致谢!

1 个答案:

答案 0 :(得分:0)

我使用glitchbone&#cordova插件YoutubeVideoPlayer让它工作。