2011-06-03 34 views
3

無法顯示視頻YouTube新的iframe代碼,我們添加了新的YouTube的iframe代碼爲我們的新聞網站。問題是視頻沒有出現在iPhone上。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上?

回答

6

的視頻的URL可能是問題。嵌入式視頻代碼是這樣

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

通知的URL如何使用嵌入代替v的。

+0

類部分是沒有必要的,我只是複製它直接從YouTube博客[http://apiblog.youtube.com/2010/07/new-way-to-embed-youtube-videos.html] – 2011-06-03 23:30:49

2

你的問題可能是YouTube的是基於Flash的,所以嵌入一個IFRAME是不會在iPhone上,不支持Flash的工作。 嘗試這樣的事情,而不是:的

<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/

0

我有一個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. 

只要確保你的「視頻視圖」添加爲一個子視圖無論何種觀點擁有它。