【发布时间】:2010-04-05 15:21:32
【问题描述】:
我试图从 iPhone 上的 kAudioSessionProperty_OtherMixableAudioShouldDuck 属性中获得一致的行为,以允许 iPod 音乐混合,但我遇到了问题。在我的应用程序开始时,我设置了一个环境类别,如下所示:
-(void) initialize
{
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryAmbient error: nil];
}
稍后当我尝试播放音频时,我使用以下方法设置了鸭子属性:
//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);
}
我称之为在播放音频之前传递一个数字“1”,如下所示:
[self toggleCrossfadeOn:1];
[player play];
然后,当我的应用程序的音频完成时,我再次调用 crossfade 方法并传递一个零,使用播放停止回调,如下所示:
-(void) playbackIsStoppingForPlayer:(MQAudioPlayer*)audioPlayer
{
NSLog(@"Releasing player");
[audioPlayer release];
[self toggleCrossfadeOn:0];
}
在我的生产应用程序中,这个确切的代码按预期工作,导致 ipod 在播放我的应用程序音频之前淡出,然后在音频播放完毕后淡入。在我最近开始的一个新项目中,我得到了不同的行为。 iPod 音频淡出,并且永远不会淡入。在我的生产应用程序中,我使用 AVAudioPlayer,在我的新应用程序中,我编写了一个使用音频队列的自定义音频播放器。有人可以帮助我了解这些差异以及如何正确使用此 API 吗?
【问题讨论】:
标签: iphone core-audio