I am a bit confused. I have the following setup running. I am using the kAudioSessionCategory_PlayAndRecord category and the iPod plays some music in the background.
If I want to play some app music with the following category overrides, the iPod music will be stopped shortly through the [[AVAudioSession sharedInstance] setActive:YES...] call, but it seems that ducking and mixing works. The same will happen as soon as my app sound stops, again with the corresponding ...:setActive:NO] call. If I will use the MediaPlayback category the "blending" between app sound and iPod sound works fine without any interruptions. Category switch is not an option for me (i need also the bluetooth override), therefore I am looking forward if someone can help me with that issue.
- (IBAction) playAppSound: (id) sender {
NSError *activationError = nil;
[[AVAudioSession sharedInstance] setActive: NO error: &activationError];
// set internal speakers as default...
UInt32 useDefaultSpeakers = 1;
AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryDefaultToSpeaker,
sizeof(useDefaultSpeakers),
&useDefaultSpeakers);
// always try to enable ducking
UInt32 shouldDuck = 1;
AudioSessionSetProperty( kAudioSessionProperty_OtherMixableAudioShouldDuck,
sizeof(UInt32),
&shouldDuck );
UInt32 doSetProperty = 1;
AudioSessionSetProperty (
kAudioSessionProperty_OverrideCategoryMixWithOthers,
sizeof (doSetProperty),
&doSetProperty
);
// Activates the audio session.
[[AVAudioSession sharedInstance] setActive: YES error: &activationError];
[appSoundPlayer play];