ReplayKit start and stop capture breaks and give me an error when switching from Immersive to Mixed and back.

Hi, I'm developing a virtual camera system using ReplayKit to capture scene video by directly accessing raw video buffers. The capture mechanism works flawlessly when repeatedly starting and stopping video capture within a continuous immersive environment. However, a critical issue arises when interrupting the immersive space:

Step 1: Enter immersive environment and start and stop capture videos(Multiple times with no issues) Step 2: Press the crown button to exit the immersive environment Step 3: Return to the immersive space subsequently Step 4: Attempt to start the video capture

At this point, the startCapture method throws an unexpected error, disrupting the video capture workflow.

This is the Xcode error that I see " [ERROR] -[RPScreenRecorder startCaptureWithHandler:completionHandler:]_block_invoke_2:500 failed to start due to error: Error Domain=com.apple.ReplayKit.RPRecordingErrorDomain Code=-5803 "Recording failed to start" UserInfo={NSLocalizedDescription=Recording failed to start}"

I have tried all possible ways to stopCapture including OnDisappear and other methods and nothing seems to solve this.

Hi @krcnow

The behavior you're describing is unexpected. I was able to recreate it with this code:

struct ImmersiveView: View {
    var body: some View {
        RealityView { content in
            
        }
        .task {
            
            RPScreenRecorder.shared().startCapture(handler: { sampleBuffer, bufferType, error in
                print("recording \(Date.now)")

            }) { error in
                print("error", error as Any)
            }
        }
    }
}

As you indicated, the error occurs when you enter the immersive space then press the Digital Crown.

Our engineering teams need to investigate this issue, as resolution may involve changes to Apple's software. I'd greatly appreciate it if you could open a bug report and post the FB number here once you do.

Bug Reporting: How and Why? has tips on creating your bug report.

I'm not sure if it will work for your use case, but this post contains sample code that uses RealityRenderer to render a RealityKit scene as an image. In theory, you can use the PixelBuffers to create video. RealityRenderer also gives you complete control over the camera.

Thanks a lot for the reply. I have created a FB and here is the number FB16836177.

Also, exploring RealityRenderer as a potential replacement.

ReplayKit start and stop capture breaks and give me an error when switching from Immersive to Mixed and back.
 
 
Q