How to call Youtube .playVideo() with jquery?
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(youTubeVideoHTM开发者_如何学编程L);
//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.
Add &autoplay=1 to the end of the youtube url.
Seems like an object should have an id like <object id='myplayer' ... />
Then: $('#myplayer').playVideo();
精彩评论