2014-11-03 4 views
2

코드도 안드로이드 프로젝트에 a YouTube iframe API을 사용하려고합니다. 내 컴퓨터의 브라우저에서 코드를 실행하면 완벽하게 실행되지만 앱을 빌드하고 휴대 전화에서 실행하면 iframe이 포함 된 페이지가로드되지 않고 콘솔에 다음 오류가 표시됩니다.Cordova/Phonegap YouTube iframe_api 오류 : XMLHttpRequest에서 chrome-extension을로드 할 수 없습니다. HTTP에 대해서만 교차 원어 요청이 지원됩니다.

XMLHttpRequest cannot load chrome-extension://boadgeojelhgndaghljhdicfkmllpafd/cast_sender.js. Cross origin requests are only supported for 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> 

감사 :

여기 내 코드입니다!

+0

나는 작동하지 않아서 glitchbone의 cordova 플러그인 [YoutubeVideoPlayer] (http://plugins.cordova.io/#/package/com.bunkerpalace.cordova.youtubevideoplayer)을 사용했다. 그러나 나는 질문을 공개적으로 남겨 둘 것이다. – justahandsomeman

답변