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];
4

1 に答える 1

1

kAudioSessionProperty_OtherMixableAudioShouldDuck セッションを設定すると kAudioSessionProperty_OverrideCategoryMixWithOtherskAudioSessionCategory_PlayAndRecord予期しないことが発生することがわかりました(つまり、ミックスのオーバーライドが失敗します)。あなたのアプリは本当に他のオーディオをダッキングする必要がありますか? アプリからその部分を削除すると、すべてが期待どおりに機能しました。

于 2013-02-05T22:06:15.030 に答える