2012-07-06 87 views
0

我有一個YouTube Javascript API的實現,它在Chrome和Safari中完美運行,但在Firefox中無法運行。是的,我在網絡服務器上執行此操作;)YouTube Javascript API:加載在Firefox中不起作用

在文檔準備就緒後,我打電話給我的函數showVideo();

這是所有相關代碼:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>  

<div id="ytplayer" class="youtubepromovideo"></div> 

<script type="text/javascript"> 
function showVideo(){ 
    var params = { allowScriptAccess: "always" }; 
    swfobject.embedSWF("http://www.youtube.com/apiplayer?enablejsapi=1&playerapiid=ytplayer", "ytplayer", "400", "400", "8", null, null, params); 
} 

function onYouTubePlayerReady(playerId) { 
    console.log("player ready: "+playerId); 
    loadNewVideo(); 
} 

function loadNewVideo() { 
    var id = 'jc8n44ddy9A'; 
    var startSeconds = 0; 
    console.log("loading video"); 
    ytplayer.loadVideoById(id, startSeconds); 
} 
</script> 

在所有的瀏覽器播放節目,但在Firefox的視頻不會加載。我的日誌顯示Firefox上的「加載視頻」消息,但之後沒有任何其他事情發生。甚至沒有錯誤。如果我在裝入所有內容後嘗試手動撥打ytplayer.loadVideoById('jc8n44ddy9A', 0);,則會收到錯誤ReferenceError: ytplayer is not defined

我意識到ytplayer沒有明確定義爲我的變量,但我的猜測(?)是,YouTube API這樣做是因爲它在其他瀏覽器中起作用。另外,如果我在全球某個地方只定義var ytplayer,那麼它不會修復它。

任何意見是非常感謝!

回答

0

不知道在其他瀏覽器獲得來自ytplayer參考,但你應該有它全局定義(你已經給了,反正例子)和基準添加到它在onYouTubePlayerReady

ytplayer = document.getElementById(playerId);

您可能會更喜歡使用iframe播放器,以便在沒有Flash的瀏覽器中提供支持。我相信它可以在沒有控制的情況下使用"controls" parameter加載。

相關問題