Using kAudioSessionProperty_OtherMixableAudioShouldDuck on iPhone
- by Cliff
Hello,
I'm trying to get consistant behavior out of the kAudioSessionProperty_OtherMixableAudioShouldDuck property on the iPhone to allow iPod music blending and I'm having trouble. At the start of my app I set an Ambient category like so:
-(void) initialize
{
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryAmbient error: nil];
}
Later on when I attempt to play audio I set the duck property using the following method:
//this will crossfade the audio with the ipod music
- (void) toggleCrossfadeOn:(UInt32)onOff
{
//crossfade the ipod music
AudioSessionSetProperty(kAudioSessionProperty_OtherMixableAudioShouldDuck,sizeof(onOff),&onOff);
AudioSessionSetActive(onOff);
}
I call this passing a numeric "1" just before playing audio like so:
[self toggleCrossfadeOn:1];
[player play];
I then call the crossfade method again passing a zero when my app's audio completes using a playback is stopping callback like so:
-(void) playbackIsStoppingForPlayer:(MQAudioPlayer*)audioPlayer
{
NSLog(@"Releasing player");
[audioPlayer release];
[self toggleCrossfadeOn:0];
}
In my production app this exact code works as expected, causing the ipod to fade out just before playing my app's audio then fade back in when the audio finishes playing. In a new project I recently started, I get different behavior. The iPod audio fades down and never fades back in. In my production app I use the AVAudioPlayer where in my new app I've written a custom audio player that uses audio queues. Could somebody help me understand the differences and how to properly use this API?