我基本上设置了一个带有播放和录制的会话,并与其他人混合选项,以便在我的应用运行时保持底层ipod继续播放。
它主要有用,但我有两个问题: 1)混合时ipod声音听起来很糟糕; 2)当我的应用程序在播放声音之前设置会话时,我的声音出现故障。
知道为什么吗?这是我的代码:
NSError *error = NULL;
BOOL success;
AVAudioSession *session = [AVAudioSession sharedInstance];
success = [session setActive:NO error:&error];
if (!success){
NSLog(@"startAudioMixAndBackground: session setActive:NO, %@", error.description);
}
AVAudioSessionCategoryOptions options = AVAudioSessionCategoryOptionAllowBluetooth
|AVAudioSessionCategoryOptionMixWithOthers;
success = [session setCategory:AVAudioSessionCategoryPlayAndRecord
withOptions: options
error: &error];
if (error) {
// Do some error handling
NSLog(@"startAudioMixAndBackground: setCategory:AVAudioSessionCategoryPlayback, %@", error.description);
}
//activate the audio session
success = [session setActive:YES error:&error];