我已经在各处寻找如何实现此操作的方法,但仍未找到答案。 是否有可能在iPhone上使用UIWebView内联播放youtube视频,即不是全屏模式? 我知道iPhone不支持Flash,但Youtube支持HTML5和H.264视频,难道我就不能这样做吗?
我已将allowsInlineMediaPlayback设置为YES,但仍然全屏播放。
我已经在各处寻找如何实现此操作的方法,但仍未找到答案。 是否有可能在iPhone上使用UIWebView内联播放youtube视频,即不是全屏模式? 我知道iPhone不支持Flash,但Youtube支持HTML5和H.264视频,难道我就不能这样做吗?
我已将allowsInlineMediaPlayback设置为YES,但仍然全屏播放。
是的,你可以,在UIWebView上设置属性即可。
webView.allowsInlineMediaPlayback=YES;
您需要在YouTube iframe嵌入代码中添加&playsinline=1。
<iframe webkit-playsinline width="200" height="200" src="https://www.youtube.com/embed/GOiIxqcbzyM?feature=player_detailpage&playsinline=1" frameborder="0"></iframe>
在运行iOS 6.1.2的iPhone 4S上测试,效果非常好。
allowsInlineMediaPlayback UIWebView属性
布尔值,用于确定HTML5视频是内联播放还是使用本地全屏控制器。(developer.apple.com)
您可以在iPad上使用此功能。在iPhone上没有此功能。如果您尝试在iPhone上使用uiwebview播放视频,则会以全屏模式播放。
是的,您可以使用"playsinline=1"的帮助在UIWebView中播放任何嵌入式视频。
源代码如下:
NSMutableString *html = [[NSMutableString alloc] initWithCapacity:1] ;
[html appendString:@"<html><head>"];
[html appendString:@"<style type=\"text/css\">"];
[html appendString:@"body {"];
[html appendString:@"background-color: transparent;"];
[html appendString:@"color: white;"];
[html appendString:@"}"];
[html appendString:@"</style>"];
[html appendString:@"</head><body style=\"margin:0\">"];
[html appendString:@"<iframe webkit-playsinline width=\"300\" height=\"220\" src=\"http://www.ustream.tv/embed/23192315?html5ui&showtitle=false&playsinline=1\" frameborder=\"0\"></iframe>"];
[html appendString:@"</body></html>"];
[self.webViewRef loadHTMLString:html baseURL:nil];