How to use iOS 5+ AirPlay for the second screen

I play with AirPlay using the iPhone 4S and I have problems. I upgraded my Apple TV 2 to the latest version (4.4.3 I think I forgot it is in another room and I'm too lazy to check) and I have iOS 5.0 on my 4S while I use Xcode 4.2 Build 4D199, I wrote a simple UIView application that tries to use the second screen when it is available. Here is what I have in my view of DidLoad:

- (void)viewDidLoad { [super viewDidLoad]; [self.view addSubview:[[MPVolumeView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)]]; NSLog(@"Registering for screen connect events..."); // Do any additional setup after loading the view, typically from a nib. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(screenDidConnect:) name:UIScreenDidConnectNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(screenDidDisconnect:) name:UIScreenDidDisconnectNotification object:nil]; NSLog(@"There are %i connected screens.", ScreenCount); if (ScreenCount > 1) { self.secondWindow = [self myScreenInit:[[UIScreen screens] objectAtIndex:1]]; [self.secondWindow addSubview:[self createFullscreenViewForText:@"Second window" withSize:CGSizeMake(640, 480)]]; } } 

This code works in the simulator when I turn on TV Out, although it always crashes if I turn on TV Out during debugging. I need to restart the application after turning on the TV-out in the hardware menu in the simulator. When I restart, I see the second UILabel screen on the second screen. On iPhone 4S, I can only do this job if I turn on AirPlay using the AirPlay control in the running task bar all the way to the left. You will notice that I added the MPVolumeView component to the startup view that I am trying to use to connect to my Apple TV to no avail.

If I use the MPVolumeView application in the application, I can successfully disconnect from the Apple TV, but when I use it again and select the Apple TV to reconnect, I do not get UIScreenDidConnectNotification. Again, the only time I see a second screen, I turn on mirroring. If I connect to either an AirPlay control, I only count 1 screen and never get a notification. In addition, every time I turn on mirroring, I see this in the console logs:

 Could not find mapped image ColorOnGrayShadow_AirPlay.png 

This seems to be broken, and I would like to know what other people have experienced in this area. I will continue the game and update this post when I learn new things.

+2
source share
1 answer

The MPVolumeView Route Menu can only control the audio stream going to AppleTV. Here is a working example of what you are trying to do: https://github.com/quellish/AirplayDemo/

The log message "ColorOnGrayShadow_AirPlay.png" is normal for iOS 5. Using the Airplay-related AppleTV as an external display, unfortunately, requires mirroring, and you cannot activate it from your application. The user must follow these instructions:

http://support.apple.com/kb/TS4085

+5
source

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


All Articles