我正在使用此代码显示YouTube视频。它用于在表格单元格中以缩略图大小显示视频。点按缩略图后,视频将以全屏模式在iPhone上播放。这正是我想要的。但是,当在iPad上打开应用程序时,视频会内嵌播放,并且不会扩展以填满屏幕。该应用程序是仅限iPhone的应用程序。我知道iPad只播放内联视频,但这并不适用于在iPad上以兼容模式运行的iPhone应用。有没有人有这种行为的解决方法?
- (YouTubeView *)initWithStringAsURL:(NSString *)urlString frame:(CGRect)frame;
{
if (self = [super init])
{
// Create webview with requested frame size
self = (YouTubeView *) [[UIWebView alloc] initWithFrame:frame];
NSString * youTubeVideoHTML = @"<!doctype html>\
<html>\
<style>body{padding:0;margin:0;}</style>\
<iframe width=\"%f\" height=\"%f\" src=\"http://www.youtube.com/embed/%@?rel=0&allowfullscreen=1&playsinline=0&showinfo=0&modestbranding=1&autohide=1&iv_load_policy=3\" frameborder=\"0\" ></iframe>\
</html>";
// Populate HTML with the URL and requested frame size
NSString * html =
[NSString stringWithFormat:youTubeVideoHTML, frame.size.width, frame.size.height,urlString];
// Load the html into the webview
[self loadHTMLString:html baseURL:nil];
self.contentMode = UIViewContentModeScaleToFill;
}
return self;
}
答案 0 :(得分:0)
原来这是iPad中的iOS错误。它已在iOS 9中修复。
答案 1 :(得分:0)
yourWebView.allowsInlineMediaPlayback = NO;