tags:

views:

28

answers:

2

I have the following, which displays an image and when the user clicks on the image, it takes them to the Youtube video:

<html>
<head>
<script src="http://www.google.com/jsapi"&gt;&lt;/script&gt;
<script type="text/javascript">
google.load("jquery", "1", {uncompressed: true});
</script>

<script>
jQuery(function($){
    $('a').click(function() {
        $(this).html('<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/Msef24JErmU&amp;hl=en_US&amp;fs=1&amp;rel=0&amp;color1=0x2b405b&amp;color2=0x6b8ab6"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/Msef24JErmU&amp;hl=en_US&amp;fs=1&amp;rel=0&amp;color1=0x2b405b&amp;color2=0x6b8ab6" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>');
        return false;
    });
});
</script>
</head>
<body>
    <a href="javascript:void();"><img src="http://www.clipov.net/pic/paul_oakenfold+%5Bstarry_eyed_surprise%5D+_+3-07+mtv_dance_beats+clear.jpg"&gt;&lt;/a&gt;
</body>
</html>

Q: How do I autoplay the video to keep the user from having to click on it (a second time)?

+1  A: 

Just add autoplay=1 to your embed src attribute:

http://www.google.com/support/youtube/bin/answer.py?hl=en&amp;answer=56107

mamoo
+1  A: 

http://www.google.com/support/youtube/bin/answer.py?hl=en&amp;answer=56107

Yes, you can autoplay movies! In the "About This Video" section of the video watch page, we give you the source code to embed the video:

<object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/OdT9z-JjtJk"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/OdT9z-JjtJk" type="application/x-shockwave-flash" width="425" height="350"></embed></object>

To make it autoplay, just append "&autoplay=1" after the video ID so it looks like this:

<object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/OdT9z-JjtJk&amp;autoplay=1"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/OdT9z-JjtJk&amp;autoplay=1" type="application/x-shockwave-flash" width="425" height="350"></embed></object>
ceejayoz
Thanks ceejayoz!
cf_PhillipSenn