YouTube 播放器 iframe API:playVideo 无法在 Firefox 9.0.1 上运行
我有一些 YouTube 嵌入代码(我将只粘贴给我带来麻烦的代码,并删除不公开的内容):
console.log(ytplayer);
ytplayer.playVideo();
Chrome 和 FF 上的 Console.log 向我展示了具有正确方法的良好对象,以及方法 playVideo( ) 存在于那里。它适用于我检查过的所有其他浏览器,但它不适用于 FF!?更有趣的是,当我使用普通的YouTube播放按钮播放视频时,我可以使用pauseVideo()方法(以及所有其他方法:寻找、控制音量),但我不能使用playVideo()方法...
我使用嵌入视频的新方式:
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 错误,也没有线索...希望有人以前遇到过这个问题并得到解决!:)
I've got some YouTube embedding code (I will paste only code which is causing the trouble for me and cut things which are not public):
console.log(ytplayer);
ytplayer.playVideo();
Console.log on Chrome and on FF shows me good objects with correct methods, and method playVideo() exists there. And it works for all other browsers I checked, but it doesn't work on FF!? What is even more interesting, that when I play video using normal YouTube play button then I can use pauseVideo() method (and all the others: seeking, controlling volume), but I can't use playVideo() method...
I use new way of embedding 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');
}
}
});
Of course 'I am ready' is in console output. I have no idea what I do wrong and why only FF is not working... There is no JS error, and no clue... Hope someone had this problem before and got it resolved!:)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我遇到了一个非常相似的问题,并且正在努力寻找答案。我对 playVideo() 的调用似乎不起作用。
原文:
问题是播放器尚不可用 - 如果我只是给它一点时间出现,那么通话就起作用了
不知道这是否是您的确切问题,但我希望它对某人有帮助
I was having a very similar issue and was struggling with an answer. My calls to playVideo() didn't seem to work.
ORIGINAL:
The issue was that the player was not yet available - if I just gave it a bit of time to show up, then the call worked
Don't know if this is your exact issue, but I hope it helps someone
更可靠的方法是检查玩家是否准备好。如果播放器尚未准备好,请对player.playVideo()进行排队,并在准备好时使用onReady事件执行它。 要点
A more robust way to do that is to check if the player is ready. If the player is not ready, queue player.playVideo() and execute it when it is ready using the onReady event. Gist
我发现这篇文章正在寻找类似的东西。我在这里找到了答案,作者:relic180:
YouTube API - Firefox/IE 对于任何“播放器”返回错误“X 不是函数”。 request
基本上,即使 div 隐藏(即
display:none
),Chrome 也可以初始化 YouTube 嵌入,但 FF 和 IE 则不能。我的解决方案是 relic180 的变体:当我希望播放器不可见但已初始化(并且可用于对
player
的其他调用)时,我将播放器移动到left:200%
或其他位置,然后在需要时将其移回屏幕上。I came across this post looking for something similar. I found my answer here, by relic180:
YouTube API - Firefox/IE return error "X is not a function" for any 'player.' request
Basically, Chrome can initialize youtube embeds even when the divs are hidden (i.e.
display:none
), but FF and IE can't. My solution was a variant of relic180's:I move my player to
left:200%
or whatever when I want it invisible but getting initialized (and available for other calls toplayer
), then move it back on screen when I need it.我个人在预设的 IFrame 上发现,如果您不使用 https://www.youtube,API 将无法正常工作。 com 作为域。所以要小心不要错过“www”。否则,API 将创建玩家对象,但无法执行方法。
I personally found on preset IFrames, that the API won't work properly if you wouldn't use https://www.youtube.com as the domain. So be careful not to miss on the "www". Otherwise the API will create the player object but will fail to execute methods.