Agora Java API Reference for Android

Classes | Public Member Functions | Static Public Attributes | List of all members
io.agora.rtc2.AgoraMediaRecorder Class Reference

## Classes
class | MediaRecorderConfiguration

## Public Member Functions
| AgoraMediaRecorder (RtcEngineImpl engine, RecorderStreamInfo info)
int | setMediaRecorderObserver (IMediaRecorderCallback callback)
int | startRecording (MediaRecorderConfiguration config)
int | stopRecording ()
void | release ()

## 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_REASON_NONE = 0
static final int | RECORDER_REASON_WRITE_FAILED = 1
static final int | RECORDER_REASON_NO_STREAM = 2
static final int | RECORDER_REASON_OVER_MAX_DURATION = 3
static final int | RECORDER_REASON_CONFIG_CHANGED = 4
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

## ◆ setMediaRecorderObserver()

int io.agora.rtc2.AgoraMediaRecorder.setMediaRecorderObserver | ( | IMediaRecorderCallback | callback | ) |

Registers the IMediaRecorderCallback object.

Since
  v4.0.0

Note
  Call this method before the startRecording method.

Parameters

  callback | The callbacks for recording audio and video streams. See {IMediaRecorderCallback}. IMediaRecorder

## ◆ startRecording()

int io.agora.rtc2.AgoraMediaRecorder.startRecording | ( | MediaRecorderConfiguration | config | ) |

Starts recording the local or remote audio and video.

After successfully calling createMediaRecorder to get the media recorder 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.

This method can record the following content:

- The audio received from remote users and encoded in AAC format.
- The video received from remote users.

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

  config | The recording configurations. See {MediaRecorderConfiguration}. 0: Success.< 0: Failure:`-1(ERR_FAILED)`: IRtcEngine does not support the request due to one of the following reasons:During remote recording, There is no subscription to the target channel or user。-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.During remote recording, ensure the user whose media streams you want record did join the channel.-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.No io.agora.rtc2.IMediaRecorderCallback IMediaRecorderCallback} object is registered.

## ◆ stopRecording()

int io.agora.rtc2.AgoraMediaRecorder.stopRecording | ( |  | ) |

Stops recording the 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`): This method is called before the initialization of `RtcEngine`. Ensure that you have called getMediaRecorder before calling `startRecording`.

## Member Data Documentation

## ◆ 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

0: No error occurs.

## ◆ 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

1: Record audio only.

## ◆ STREAM_TYPE_VIDEO

final int io.agora.rtc2.AgoraMediaRecorder.STREAM_TYPE_VIDEO = 0x2
| static

2: Record video only.

## ◆ STREAM_TYPE_BOTH

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

3: Record both audio and video.

## ◆ CONTAINER_MP4

final int io.agora.rtc2.AgoraMediaRecorder.CONTAINER_MP4 = 1
| static

1: MP4 format.