Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS ReplayKit stop recording microphone if i play AVPlayer during recording

i am using ReplayKit's RPScreenRecorder.shared().startCapture method to record screen and microphone, but i am facing an issue. if i play AVPlayer while ScreenRecording, the microphone stops recording audio. Below are two scenario. in first everything working fine but in second voice recording not working.

  1. started AVPlayer and then start screenRecording, AVPlayer's Audio stop and my screen and microphone start recording

  2. started screenRecording and working fine. then i start the AVPlayer and when AVPlayer play the audio the voice recording is stopped

like image 713
Ajay saini Avatar asked Oct 12 '25 05:10

Ajay saini


1 Answers

After digging a lot i found a solution. Default AVFoundation Allow to use either Microphone or Speaker at a time and ReplayKit is incompatible with AVPlayer content. So if we want to use both of them at a time we need to set AVAudioSession's Category to AVAudioSessionCategoryMultiRoute.

do {
    try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryMultiRoute)
} catch let error as NSError {
    print(error)
}

do {
    try AVAudioSession.sharedInstance().setActive(true)
} catch let error as NSError {
    print(error)
} 
like image 192
Ajay saini Avatar answered Oct 14 '25 20:10

Ajay saini



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!