views:

44

answers:

2

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]&amp;amp;hl=en_US&amp;amp;fs=1?rel=0enablejsapi=1&amp;playerapiid=player"&gt;&lt;/param&gt;' +
                        '<param name="allowFullScreen" value="false"></param><param name="allowscriptaccess"' +
                        'value="always"></param><embed src="http://www.youtube.com/v/[ID]&amp;amp;hl=en_US&amp;amp;fs=1?rel=0enablejsapi=1&amp;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.

+2  A: 

Add &autoplay=1 to the end of the youtube url.

Fosco
Fosco
wow. and here I was, trying to figure out a Javascript solution for the thing. simple solutions rock.
Richard Neil Ilagan
Ah that's nifty solution :) thank you. Since the video doesn't exist until I add it to the page I can give it that property, and it will play when the object gets appended. Thank you :)
Andrew
A: 

Seems like an object should have an id like <object id='myplayer' ... />

Then: $('#myplayer').playVideo();

DataGreed
I get an error saying playVideo(); is not a function.
Andrew