ReplayKit doesn't work when work with webrtc

1.1k views Asked by At

I use WebRtc to create a peer to peer connection to share video and audio. i want to use replaykit to record Screen & Microphone.if i start recording after the peer connection has been established which means the two can share video and audio from each other.in this case,repalykit failed to record Screen & Microphone and previewController was black.if i start to record before connection has been established replaykit works well.if i choose record screen only or don't add RTCAudioTrack,it works all the time.
So how to use replaykit with webrtc?
You can start to test with apprtc-ios

1

There are 1 answers

0
Apparao Mulpuri On

Once the call is started, the device speaker, Microphone and Camera streams are added to the Peer connection and it won't available for other outputs in the app. Following new API introduced in iOS 11.

/*! @abstract Starts screen and audio capture and continually calls the 
supplied handler with the current sampleBuffer and bufferType and passed it 
back to the application. Note that before recording actually starts, the 
user may be prompted with UI to confirm recording.
@result handler Called continually with sampleBuffers and the bufferType. 
Will be passed an optional NSError in the RPRecordingErrorDomain domain if 
there was an issue starting the capture.
*/

- (void)startCaptureWithHandler:(nullable void(^)(CMSampleBufferRef 
sampleBuffer, RPSampleBufferType bufferType, NSError * _Nullable 
error))captureHandler completionHandler:(nullable void(^)(NSError * 
_Nullable error))completionHandler API_AVAILABLE(ios(11.0), tvos(11.0));

This API used for capturing the Speaker, Mic and Video sample buffers and you can able to write them into a file using AVAssetWriter from AVFoundation.