2013-05-22 45 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]; 
} 

希望它能帮助。

相关问题