Search code examples
ios5uiwebviewhtml5-videomirroringairplay

Airplay Mirroring + External UIScreen = fullscreen UIWebView video playback?


I'm currently playing around with some app ideas using AirPlay mirroring and a second UIScreen (a la Real Racing) on my Apple TV2 along with HTML5 video content (x-webkit-airplay="deny") within a UIWebView (allowsInlineMediaPlayback=YES, mediaPlaybackAllowsAirPlay=NO) on my iPad in iOS 5.

Without Airplay, the content in the UIWebView renders inline on the iPad (as expected). Once Airplay Mirroring is enabled, the content always plays full screen on the Apple TV (obscuring the external screen's UI) and shows the "video playing on Apple TV" image in the UIWebView on the main screen:

airplay indicator

Here's my HTML:

<html>
   <head>
     <title>HTML 5 Video</title>
   </head>
   <body>
      <video controls="controls" x-webkit-airplay="deny" width="280" height="200">
         <source src="http://html5demos.com/assets/dizzy.mp4" type="video/mp4" />
         <source src="http://html5demos.com/assets/dizzy.webm" type="video/webm" />
         <source src="http://html5demos.com/assets/dizzy.ogv" type="video/ogv" />
      </video> 
   </body>
</html>

Here's the relevant snippet of my project code:

NSString *urlString = @"http://medialog.roamrlog.com/video.html";
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *urlRequest = [[NSURLRequest alloc] initWithURL:url];

_webView = [[UIWebView alloc] initWithFrame:CGRectMake(50, 20, 280, 200)];

_webView.delegate = self;

_webView.allowsInlineMediaPlayback = YES;
_webView.mediaPlaybackAllowsAirPlay = NO;

[_webView loadRequest:urlRequest];

It seems to ignore all settings when mirroring is on:

airplay mirroring on

(audio and video are transmitted to ATV via AirPlay with Mirroring as is not expected)

And acknowledges them partly (read below) when mirroring is off:

airplay mirroring off

(audio is transmitted to ATV via AirPlay without Mirroring as is not expected - video is not as is expected)

I need the UIWebView content to always play inline regardless of AirPlay Mirroring. Any ideas how I can get around this issue?

Thanks in advance!


Solution

  • I am not aware of any way to do this and it's something I need as well.

    There is a property of UIWebView that should disable AirPlay on the UIWebView, but it does not seem to be working, at least for me:

    http://developer.apple.com/library/ios/documentation/uikit/reference/UIWebView_Class/Reference/Reference.html#//apple_ref/occ/instp/UIWebView/mediaPlaybackAllowsAirPlay

    I have a question on this already, so purpose you'll want to close this question and vote mine up. If you try to use that property and get better results than I did, I'd love to hear about it!

    My question: Purpose of mediaPlaybackAllowsAirPlay property on UIWebView