IOS AirPlay: is my app only notified of the external display when mirroring is on?

I am trying to enable AirPlay support in my application. I do not make a video; I want to use an external display as a "second display".

Here is my problem: if I select "AppleTV" from my AirPlay button, my application will not receive a notification. The only time my application is notified about this, when I leave the application, go to the AirPlay button at the OS level, select "AppleTV" and turn on mirroring. If I turn off the mirror, my application will report that the external display is not working.

So:

  • Why is my application not notified when I select an external display from within my application?
  • Why does my application receive a notification about the presence of an external display when I turn the mirror on ... and not earlier? I obviously misunderstand something, but it seems that turning on mirroring should inform my application that the external screen has disappeared (and is not now available, since the OS should now use this external display for mirroring.)

Sample code below. Thanks in advance for your help!

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. // Is there already an external screen? if (UIScreen.screens.count > 1)] { [self prepareExternalScreen:UIScreen.screens.lastObject]; } // Tell us when an external screen is added or removed. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(externalScreenDidConnect:) name:UIScreenDidConnectNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(externalScreenDidDisconnect:) name:UIScreenDidDisconnectNotification object:nil]; self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; self.window.rootViewController = self.viewController; // Add AirPlay control to view controller. MPVolumeView* airplayButtonView = [[MPVolumeView alloc] init]; airplayButtonView.frame = CGRectMake(300, 300, 50, 50); airplayButtonView.backgroundColor = [UIColor blackColor]; airplayButtonView.showsVolumeSlider = NO; airplayButtonView.showsRouteButton = YES; [self.viewController.view addSubview:airplayButtonView]; [self.window makeKeyAndVisible]; return YES; } #pragma mark - External screen handling - (void)externalScreenDidConnect:(NSNotification*)notification { [self prepareExternalScreen:notification.object]; } - (void)externalScreenDidDisconnect:(NSNotification*)notification { // Don't need these anymore. self.externalWindow = nil; } - (void)prepareExternalScreen:(UIScreen*)externalScreen { NSLog(@"PREPPING EXTERNAL SCREEN."); self.viewController.view.backgroundColor = [UIColor blueColor]; CGRect frame = externalScreen.bounds; self.externalWindow = [[UIWindow alloc] initWithFrame:frame]; self.externalWindow.screen = externalScreen; self.externalWindow.hidden = NO; self.externalWindow.backgroundColor = [UIColor redColor]; } 
+6
source share
3 answers

This is correct, unfortunately. The secondary display (broadcast screen) is only available with mirroring.

Here is an application that shows how to implement this: https://github.com/quellish/AirplayDemo

Looking at your code, you MUST get UIScreenDidConnectNotification when the user goes to the broadcast menu and turns on mirroring while your application is active. The "Airplay Button", controlled by the MPVolumeView or video controller, does not control mirroring (and therefore the external functionality of the display). The video and audio output, unfortunately, are separate from mirroring, and mirroring can be turned on or off using the full mirror UI.

Bottom line: you cannot enable this AirPlay screen from your application.

+8
source

Finally, if you find the answer, you must enable mirroring to receive a new notification about the screen, but then you must rewrite the screen with the second contents of the screen. Very confusing!

See this example:

UIScreen screens always return 1 screen

Now the worst part. You can add an AirPlay button inside your application using the following command:

 MPVolumeView *volumeView = [ [MPVolumeView alloc] init] ; [view addSubview:volumeView]; 

However, you cannot enable mirroring from this collector! And there is no software way to enable mirroring.

How to enable AirPlay software mirroring on iPhone 4S

Thus, apparently, the only way to get a second experience with the screen is to instruct your user how to turn on AirPlay from the multitasking panel and make sure that they turn on the mirror.

+2
source

Unfortunately, because of the application, it does not seem to be possible. Only live audio can be turned on from within the afaik app. Here's an example application using a second screen with OpenGL and sounds http://developer.apple.com/library/ios/samplecode/GLAirplay/Introduction/Intro.html

0
source

Source: https://habr.com/ru/post/906972/


All Articles