2015-04-03 19 views
1

這很奇怪。我正在使用youtube JavaScript API在我的網站上嵌入播放列表。除了我最近檢查我的工人正在發生的事情之外,這將會很好。看起來API決定將它的消息發送給其中的一個。Youtube API使用不相關的工作人員?

這裏是我的工作人員收到的數據。

bubbles: falsecancelBubble: falsecancelable: falsecurrentTarget: Windowdata: "{"event":"infoDelivery","info":{"currentTime":109.455757,"videoBytesLoaded":1,"videoLoadedFraction":1},"id":1}"defaultPrevented: falseeventPhase: 0lastEventId: ""origin: "https://www.youtube.com"path: Array[1]ports: Array[0]returnValue: truesource: WindowsrcElement: Windowtarget: WindowtimeStamp: 1428083437641type: "message"__proto__: MessageEvent 

而且正如我在另一個問題的Youtube API見過這是否

www-embed-player.js:167 GET chrome-extension://enhhojjnijigcajfphajepfemndkmdlo/cast_sender.js net::ERR_FAILED 

我沒想到谷歌創造這樣錯誤的API。有沒有辦法禁用這些東西?

回答

0

快速實驗提供了一個解決方案。將所有的youtube代碼移動到一個單獨的html並嵌入到我的父頁面中。

<iframe id="youtubePlayer" src="mediaPlayer.html"> 

您仍然可以從您的主頁訪問YouTube API取得這樣的

var mediaPlater = document.getElementById('youtubeFrame').contentWindow.player; 
    // i.e. skip to next video 
    mediaPlayer.nextVideo(); 

這解決了完全意想不到的工人活動。這個控制檯錯誤仍然存​​在,但在閱讀後,這是一個不可修復的問題,它不會打擾我。

www-embed-player.js:167 GET chrome-extension:// 

內容我mediaPlayer.html的

<div id="ytplayer" class="musicPlayer"></div> 
<script> 
var player = null; 
// Load the IFrame Player API code asynchronously. 
var tag = document.createElement('script'); 
tag.src = 'https://www.youtube.com/player_api'; 
var firstScriptTag = document.getElementsByTagName('script')[0]; 
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); 

// Replace the 'ytplayer' element with an <iframe> and 
// YouTube player after the API code downloads. 
function onYouTubePlayerAPIReady() { 
    player = new YT.Player('ytplayer', { 
     height: '180', 
     width: '280', 
     playerVars: { 
      autoplay: 1, 
      controls: 0, 
      listType: 'playlist', 
      list: 'RD4-OlYiH1DXI' 
     }, 
     events: { 
      'onReady': onPlayerReady, 
      'onError': function() { 
       setTimeout(function() { 
        player.nextVideo(); 
       }, 200); 
      } 
     } 
    }); 
} 


function onPlayerReady() { 
    // fixes firefox ignoring first onerror if the first video is faulty 
    player.nextVideo(); 
} 
</script> 
相關問題