Embed youtube for mobile page

MTilsted picture MTilsted · Mar 25, 2011 · Viewed 29.5k times · Source

Is there a way to embed a link to a youtube video, so that the video will play in fullscreen on a mobile phone when the user click on the link?

The default iframe embed code will play the video inline on android phones -(

If I go to m.youtube.com they kinda does what i need, but they do it in an odd way because they generate different html and different links and protocols for viewing the video depending on which mobile phone I have.

This does make sense because the way to serve the video depend on the users phone, but is there a way for me to get some javascript/html from youtube so I can do the same thing on my own page?

Answer

webmat picture webmat · May 11, 2011

The proper way to do it seems to be like so:

<iframe class="youtube-player" type="text/html" width="640" height="385" 
src="http://www.youtube.com/embed/VIDEO_ID" frameborder="0">
</iframe>

Check out the Youtube blog or that other blog post.

Now you only need to find a way to figure out which width and height to use for each device.