2

Trying to show a custom screen on an external display connected to apple tv using airplay. We are also trying to stream audio via AppleTV after the pairing. (Audio is optional here, it's good to have but not required).

The problem is, if we do audio playback (using AVAudioPlayer), it works fine as expected, but cannot display the custom screen. On the other hand, selecting it from the Control Center makes it work fine except that we don't want to mirror the screen, we want to display a custom view.

Any help in this regard is much appreciated.

Uploaded a sample code for the AirPlay issue in dropbox - https://dl.dropboxusercontent.com/u/1307156/AirplayDemo.zip

user845730
  • 93
  • 1
  • 1
  • 6

1 Answers1

2

What you're trying to do is actually quite simple: Once an external screen has been added you can create a new UIWindow, a new UIViewController, which will be controlling your custom view displayed to the external screen, and set that just created window to the external UIScreen.

// new window binding
newWindow.screen = externalScreen;
[newWindow makeKeyAndVisible];

You can observe changes over external screens (a screen added, removed, changes over screenModes) through the NSNotificationCenter and do something accordingly for your purposes.

HepaKKes
  • 1,555
  • 13
  • 22
  • Only thing is I need to use the mirroring to make it work. Is there any way to do it within the app? – user845730 Jun 05 '14 at 03:50
  • No, there's no way. Apple doesn't allow developers to enable screen mirroring programmatically. I.e., screen mirroring starts as long as users decide to do so through Control Centre. There are a few hacky solutions which don't resolve the main issue...I stumbled upon this [one](http://spin.atomicobject.com/2012/04/23/ios-mirroring-and-programmatic-airplay-selection/), but the iOS-runtime-headers cited in there don't do the trick apparently. Plus, that would be a solution that Apple is never going to approve. :) – HepaKKes Jun 05 '14 at 13:34