The AgoraMediaRecorder class, for recording the audio and video on the client. AgoraMediaRecorder can record the following content:
More...
The AgoraMediaRecorder class, 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 by the SDK.
- The video captured by the local camera and encoded by the SDK.
- Since
- v3.5.2
- 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.
◆ setMediaRecorderObserver()
Registers an IMediaRecorderCallback observer.
- Since
- v4.0.0
This method sets the callback for audio and video recording, so that the app can be notified of the recording status and information of the audio and video streams during the recording process. Before calling this method, make sure that:
- The
RtcEngine object has been created and initialized.
- The audio and video recording object has been created via
createMediaRecorder.
- Parameters
-
- Returns
- 0: The method call succeeds.
- < 0: The method call fails.
◆ startRecording()
Starts recording audio and video streams.
This method starts recording audio and video streams. The Agora SDK supports recording both local and remote users' audio and video streams simultaneously. Before starting the recording, make sure that:
- You have created a media recorder object using
createMediaRecorder.
- You have registered a media recorder observer using
setMediaRecorderObserver to listen for recording-related callbacks.
- You have joined a channel.
This method supports recording the following data:
- Audio captured by the microphone in AAC format.
- Video captured by the camera in H.264 or H.265 format.
After recording starts, if the video resolution changes during the recording process, the SDK stops the recording. If the audio sample rate or number of channels changes, the SDK continues recording and generates a single MP4 file. A recording file is successfully generated only when recordable audio or video streams are detected. If no recordable stream is available, or if the audio or video stream is interrupted for more than 5 seconds during recording, the SDK stops the recording and triggers the onRecorderStateChanged (RECORDER_STATE_ERROR, RECORDER_REASON_NO_STREAM) callback.
- Note
- If you want to record the local audio and video streams, make sure the local user role is set to broadcaster before starting the recording.
- If you want to record remote users' audio and video streams, make sure you have subscribed to the remote users' audio and video streams before starting the recording.
- Parameters
-
- Returns
- 0: The method call succeeds.
- < 0: The method call fails.
- -2: Invalid parameter. Make sure that:
- The specified file path for saving the recording is correct and writable.
- The specified recording file format is correct.
- The maximum recording duration is set correctly.
- -4: The current state of
RtcEngine does not support this operation. This may occur if recording is already in progress or if it stopped due to an error.
- -7: The method is called before
RtcEngine is initialized. Make sure you have created the AgoraMediaRecorder object before calling this method.
◆ stopRecording()
| int io.agora.rtc2.AgoraMediaRecorder.stopRecording |
( |
| ) |
|
Stops recording audio and video streams.
- Note
- After calling
startRecording, if you want to stop the recording, you must call this method; otherwise, the generated recording file may not play properly.
- Returns
- 0: The method call succeeds.
- < 0: The method call fails:
- -7: The method is called before the
RtcEngine is initialized. Make sure that the Recorder object has been created before calling this method.
◆ RECORDER_STATE_ERROR
| final int io.agora.rtc2.AgoraMediaRecorder.RECORDER_STATE_ERROR = -1 |
|
static |
-1: An error occurs during the recording. See error message for the reason.
◆ RECORDER_STATE_START
| final int io.agora.rtc2.AgoraMediaRecorder.RECORDER_STATE_START = 2 |
|
static |
2: The audio and video recording is started.
◆ RECORDER_STATE_STOP
| final int io.agora.rtc2.AgoraMediaRecorder.RECORDER_STATE_STOP = 3 |
|
static |
3: The audio and video recording is stopped.
◆ RECORDER_REASON_NONE
| final int io.agora.rtc2.AgoraMediaRecorder.RECORDER_REASON_NONE = 0 |
|
static |
◆ RECORDER_REASON_WRITE_FAILED
| final int io.agora.rtc2.AgoraMediaRecorder.RECORDER_REASON_WRITE_FAILED = 1 |
|
static |
1: The SDK fails to write the recorded data to a file.
◆ RECORDER_REASON_NO_STREAM
| final int io.agora.rtc2.AgoraMediaRecorder.RECORDER_REASON_NO_STREAM = 2 |
|
static |
2: The SDK does not detect audio and video streams to be recorded, or audio and video streams are interrupted for more than five seconds during recording.
◆ RECORDER_REASON_OVER_MAX_DURATION
| final int io.agora.rtc2.AgoraMediaRecorder.RECORDER_REASON_OVER_MAX_DURATION = 3 |
|
static |
3: The recording duration exceeds the upper limit.
◆ RECORDER_REASON_CONFIG_CHANGED
| final int io.agora.rtc2.AgoraMediaRecorder.RECORDER_REASON_CONFIG_CHANGED = 4 |
|
static |
4: The recording configuration changes.
◆ STREAM_TYPE_AUDIO
| final int io.agora.rtc2.AgoraMediaRecorder.STREAM_TYPE_AUDIO = 0x1 |
|
static |
◆ STREAM_TYPE_VIDEO
| final int io.agora.rtc2.AgoraMediaRecorder.STREAM_TYPE_VIDEO = 0x2 |
|
static |
◆ STREAM_TYPE_BOTH
3: Record both audio and video.
◆ CONTAINER_MP4
| final int io.agora.rtc2.AgoraMediaRecorder.CONTAINER_MP4 = 1 |
|
static |