2013-05-22 43 views
4

我已經嵌入了一個youtube iFrame在UIWebView網頁中播放視頻。鏈接「在YouTube上觀看」不適用於iOS UIWebView?

鏈接 「YouTube觀看」 不工作:

enter image description here

的代碼是:

<iframe name="player" id="player" src="http://www.youtube.com/embed/{$firstParsedVideo}?HD=1;rel=0;showinfo=0" width="279" height="155"></iframe> 

其中$ firstParsedVideo是視頻ID。

我在Cocoa Osx WebView中做了同樣的事情,它完美地工作。

感謝

回答

0

它不起作用的原因是Web視圖基本URL被設置爲本地。由於我的Web視圖加載本地資源(圖像),我需要將其設置爲本地。但這意味着我無法加載在線資源(YouTube視頻)。無論是其中一個還是其他。

1

據我所知,蘋果公司不會讓你在網頁視圖在自己的應用程序播放YouTube視頻,他們也會拒絕你的應用程序。因爲我以前有過這種經歷。

順便說一句,我寫我的應用程序來播放YouTube視頻的方法:

- (void)embedYouTube:(NSString*)videoId frame:(CGRect)frame { 

NSString* embedHTML = @"\ 
    <html><head>\ 
<style type=\"text/css\">\ 
body {\ 
background-color: transparent;\ 
color: white;\ 
}\ 
</style>\ 
</head><body style=\"margin:0\">\ 
    <embed id=\"yt\" src=\"http://www.youtube.com/watch?v=%@\" type=\"application/x-shockwave-flash\" \ 
width=\"%0.0f\" height=\"%0.0f\"></embed>\ 
    </body></html>"; 
NSString* html = [NSString stringWithFormat:embedHTML, videoId, frame.size.width, frame.size.height]; 
[self.webView loadHTMLString:html baseURL:nil]; 
} 

希望它能幫助。

相關問題