AVAudioSession AVAudioSessionCategoryPlayAndRecord glitch

佐手、 提交于 2019-12-02 23:52:35

As pointed out by @Cbas in the comments, an Apple Staff has confirmed there is glitch when switching from output-only to input+output routes and that there is no workaround for that issue, a possible workaround is to totally avoid switching from output-only to input-output routes by always use the AVAudioSessionCategoryPlayAndRecord category even when the app is not recording. Also, don't set the audio session category again if it has already be set to AVAudioSessionCategoryPlayAndRecord or the glitch will occur.

[self.captureSession startRunning];
[[AVAudioSession sharedInstance] setActive:NO withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:nil];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionMixWithOthers error:nil];
[[AVAudioSession sharedInstance] setActive:YES withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:nil];

When capureSession startRunning, deactive current audioSession and resume other interrupted music app on the background use this option AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation.

Reset the category AVAudioSessionCategoryPlayAndRecord with current audioSession,and avtive again.

I hope it works for you.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!