2

I'm trying to use ReplayKit to create a live broadcast inside of my app. Basically I want to share my screen and see the screen of the other user.

To get the buffers, ReplayKit offers the next function:

func startCapture(handler captureHandler: ((CMSampleBuffer, RPSampleBufferType, Error?) -> Void)?, completionHandler: ((Error?) -> Void)? = nil)

So this is my method to startup ReplayKit and get the buffers:

private func startRecording() {
    RPScreenRecorder.shared().startCapture(handler: { (sampleBuffer, bufferType, error) in
        switch bufferType {

        case RPSampleBufferType.video:
            // Handle buffer and send it to server
            break

        case RPSampleBufferType.audioApp:
            break
        case RPSampleBufferType.audioMic:
            break
        }

    }, completionHandler: nil)
}

This works perfectly, but I'm facing the next issue; if the screen gets changes constantly, like a flashing button, when I send the app to background and come back several times ReplayKit stops calling its capture handler.

Maybe the problem is that the function startCapture is made to record the screen for a limited time, and not for a live broadcast.

I have made an example in Github with a flashing button that shows the problem that I'm having; ReplayKit runs normally until going to background repeatedly; then it stops, and the only way to make it work again is to reboot the device.

DiegoQ
  • 1,114
  • 11
  • 20

0 Answers0