iOS 播放音频与录制音频并发

在进行智能语音控制VR场景的功能需求下, 遇到了H5展示的krpano语音播放背景音乐, 与智能语音 录制检测 控制产生了冲突, 二者只能存其一, 小知识点解决方案记录:

-(void)setRecordPlayAtSameTime
{
    if(![[AVAudioSession sharedInstance].category isEqualToString: AVAudioSessionCategoryPlayAndRecord] ||
       !([AVAudioSession sharedInstance].categoryOptions== (AVAudioSessionCategoryOptionDefaultToSpeaker | AVAudioSessionCategoryOptionMixWithOthers))) {
        
        [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker |
         AVAudioSessionCategoryOptionMixWithOthers error:nil];
        
    }
    
    [[AVAudioSession sharedInstance]setActive:YES error:nil];
}

特此记录

你可能感兴趣的:(iOS 播放音频与录制音频并发)