如何使用 jquery 调用 Youtube .playVideo() ?
我想插入一个 youtube 视频并立即播放,我不太确定如何让它在实时点击时与 jquery 一起使用。有什么想法吗?
var youTubeVideo = '<object width="370" height="260"><param name="movie"' +
' value="http://www.youtube.com/v/[ID]&hl=en_US&fs=1?rel=0enablejsapi=1&playerapiid=player"></param>' +
'<param name="allowFullScreen" value="false"></param><param name="allowscriptaccess"' +
'value="always"></param><embed src="http://www.youtube.com/v/[ID]&hl=en_US&fs=1?rel=0enablejsapi=1&playerapiid=player"' +
'type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="false"' +
'width="370" height="260"></embed></object>';
$('#MyVideo').live('click',function () {
$(this).append(youTubeVideoHTML);
//How do you accomplish this call?
//player.playVideo();
});
我必须通过单击单独的元素来完成此操作,因此无法立即开始播放。我也不想使用任何外部 api。
I would like to insert a youtube video and play it right away, I am not quite sure how to get this to work with jquery on live click. Any ideas?
var youTubeVideo = '<object width="370" height="260"><param name="movie"' +
' value="http://www.youtube.com/v/[ID]&hl=en_US&fs=1?rel=0enablejsapi=1&playerapiid=player"></param>' +
'<param name="allowFullScreen" value="false"></param><param name="allowscriptaccess"' +
'value="always"></param><embed src="http://www.youtube.com/v/[ID]&hl=en_US&fs=1?rel=0enablejsapi=1&playerapiid=player"' +
'type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="false"' +
'width="370" height="260"></embed></object>';
$('#MyVideo').live('click',function () {
$(this).append(youTubeVideoHTML);
//How do you accomplish this call?
//player.playVideo();
});
I have to do this on a click of a seperate element so starting the play right away is not an option. I would also prefer to not use any external api's.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将 &autoplay=1 添加到 YouTube 网址的末尾。
Add &autoplay=1 to the end of the youtube url.
看起来对象应该有一个像
然后:
$('#myplayer').playVideo();
Seems like an object should have an id like
<object id='myplayer' ... />
Then:
$('#myplayer').playVideo();