2

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];
Alathink
  • 263
  • 1
  • 3
  • 11
  • 1
    I have some additional findings on that issue. In case of using the MediaPlayback category no route change will be triggered. Therefore no interruption is there. With the PlayAndRecord category a route change will be triggered with the kAudioSessionRouteChangeReason_CategoryChange reason. Because of this a small interruption occurs. Can I prevent this CategoryChange reason? – Alathink Feb 04 '13 at 13:45

1 Answers1

1

I've found that setting kAudioSessionProperty_OtherMixableAudioShouldDuck and kAudioSessionProperty_OverrideCategoryMixWithOthers on a kAudioSessionCategory_PlayAndRecord session makes unexpected things happen (ie the mix override fails). Does your app really have to duck other audio? When I removed that part from my app everything worked as I expected.

Spencer Williams
  • 902
  • 8
  • 26
  • Thanks for your comment, at least the interruption is gone if I am disabling the ducking. But it would be nice do have both, mixing and ducking that I still can hear the iPod sound in the background. I am looking forward for additional comments. Could this be a bug? It is not clear to me why a route change happens in case of using the PlayAndRecord category. Whats the difference here? – Alathink Feb 06 '13 at 13:48
  • Unfortunately I'm pretty new at this myself. I just noticed that PlayAndRecord doesn't like to duck others. If I uncover any more clues I'll share them. – Spencer Williams Feb 06 '13 at 18:46