【问题标题】:New YouTube iframe code not displaying video on iPhone新的 YouTube iframe 代码不在 iPhone 上显示视频
【发布时间】:2011-09-08 04:11:14
【问题描述】:
我们将新的 YouTube iframe 代码添加到我们的新闻网站中。问题是视频没有出现在 iPhone 上。
这是我的page 和代码:
<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>
如何让 YouTube 视频出现在 iPhone 上?
【问题讨论】:
标签:
iphone
iframe
youtube
mobile-safari
【解决方案1】:
您的问题可能是 YouTube 是基于 Flash 的,因此嵌入 iframe 无法在不支持 Flash 的 iPhone 上工作。
试试这样的:
<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>
代码来自:http://learningtheworld.eu/2009/youtube-embed/
【解决方案2】:
视频的 URL 可能是问题所在。嵌入的视频代码是这样的
<iframe class="youtube-player" type="text/html" width="640" height="385" src="http://www.youtube.com/embed/VIDEO_ID" frameborder="0">
</iframe>
注意 URL 如何使用 embed 而不是 v。
【解决方案3】:
我有一个 UIWebView 的子类来完成这个,它是这样工作的:
(在初始化中:)
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.
只需确保将您的“视频视图”添加为拥有它的任何视图的子视图。