在现有播放器上启用YouTube API [英] Enable YouTube API on existing player
问题描述
我有一个嵌入了youtube视频,我希望应用YouTube API。我使用jQuery添加url参数如下(演示):
I have an embeded youtube video which I want the YouTube API applied. I add the url parameter using jQuery as follows (demo):
$(document).ready(function(){
var obj = $('object');
obj.find('embed').attr('src', function(i,s){return s+'&enablejsapi=1&version=3'})
obj.find('param[name=movie]').attr('value', function(i,v){return v+'&enablejsapi=1&version=3'})
$('.play').click(function(){
obj.find('embed')[0].playVideo();
});
$('.pause').click(function(){
obj.find('embed')[0].pauseVideo();
})
});
此方法在Firefox中运行良好,但在IE或Chrome中根本不适用(不确定其他浏览器) )。所以我的问题是如何修改它以使API在其他浏览器中工作?我是否必须完全删除对象并使用 SWFObject 替换它?
This method works great in Firefox, but not at all in IE or Chrome (not sure about other browsers). So my question is how do I modify this to make the API work in other browsers? Would I have to completely remove the object and replace it using SWFObject?
注意:嵌入代码直接来自YouTube。
Note: The embed code is directly from YouTube.
更新:我想如果我删除对象,添加url参数然后添加对象,我现在可以让它在Chrome中工作,但仍然不是IE(更新的演示)。
Update: I figured out if I remove the object, add the url parameters then add the object back, I can now get it to work in Chrome, but still not IE (updated demo).
附录:为什么没有YouTube API当object / embed已经包含启用代码时,该函数是什么?我试图避免使SWFObject成为依赖。
Addendum: Why doesn't the YouTube API function when the object/embed already has the enable code within it? I'm trying to avoid making SWFObject a dependancy.
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="640" height="385">
<param name="movie" value="http://www.youtube.com/v/2Qj8PhxSnhg&hl=en_US&fs=1&enablejsapi=1&version=3"></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"></param>
<embed src="http://www.youtube.com/v/2Qj8PhxSnhg&hl=en_US&fs=1&enablejsapi=1&version=3" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed>
</object>
推荐答案
关于swfobject - 是的。 IE对Flash嵌入的处理方式略有不同(感谢activex),而不是其他所有浏览器。看看这篇文章了解原因,以及 SWFObject文档了解更多信息。
Regarding swfobject - yes. IE treats flash embeds slightly differently (thanks activex) than all the other browsers. check out this article to get an idea of why, and the SWFObject documentation for more information.
另外,我最近创建了一个jQuery插件来帮助使用播放器API控制嵌入式播放器(基本上你是什么这样做)。
Also, I recently created a jQuery plugin to help control the embedded player using the player API (basically what you're doing).
检查出来,它是jQuery TubePlayer插件 - http://www.tikku.com/jquery-youtube-tubeplayer-plugin
Check it out, it's the jQuery TubePlayer plugin - http://www.tikku.com/jquery-youtube-tubeplayer-plugin
这篇关于在现有播放器上启用YouTube API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!