Agora Java API Reference for Android
io.agora.rtc.AgoraMediaRecorder Class Reference

Classes

interface  IMediaRecorderCallback
 
class  MediaRecorderConfiguration
 
class  RecorderInfo
 

Public Member Functions

int startRecording (MediaRecorderConfiguration config)
 
int stopRecording ()
 
void release ()
 

Static Public Member Functions

static AgoraMediaRecorder getMediaRecorder (RtcEngine engine, IMediaRecorderCallback callback)
 

Static Public Attributes

static final int RECORDER_STATE_ERROR = -1
 
static final int RECORDER_STATE_START = 2
 
static final int RECORDER_STATE_STOP = 3
 
static final int RECORDER_ERROR_NONE = 0
 
static final int RECORDER_ERROR_WRITE_FAILED = 1
 
static final int RECORDER_ERROR_NO_STREAM = 2
 
static final int RECORDER_ERROR_OVER_MAX_DURATION = 3
 
static final int RECORDER_ERROR_CONFIG_CHANGED = 4
 
static final int RECORDER_ERROR_CUSTOM_STREAM_DETECTED = 5
 
static final int STREAM_TYPE_AUDIO = 0x1
 
static final int STREAM_TYPE_VIDEO = 0x2
 
static final int STREAM_TYPE_BOTH = STREAM_TYPE_AUDIO | STREAM_TYPE_VIDEO
 
static final int CONTAINER_MP4 = 1
 

Detailed Description

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.

Member Function Documentation

◆ getMediaRecorder()

static AgoraMediaRecorder io.agora.rtc.AgoraMediaRecorder.getMediaRecorder ( RtcEngine  engine,
IMediaRecorderCallback  callback 
)
static

Gets the AgoraMediaRecorder object.

Note
Call this method after initializing the RtcEngine object.
Parameters
engineThe RtcEngine object. See RtcEngine.
callbackThe IMediaRecorderCallback instance. See IMediaRecorderCallback.
Returns
The AgoraMediaRecorder object.

◆ startRecording()

int io.agora.rtc.AgoraMediaRecorder.startRecording ( MediaRecorderConfiguration  config)

Starts recording the local audio and video.

After successfully getting the AgoraMediaRecorder 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 onRecorderStateChanged(RECORDER_STATE_ERROR, RECORDER_ERROR_NO_STREAM) callback.

Note
Call this method after joining the channel.
Parameters
configThe recording configurations. See MediaRecorderConfiguration.
Returns
  • 0: Success.
  • < 0: Failure:
    • -2(ERR_INVALID_ARGUMENT): 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(ERR_NOT_SUPPORTED): RtcEngine does not support the request due to one of the following reasons:
      • The recording is ongoing.
      • The recording stops because an error occurs.
    • -7(ERR_NOT_INITIALIZED): The SDK is not initialized before calling this method. Ensure that you have called getMediaRecorder before calling startRecording.

◆ stopRecording()

int io.agora.rtc.AgoraMediaRecorder.stopRecording ( )

Stops recording the local audio and video.

Note
After calling startRecording, if you want to stop the recording, you must call stopRecording; otherwise, the generated recording files might not be playable.
Returns
  • 0: Success.
  • < 0: Failure:
    • -7(ERR_NOT_INITIALIZED): The SDK is not initialized before calling this method. Ensure that you have called getMediaRecorder before calling startRecording.

◆ release()

void io.agora.rtc.AgoraMediaRecorder.release ( )

Releases the AgoraMediaRecorder object.

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

Member Data Documentation

◆ RECORDER_STATE_ERROR

final int io.agora.rtc.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.rtc.AgoraMediaRecorder.RECORDER_STATE_START = 2
static

2: The audio and video recording is started.

◆ RECORDER_STATE_STOP

final int io.agora.rtc.AgoraMediaRecorder.RECORDER_STATE_STOP = 3
static

3: The audio and video recording is stopped.

◆ RECORDER_ERROR_NONE

final int io.agora.rtc.AgoraMediaRecorder.RECORDER_ERROR_NONE = 0
static

0: No error occurs.

◆ RECORDER_ERROR_WRITE_FAILED

final int io.agora.rtc.AgoraMediaRecorder.RECORDER_ERROR_WRITE_FAILED = 1
static

1: The SDK fails to write the recorded data to a file.

◆ RECORDER_ERROR_NO_STREAM

final int io.agora.rtc.AgoraMediaRecorder.RECORDER_ERROR_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_ERROR_OVER_MAX_DURATION

final int io.agora.rtc.AgoraMediaRecorder.RECORDER_ERROR_OVER_MAX_DURATION = 3
static

3: The recording duration exceeds the upper limit.

◆ RECORDER_ERROR_CONFIG_CHANGED

final int io.agora.rtc.AgoraMediaRecorder.RECORDER_ERROR_CONFIG_CHANGED = 4
static

4: The recording configuration (MediaRecorderConfiguration) changes.

◆ RECORDER_ERROR_CUSTOM_STREAM_DETECTED

final int io.agora.rtc.AgoraMediaRecorder.RECORDER_ERROR_CUSTOM_STREAM_DETECTED = 5
static

5: The SDK detects audio and video streams from users using versions of the SDK earlier than v3.0.0 in the COMMUNICATION channel profile.

◆ STREAM_TYPE_AUDIO

final int io.agora.rtc.AgoraMediaRecorder.STREAM_TYPE_AUDIO = 0x1
static

1: Record audio only.

◆ STREAM_TYPE_VIDEO

final int io.agora.rtc.AgoraMediaRecorder.STREAM_TYPE_VIDEO = 0x2
static

2: Record video only.

◆ STREAM_TYPE_BOTH

final int io.agora.rtc.AgoraMediaRecorder.STREAM_TYPE_BOTH = STREAM_TYPE_AUDIO | STREAM_TYPE_VIDEO
static

3: Record both audio and video.

◆ CONTAINER_MP4

final int io.agora.rtc.AgoraMediaRecorder.CONTAINER_MP4 = 1
static

1: MP4 format.