YouTube播放器iframe API:playVideo无法在Firefox 9.0.1上运行

我有一些YouTube嵌入代码(我只会粘贴代码,这会给我带来麻烦并削减不公开的内容):

console.log(ytplayer); ytplayer.playVideo(); 

Chrome和FF上的Console.log向我展示了使用正确方法的好对象,并且存在方法playVideo()。 它适用于我检查的所有其他浏览器,但它不适用于FF!? 更有趣的是,当我使用普通的YouTube播放按钮播放video时,我可以使用pauseVideo()方法(以及所有其他方法:搜索,控制音量),但我不能使用playVideo()方法……

我使用新的嵌入video方式:

 ytplayer = new YT.Player(player, { height: height, width: width, videoId: videoid, allowfullscreen: 'true', playerVars: { controls: 0, showinfo: 0, wmode: 'opaque', autoplay: (autoplay ? 1 : 0) }, events: { 'onReady': function () { console.log('I am ready'); } } }); 

当然’我准备好’是在控制台输出。 我不知道我做错了什么,为什么只有FF不工作…没有JS错误,也没有任何线索…希望有人之前遇到过这个问题并得到解决!:)

我遇到了一个非常相似的问题,正在努力寻找答案。 我对playVideo()的调用似乎不起作用。

原版的:

 $('#play_movie').click(function(){ $('#video').show(); if(player) { if(typeof player.playVideo == 'function') { player.playVideo(); } } 

问题是玩家还没有 – 如果我只是花了一点时间来展示,那么这个电话就可以了

 $('#play_movie').click(function(){ $('#video').show(); if(player) { var fn = function(){ player.playVideo(); } setTimeout(fn, 1000); } 

不知道这是否是你的确切问题,但我希望它对某人有所帮助

更有效的方法是检查播放器是否准备就绪。 如果播放器未就绪,请将player.playVideo()排队并在使用onReady事件准备就绪时执行它。 要旨

 var playerConfig = {}, // Define the player config here queue = { // To queue a function and invoke when player is ready content: null, push: function(fn) { this.content = fn; }, pop: function() { this.content.call(); this.content = null; } }, player; window.onYouTubeIframeAPIReady = function() { player = new YT.Player('player', { videoId: 'player', playerVars: playerConfig, events: { onReady: onPlayerReady } }); }; // API event: when the player is ready, call the function in the queue function onPlayerReady() { if (queue.content) queue.pop(); } // Helper function to check if the player is ready function isPlayerReady(player) { return player && typeof player.playVideo === 'function'; } // Instead of calling player.playVideo() directly, // using this function to play the video. // If the player is not ready, queue player.playVideo() and invoke it when the player is ready function playVideo(player) { isPlayerReady(player) ? player.playVideo() : queue.push(function() { player.playVideo(); }); } 

我遇到这篇文章寻找类似的东西。 我在这里找到了答案,由relic180:

YouTube API – Firefox / IE为任何“播放器”返回错误“X不是函数”。 请求

基本上,Chrome可以初始化youtube嵌入,即使隐藏div(即display:none ),但FF和IE不能。 我的解决方案是relic180的变种:

我将我的播放器left:200%移动left:200%或者其他什么,当我想让它看不见但是初始化(并且可用于其他对player调用),然后在我需要时将其移回屏幕。

我个人在预设的IFrame上发现,如果您不使用https://www.youtube.com作为域,API将无法正常工作。 所以要小心不要错过“www”。 否则,API将创建播放器对象,但无法执行方法。