iOS: Is there a way to programmatically reset AirPlay back to the iPad?

| | August 18, 2015

I have an iOS app that plays video using the AVPlayer, and I want to enable AirPlay. Using information from here: https://developer.apple.com/library/iad/documentation/AudioVideo/Conceptual/AirPlayGuide/EnrichYourAppforAirPlay/EnrichYourAppforAirPlay.html, I successfully added the AirPlay icon:

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

And it works. When the video is playing, I can tap the icon, select my Apple TV, the icon turns blue, and the video plays through the Apple TV.

Now here’s my question: If I simply exit from the player portion of my app, AirPlay seems to remain set to the Apple TV. If I play another video, even though my app creates a new instance of AVPlayer, the icon is blue and the video plays through the Apple TV. Is there a way that I can programmatically reset AirPlay back to the IPad when the user exits from the player portion of my app? I don’t see anything on MPVolumeView that looks like it would do that.

Leave a Reply