AgoraMediaRecorder Class Reference

Inherits from NSObject
Declared in AgoraRtcEngineKit.h

Overview

The AgoraMediaRecorder interface, for recording the audio and video on the client. AgoraMediaRecorder can record the following content:

  • The audio captured by the local microphone and encoded in AAC format.
  • The video captured by the local camera and encoded by the SDK.

Note: In the Communication channel profile, this function is unavailable when there are users using versions of the SDK earlier than v3.0.0 in the channel.

+ sharedMediaRecorderWithRtcEngine:delegate:

Creates an AgoraMediaRecorder instance.

+ (instancetype _Nonnull)sharedMediaRecorderWithRtcEngine:(AgoraRtcEngineKit *_Nonnull)engine delegate:(id<AgoraMediaRecorderDelegate> _Nullable)delegate

Parameters

engine

AgoraRtcEngineKit

delegate

AgoraMediaRecorderDelegate

Return Value

AgoraMediaRecorder

Availability

v3.5.2

Discussion

Note: Call this method after creating AgoraRtcEngineKit.

Declared In

AgoraRtcEngineKit.h

+ destroy

Destroys the AgoraMediaRecorder instance.

+ (void)destroy

Availability

v3.5.2

This method releases AgoraRtcEngineKit and all other resources used by AgoraMediaRecorder. After calling this method, if you want to enable the recording again, you must call sharedMediaRecorderWithRtcEngine to get AgoraMediaRecorder.

Declared In

AgoraRtcEngineKit.h

– enableMainQueueDispatch:

Enables/Disables dispatching delegate methods to the main queue.

- (int)enableMainQueueDispatch:(BOOL)enabled

Parameters

enabled

Sets whether or not to dispatch delegate methods to the main queue:

  • YES: Dispatch delegate methods to the main queue.
  • NO: Do not dispatch delegate methods to the main queue

Return Value

  • 0: Success.
  • < 0: Failure.

Availability

v3.5.2

If disabled, the app should dispatch UI operations to the main queue.

Declared In

AgoraRtcEngineKit.h

– startRecording:

Starts recording the local audio and video.

- (int)startRecording:(AgoraMediaRecorderConfiguration *_Nonnull)config

Parameters

config

The recording configurations. See AgoraMediaRecorderConfiguration.

Return Value

  • 0: Success.
  • < 0: Failure.

  • -2(AgoraErrorCodeInvalidArgument): 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(AgoraErrorCodeNotSupported): AgoraRtcEngineKit does not support the request due to one of the following reasons:

    • The recording is ongoing.
    • The recording stops because an error occurs.
  • -7(AgoraErrorCodeNotInitialized): This method is called before you create AgoraRtcEngineKit. Ensure that you have called sharedMediaRecorderWithRtcEngine before calling startRecording.

Availability

v3.5.2

After successfully getting the object, you can call this method to enable the recording of the local audio and video.

This method can record the following content:

  • The audio captured by the local microphone and encoded in AAC format.
  • The video captured by the local camera and encoded by the SDK.

The SDK can generate a recording file only when it detects the recordable 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 recording and triggers the stateDidChanged(AgoraMediaRecorderStateError, AgoraMediaRecorderErrorCodeNoStream)callback.

Discussion

Note: Call this method after joining the channel.

Declared In

AgoraRtcEngineKit.h

– stopRecording

Stops recording the local audio and video.

- (int)stopRecording

Return Value

  • 0: Success.
  • < 0: Failure.

    • -7(AgoraErrorCodeNotInitialized): This method is called before you create AgoraRtcEngineKit. Ensure that you have called sharedMediaRecorderWithRtcEngine before calling stopRecording.

Availability

v3.5.2

Discussion

Note: After calling startRecording, if you want to stop the recording, you must call stopRecording; otherwise, the generated recording files might not be playable.

Declared In

AgoraRtcEngineKit.h