New YouTube iframe code not displaying video on iPhone
We added the new YouTube iframe code into our News site. The problem is the video doesn't appear on the iPhone.
Here's my page and code:
<iframe width="620" height="390" src="http://www.youtube.com/v/A2V1WTF8tp4?hl=en&fs=1&autoplay=0&hd=1" frameborder开发者_运维知识库="0" allowfullscreen="true"></iframe>
How can I get YouTube video to appear on the iPhone?
The URL for the video might be the problem. The embedded video code goes like this
<iframe class="youtube-player" type="text/html" width="640" height="385" src="http://www.youtube.com/embed/VIDEO_ID" frameborder="0">
</iframe>
Notice how the URL uses embed instead of v.
Your problem may be that YouTube is Flash based, so embedding an iframe isn't going to work on the iPhone, which doesn't support Flash. Try something like this instead:
<object type="application/x-shockwave-flash" data="http://www.youtube.com/v/A2V1WTF8tp4?hl=en&fs=1&autoplay=0&hd=1" width="620" height="3900">
<param name="movie" value="http://www.youtube.com/v/A2V1WTF8tp4" />
<param name="quality" value="high" />
<param name="allowFullScreen" value="true" />
<!-- Fallback content -->
<a href="http://www.youtube.com/watch?v=A2V1WTF8tp4">
<img src="http://img.youtube.com/vi/A2V1WTF8tp4/0.jpg" width="620" height="390" alt="Staff Gathers for Multicultural Springfest" />
</a>
</object>
code courtesy of: http://learningtheworld.eu/2009/youtube-embed/
I have a subclass of UIWebView to accomplish this, and this is how it works:
(in init:)
NSString* url = [NSString stringWithFormat: @"http://www.youtube.com/embed/A2V1WTF8tp4"];
CGRect theFrame = CGRectMake(0, 0, 400, 300);
NSString* embedHTML = [NSString stringWithFormat: @"<iframe width=%i height=%i src=%@ frameborder=10 allowfullscreen></iframe>", theFrame.size.width, theFrame.size.height, url];
[self loadHTMLString: embedHTML baseURL: nil]; // this method is part of UIWebView.
Just ensure your "video view" is added as a subview of whichever view owns it.
精彩评论