I would like to record videos with audio using AVCaptureSession
. For this I need the AudioSessionCategory AVAudioSessionCategoryPlayAndRecord
, since my
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.