我試圖從iPhone上的kAudioSessionProperty_OtherMixableAudioShouldDuck屬性中獲得一致性行爲,以允許iPod音樂混合,並且遇到了麻煩。在我的應用程序開始我設定的環境類,像這樣:在iPhone上使用kAudioSessionProperty_OtherMixableAudioShouldDuck
-(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];
我再調用淡入淡出方法再次傳遞一個零,當我的應用程序的音頻完成使用播放停止回調,像這樣:
-(void) playbackIsStoppingForPlayer:(MQAudioPlayer*)audioPlayer
{
NSLog(@"Releasing player");
[audioPlayer release];
[self toggleCrossfadeOn:0];
}
在我的生產應用這個確切的代碼如預期,導致了iPod只是打我的應用程序的音頻,然後當音頻播放完畢的漸退之前淡出的作品。在我最近開始的一個新項目中,我得到了不同的行爲。 iPod音頻淡入淡出,永不褪色。在我的製作應用程序中,我使用AVAudioPlayer,在我的新應用程序中,我編寫了一個使用音頻隊列的自定義音頻播放器。有人可以幫助我理解差異以及如何正確使用此API?