2
votes

I am using this code to display a youtube video. It is used to display the video in thumbnail size in a table cell. When the thumbnail is tapped, the video plays in full screen mode, on an iPhone. This is exactly what I want. However when the app is opened on an iPad, the video plays inline and doesn't expand to fill the screen. The app is an iPhone only app. I'm aware that iPad plays videos inline only, but this shouldn't apply to iPhone apps running in compatibility mode on the iPad. Does anyone have a workaround for this behaviour?

- (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;   
}
2

2 Answers

0
votes

Turns out this was an iOS bug in the iPad. It was fixed in iOS 9.

0
votes

yourWebView.allowsInlineMediaPlayback = NO;