AgoraMediaRecorder
Used for recording audio and video on the client.
- The audio captured by the local microphone and encoded in AAC format.
- The video captured by the local camera and encoded by the SDK.
COMMUNICATION
channel profile, this feature is unavailable when there are users using
SDK versions earlier than v3.0.0.sharedMediaRecorderWithRtcEngine
Creates an AgoraMediaRecorder instance.
+ (instancetype _Nonnull)sharedMediaRecorderWithRtcEngine:(AgoraRtcEngineKit* _Nonnull)engine;
Parameters
- engine
- An AgoraRtcEngineKit object.
Returns
One AgoraMediaRecorder object.
enableMainQueueDispatch
Enables/Disables dispatching delegate methods to the main queue.
- (int)enableMainQueueDispatch:(BOOL)enabled;
If disabled, the app should dispatch UI operations to the main queue.
Parameters
- enabled
-
YES
: Dispatch delegate methods to the main queue.NO
: Do not dispatch delegate methods to the main queue.
Returns
- 0: Success.
- < 0: Failure.
setMediaRecorderDelegate
Registers one AgoraMediaRecorderDelegate object.
- (int)setMediaRecorderDelegate:(AgoraRtcConnection * _Nonnull)connection delegate:(id<AgoraMediaRecorderDelegate> _Nullable)delegate;
Make sure the AgoraRtcEngineKit is initialized before you call this method.
Parameters
- connection
- The connection information. See AgoraRtcConnection.
- callback
- The callbacks for recording local audio and video streams. See AgoraMediaRecorderDelegate.
Returns
- 0: Success.
- < 0: Failure.
startRecording
Starts recording the local audio and video.
- (int)startRecording:(AgoraRtcConnection * _Nonnull)connection config:(AgoraMediaRecorderConfiguration* _Nonnull)config;
After successfully getting the AgoraMediaRecorder object, you can all this method to enable the recoridng of the local audio and video.
This method can record the audio captured by the local microphone and encoded in AAC format, and the video captured by the local camera and encoded in H.264 format. The SDK can generate a recording file only when it detects audio and video streams; when there are no audio and video streams to be recorded or the audio and video streams are interrupted for more than five seconds, the SDK stops the recording and triggers the stateDidChanged(AgoraMediaRecorderStateError, AgoraMediaRecorderErrorCodeNoStream)
callback.
Once the recording is started, if the video resolution is changed, the SDK stops the recording; if the sampling rate and audio channel changes, the SDK continues recording and generates audio files respectively.
Parameters
- connection
- The connection information. See AgoraRtcConnection.
- config
- The recording configuration. See AgoraMediaRecorderConfiguration.
Returns
- 0: Success.
- < 0: Failure.
- 2: The parameter is invalid. Ensure the following:
- The specified path of the recording file exists and is writable.
- The specified format of the recording file is supported.
- The maximum recording duration is correctly set.
- 4: AgoraRtcEngineKit does not support the request. The recording is ongoing or the recording stops because an error occurs.
- 7: A method is called before AgoraRtcEngineKit is initialized. Ensure that you have called sharedMediaRecorderWithRtcEngine before calling this method.
- 2: The parameter is invalid. Ensure the following:
stopRecording
Stops recording the local audio and video.
- (int)stopRecording:(AgoraRtcConnection * _Nonnull)connection;
Parameters
- connection
- The connection information. See AgoraRtcConnection.
Returns
- 0: Success.
- < 0: Failure.
- -7: A method is called before AgoraRtcEngineKit is initialized. Ensure that you have called sharedMediaRecorderWithRtcEngine before calling this method.
destroy
Release the AgoraMediaRecorder object.
+ (void)destroy;
This method releases the AgoraMediaRecorder object and all resources used by the AgoraRtcEngineKit object. After calling this method, if you need to start recording again, you need to call sharedMediaRecorderWithRtcEngine again to get the AgoraMediaRecorder object.