3

I'm working on an app that displays 10 second preview videos to airplay enabled devices via MPMoviePlayerViewController. The user selects an airplay enabled device through the system action sheet provided by MPVolumeView, and then we start the MPMoviePlayerViewController.

I'm able to programmatically stop the movieplayer after 10 seconds, but I'd like to also "force" a route change so that the device doesn't think the route is still active (and so that the user doesn't need to first deselect that route before selecting other routes each subsequent time). I've been able to achieve the desired route change initially by using the following code, which assumes I've got a strong pointer to a shared AVAudioSession instance:

NSError *activationError = nil;
AVAudioSession *session = [AVAudioSession sharedInstance];
self.audioSession = session;
[self.audioSession setActive:YES error: &activationError];
[self.audioSession setCategory:AVAudioSessionCategoryPlayAndRecord
                         error: nil];
[self.audioSession overrideOutputAudioPort:AVAudioSessionPortOverrideNone error:nil];
[self.audioSession setCategory:AVAudioSessionCategorySoloAmbient
                         error: nil];

I'm setting the category to PlayAndRecord prior to overriding overrideOutputAudioPort as per Apple's documentation, and then attempting to set the category BACK to its default (SoloAmbient) right afterwards. Unfortunately, every subsequent time the user taps the MPVolumeView button and selects a route, the device turns on mirroring for that airplay enabled device and doesn't use the MPMoviePlayerController as desired.

Any thoughts on why mirroring gets turned on by default and/or how I can achieve the above desired effect without using deprecated methods?

Thanks in advance.

maxhs
  • 868
  • 2
  • 10
  • 14

0 Answers0