Search code examples
iosswiftreplaykit

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


Solution

  • 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)
    }