My app supports either Audio from an external music app (like Pandora) or playing from within the app, using an AVPlayer to play AVPlayerItem from iPod library.
In my AppDelegate, I call: - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
AudioSessionInitialize(NULL, NULL, interruptionListenerCallback, self);
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: nil];
UInt32 otherAudioIsPlaying;
UInt32 propertySize = sizeof (otherAudioIsPlaying);
AudioSessionGetProperty (
kAudioSessionProperty_OtherAudioIsPlaying,
&propertySize,
&otherAudioIsPlaying
);
if (otherAudioIsPlaying) {
NSLog(@"Allow Mixing for background music (like Pandora,...)");
UInt32 allowMixing = true;
AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof (allowMixing), &allowMixing);
}
[[AVAudioSession sharedInstance] setActive: YES error: NULL];
...
note that I register also for interruption.
So, if app is started while Pandora is playing, Pandora will keep playing.
Later, if USer decides to play music from iPod library, I call: [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback withOptions: 0 error: nil]; and to make sure, I receive remote control events, I call: [self becomeFirstResponder]; [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
until here, everything works fine: app now plays music from iPod library (and Pandora was stopped when setting the category to Playback).
My problem comes when clicking the center button on headset. In the sequence described above, when clicking the center button, the interruptionListenerCallback gets called! I was expecting the remoteControlReceivedWithEvent callback to be c