RtcEngine

The basic interface of the Agora SDK that implements the core functions of real-time communication.

RtcEngine provides the main methods that your app can call.

Before calling other APIs, you must call createAgoraRtcEngine to create an RtcEngine object.

addVideoWatermark

Adds a watermark image to the local video.

Future<void> addVideoWatermark(
    {required String watermarkUrl, required WatermarkOptions options});

Details

This method adds a PNG watermark image to the local video in the live streaming. Once the watermark image is added, all the audience in the channel (CDN audience included), and the capturing device can see and capture it. The Agora SDK supports adding only one watermark image onto a local video or CDN live stream. The newly added watermark image replaces the previous one.

The watermark coordinates are dependent on the settings in the setVideoEncoderConfiguration method:
  • If the orientation mode of the encoding video (OrientationMode) is fixed landscape mode or the adaptive landscape mode, the watermark uses the landscape orientation.
  • If the orientation mode of the encoding video (OrientationMode) is fixed portrait mode or the adaptive portrait mode, the watermark uses the portrait orientation.
  • When setting the watermark position, the region must be less than the dimensions set in the setVideoEncoderConfiguration method; otherwise, the watermark image will be cropped.
Attention:
  • Ensure that calling this method after enableVideo.
  • If you only want to add a watermark to the media push, you can call this method or the method.
  • This method supports adding a watermark image in the PNG file format only. Supported pixel formats of the PNG image are RGBA, RGB, Palette, Gray, and Alpha_gray.
  • If the dimensions of the PNG image differ from your settings in this method, the image will be cropped or zoomed to conform to your settings.
  • If you have enabled the mirror mode for the local video, the watermark on the local video is also mirrored. To avoid mirroring the watermark, Agora recommends that you do not use the mirror and watermark functions for the local video at the same time. You can implement the watermark function in your application layer.

Parameters

watermarkUrl
The local file path of the watermark image to be added. This method supports adding a watermark image from the local absolute or relative file path.
options
The options of the watermark image to be added. See WatermarkOptions.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

adjustAudioMixingPlayoutVolume

Adjusts the volume of audio mixing for local playback.

Future<void> adjustAudioMixingPlayoutVolume(int volume);

Details

Attention: Call this method after calling startAudioMixing and receiving the onAudioMixingStateChanged(audioMixingStatePlaying) callback.

Parameters

volume
The volume of audio mixing for local playback. The value ranges between 0 and 100 (default). 100 represents the original volume.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

adjustAudioMixingPublishVolume

Adjusts the volume of audio mixing for publishing.

Future<void> adjustAudioMixingPublishVolume(int volume);

Details

This method adjusts the volume of audio mixing for publishing (sending to other users).

Attention:

Call this method after calling startAudioMixing and receiving the onAudioMixingStateChanged(audioMixingStatePlaying) callback.

Parameters

volume
The volume of audio mixing for local playback. The value ranges between 0 and 100 (default). 100 represents the original volume.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

adjustAudioMixingVolume

Adjusts the volume during audio mixing.

Future<void> adjustAudioMixingVolume(int volume);

Details

This method adjusts the audio mixing volume on both the local client and remote clients.

Attention:

Parameters

volume
Audio mixing volume. The value ranges between 0 and 100. The default value is 100, which means the original volume.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

adjustCustomAudioPlayoutVolume

Adjusts the volume of the custom audio track played locally.

Future<void> adjustCustomAudioPlayoutVolume(
      {required int trackId, required int volume});

Details

Attention: Ensure you have called the createCustomAudioTrack method to create a custom audio track before calling this method.

If you want to change the volume of the audio to be played locally, you need to call this method again.

Parameters

trackId
The audio track ID. Set this parameter to the custom audio track ID returned in createCustomAudioTrack.
volume
The volume of the audio source. The value can range from 0 to 100. 0 means mute; 100 means the original volume.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

  • < 0: Failure.

adjustCustomAudioPublishVolume

Adjusts the volume of the custom audio track played remotely.

Future<void> adjustCustomAudioPublishVolume(
      {required int trackId, required int volume});

Details

Attention: Ensure you have called the createCustomAudioTrack method to create a custom audio track before calling this method.

If you want to change the volume of the audio played remotely, you need to call this method again.

Parameters

trackId
The audio track ID. Set this parameter to the custom audio track ID returned in createCustomAudioTrack.
volume
The volume of the audio source. The value can range from 0 to 100. 0 means mute; 100 means the original volume.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

  • < 0: Failure.

adjustLoopbackSignalVolume

Adjusts the volume of the signal captured by the sound card.

Future<void> adjustLoopbackSignalVolume(int volume);

Details

After calling enableLoopbackRecording to enable loopback audio capturing, you can call this method to adjust the volume of the signal captured by the sound card.

Parameters

volume
Audio mixing volume. The value ranges between 0 and 100. The default value is 100, which means the original volume.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

  • < 0: Failure.

adjustPlaybackSignalVolume

Adjusts the playback signal volume of all remote users.

Future<void> adjustPlaybackSignalVolume(int volume);

Details

Attention:
  • This method adjusts the playback volume that is the mixed volume of all remote users.
  • You can call this method either before or after joining a channel.

Parameters

volume
The volume of the user. The value range is [0,400].
  • 0: Mute.
    Note: If you only need to mute the audio signal, Agora recommends that you use muteRecordingSignal instead.
  • 100: (Default) The original volume.
  • 400: Four times the original volume (amplifying the audio signals by four times).

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

adjustRecordingSignalVolume

Adjusts the capturing signal volume.

Future<void> adjustRecordingSignalVolume(int volume);

Details

Attention:

You can call this method either before or after joining a channel.

Parameters

volume
The volume of the user. The value range is [0,400].
  • 0: Mute.
    Note: If you only need to mute the audio signal, Agora recommends that you use muteRecordingSignal instead.
  • 100: (Default) The original volume.
  • 400: Four times the original volume (amplifying the audio signals by four times).

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

adjustUserPlaybackSignalVolume

Adjusts the playback signal volume of a specified remote user.

Future<void> adjustUserPlaybackSignalVolume(
    {required int uid, required int volume});

Details

You can call this method to adjust the playback volume of a specified remote user. To adjust the playback volume of different remote users, call the method as many times, once for each remote user.

Attention:
  • Call this method after joining a channel.
  • The playback volume here refers to the mixed volume of a specified remote user.

Parameters

uid
The user ID of the remote user.
volume
Audio mixing volume. The value ranges between 0 and 100. The default value is 100, which means the original volume.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

clearVideoWatermarks

Removes the watermark image from the video stream.

Future<void> clearVideoWatermarks();

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

complain

Allows a user to complain about the call quality after a call ends.

Future<void> complain({required String callId, required String description});

Details

This method allows users to complain about the quality of the call. Call this method after the user leaves the channel.

Parameters

callId
The current call ID. You can get the call ID by calling getCallId.
description
A description of the call. The string length should be less than 800 bytes.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

configRhythmPlayer

Configures the virtual metronome.

Future<void> configRhythmPlayer(AgoraRhythmPlayerConfig config);

Details

After calling startRhythmPlayer, you can call this method to reconfigure the virtual metronome.

After successfully calling this method, the SDK triggers the onRhythmPlayerStateChanged callback locally to report the status of the virtual metronome.

Attention:
  • This method is for Android and iOS only.
  • After enabling the virtual metronome, the SDK plays the specified audio effect file from the beginning, and controls the playback duration of each file according to beatsPerMinute you set in AgoraRhythmPlayerConfig. For example, if you set beatsPerMinute as 60, the SDK plays one beat every second. If the file duration exceeds the beat duration, the SDK only plays the audio within the beat duration.
  • By default, the sound of the virtual metronome is published in the channel. If you do not want the sound to be heard by the remote users, you can set publishRhythmPlayerTrack in ChannelMediaOptions as false.

Parameters

config
The metronome configuration. See AgoraRhythmPlayerConfig.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

initialize

Initializes RtcEngine.

Future<void> initialize(RtcEngineContext context);

Details

All called methods provided by the RtcEngine class are executed asynchronously. Agora recommends calling these methods in the same thread.

Attention:
  • Before calling other APIs, you must call createAgoraRtcEngine and initialize to create and initialize the RtcEngine object.
  • The SDK supports creating only one RtcEngine instance for an app.

Parameters

context

Configurations for the RtcEngine instance. See RtcEngineContext.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

  • < 0: Failure.
    • -1: A general error occurs (no specified reason).
    • -2: The parameter is invalid.
    • -7: The SDK is not initialized.
    • -22: The resource request failed. The SDK fails to allocate resources because your app consumes too much system resource or the system resources are insufficient.
    • -101: The App ID is invalid.

createAgoraRtcEngine

Creates one RtcEngine object.

RtcEngine createAgoraRtcEngine() {
  return impl.RtcEngineImpl.create();
}

Details

Currently, the Agora RTC SDK v6.x supports creating only one RtcEngine object for each app.

Returns

One RtcEngine object.

createDataStream

Creates a data stream.

Future<int> createDataStream(DataStreamConfig config);

Details

Creates a data stream. Each user can create up to five data streams in a single channel.

Parameters

config
The configurations for the data stream. See DataStreamConfig.

Returns

  • ID of the created data stream, if the method call succeeds.
  • < 0: Failure.

createMediaPlayer

Creates a media player instance.

Future<MediaPlayer> createMediaPlayer();

Returns

  • The MediaPlayer instance, if the method call succeeds.
  • An empty pointer, if the method call fails.

createCustomVideoTrack

Creates a custom video track.

Future<int> createCustomVideoTrack();

Details

To publish a custom video source, see the following steps:
  1. Call this method to create a video track and get the video track ID.
  2. Call joinChannel to join the channel. In ChannelMediaOptions, set customVideoTrackId to the video track ID that you want to publish, and set publishCustomVideoTrack to true.
  3. Call pushVideoFrame and specify videoTrackId as the video track ID set in step 2. You can then publish the corresponding custom video source in the channel.

Returns

  • If the method call is successful, the video track ID is returned as the unique identifier of the video track.
  • If the method call fails, a negative value is returned.

destroyCustomVideoTrack

Destroys the specified video track.

Future<void> destroyCustomVideoTrack(int videoTrackId);

Parameters

videoTrackId
The video track ID returned by calling the createCustomVideoTrack method.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

destroyMediaPlayer

Destroys the media player instance.

Future<void> destroyMediaPlayer(MediaPlayer mediaPlayer);

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

  • < 0: Failure.

disableAudio

Disables the audio module.

Future<void> disableAudio();

Details

Attention:
  • This method disables the internal engine and can be called anytime after initialization. It is still valid after one leaves channel.
  • This method resets the internal engine and takes some time to take effect. Agora recommends using the following API methods to control the audio modules separately:

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

disableAudioSpectrumMonitor

Disables audio spectrum monitoring.

Future<void> disableAudioSpectrumMonitor();

Details

After calling enableAudioSpectrumMonitor, if you want to disable audio spectrum monitoring, you can call this method.

Attention:

You can call this method either before or after joining a channel.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

disableVideo

Disables the video module.

Future<void> disableVideo();

Details

This method can be called before joining a channel or during a call to disable the video module. If it is called before joining a channel, an audio call starts when you join the channel; if called during a call, a video call switches to an audio call. Call enableVideo to enable the video module.

A successful call of this method triggers the onUserEnableVideo (false) callback on the remote client.

Attention:
  • This method affects the internal engine and can be called after leaving the channel.
  • This method resets the internal engine and thus might takes some time to take effect. Agora recommends using the following APIs to control the video modules separately:

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

enableAudio

Enables the audio module.

Future<void> enableAudio();

Details

The audio mode is enabled by default.

Attention:
  • This method enables the internal engine and can be called anytime after initialization. It is still valid after one leaves channel.
  • Calling this method will reset the entire engine, resulting in a slow response time. Instead of callling this method, you can independently control a specific audio module based on your actual needs using the following methods:
  • A successful call of this method resets enableLocalAudio, muteRemoteAudioStream, and muteAllRemoteAudioStreams. Proceed it with caution.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

enableAudioSpectrumMonitor

Turns on audio spectrum monitoring.

Future<void> enableAudioSpectrumMonitor({int intervalInMS = 100});

Details

If you want to obtain the audio spectrum data of local or remote users, you can register the audio spectrum observer and enable audio spectrum monitoring.

Attention:

You can call this method either before or after joining a channel.

Parameters

intervalInMS

The interval (in milliseconds) at which the SDK triggers the onLocalAudioSpectrum and onRemoteAudioSpectrum callbacks. The default value is 100. Do not set this parameter to a value less than 10, otherwise calling this method would fail.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

enableAudioVolumeIndication

Enables the reporting of users' volume indication.

Future<void> enableAudioVolumeIndication(
    {required int interval, required int smooth, required bool reportVad});

Details

This method enables the SDK to regularly report the volume information to the app of the local user who sends a stream and remote users (three users at most) whose instantaneous volumes are the highest. Once you call this method and users send streams in the channel, the SDK triggers the onAudioVolumeIndication callback at the time interval set in this method.

Attention: You can call this method either before or after joining a channel.

Parameters

interval
Sets the time interval between two consecutive volume indications:
  • ≤ 0: Disables the volume indication.
  • > 0: Time interval (ms) between two consecutive volume indications. Ensure this parameter is set to a value greater than 10, otherwise you will not receive the onAudioVolumeIndication callback. Agora recommends that this value is set as greater than 100.
smooth
The smoothing factor that sets the sensitivity of the audio volume indicator. The value ranges between 0 and 10. The recommended value is 3. The greater the value, the more sensitive the indicator.
reportVad
  • true: Enables the voice activity detection of the local user. Once it is enabled, the vad parameter of the onAudioVolumeIndication callback reports the voice activity status of the local user.
  • false: (Default) Disables the voice activity detection of the local user. Once it is disabled, the vad parameter of the onAudioVolumeIndication callback does not report the voice activity status of the local user, except for the scenario where the engine automatically detects the voice activity of the local user.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

  • < 0: Failure.

enableContentInspect

Enables or disables video screenshot and upload.

Future<void> enableContentInspect(
      {required bool enabled, required ContentInspectConfig config});

Details

When video screenshot and upload function is enabled, the SDK takes screenshots and uploads videos sent by local users based on the type and frequency of the module you set in ContentInspectConfig. After video screenshot and upload, the Agora server sends the callback notification to your app server in HTTPS requests and sends all screenshots to the third-party cloud storage service.

Note: Before calling this method, ensure that you have contacted technical support to activate the video screenshot upload service.

Parameters

enabled
Whether to enable video screenshot and upload:
  • true: Enables video screenshot and upload.
  • false: Disables video screenshot and upload.
config
Configuration of video screenshot and upload. See ContentInspectConfig.
Note: When the video moderation module is set to video moderation via Agora self-developed extension(contentInspectSupervision), the video screenshot and upload dynamic library libagora_content_inspect_extension.dll is required. Deleting this library disables the screenshot and upload feature.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

enableDualStreamMode

Sets the dual-stream mode on the sender side and the low-quality video stream.

Future<void> enableDualStreamMode(
      {required bool enabled, SimulcastStreamConfig? streamConfig});

Details

Deprecated:
This method is deprecated as of v4.2.0. Use setDualStreamMode instead.
You can call this method to enable or disable the dual-stream mode on the publisher side. Dual streams are a pairing of a high-quality video stream and a low-quality video stream:
  • High-quality video stream: High bitrate, high resolution.
  • Low-quality video stream: Low bitrate, low resolution.

After you enable dual-stream mode, you can call setRemoteVideoStreamType to choose to receive either the high-quality video stream or the low-quality video stream on the subscriber side.

Note:
  • This method is applicable to all types of streams from the sender, including but not limited to video streams collected from cameras, screen sharing streams, and custom-collected video streams.
  • If you need to enable dual video streams in a multi-channel scenario, you can call the enableDualStreamModeEx method.
  • You can call this method either before or after joining a channel.

Parameters

enabled
Whether to enable dual-stream mode:
  • true: Enable dual-stream mode.
  • false: (Default) Disable dual-stream mode.
streamConfig
The configuration of the low-quality video stream. See SimulcastStreamConfig.
Note: When setting mode to disableSimulcastStream, setting streamConfig will not take effect.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

enableEncryption

Enables or disables the built-in encryption.

Future<void> enableEncryption(
    {required bool enabled, required EncryptionConfig config});

Details

In scenarios requiring high security, Agora recommends calling this method to enable the built-in encryption before joining a channel.

All users in the same channel must use the same encryption mode and encryption key. After the user leaves the channel, the SDK automatically disables the built-in encryption. To enable the built-in encryption, call this method before the user joins the channel again.

Attention: If you enable the built-in encryption, you cannot use the Media Push function.

Parameters

enabled
Whether to enable built-in encryption:
  • true: Enable the built-in encryption.
  • false: Disable the built-in encryption.
config
Built-in encryption configurations. See EncryptionConfig.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

enableExtension

Enables or disables extensions.

Future<void> enableExtension(
    {required String provider,
    required String extension,
    bool enable = true,
    MediaSourceType type = MediaSourceType.unknownMediaSource});

Details

To call this method, call it immediately after initializing the RtcEngine object.

Note:
  • If you want to enable multiple extensions, you need to call this method multiple times.
  • The data processing order of different extensions in the SDK is determined by the order in which the extensions are enabled. That is, the extension that is enabled first will process the data first.

Parameters

provider
The name of the extension provider.
extension
The name of the extension.
enable
Whether to enable the extension:
  • true: Enable the extension.
  • false: Disable the extension.
type
Source type of the extension. See MediaSourceType.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

enableFaceDetection

Enables or disables face detection for the local user.

Future<void> enableFaceDetection(bool enabled);

Details

You can call this method either before or after joining a channel.

Attention: This method is for Android and iOS only.
Once face detection is enabled, the SDK triggers the onFacePositionChanged callback to report the face information of the local user, which includes the following:
  • The width and height of the local video.
  • The position of the human face in the local view.
  • The distance between the human face and the screen.

This method needs to be called after the camera is started (for example, by calling startPreview orenableVideo ).

Parameters

enabled
Whether to enable face detection for the local user:
  • true: Enable face detection.
  • false: (Default) Disable face detection.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

enableInEarMonitoring

Enables in-ear monitoring.

Future<void> enableInEarMonitoring(
      {required bool enabled,
      required EarMonitoringFilterType includeAudioFilters});

Details

This method enables or disables in-ear monitoring.

Attention:
  • Users must use earphones (wired or Bluetooth) to hear the in-ear monitoring effect.
  • You can call this method either before or after joining a channel.

Parameters

enabled
Enables or disables in-ear monitoring.
  • true: Enables in-ear monitoring.
  • false: (Default) Disables in-ear monitoring.
includeAudioFilters
The audio filter of in-ear monitoring: See EarMonitoringFilterType.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

  • < 0: Failure.
    • - 8: Make sure the current audio routing is Bluetooth or headset.

enableLocalAudio

Enables or disables the local audio capture.

Future<void> enableLocalAudio(bool enabled);

Details

The audio function is enabled by default when users joining a channel. This method disables or re-enables the local audio function to stop or restart local audio capturing.

This method does not affect receiving the remote audio streams, and enableLocalAudio(false) is applicable to scenarios where the user wants to receive remote audio streams without sending any audio stream to other users in the channel.

Once the local audio function is disabled or re-enabled, the SDK triggers the onLocalAudioStateChanged callback, which reports localAudioStreamStateStopped(0) or localAudioStreamStateRecording(1).
Attention:
  • The difference between this method and muteLocalAudioStream are as follow:
    • enableLocalAudio: Disables or re-enables the local audio capturing and processing. If you disable or re-enable local audio capturing using the enableLocalAudio method, the local user might hear a pause in the remote audio playback.
    • muteLocalAudioStream: Sends or stops sending the local audio streams.
  • You can call this method either before or after joining a channel. Calling it before joining a channel only sets the device state, and it takes effect immediately after you join the channel.

Parameters

enabled
  • true: (Default) Re-enable the local audio function, that is, to start the local audio capturing device (for example, the microphone).
  • false: Disable the local audio function, that is, to stop local audio capturing.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

enableLocalVideo

Enables/Disables the local video capture.

Future<void> enableLocalVideo(bool enabled);

Details

This method disables or re-enables the local video capture, and does not affect receiving the remote video stream.

After calling enableVideo, the local video capture is enabled by default.

If you call enableLocalVideo(false) to disable local video capture within the channel, it also simultaneously stops publishing the video stream within the channel. If you want to restart video catpure, you can call enableLocalVideo(true) and then call updateChannelMediaOptions to set the options parameter to publish the locally captured video stream in the channel.

After the local video capturer is successfully disabled or re-enabled, the SDK triggers the onRemoteVideoStateChanged callback on the remote client.

Attention:
  • You can call this method either before or after joining a channel.
  • This method enables the internal engine and is valid after leaving the channel.

Parameters

enabled

Whether to enable the local video capture.

  • true: (Default) Enable the local video capture.
  • false: Disable the local video capture. Once the local video is disabled, the remote users cannot receive the video stream of the local user, while the local user can still receive the video streams of remote users. When set to false, this method does not require a local camera.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

enableLoopbackRecording

Enables loopback audio capturing.

Future<void> enableLoopbackRecording(
    {required bool enabled, String? deviceName});

Details

If you enable loopback audio capturing, the output of the sound card is mixed into the audio stream sent to the other end.

Attention:
  • This method applies to the macOS and Windows only.
  • macOS does not support loopback audio capture of the default sound card. If you need to use this function, use a virtual sound card and pass its name to the deviceName parameter. Agora recommends using AgoraALD as the virtual sound card for audio capturing.
  • You can call this method either before or after joining a channel.
  • If you call the disableAudio method to disable the audio module, audio capturing will be disabled as well. If you need to enable audio capturing, call the enableAudio method to enable the audio module and then call the enableLoopbackRecording method.

Parameters

enabled
Sets whether to enable loopback audio capturing.
  • true: Enable loopback audio capturing.
  • false: (Default) Disable loopback audio capturing.
deviceName
  • macOS: The device name of the virtual sound card. The default value is set to NULL, which means using AgoraALD for loopback audio capturing.
  • Windows: The device name of the sound card. The default is set to NULL, which means the SDK uses the sound card of your device for loopback audio capturing.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

enableMultiCamera

Enables or disables multi-camera capture.

Future<void> enableMultiCamera(
      {required bool enabled, required CameraCapturerConfiguration config});

Details

In scenarios where there are existing cameras to capture video, Agora recommends that you use the following steps to capture and publish video with multiple cameras:
  1. Call this method to enable multi-channel camera capture.
  2. Call startPreview to start the local video preview.
  3. Call startCameraCapture, and set sourceType to start video capture with the second camera.
  4. Call joinChannelEx, and set publishSecondaryCameraTrack to true to publish the video stream captured by the second camera in the channel.
If you want to disable multi-channel camera capture, use the following steps:
  1. Call stopCameraCapture.
  2. Call this method with enabled set to false.
Note:
You can call this method before and after startPreview to enable multi-camera capture:
  • If it is enabled before startPreview, the local video preview shows the image captured by the two cameras at the same time.
  • If it is enabled after startPreview, the SDK stops the current camera capture first, and then enables the primary camera and the second camera. The local video preview appears black for a short time, and then automatically returns to normal.

This method applies to iOS only.

When using this function, ensure that the system version is 13.0 or later.

The minimum iOS device types that support multi-camera capture are as follows:
  • iPhone XR
  • iPhone XS
  • iPhone XS Max
  • iPad Pro 3rd generation and later

Parameters

enabled
Whether to enable multi-camera video capture mode:
  • true: Enable multi-camera capture mode; the SDK uses multiple cameras to capture video.
  • false: Disable multi-camera capture mode; the SDK uses a single camera to capture video.
config
Capture configuration for the second camera. See CameraCapturerConfiguration.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

enableSpatialAudio

Enables or disables the spatial audio effect.

Future<void> enableSpatialAudio(bool enabled);

Details

After enabling the spatial audio effect, you can call setRemoteUserSpatialAudioParams to set the spatial audio effect parameters of the remote user.

Note:
  • You can call this method either before or after joining a channel.
  • This method relies on the spatial audio dynamic library libagora_spatial_audio_extension.dll. If the dynamic library is deleted, the function cannot be enabled normally.

Parameters

enabled
Whether to enable the spatial audio effect:
  • true: Enable the spatial audio effect.
  • false: Disable the spatial audio effect.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

enableSoundPositionIndication

Enables or disables stereo panning for remote users.

Future<void> enableSoundPositionIndication(bool enabled);

Details

Ensure that you call this method before joining a channel to enable stereo panning for remote users so that the local user can track the position of a remote user by calling setRemoteVoicePosition.

Parameters

enabled
Whether to enable stereo panning for remote users:
  • true: Enable stereo panning.
  • false: Disable stereo panning.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

enableVideo

Enables the video module.

Future<void> enableVideo();

Details

Call this method either before joining a channel or during a call. If this method is called before joining a channel, the call starts in the video mode; if called during a call, the audio call switches to a video call. Call disableVideo to disable the video mode.

A successful call of this method triggers the onRemoteVideoStateChanged callback on the remote client.

Attention:
  • This method enables the internal engine and is valid after leaving the channel.
  • Calling this method will reset the entire engine, resulting in a slow response time. Instead of callling this method, you can independently control a specific video module based on your actual needs using the following methods:
  • A successful call of this method resets enableLocalVideo, muteRemoteVideoStream, and muteAllRemoteVideoStreams. Proceed it with caution.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

enableVideoImageSource

Sets whether to replace the current video feeds with images when publishing video streams.

Future<void> enableVideoImageSource(
      {required bool enable, required ImageTrackOptions options});

Details

Attention: Agora recommends that you call this method after joining a channel.

When publishing video streams, you can call this method to replace the current video feeds with custom images.

Once you enable this function, you can select images to replace the video feeds through the ImageTrackOptions parameter. If you disable this function, the remote users see the video feeds that you publish.

Parameters

enable
Whether to replace the current video feeds with custom images:
  • true: Replace the current video feeds with custom images.
  • false: (Default) Do not replace the current video feeds with custom images.
options
Image configurations. See ImageTrackOptions.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

  • < 0: Failure.

enableVirtualBackground

Enables/Disables the virtual background.

Future<void> enableVirtualBackground(
      {required bool enabled,
      required VirtualBackgroundSource backgroundSource,
      required SegmentationProperty segproperty,
      MediaSourceType type = MediaSourceType.primaryCameraSource});

Details

The virtual background feature enables the local user to replace their original background with a static image, dynamic video, blurred background, or portrait-background segmentation to achieve picture-in-picture effect. Once the virtual background feature is enabled, all users in the channel can see the custom background.

Call this method before calling enableVideo or startPreview.

Attention:
  • This feature has high requirements on device performance. When calling this method, the SDK automatically checks the capabilities of the current device. Agora recommends you use virtual background on devices with the following processors:
    • Snapdragon 700 series 750G and later
    • Snapdragon 800 series 835 and later
    • Dimensity 700 series 720 and later
    • Kirin 800 series 810 and later
    • Kirin 900 series 980 and later
    • Devices with an A9 chip and better, as follows:
      • iPhone 6S and later
      • iPad Air 3rd generation and later
      • iPad 5th generation and later
      • iPad Pro 1st generation and later
      • iPad mini 5th generation and later
  • Agora recommends that you use this feature in scenarios that meet the following conditions:
    • A high-definition camera device is used, and the environment is uniformly lit.
    • There are few objects in the captured video. Portraits are half-length and unobstructed. Ensure that the background is a solid color that is different from the color of the user's clothing.
  • This method relies on the virtual background dynamic library libagora_segmentation_extension.dll. If the dynamic library is deleted, the function cannot be enabled normally.

Parameters

enabled
Whether to enable virtual background:
  • true: Enable virtual background.
  • false: Disable virtual background.
backgroundSource
The custom background. See VirtualBackgroundSource. To adapt the resolution of the custom background image to that of the video captured by the SDK, the SDK scales and crops the custom background image while ensuring that the content of the custom background image is not distorted.
segproperty
Processing properties for background images. See SegmentationProperty.
type
The type of the video source. See MediaSourceType.
Attention: In this method, this parameter supports only the following two settings:
  • The default value is primaryCameraSource.
  • If you want to use the second camera to capture video, set this parameter to secondaryCameraSource.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

enableWebSdkInteroperability

Enables interoperability with the Agora Web SDK (applicable only in the live streaming scenarios).

Future<void> enableWebSdkInteroperability(bool enabled);

Details

Deprecated:
The SDK automatically enables interoperability with the Web SDK, so you no longer need to call this method.

You can call this method to enable or disable interoperability with the Agora Web SDK. If a channel has Web SDK users, ensure that you call this method, or the video of the Native user will be a black screen for the Web user.

This method is only applicable in live streaming scenarios, and interoperability is enabled by default in communication scenarios.

Parameters

enabled
Whether to enable interoperability:
  • true: Enable interoperability.
  • false: (Default) Disable interoperability.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

getAudioDeviceInfo

Gets the audio device information.

Future<DeviceInfo> getAudioDeviceInfo();

Details

After calling this method, you can get whether the audio device supports ultra-low-latency capture and playback.

Attention:
  • This method is for Android only.
  • You can call this method either before or after joining a channel.

Returns

The DeviceInfo object that identifies the audio device information.
  • Not null: Success.
  • Null: Failure.

getAudioMixingCurrentPosition

Retrieves the playback position (ms) of the music file.

Future<int> getAudioMixingCurrentPosition();

Details

Retrieves the playback position (ms) of the audio.

Attention:
  • You need to call this method after calling startAudioMixing and receiving the onAudioMixingStateChanged(audioMixingStatePlaying) callback.
  • If you need to call getAudioMixingCurrentPosition multiple times, ensure that the time interval between calling this method is more than 500 ms.

Returns

  • ≥ 0: The current playback position (ms) of the audio mixing, if this method call succeeds. 0 represents that the current music file does not start playing.
  • < 0: Failure.

getAudioMixingDuration

Retrieves the duration (ms) of the music file.

Future<int> getAudioMixingDuration();

Details

Retrieves the total duration (ms) of the audio.

Attention:

You need to call this method after calling startAudioMixing and receiving the onAudioMixingStateChanged(audioMixingStatePlaying) callback.

Returns

  • ≥ 0: The audio mixing duration, if this method call succeeds.
  • < 0: Failure.

getAudioMixingPlayoutVolume

Retrieves the audio mixing volume for local playback.

Future<int> getAudioMixingPlayoutVolume();

Details

This method helps troubleshoot audio volume‑related issues.

Attention:

You need to call this method after calling startAudioMixing and receiving the onAudioMixingStateChanged(audioMixingStatePlaying) callback.

Returns

  • ≥ 0: The audio mixing volume, if this method call succeeds. The value range is [0,100].
  • < 0: Failure.

getAudioMixingPublishVolume

Retrieves the audio mixing volume for publishing.

Future<int> getAudioMixingPublishVolume();

Details

This method helps troubleshoot audio volume‑related issues.

Attention: You need to call this method after calling startAudioMixing and receiving the onAudioMixingStateChanged(audioMixingStatePlaying) callback.

Returns

  • ≥ 0: The audio mixing volume, if this method call succeeds. The value range is [0,100].
  • < 0: Failure.

getAudioTrackCount

Gets the index of audio tracks of the current music file.

Future<int> getAudioTrackCount();

Details

Note:
  • You need to call this method after calling startAudioMixing and receiving the onAudioMixingStateChanged(audioMixingStatePlaying) callback.

Returns

  • The SDK returns the index of the audio tracks if the method call succeeds.
  • < 0: Failure.

getCallId

Retrieves the call ID.

Future<String> getCallId();

Details

When a user joins a channel on a client, a callId is generated to identify the call from the client. Some methods, such as rate and complain, must be called after the call ends to submit feedback to the SDK. These methods require the callId parameter.

Attention: Call this method after joining a channel.

Returns

The current call ID.

getCameraMaxZoomFactor

Gets the maximum zoom ratio supported by the camera.

Future<double> getCameraMaxZoomFactor();

Details

Attention:
  • This method is for Android and iOS only.
  • This method must be called after the camera is successfully enabled, that is, after the SDK triggers the onLocalVideoStateChanged callback and returns the local video state as localVideoStreamStateCapturing (1).

Returns

The maximum zoom factor.

getConnectionState

Gets the current connection state of the SDK.

Future<ConnectionStateType> getConnectionState();

Details

You can call this method either before or after joining a channel.

Returns

The current connection state. See ConnectionStateType.

getEffectCurrentPosition

Retrieves the playback position of the audio effect file.

Future<int> getEffectCurrentPosition(int soundId);

Details

Attention: Call this method after playEffect.

Parameters

soundId
The audio effect ID. The ID of each audio effect file is unique.

Returns

  • The playback position (ms) of the specified audio effect file, if the method call succeeds.
  • < 0: Failure.

getEffectDuration

Retrieves the duration of the audio effect file.

Future<int> getEffectDuration(String filePath);

Details

Attention: Call this method after joining a channel.

Parameters

filePath
File path:
  • Android: The file path, which needs to be accurate to the file name and suffix. Agora supports URL addresses, absolute paths, or file paths that start with /assets/. You might encounter permission issues if you use an absolute path to access a local file, so Agora recommends using a URI address instead. For example: content://com.android.providers.media.documents/document/audio%3A14441
  • Windows: The absolute path or URL address (including the suffixes of the filename) of the audio effect file. For example: C:\music\audio.mp4.
  • iOS or macOS: The absolute path or URL address (including the suffixes of the filename) of the audio effect file. For example: /var/mobile/Containers/Data/audio.mp4.

Returns

  • The total duration (ms) of the specified audio effect file, if the method call succeeds.
  • < 0: Failure.

getEffectsVolume

Retrieves the volume of the audio effects.

Future<int> getEffectsVolume();

Details

The volume is an integer ranging from 0 to 100. The default value is 100, which means the original volume.

Attention: Call this method after playEffect.

Returns

  • Volume of the audio effects, if this method call succeeds.
  • < 0: Failure.

getErrorDescription

Gets the warning or error description.

Future<String> getErrorDescription(int code);

Parameters

code
The error code or warning code reported by the SDK.

Returns

The specific error or warning description.

getExtensionProperty

Gets detailed information on the extensions.

Future<String> getExtensionProperty(
      {required String provider,
      required String extension,
      required String key,
      required int bufLen,
      MediaSourceType type = MediaSourceType.unknownMediaSource});

Details

Parameters

provider
The name of the extension provider.
extension
The name of the extension.
key
The key of the extension.
type
Source type of the extension. See MediaSourceType.
bufLen
Maximum length of the JSON string indicating the extension property. The maximum value is 512 bytes.

Returns

  • The extension information, if the method call succeeds.
  • An empty string, if the method call fails.

getNativeHandle

Gets the C++ handle of the Native SDK.

Future<int> getNativeHandle();

Details

This method retrieves the C++ handle of the SDK, which is used for registering the audio and video frame observer.

Returns

The native handle of the SDK.

getNetworkType

Gets the type of the local network connection.

Future<int> getNetworkType();

Details

You can use this method to get the type of network in use at any stage.

Note: You can call this method either before or after joining a channel.

Returns

  • ≥ 0: The method call is successful, and the local network connection type is returned.
    • 0: The SDK disconnects from the network.
    • 1: The network type is LAN.
    • 2: The network type is Wi-Fi (including hotspots).
    • 3: The network type is mobile 2G.
    • 4: The network type is mobile 3G.
    • 5: The network type is mobile 4G.
    • 6: The network type is mobile 5G.
  • < 0: The method call failed with an error code.
    • -1: The network type is unknown.

getScreenCaptureSources

Gets a list of shareable screens and windows.

Future<List<ScreenCaptureSourceInfo>> getScreenCaptureSources(
    {required Size thumbSize,
    required Size iconSize,
    required bool includeScreen});

Details

You can call this method before sharing a screen or window to get a list of shareable screens and windows, which enables a user to use thumbnails in the list to easily choose a particular screen or window to share. This list also contains important information such as window ID and screen ID, with which you can call startScreenCaptureByWindowId or startScreenCaptureByDisplayId to start the sharing.

Note: This method applies to macOS and Windows only.

Parameters

thumbSize
The target size of the screen or window thumbnail (the width and height are in pixels). The SDK scales the original image to make the length of the longest side of the image the same as that of the target size without distorting the original image. For example, if the original image is 400 × 300 and thumbSize is 100 × 100, the actual size of the thumbnail is 100 × 75. If the target size is larger than the original size, the thumbnail is the original image and the SDK does not scale it.
iconSize
The target size of the icon corresponding to the application program (the width and height are in pixels). The SDK scales the original image to make the length of the longest side of the image the same as that of the target size without distorting the original image. For example, if the original image is 400 × 300 and iconSize is 100 × 100, the actual size of the icon is 100 × 75. If the target size is larger than the original size, the icon is the original image and the SDK does not scale it.
includeScreen
Whether the SDK returns the screen information in addition to the window information:
  • true: The SDK returns screen and window information.
  • false: The SDK returns window information only.

Returns

The ScreenCaptureSourceInfo array.

getUserInfoByUid

Gets the user information by passing in the user ID.

Future<UserInfo> getUserInfoByUid(int uid);

Details

After a remote user joins the channel, the SDK gets the user ID and account of the remote user, caches them in a mapping table object, and triggers the onUserInfoUpdated callback on the local client. After receiving the callback, you can call this method to get the user account of the remote user from the UserInfo object by passing in the user ID.

Parameters

uid
The user ID.

Returns

  • A pointer to the UserInfo instance, if the method call succeeds.
  • If the call fails, returns NULL.

getUserInfoByUserAccount

Gets the user information by passing in the user account.

Future<UserInfo> getUserInfoByUserAccount(String userAccount);

Details

After a remote user joins the channel, the SDK gets the user ID and account of the remote user, caches them in a mapping table object, and triggers the onUserInfoUpdated callback on the local client. After receiving the callback, you can call this method to get the user account of the remote user from the UserInfo object by passing in the user ID.

Parameters

userAccount
The user account.

Returns

  • A pointer to the UserInfo instance, if the method call succeeds.
  • If the call fails, returns NULL.

getVersion

Gets the SDK version.

Future<SDKBuildInfo> getVersion();

Parameters

Returns

One SDKBuildInfo object.

getVolumeOfEffect

Gets the volume of a specified audio effect file.

Future<int> getVolumeOfEffect(int soundId);

Parameters

soundId
The ID of the audio effect file.

Returns

  • ≥ 0: Returns the volume of the specified audio effect, if the method call is successful. The value ranges between 0 and 100. 100 represents the original volume.
  • < 0: Failure.

isCameraAutoExposureFaceModeSupported

Checks whether the device supports auto exposure.

Future<bool> isCameraAutoExposureFaceModeSupported();

Details

Attention:
  • This method applies to iOS only.
  • This method must be called after the camera is successfully enabled, that is, after the SDK triggers the onLocalVideoStateChanged callback and returns the local video state as localVideoStreamStateCapturing (1).

Returns

  • true: The device supports auto exposure.
  • false: The device does not support auto exposure.

isCameraAutoFocusFaceModeSupported

Checks whether the device supports the face auto-focus function.

Future<bool> isCameraAutoFocusFaceModeSupported();

Details

Attention:
  • This method is for Android and iOS only.
  • This method must be called after the camera is successfully enabled, that is, after the SDK triggers the onLocalVideoStateChanged callback and returns the local video state as localVideoStreamStateCapturing (1).

Returns

  • true: The device supports the face auto-focus function.
  • false: The device does not support the face auto-focus function.

isCameraExposurePositionSupported

Checks whether the device supports manual exposure.

Future<bool> isCameraExposurePositionSupported();

Details

Attention:
  • This method is for Android and iOS only.
  • This method must be called after the camera is successfully enabled, that is, after the SDK triggers the onLocalVideoStateChanged callback and returns the local video state as localVideoStreamStateCapturing (1).

Returns

  • true: The device supports manual exposure.
  • false: The device does not support manual exposure.

isCameraExposureSupported

Queries whether the current camera supports adjusting exposure value.

Future<bool> isCameraExposureSupported();

Details

Attention:
  • This method is for Android and iOS only.
  • This method must be called after the camera is successfully enabled, that is, after the SDK triggers the onLocalVideoStateChanged callback and returns the local video state as localVideoStreamStateCapturing (1).
  • Before calling setCameraExposureFactor, Agora recoomends that you call this method to query whether the current camera supports adjusting the exposure value.
  • By calling this method, you adjust the exposure value of the currently active camera, that is, the camera specified when calling setCameraCapturerConfiguration.

Returns

  • true: Success.
  • false: Failure.

isCameraFaceDetectSupported

Checks whether the device camera supports face detection.

Future<bool> isCameraFaceDetectSupported();
Attention:
  • This method is for Android and iOS only.
  • This method must be called after the camera is successfully enabled, that is, after the SDK triggers the onLocalVideoStateChanged callback and returns the local video state as localVideoStreamStateCapturing (1).

Returns

  • true: The device camera supports face detection.
  • false: The device camera does not support face detection.

isCameraFocusSupported

Check whether the device supports the manual focus function.

Future<bool> isCameraFocusSupported();

Details

Attention:
  • This method is for Android and iOS only.
  • This method must be called after the camera is successfully enabled, that is, after the SDK triggers the onLocalVideoStateChanged callback and returns the local video state as localVideoStreamStateCapturing (1).

Returns

  • true: The device supports the manual focus function.
  • false: The device does not support the manual focus function.

isCameraTorchSupported

Checks whether the device supports camera flash.

Future<bool> isCameraTorchSupported();

Details

Attention:
  • This method is for Android and iOS only.
  • This method must be called after the camera is successfully enabled, that is, after the SDK triggers the onLocalVideoStateChanged callback and returns the local video state as localVideoStreamStateCapturing (1).
  • The app enables the front camera by default. If your front camera does not support flash, this method returns false. If you want to check whether the rear camera supports the flash function, call switchCamera before this method.
  • On iPads with system version 15, even if isCameraTorchSupported returns true, you might fail to successfully enable the flash by calling setCameraTorchOn due to system issues.

Returns

  • true: The device supports camera flash.
  • false: The device does not support camera flash.

isCameraZoomSupported

Checks whether the device supports camera zoom.

Future<bool> isCameraZoomSupported();

Details

Attention:
  • This method is for Android and iOS only.
  • This method must be called after the camera is successfully enabled, that is, after the SDK triggers the onLocalVideoStateChanged callback and returns the local video state as localVideoStreamStateCapturing (1).

Returns

  • true: The device supports camera zoom.
  • false: The device does not support camera zoom.

isFeatureAvailableOnDevice

Checks whether the device supports the specified advanced feature.

Future<bool> isFeatureAvailableOnDevice(FeatureType type);

Details

Checks whether the capabilities of the current device meet the requirements for advanced features such as virtual background and image enhancement.

Applicable scenarios

Before using advanced features, you can check whether the current device supports these features based on the call result. This helps to avoid performance degradation or unavailable features when enabling advanced features on low-end devices. Based on the return value of this method, you can decide whether to display or enable the corresponding feature button, or notify the user when the device's capabilities are insufficient.

Parameters

type
The type of the advanced feature, see FeatureType.

Returns

  • true: The current device supports the specified feature.
  • false: The current device does not support the specified feature.

isSpeakerphoneEnabled

Checks whether the speakerphone is enabled.

Future<bool> isSpeakerphoneEnabled();
Note:
  • This method is for Android and iOS only.
  • You can call this method either before or after joining a channel.

Returns

  • true: The speakerphone is enabled, and the audio plays from the speakerphone.
  • false: The speakerphone is not enabled, and the audio plays from devices other than the speakerphone. For example, the headset or earpiece.

Joins a channel.

Future<void> joinChannel(
    {required String token,
    required String channelId,
    required String info,
    required int uid});

Details

This method enables users to join a channel. Users in the same channel can talk to each other, and multiple users in the same channel can start a group chat. Users with different App IDs cannot call each other.

A successful call of this method triggers the following callbacks:

When the connection between the client and Agora's server is interrupted due to poor network conditions, the SDK tries reconnecting to the server. When the local client successfully rejoins the channel, the SDK triggers the onRejoinChannelSuccess callback on the local client.

Attention: Once a user joins the channel, the user subscribes to the audio and video streams of all the other users in the channel by default, giving rise to usage and billing calculation. To stop subscribing to a specified stream or all remote streams, call the corresponding mute methods.

Parameters

token
The token generated on your server for authentication. See .
Note: If you need to join different channels at the same time or switch between channels, Agora recommends using a wildcard token so that you don't need to apply for a new token every time joining a channel. See Secure authentication with tokens.
channelId
The channel name. This parameter signifies the channel in which users engage in real-time audio and video interaction. Under the premise of the same App ID, users who fill in the same channel ID enter the same channel for audio and video interaction. The string length must be less than 64 bytes. Supported characters:
  • All lowercase English letters: a to z.
  • All uppercase English letters: A to Z.
  • All numeric characters: 0 to 9.
  • Space
  • "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", "{", "}", "|", "~", ","
info
(Optional) Reserved for future use.
uid
The user ID. This parameter is used to identify the user in the channel for real-time audio and video interaction. You need to set and manage user IDs yourself, and ensure that each user ID in the same channel is unique. This parameter is a 32-bit unsigned integer. The value range is 1 to 232-1. If the user ID is not assigned (or set to 0), the SDK assigns a random user ID and returns it in the onJoinChannelSuccess callback. Your application must record and maintain the returned user ID, because the SDK does not do so.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

  • < 0: Failure.
    • -2: The parameter is invalid. For example, the token is invalid, the uid parameter is not set to an integer, or the value of a member in ChannelMediaOptions is invalid. You need to pass in a valid parameter and join the channel again.
    • -3: Failes to initialize the RtcEngine object. You need to reinitialize the RtcEngine object.
    • -7: The RtcEngine object has not been initialized. You need to initialize the RtcEngine object before calling this method.
    • -8: The internal state of the RtcEngine object is wrong. The typical cause is that you call this method to join the channel without calling startEchoTest to stop the test after calling stopEchoTest to start a call loop test. You need to call stopEchoTest before calling this method.
    • -17: The request to join the channel is rejected. The typical cause is that the user is in the channel. Agora recommends that you use the onConnectionStateChanged callback to determine whether the user exists in the channel. Do not call this method to join the channel unless you receive the connectionStateDisconnected(1) state.
    • -102: The channel name is invalid. You need to pass in a valid channelname in channelId to rejoin the channel.
    • -121: The user ID is invalid. You need to pass in a valid user ID in uid to rejoin the channel.

joinChannel

Joins a channel with media options.

Future<void> joinChannel(
      {required String token,
      required String channelId,
      required int uid,
      required ChannelMediaOptions options});

Details

This method enables users to join a channel. Users in the same channel can talk to each other, and multiple users in the same channel can start a group chat. Users with different App IDs cannot call each other.

A successful call of this method triggers the following callbacks:

When the connection between the client and Agora's server is interrupted due to poor network conditions, the SDK tries reconnecting to the server. When the local client successfully rejoins the channel, the SDK triggers the onRejoinChannelSuccess callback on the local client.

Attention:
  • This method allows users to join only one channel at a time.
  • Ensure that the app ID you use to generate the token is the same app ID that you pass in the initialize method; otherwise, you may fail to join the channel by token.

Parameters

token
The token generated on your server for authentication. See .
Note: If you need to join different channels at the same time or switch between channels, Agora recommends using a wildcard token so that you don't need to apply for a new token every time joining a channel. See Secure authentication with tokens.
channelId
The channel name. This parameter signifies the channel in which users engage in real-time audio and video interaction. Under the premise of the same App ID, users who fill in the same channel ID enter the same channel for audio and video interaction. The string length must be less than 64 bytes. Supported characters:
  • All lowercase English letters: a to z.
  • All uppercase English letters: A to Z.
  • All numeric characters: 0 to 9.
  • Space
  • "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", "{", "}", "|", "~", ","
uid
The user ID. This parameter is used to identify the user in the channel for real-time audio and video interaction. You need to set and manage user IDs yourself, and ensure that each user ID in the same channel is unique. This parameter is a 32-bit unsigned integer. The value range is 1 to 232-1. If the user ID is not assigned (or set to 0), the SDK assigns a random user ID and returns it in the onJoinChannelSuccess callback. Your app must record and maintain the returned user ID, because the SDK does not do so.
options
The channel media options. See ChannelMediaOptions.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

  • < 0: Failure.
    • -2: The parameter is invalid. For example, the token is invalid, the uid parameter is not set to an integer, or the value of a member in ChannelMediaOptions is invalid. You need to pass in a valid parameter and join the channel again.
    • -3: Failes to initialize the RtcEngine object. You need to reinitialize the RtcEngine object.
    • -7: The RtcEngine object has not been initialized. You need to initialize the RtcEngine object before calling this method.
    • -8: The internal state of the RtcEngine object is wrong. The typical cause is that you call this method to join the channel without calling startEchoTest to stop the test after calling stopEchoTest to start a call loop test. You need to call stopEchoTest before calling this method.
    • -17: The request to join the channel is rejected. The typical cause is that the user is in the channel. Agora recommends that you use the onConnectionStateChanged callback to determine whether the user exists in the channel. Do not call this method to join the channel unless you receive the connectionStateDisconnected(1) state.
    • -102: The channel name is invalid. You need to pass in a valid channelname in channelId to rejoin the channel.
    • -121: The user ID is invalid. You need to pass in a valid user ID in uid to rejoin the channel.

joinChannelWithUserAccount

Joins the channel with a user account, and configures whether to automatically subscribe to audio or video streams after joining the channel.

Future<void> joinChannelWithUserAccount(
    {required String token,
    required String channelId,
    required String userAccount,
    ChannelMediaOptions? options});

Details

This method allows a user to join the channel with the user account. After the user successfully joins the channel, the SDK triggers the following callbacks:

Once a user joins the channel, the user subscribes to the audio and video streams of all the other users in the channel by default, giving rise to usage and billing calculation. To stop subscribing to a specified stream or all remote streams, call the corresponding mute methods.

Attention: To ensure smooth communication, use the same parameter type to identify the user. For example, if a user joins the channel with a user ID, then ensure all the other users use the user ID too. The same applies to the user account. If a user joins the channel with the Agora Web SDK, ensure that the ID of the user is set to the same parameter type.

Parameters

token
The token generated on your server for authentication. See .
Note: If you need to join different channels at the same time or switch between channels, Agora recommends using a wildcard token so that you don't need to apply for a new token every time joining a channel. See Secure authentication with tokens.
channelId
The channel name. This parameter signifies the channel in which users engage in real-time audio and video interaction. Under the premise of the same App ID, users who fill in the same channel ID enter the same channel for audio and video interaction. The string length must be less than 64 bytes. Supported characters:
  • All lowercase English letters: a to z.
  • All uppercase English letters: A to Z.
  • All numeric characters: 0 to 9.
  • Space
  • "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", "{", "}", "|", "~", ","
userAccount
The user account. This parameter is used to identify the user in the channel for real-time audio and video engagement. You need to set and manage user accounts yourself and ensure that each user account in the same channel is unique. The maximum length of this parameter is 255 bytes. Ensure that you set this parameter and do not set it as NULL. Supported characters are (89 in total):
  • The 26 lowercase English letters: a to z.
  • The 26 uppercase English letters: A to Z.
  • All numeric characters: 0 to 9.
  • Space
  • "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", "{", "}", "|", "~", ","
options
The channel media options. See ChannelMediaOptions.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

  • < 0: Failure.
    • -2: The parameter is invalid. For example, the token is invalid, the uid parameter is not set to an integer, or the value of a member in ChannelMediaOptions is invalid. You need to pass in a valid parameter and join the channel again.
    • -3: Failes to initialize the RtcEngine object. You need to reinitialize the RtcEngine object.
    • -7: The RtcEngine object has not been initialized. You need to initialize the RtcEngine object before calling this method.
    • -8: The internal state of the RtcEngine object is wrong. The typical cause is that you call this method to join the channel without calling startEchoTest to stop the test after calling stopEchoTest to start a call loop test. You need to call stopEchoTest before calling this method.
    • -17: The request to join the channel is rejected. The typical cause is that the user is in the channel. Agora recommends that you use the onConnectionStateChanged callback to determine whether the user exists in the channel. Do not call this method to join the channel unless you receive the connectionStateDisconnected(1) state.
    • -102: The channel name is invalid. You need to pass in a valid channelname in channelId to rejoin the channel.
    • -121: The user ID is invalid. You need to pass in a valid user ID in uid to rejoin the channel.

joinChannelWithUserAccountEx

Joins the channel with a user account, and configures whether to automatically subscribe to audio or video streams after joining the channel.

Future<void> joinChannelWithUserAccountEx(
    {required String token,
    required String channelId,
    required String userAccount,
    required ChannelMediaOptions options});

Details

This method allows a user to join the channel with the user account. After the user successfully joins the channel, the SDK triggers the following callbacks:

Once a user joins the channel, the user subscribes to the audio and video streams of all the other users in the channel by default, giving rise to usage and billing calculation. To stop subscribing to a specified stream or all remote streams, call the corresponding mute methods.

Attention: To ensure smooth communication, use the same parameter type to identify the user. For example, if a user joins the channel with a user ID, then ensure all the other users use the user ID too. The same applies to the user account. If a user joins the channel with the Agora Web SDK, ensure that the ID of the user is set to the same parameter type.

Parameters

token
The token generated on your server for authentication. See .
Note: If you need to join different channels at the same time or switch between channels, Agora recommends using a wildcard token so that you don't need to apply for a new token every time joining a channel. See Secure authentication with tokens.
channelId
The channel name. This parameter signifies the channel in which users engage in real-time audio and video interaction. Under the premise of the same App ID, users who fill in the same channel ID enter the same channel for audio and video interaction. The string length must be less than 64 bytes. Supported characters:
  • All lowercase English letters: a to z.
  • All uppercase English letters: A to Z.
  • All numeric characters: 0 to 9.
  • Space
  • "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", "{", "}", "|", "~", ","
userAccount
The user account. This parameter is used to identify the user in the channel for real-time audio and video engagement. You need to set and manage user accounts yourself and ensure that each user account in the same channel is unique. The maximum length of this parameter is 255 bytes. Ensure that you set this parameter and do not set it as NULL. Supported characters are (89 in total):
  • The 26 lowercase English letters: a to z.
  • The 26 uppercase English letters: A to Z.
  • All numeric characters: 0 to 9.
  • Space
  • "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", "{", "}", "|", "~", ","
options
The channel media options. See ChannelMediaOptions.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

leaveChannel

Sets channel options and leaves the channel.

Future<void> leaveChannel({LeaveChannelOptions? options});

Details

This method will release all resources related to the session, leave the channel, that is, hang up or exit the call. This method can be called whether or not a call is currently in progress.

After joining the channel, you must call this method or to end the call, otherwise, the next call cannot be started.

This method call is asynchronous. When this method returns, it does not necessarily mean that the user has left the channel. After actually leaving the channel, the local user triggers the onLeaveChannel callback; after the user in the communication scenario and the host in the live streaming scenario leave the channel, the remote user triggers the onUserOffline callback.

Attention:
  • If you call release immediately after calling this method, the SDK does not trigger the onLeaveChannel callback.
  • If you have called joinChannelEx to join multiple channels, calling this method will leave the channels when calling joinChannel and joinChannelEx at the same time.

Parameters

options
The options for leaving the channel. See LeaveChannelOptions.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

loadExtensionProvider

Adds an extension to the SDK.

Future<void> loadExtensionProvider(
      {required String path, bool unloadAfterUse = false});

Details

Attention: (For Windows and Android only)

Parameters

path
The extension library path and name. For example: /library/libagora_segmentation_extension.dll.
unloadAfterUse
Whether to uninstall the current extension when you no longer using it:
  • true: Uninstall the extension when the RtcEngine is destroyed.
  • false: (Rcommended) Do not uninstall the extension until the process terminates.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

muteAllRemoteAudioStreams

Stops or resumes subscribing to the audio streams of all remote users.

Future<void> muteAllRemoteAudioStreams(bool mute);

Details

After successfully calling this method, the local user stops or resumes subscribing to the audio streams of all remote users, including all subsequent users.

Attention:
  • Call this method after joining a channel.
  • If you do not want to subscribe the audio streams of remote users before joining a channel, you can set autoSubscribeAudio as false when calling joinChannel.

Parameters

mute
Whether to stop subscribing to the audio streams of all remote users:
  • true: Stops subscribing to the audio streams of all remote users.
  • false: (Default) Subscribes to the audio streams of all remote users by default.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

muteAllRemoteVideoStreams

Stops or resumes subscribing to the video streams of all remote users.

Future<void> muteAllRemoteVideoStreams(bool mute);

Details

After successfully calling this method, the local user stops or resumes subscribing to the audio streams of all remote users, including all subsequent users.

Attention:
  • Call this method after joining a channel.
  • If you do not want to subscribe the video streams of remote users before joining a channel, you can call joinChannel and set autoSubscribeVideo as false.

Parameters

mute
Whether to stop subscribing to the video streams of all remote users.
  • true: Stop subscribing to the video streams of all remote users.
  • false: (Default) Subscribe to the audio streams of all remote users by default.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

muteLocalAudioStream

Stops or resumes publishing the local audio stream.

Future<void> muteLocalAudioStream(bool mute);

Details

Attention: This method does not affect any ongoing audio recording, because it does not disable the audio capture device.

A successful call of this method triggers the onUserMuteAudio and onRemoteAudioStateChanged callbacks on the remote client.

Parameters

mute
Whether to stop publishing the local audio stream:
  • true: Stops publishing the local audio stream.
  • false: (Default) Resumes publishing the local audio stream.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

muteLocalVideoStream

Stops or resumes publishing the local video stream.

Future<void> muteLocalVideoStream(bool mute);

Details

A successful call of this method triggers the onUserMuteVideo callback on the remote client.

Attention:
  • This method executes faster than the enableLocalVideo(false) method, which controls the sending of the local video stream.
  • This method does not affect any ongoing video recording, because it does not disable the camera.

Parameters

mute
Whether to stop publishing the local video stream.
  • true: Stop publishing the local video stream.
  • false: (Default) Publish the local video stream.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

muteRecordingSignal

Whether to mute the recording signal.

Future<void> muteRecordingSignal(bool mute);

Parameters

mute
  • true: The media file is muted.
  • false: (Default) Do not mute the recording signal.
Note: If you have already called adjustRecordingSignalVolume to adjust the volume, then when you call this method and set it to true, the SDK will record the current volume and mute it. To restore the previous volume, call this method again and set it to false.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

muteRemoteAudioStream

Stops or resumes subscribing to the audio stream of a specified user.

Future<void> muteRemoteAudioStream({required int uid, required bool mute});

Details

Attention:
  • Call this method after joining a channel.

Parameters

uid
The user ID of the specified user.
mute
Whether to subscribe to the specified remote user's audio stream.
  • true: Stop subscribing to the audio stream of the specified user.
  • false: (Default) Subscribe to the audio stream of the specified user.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

muteRemoteVideoStream

Stops or resumes subscribing to the video stream of a specified user.

Future<void> muteRemoteVideoStream({required int uid, required bool mute});

Details

Attention:
  • Call this method after joining a channel.

Parameters

uid
The user ID of the specified user.
mute
Whether to subscribe to the specified remote user's video stream.
  • true: Stop subscribing to the video streams of the specified user.
  • false: (Default) Subscribe to the video stream of the specified user.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

  • < 0: Failure.

pauseAllChannelMediaRelay

Pauses the media stream relay to all target channels.

Future<void> pauseAllChannelMediaRelay();

Details

After the cross-channel media stream relay starts, you can call this method to pause relaying media streams to all target channels; after the pause, if you want to resume the relay, call resumeAllChannelMediaRelay.

Attention: Call this method after startOrUpdateChannelMediaRelay.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

pauseAllEffects

Pauses all audio effects.

Future<void> pauseAllEffects();

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

pauseAudioMixing

Pauses playing and mixing the music file.

Future<void> pauseAudioMixing();

Details

Call this method after joining a channel.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

pauseEffect

Pauses a specified audio effect file.

Future<void> pauseEffect(int soundId);

Parameters

soundId
The audio effect ID. The ID of each audio effect file is unique.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

playAllEffects

Plays all audio effect files.

Future<void> playAllEffects(
    {required int loopCount,
    required double pitch,
    required double pan,
    required int gain,
    bool publish = false});

Details

After calling preloadEffect multiple times to preload multiple audio effects into the memory, you can call this method to play all the specified audio effects for all users in the channel.

Parameters

loopCount
The number of times the audio effect loops:
  • -1: Play the audio effect files in an indefinite loop until you call stopEffect or stopAllEffects.
  • 0: Play the audio effect once.
  • 1: Play the audio effect twice.
pitch

The pitch of the audio effect. The value ranges between 0.5 and 2.0. The default value is 1.0 (original pitch). The lower the value, the lower the pitch.

pan
The spatial position of the audio effect. The value ranges between -1.0 and 1.0:
  • -1.0: The audio effect shows on the left.
  • 0: The audio effect shows ahead.
  • 1.0: The audio effect shows on the right.
gain

The volume of the audio effect. The value range is [0, 100]. The default value is 100 (original volume). The smaller the value, the lower the volume.

publish
Whether to publish the audio effect to the remote users:
  • true: Publish the audio effect to the remote users. Both the local user and remote users can hear the audio effect.
  • false: (Default) Do not publish the audio effect to the remote users. Only the local user can hear the audio effect.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

playEffect

Plays the specified local or online audio effect file.

Future<void> playEffect(
    {required int soundId,
    required String filePath,
    required int loopCount,
    required double pitch,
    required double pan,
    required int gain,
    bool publish = false,
    int startPos = 0});

Details

Attention: If you use this method to play an online audio effect file, Agora recommends that you cache the online audio effect file to your local device, call preloadEffect to preload the cached audio effect file into memory, and then call this method to play the audio effect. Otherwise, you might encounter playback failures or no sound during playback due to loading timeouts or failures.

To play multiple audio effect files at the same time, call this method multiple times with different soundId and filePath. To achieve the optimal user experience, Agora recommends that do not playing more than three audio files at the same time. After the playback of an audio effect file completes, the SDK triggers the onAudioEffectFinished callback.

Parameters

soundId
The audio effect ID. The ID of each audio effect file is unique.
Attention: If you have preloaded an audio effect into memory by calling preloadEffect, ensure that the value of this parameter is the same as that of soundId in preloadEffect.
filePath

The absolute path or URL address (including the suffixes of the filename) of the audio effect file. For example, C:\music\audio.mp4. Supported audio formats include MP3, AAC, M4A, MP4, WAV, and 3GP. See supported audio formats.

Attention: If you have preloaded an audio effect into memory by calling preloadEffect, ensure that the value of this parameter is the same as that of filePath in preloadEffect.
loopCount
The number of times the audio effect loops.
  • ≥ 0: The number of playback times. For example, 1 means looping one time, which means playing the audio effect two times in total.
  • -1: Play the audio file in an infinite loop.
pitch
The pitch of the audio effect. The value range is 0.5 to 2.0. The default value is 1.0, which means the original pitch. The lower the value, the lower the pitch.
pan
The spatial position of the audio effect. The value ranges between -1.0 and 1.0:
  • -1.0: The audio effect is heard on the left of the user.
  • 0.0: The audio effect is heard in front of the user.
  • 1.0: The audio effect is heard on the right of the user.
gain
The volume of the audio effect. The value range is 0.0 to 100.0. The default value is 100.0, which means the original volume. The smaller the value, the lower the volume.
publish
Whether to publish the audio effect to the remote users:
  • true: Publish the audio effect to the remote users. Both the local user and remote users can hear the audio effect.
  • false: Do not publish the audio effect to the remote users. Only the local user can hear the audio effect.
startPos

The playback position (ms) of the audio effect file.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

  • < 0: Failure.

preloadChannel

Preloads a channel with token, channelId, and uid.

Future<void> preloadChannel(
      {required String token, required String channelId, required int uid});

Details

When audience members need to switch between different channels frequently, calling the method can help shortening the time of joining a channel, thus reducing the time it takes for audience members to hear and see the host. As it may take a while for the SDK to preload a channel, Agora recommends that you call this method as soon as possible after obtaining the channel name and user ID to join a channel.

Note:
  • When calling this method, ensure you set the user role as audience and do not set the audio scenario as audioScenarioChorus, otherwise, this method does not take effect.
  • You also need to make sure that the channel name, user ID and token passed in for preloading are the same as the values passed in when joinning the channel, otherwise, this method does not take effect.
  • One RtcEngine instance supports preloading 20 channels at most. When exceeding this limit, the latest 20 preloaded channels take effect.
  • Failing to preload a channel does not mean that you can't join a channel, nor will it increase the time of joining a channel.

If you join a preloaded channel, leave it and want to rejoin the same channel, you do not need to call this method unless the token for preloading the channel expires.

Parameters

token
The token generated on your server for authentication. See .
When the token for preloading channels expires, you can update the token based on the number of channels you preload.
  • When preloading one channel, calling this method to pass in the new token.
  • When preloading more than one channels:
    • If you use a wildcard token for all preloaded channels, call updatePreloadChannelToken to update the token.
      Note: When generating a wildcard token, ensure the user ID is not set as 0. See Secure authentication with tokens.
    • If you use different tokens to preload different channels, call this method to pass in your user ID, channel name and the new token.
channelId
The channel name that you want to preload. This parameter signifies the channel in which users engage in real-time audio and video interaction. Under the premise of the same App ID, users who fill in the same channel ID enter the same channel for audio and video interaction. The string length must be less than 64 bytes. Supported characters (89 characters in total):
  • All lowercase English letters: a to z.
  • All uppercase English letters: A to Z.
  • All numeric characters: 0 to 9.
  • Space
  • "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", "{", "}", "|", "~", ","
uid
The user ID. This parameter is used to identify the user in the channel for real-time audio and video interaction. You need to set and manage user IDs yourself, and ensure that each user ID in the same channel is unique. This parameter is a 32-bit unsigned integer. The value range is 1 to 232-1. If the user ID is not assigned (or set to 0), the SDK assigns a random user ID and returns it in the onJoinChannelSuccess callback. Your application must record and maintain the returned user ID, because the SDK does not do so.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

  • < 0: Failure.
    • -7: The RtcEngine object has not been initialized. You need to initialize the RtcEngine object before calling this method.
    • -102: The channel name is invalid. You need to pass in a valid channel name and join the channel again.

preloadChannelWithUserAccount

Preloads a channel with token, channelId, and userAccount.

Future<void> preloadChannelWithUserAccount(
      {required String token,
      required String channelId,
      required String userAccount});

Details

When audience members need to switch between different channels frequently, calling the method can help shortening the time of joining a channel, thus reducing the time it takes for audience members to hear and see the host. As it may take a while for the SDK to preload a channel, Agora recommends that you call this method as soon as possible after obtaining the channel name and user ID to join a channel.

Note:
  • When calling this method, ensure you set the user role as audience and do not set the audio scenario as audioScenarioChorus, otherwise, this method does not take effect.
  • You also need to make sure that the User Account, channel ID and token passed in for preloading are the same as the values passed in when joining the channel, otherwise, this method does not take effect.
  • One RtcEngine instance supports preloading 20 channels at most. When exceeding this limit, the latest 20 preloaded channels take effect.
  • Failing to preload a channel does not mean that you can't join a channel, nor will it increase the time of joining a channel.

If you join a preloaded channel, leave it and want to rejoin the same channel, you do not need to call this method unless the token for preloading the channel expires.

Parameters

token
The token generated on your server for authentication. See .
When the token for preloading channels expires, you can update the token based on the number of channels you preload.
  • When preloading one channel, calling this method to pass in the new token.
  • When preloading more than one channels:
    • If you use a wildcard token for all preloaded channels, call updatePreloadChannelToken to update the token.
      Note: When generating a wildcard token, ensure the user ID is not set as 0. See Secure authentication with tokens.
    • If you use different tokens to preload different channels, call this method to pass in your user ID, channel name and the new token.
channelId
The channel name that you want to preload. This parameter signifies the channel in which users engage in real-time audio and video interaction. Under the premise of the same App ID, users who fill in the same channel ID enter the same channel for audio and video interaction. The string length must be less than 64 bytes. Supported characters (89 characters in total):
  • All lowercase English letters: a to z.
  • All uppercase English letters: A to Z.
  • All numeric characters: 0 to 9.
  • Space
  • "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", "{", "}", "|", "~", ","
userAccount
The user account. This parameter is used to identify the user in the channel for real-time audio and video engagement. You need to set and manage user accounts yourself and ensure that each user account in the same channel is unique. The maximum length of this parameter is 255 bytes. Ensure that you set this parameter and do not set it as NULL. Supported characters are (89 in total):
  • The 26 lowercase English letters: a to z.
  • The 26 uppercase English letters: A to Z.
  • All numeric characters: 0 to 9.
  • Space
  • "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", "{", "}", "|", "~", ","

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

  • < 0: Failure.
    • -2: The parameter is invalid. For example, the User Account is empty. You need to pass in a valid parameter and join the channel again.
    • -7: The RtcEngine object has not been initialized. You need to initialize the RtcEngine object before calling this method.
    • -102: The channel name is invalid. You need to pass in a valid channel name and join the channel again.

preloadEffect

Preloads a specified audio effect file into the memory.

Future<void> preloadEffect(
    {required int soundId, required String filePath, int startPos = 0});

Details

To ensure smooth communication, It is recommended that you limit the size of the audio effect file. You can call this method to preload the audio effect before calling joinChannel.

Note:

For the audio file formats supported by this method, see What formats of audio files does the Agora RTC SDK support.

Parameters

soundId
The audio effect ID. The ID of each audio effect file is unique.
filePath
File path:
  • Android: The file path, which needs to be accurate to the file name and suffix. Agora supports URL addresses, absolute paths, or file paths that start with /assets/. You might encounter permission issues if you use an absolute path to access a local file, so Agora recommends using a URI address instead. For example: content://com.android.providers.media.documents/document/audio%3A14441
  • Windows: The absolute path or URL address (including the suffixes of the filename) of the audio effect file. For example: C:\music\audio.mp4.
  • iOS or macOS: The absolute path or URL address (including the suffixes of the filename) of the audio effect file. For example: /var/mobile/Containers/Data/audio.mp4.
startPos
The playback position (ms) of the audio effect file.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

queryDeviceScore

Queries device score.

Future<int> queryDeviceScore();

Details

Applicable scenarios

In high-definition or ultra-high-definition video scenarios, you can first call this method to query the device's score. If the returned score is low (for example, below 60), you need to lower the video resolution to avoid affecting the video experience. The minimum device score required for different business scenarios is varied. For specific score recommendations, please technical support.

Exceptions

When the method call succeeds, it returns a value in the range of [0,100], indicating the current device's score. The larger the value, the stronger the device capability. Most devices are rated between 60 and 100. When the method call fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

  • < 0: Failure.

rate

Allows a user to rate a call after the call ends.

Future<void> rate(
    {required String callId,
    required int rating,
    required String description});

Details

Attention: Ensure that you call this method after leaving a channel.

Parameters

callId
The current call ID. You can get the call ID by calling getCallId.
rating
The rating of the call. The value is between 1 (the lowest score) and 5 (the highest score). If you set a value out of this range, the SDK returns the -2 (ERR_INVALID_ARGUMENT) error.
description
A description of the call. The string length should be less than 800 bytes.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

registerAudioEncodedFrameObserver

Registers an encoded audio observer.

void registerAudioEncodedFrameObserver(
      {required AudioEncodedFrameObserverConfig config,
      required AudioEncodedFrameObserver observer});

Details

Attention:
  • Call this method after joining a channel.
  • You can call this method or startAudioRecording to set the recording type and quality of audio files, but Agora does not recommend using this method and startAudioRecording at the same time. Only the method called later will take effect.

Parameters

config
Observer settings for the encoded audio. See AudioEncodedFrameObserverConfig.
observer
The encoded audio observer. See AudioEncodedFrameObserver.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

registerAudioSpectrumObserver

Register an audio spectrum observer.

void registerAudioSpectrumObserver(AudioSpectrumObserver observer);

Details

After successfully registering the audio spectrum observer and calling enableAudioSpectrumMonitor to enable the audio spectrum monitoring, the SDK reports the callback that you implement in the AudioSpectrumObserver class according to the time interval you set.

Attention: You can call this method either before or after joining a channel.

Parameters

observer

The audio spectrum observer. See AudioSpectrumObserver.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

registerExtension

Registers an extension.

Future<void> registerExtension(
      {required String provider,
      required String extension,
      MediaSourceType type = MediaSourceType.unknownMediaSource});

Details

After the extension is loaded, you can call this method to register the extension.

Attention:
  • Before calling this method, you need to call loadExtensionProvider to load the extension first.
  • For extensions external to the SDK (such as Extensions Marketplace extensions and SDK extensions), you need to call this method before calling setExtensionProperty.

Parameters

provider
The name of the extension provider.
extension
The name of the extension.
type
Source type of the extension. See MediaSourceType.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

registerEventHandler

Adds event handlers

void registerEventHandler(RtcEngineEventHandler eventHandler);

Details

The SDK uses the RtcEngineEventHandler class to send callbacks to the app. The app inherits the methods of this class to receive these callbacks. All methods in this class have default (empty) implementations. Therefore, apps only need to inherits callbacks according to the scenarios. In the callbacks, avoid time-consuming tasks or calling APIs that can block the thread, such as the sendStreamMessage method. Otherwise, the SDK may not work properly.

Parameters

eventHandler
Callback events to be added. See RtcEngineEventHandler.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

registerLocalUserAccount

Registers a user account.

Future<void> registerLocalUserAccount(
    {required String appId, required String userAccount});

Details

Once registered, the user account can be used to identify the local user when the user joins the channel. After the registration is successful, the user account can identify the identity of the local user, and the user can use it to join the channel.

After the user successfully registers a user account, the SDK triggers the onLocalUserRegistered callback on the local client, reporting the user ID and account of the local user.

This method is optional. To join a channel with a user account, you can choose either of the following ways:
  • Call registerLocalUserAccount to create a user account, and then call joinChannelWithUserAccount to join the channel.
  • Call the joinChannelWithUserAccount method to join the channel.

The difference between the two ways is that the time elapsed between calling the registerLocalUserAccount method and joining the channel is shorter than directly calling joinChannelWithUserAccount.

Attention:
  • Ensure that you set the userAccount parameter; otherwise, this method does not take effect.
  • Ensure that the userAccount is unique in the channel.
  • To ensure smooth communication, use the same parameter type to identify the user. For example, if a user joins the channel with a user ID, then ensure all the other users use the user ID too. The same applies to the user account. If a user joins the channel with the Agora Web SDK, ensure that the ID of the user is set to the same parameter type.

Parameters

appId
The App ID of your project on Agora Console.
userAccount
The user account. This parameter is used to identify the user in the channel for real-time audio and video engagement. You need to set and manage user accounts yourself and ensure that each user account in the same channel is unique. The maximum length of this parameter is 255 bytes. Ensure that you set this parameter and do not set it as NULL. Supported characters are as follow(89 in total):
  • The 26 lowercase English letters: a to z.
  • The 26 uppercase English letters: A to Z.
  • All numeric characters: 0 to 9.
  • Space
  • "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", "{", "}", "|", "~", ","

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

registerMediaMetadataObserver

Registers the metadata observer.

void registerMediaMetadataObserver(
      {required MetadataObserver observer, required MetadataType type});

Details

You need to implement the MetadataObserver class and specify the metadata type in this method. This method enables you to add synchronized metadata in the video stream for more diversified live interactive streaming, such as sending shopping links, digital coupons, and online quizzes.

Attention: Call this method before joinChannel.

Parameters

observer
The metadata observer. See MetadataObserver.
type

The metadata type. The SDK currently only supports videoMetadata.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

  • < 0: Failure.

release

Releases the RtcEngine instance.

Future<void> release({bool sync = false});

Details

This method releases all resources used by the Agora SDK. Use this method for apps in which users occasionally make voice or video calls. When users do not make calls, you can free up resources for other operations.

After a successful method call, you can no longer use any method or callback in the SDK anymore. If you want to use the real-time communication functions again, you must call createAgoraRtcEngine and initialize to create a new RtcEngine instance.

Attention:
  • This method can be called synchronously. You need to wait for the resource of RtcEngine to be released before performing other operations (for example, create a new RtcEngine object). Therefore, Agora recommends calling this method in the child thread to avoid blocking the main thread.
  • Besides, Agora does not recommend you calling release in any callback of the SDK. Otherwise, the SDK cannot release the resources until the callbacks return results, which may result in a deadlock.

Parameters

sync

Whether the method is called synchronously:

  • true: Synchronous call.
  • false: Asynchronous call. Currently this method only supports synchronous calls. Do not set this parameter to this value.

unregisterEventHandler

Removes the specified callback handler.

void unregisterEventHandler(RtcEngineEventHandler eventHandler);

Details

This method removes the specified callback handler. For callback events that you want to listen for only once, call this method to remove the relevant callback handler after you have received them.

Parameters

eventHandler
The callback handler to be deleted. See RtcEngineEventHandler.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

renewToken

Renews the token.

Future<void> renewToken(String token);

Details

You can call this method to pass a new token to the SDK. A token expires after a certain period of time. In the following two cases, the app should call this method to pass in a new token. Failure to do so will result in the SDK disconnecting from the server.

Parameters

token
The new token.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

resumeAllChannelMediaRelay

Resumes the media stream relay to all target channels.

Future<void> resumeAllChannelMediaRelay();

Details

After calling the pauseAllChannelMediaRelay method, you can call this method to resume relaying media streams to all destination channels.

Attention: Call this method after pauseAllChannelMediaRelay.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

  • < 0: Failure.

resumeAllEffects

Resumes playing all audio effect files.

Future<void> resumeAllEffects();

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

resumeAudioMixing

Resumes playing and mixing the music file.

Future<void> resumeAudioMixing();

Details

This method resumes playing and mixing the music file. Call this method when you are in a channel.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

resumeEffect

Resumes playing a specified audio effect.

Future<void> resumeEffect(int soundId);

Parameters

soundId
The audio effect ID. The ID of each audio effect file is unique.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

selectAudioTrack

Selects the audio track used during playback.

Future<void> selectAudioTrack(int index);

Details

After getting the track index of the audio file, you can call this method to specify any track to play. For example, if different tracks of a multi-track file store songs in different languages, you can call this method to set the playback language.

Note:

Parameters

index
The audio track you want to specify. The value range is [0, getAudioTrackCount()].

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

selectMultiAudioTrack

Selects the audio tracks that you want to play on your local device and publish to the channel respectively.

Future<void> selectMultiAudioTrack(
    {required int playoutTrackIndex, required int publishTrackIndex});

Details

You can call this method to determine the audio track to be played on your local device and published to the channel.

Before calling this method, you need to open the media file with the openWithMediaSource method and set enableMultiAudioTrack in MediaSource as true.

Applicable scenarios

For example, in KTV scenarios, the host can choose to play the original sound locally and publish the accompaniment track to the channel.

Parameters

playoutTrackIndex
The index of audio tracks for local playback. You can obtain the index through getStreamInfo.
publishTrackIndex
The index of audio tracks to be published in the channel. You can obtain the index through getStreamInfo.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

  • < 0: Failure.

sendCustomReportMessage

Reports customized messages.

Future<void> sendCustomReportMessage(
    {required String id,
    required String category,
    required String event,
    required String label,
    required int value});

Details

Agora supports reporting and analyzing customized messages. This function is in the beta stage with a free trial. The ability provided in its beta test version is reporting a maximum of 10 message pieces within 6 seconds, with each message piece not exceeding 256 bytes and each string not exceeding 100 bytes. To try out this function, contact support@agora.io and discuss the format of customized messages with us.

sendMetaData

Sends media metadata.

Future<void> sendMetaData(
    {required Metadata metadata, required VideoSourceType sourceType});

Details

If the metadata is sent successfully, the SDK triggers the onMetadataReceived callback on the receiver.

Parameters

metadata
Media metadata. See Metadata.
sourceType
The type of the video source. See VideoSourceType.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

  • < 0: Failure.

sendStreamMessage

Sends data stream messages.

Future<void> sendStreamMessage(
    {required int streamId, required Uint8List data, required int length});

Details

Sends data stream messages to all users in a channel. The SDK has the following restrictions on this method:
  • Up to 30 packets can be sent per second in a channel with each packet having a maximum size of 1 KB.
  • Each client can send up to 6 KB of data per second.
  • Each user can have up to five data streams simultaneously.

A successful method call triggers the onStreamMessage callback on the remote client, from which the remote user gets the stream message. A failed method call triggers the onStreamMessageError callback on the remote client.

Attention:
  • Ensure that you call createDataStream to create a data channel before calling this method.
  • In live streaming scenarios, this method only applies to hosts.

Parameters

streamId
The data stream ID. You can get the data stream ID by calling createDataStream.
data
The message to be sent.
length
The length of the data.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setAdvancedAudioOptions

Sets audio advanced options.

Future<void> setAdvancedAudioOptions(AdvancedAudioOptions options);

Details

If you have advanced audio processing requirements, such as capturing and sending stereo audio, you can call this method to set advanced audio options.

Attention: Call this method after calling joinChannel, enableAudio and enableLocalAudio.

Parameters

options
The advanced options for audio. See AdvancedAudioOptions.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setAudioEffectParameters

Sets parameters for SDK preset audio effects.

Future<void> setAudioEffectParameters(
  {required AudioEffectPreset preset,
  required int param1,
  required int param2});

Details

Call this method to set the following parameters for the local user who sends an audio stream:
  • 3D voice effect: Sets the cycle period of the 3D voice effect.
  • Pitch correction effect: Sets the basic mode and tonic pitch of the pitch correction effect. Different songs have different modes and tonic pitches. Agora recommends bounding this method with interface elements to enable users to adjust the pitch correction interactively.

After setting the audio parameters, all users in the channel can hear the effect.

Attention:

Parameters

preset
The options for SDK preset audio effects:
  • roomAcoustics3dVoice, 3D voice effect:
    • Call setAudioProfile and set the profile parameter in to audioProfileMusicStandardStereo(3) or audioProfileMusicHighQualityStereo(5) before setting this enumerator; otherwise, the enumerator setting does not take effect.
    • If the 3D voice effect is enabled, users need to use stereo audio playback devices to hear the anticipated voice effect.
  • pitchCorrection, Pitch correction effect: To achieve better audio effect quality, Agora recommends setting the profile parameter in setAudioProfile to audioProfileMusicHighQuality(4) or audioProfileMusicHighQualityStereo(5) before setting this enumerator.
param1
  • If you set preset to roomAcoustics3dVoice, param1 sets the cycle period of the 3D voice effect. The value range is [1,60] and the unit is seconds. The default value is 10, indicating that the voice moves around you every 10 seconds.
  • If you set preset to pitchCorrection, param1 indicates the basic mode of the pitch correction effect:
    • 1: (Default) Natural major scale.
    • 2: Natural minor scale.
    • 3: Japanese pentatonic scale.
param2
  • If you set preset to roomAcoustics3dVoice , you need to set param2 to 0.
  • If you set preset to pitchCorrection, param2 indicates the tonic pitch of the pitch correction effect:
    • 1: A
    • 2: A#
    • 3: B
    • 4: (Default) C
    • 5: C#
    • 6: D
    • 7: D#
    • 8: E
    • 9: F
    • 10: F#
    • 11: G
    • 12: G#

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setAudioEffectPreset

Sets an SDK preset audio effect.

Future<void> setAudioEffectPreset(AudioEffectPreset preset);

Details

Call this method to set an SDK preset audio effect for the local user who sends an audio stream. This audio effect does not change the gender characteristics of the original voice. After setting an audio effect, all users in the channel can hear the effect.

To get better audio effect quality, Agora recommends setting the scenario parameter of setAudioProfile as audioScenarioGameStreaming(3) before calling this method.

Attention:
  • You can call this method either before or after joining a channel.
  • Do not set the profile parameter in setAudioProfile to audioProfileSpeechStandard(1)audioProfileIot or (6), or the method does not take effect.
  • This method has the best effect on human voice processing, and Agora does not recommend calling this method to process audio data containing music.
  • If you call setAudioEffectPreset and set enumerators except for roomAcoustics3dVoice or pitchCorrection, do not call setAudioEffectParameters; otherwise, setAudioEffectPreset is overridden.
  • After calling setAudioEffectPreset, Agora does not recommend you to call the following methods, otherwise the effect set by setAudioEffectPreset will be overwritten:
  • This method relies on the voice beautifier dynamic library libagora_audio_beauty_extension.dll. If the dynamic library is deleted, the function cannot be enabled normally.

Parameters

preset
The options for SDK preset audio effects. See AudioEffectPreset.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setAudioMixingDualMonoMode

Sets the channel mode of the current audio file.

Future<void> setAudioMixingDualMonoMode(AudioMixingDualMonoMode mode);

Details

In a stereo music file, the left and right channels can store different audio data. According to your needs, you can set the channel mode to original mode, left channel mode, right channel mode, or mixed channel mode. For example, in the KTV scenario, the left channel of the music file stores the musical accompaniment, and the right channel stores the singing voice. If you only need to listen to the accompaniment, call this method to set the channel mode of the music file to left channel mode; if you need to listen to the accompaniment and the singing voice at the same time, call this method to set the channel mode to mixed channel mode.

Attention:

Parameters

mode
The channel mode. See AudioMixingDualMonoMode.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setAudioMixingPitch

Sets the pitch of the local music file.

Future<void> setAudioMixingPitch(int pitch);

Details

When a local music file is mixed with a local human voice, call this method to set the pitch of the local music file only.

Attention: You need to call this method after calling startAudioMixing and receiving the onAudioMixingStateChanged(audioMixingStatePlaying) callback.

Parameters

pitch
Sets the pitch of the local music file by the chromatic scale. The default value is 0, which means keeping the original pitch. The value ranges from -12 to 12, and the pitch value between consecutive values is a chromatic value. The greater the absolute value of this parameter, the higher or lower the pitch of the local music file.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setAudioMixingPosition

Sets the audio mixing position.

Future<void> setAudioMixingPosition(int pos);

Details

Call this method to set the playback position of the music file to a different starting position (the default plays from the beginning).

Attention: You need to call this method after calling startAudioMixing and receiving the onAudioMixingStateChanged(audioMixingStatePlaying) callback.

Parameters

pos
Integer. The playback position (ms).

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setAudioProfile

Sets the audio profile and audio scenario.

Future<void> setAudioProfile(
    {required AudioProfileType profile,
    AudioScenarioType scenario = AudioScenarioType.audioScenarioDefault});

Details

Attention:
  • You can call this method either before or after joining a channel.
  • Due to iOS system restrictions, some audio routes cannot be recognized in call volume mode. Therefore, if you need to use an external sound card, it is recommended to set the audio scenario to audioScenarioGameStreaming (3). In this scenario, the SDK will switch to media volume to avoid this issue.
  • In scenarios requiring high-quality audio, such as online music tutoring, Agora recommends you set profile as audioProfileMusicHighQuality(4)and scenario as audioScenarioGameStreaming(3).

Parameters

profile

The audio profile, including the sampling rate, bitrate, encoding mode, and the number of channels. See AudioProfileType.

scenario
The audio scenarios. Under different audio scenarios, the device uses different volume types. See AudioScenarioType.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setAudioScenario

Sets audio scenarios.

Future<void> setAudioScenario(AudioScenarioType scenario);

Details

Attention:
  • You can call this method either before or after joining a channel.
  • Due to iOS system restrictions, some audio routes cannot be recognized in call volume mode. Therefore, if you need to use an external sound card, it is recommended to set the audio scenario to audioScenarioGameStreaming (3). In this scenario, the SDK will switch to media volume to avoid this issue.

Parameters

scenario
The audio scenarios. Under different audio scenarios, the device uses different volume types. See AudioScenarioType.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setBeautyEffectOptions

Sets the image enhancement options.

Future<void> setBeautyEffectOptions(
    {required bool enabled,
    required BeautyOptions options,
    MediaSourceType type = MediaSourceType.primaryCameraSource});

Details

Enables or disables image enhancement, and sets the options.

Note:
  • Call this method before calling enableVideo or startPreview.
  • This method relies on the image enhancement dynamic library libagora_clear_vision_extension.dll. If the dynamic library is deleted, the function cannot be enabled normally.
  • This feature has high requirements on device performance. When calling this method, the SDK automatically checks the capabilities of the current device.

Parameters

enabled
Whether to enable the image enhancement function:
  • true: Enable the image enhancement function.
  • false: (Default) Disable the image enhancement function.
options
The image enhancement options. See BeautyOptions.
type
Source type of the extension. See MediaSourceType.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setCameraAutoFocusFaceModeEnabled

Enables the camera auto-face focus function.

Future<void> setCameraAutoFocusFaceModeEnabled(bool enabled);

Details

By default, the SDK disables face autofocus on Android and enables face autofocus on iOS. To set face autofocus, call this method.

Attention:
  • This method is for Android and iOS only.
  • You must call this method after enableVideo. The setting result will take effect after the camera is successfully turned on, that is, after the SDK triggers the onLocalVideoStateChanged callback and returns the local video state as localVideoStreamStateCapturing (1).

Parameters

enabled
Whether to enable face autofocus:
  • true: Enable the camera auto-face focus function.
  • false: Disable face autofocus.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setCameraAutoExposureFaceModeEnabled

Sets whether to enable auto exposure.

Future<void> setCameraAutoExposureFaceModeEnabled(bool enabled);

Details

Attention:
  • This method applies to iOS only.
  • You must call this method after enableVideo. The setting result will take effect after the camera is successfully turned on, that is, after the SDK triggers the onLocalVideoStateChanged callback and returns the local video state as localVideoStreamStateCapturing (1).

Parameters

enabled
Whether to enable auto exposure:
  • true: Enable auto exposure.
  • false: Disable auto exposure.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setCameraCapturerConfiguration

Sets the camera capture configuration.

Future<void> setCameraCapturerConfiguration(
      CameraCapturerConfiguration config);

Details

Attention:
  • This method is for Android and iOS only.
  • Call this method before enabling local camera capture, such as before calling startPreview and joinChannel.

Parameters

config
The camera capture configuration. See CameraCapturerConfiguration.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

  • < 0: Failure.

setCameraDeviceOrientation

Sets the rotation angle of the captured video.

Future<void> setCameraDeviceOrientation(
    {required VideoSourceType type, required VideoOrientation orientation});

Details

Attention:
  • This method applies to Windows only.
  • You must call this method after enableVideo. The setting result will take effect after the camera is successfully turned on, that is, after the SDK triggers the onLocalVideoStateChanged callback and returns the local video state as localVideoStreamStateCapturing (1).
  • When the video capture device does not have the gravity sensing function, you can call this method to manually adjust the rotation angle of the captured video.

Parameters

type
The video source type. See VideoSourceType.
orientation
The clockwise rotation angle. See VideoOrientation.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setCameraExposureFactor

Sets the camera exposure value.

Future<void> setCameraExposureFactor(double factor);

Details

Insufficient or excessive lighting in the shooting environment can affect the image quality of video capture. To achieve optimal video quality, you can use this method to adjust the camera's exposure value.

Attention:
  • This method is for Android and iOS only.
  • You must call this method after enableVideo. The setting result will take effect after the camera is successfully turned on, that is, after the SDK triggers the onLocalVideoStateChanged callback and returns the local video state as localVideoStreamStateCapturing (1).
  • Before calling this method, Agora recommends calling isCameraExposureSupported to check whether the current camera supports adjusting the exposure value.
  • By calling this method, you adjust the exposure value of the currently active camera, that is, the camera specified when calling setCameraCapturerConfiguration.

Parameters

factor

The camera exposure value. The default value is 0, which means using the default exposure of the camera. The larger the value, the greater the exposure. When the video image is overexposed, you can reduce the exposure value; when the video image is underexposed and the dark details are lost, you can increase the exposure value. If the exposure value you specified is beyond the range supported by the device, the SDK will automatically adjust it to the actual supported range of the device.

On Android, the value range is [-20.0, 20.0]. On iOS, the value range is [-8.0, 8.0].

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setCameraExposurePosition

Sets the camera exposure position.

Future<void> setCameraExposurePosition(
    {required double positionXinView, required double positionYinView});

Details

Attention:
  • This method is for Android and iOS only.
  • You must call this method after enableVideo. The setting result will take effect after the camera is successfully turned on, that is, after the SDK triggers the onLocalVideoStateChanged callback and returns the local video state as localVideoStreamStateCapturing (1).
  • After a successful method call, the SDK triggers the onCameraExposureAreaChanged callback.

Parameters

positionXinView
The horizontal coordinate of the touchpoint in the view.
positionYinView
The vertical coordinate of the touchpoint in the view.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setCameraFocusPositionInPreview

Sets the camera manual focus position.

Future<void> setCameraFocusPositionInPreview(
    {required double positionX, required double positionY});

Details

Attention:
  • This method is for Android and iOS only.
  • You must call this method after enableVideo. The setting result will take effect after the camera is successfully turned on, that is, after the SDK triggers the onLocalVideoStateChanged callback and returns the local video state as localVideoStreamStateCapturing (1).
  • After a successful method call, the SDK triggers the onCameraFocusAreaChanged callback.

Parameters

positionX
The horizontal coordinate of the touchpoint in the view.
positionY
The vertical coordinate of the touchpoint in the view.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setCameraTorchOn

Enables the camera flash.

Future<void> setCameraTorchOn(bool isOn);

Details

Attention:
  • This method is for Android and iOS only.
  • You must call this method after enableVideo. The setting result will take effect after the camera is successfully turned on, that is, after the SDK triggers the onLocalVideoStateChanged callback and returns the local video state as localVideoStreamStateCapturing (1).

Parameters

isOn
Whether to turn on the camera flash:
  • true: Turn on the flash.
  • false: (Default) Turn off the flash.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setCameraZoomFactor

Sets the camera zoom ratio.

Future<void> setCameraZoomFactor(double factor);

Details

Attention:
  • This method is for Android and iOS only.
  • You must call this method after enableVideo. The setting result will take effect after the camera is successfully turned on, that is, after the SDK triggers the onLocalVideoStateChanged callback and returns the local video state as localVideoStreamStateCapturing (1).

Parameters

factor
The camera zoom ratio. The value ranges between 1.0 and the maximum zoom supported by the device. You can get the maximum zoom ratio supported by the device by calling the getCameraMaxZoomFactor method.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

  • < 0: if the method if failed.

setChannelProfile

Sets the channel profile.

Future<void> setChannelProfile(ChannelProfileType profile);

Details

After initializing the SDK, the default channel profile is the live streaming profile. You can call this method to set the channel profile. The Agora SDK differentiates channel profiles and applies optimization algorithms accordingly. For example, it prioritizes smoothness and low latency for a video call and prioritizes video quality for interactive live video streaming.

Attention:
  • To ensure the quality of real-time communication, Agora recommends that all users in a channel use the same channel profile.
  • This method must be called and set before joinChannel, and cannot be set again after joining the channel.

Parameters

profile

The channel profile. See ChannelProfileType.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

  • < 0: Failure.
    • -2: The parameter is invalid.
    • -7: The SDK is not initialized.

setCloudProxy

Sets up cloud proxy service.

Future<void> setCloudProxy(CloudProxyType proxyType);

Details

When users' network access is restricted by a firewall, configure the firewall to allow specific IP addresses and ports provided by Agora; then, call this method to enable the cloud proxyType and set the cloud proxy type with the proxyType parameter.

After successfully connecting to the cloud proxy, the SDK triggers the onConnectionStateChanged (connectionStateConnecting, connectionChangedSettingProxyServer) callback.

To disable the cloud proxy that has been set, call the setCloudProxy(noneProxy).

To change the cloud proxy type that has been set, call the setCloudProxy(noneProxy) first, and then call the setCloudProxy to set the proxyType you want.

Attention:
  • Agora recommends that you call this method after joining a channel.
  • When a user is behind a firewall and uses the Force UDP cloud proxy, the services for Media Push and cohosting across channels are not available.
  • When you use the Force TCP cloud proxy, note that an error would occur when calling the startAudioMixing method to play online music files in the HTTP protocol. The services for Media Push and cohosting across channels use the cloud proxy with the TCP protocol.

Parameters

proxyType

The type of the cloud proxy. See CloudProxyType.

This parameter is mandatory. The SDK reports an error if you do not pass in a value.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setClientRole

Sets the user role and level in an interactive live streaming channel.

Future<void> setClientRole(
    {required ClientRoleType role, ClientRoleOptions? options});

Details

In the interactive live streaming profile, the SDK sets the user role as audience by default. You can call this method to set the user role as host.

You can call this method either before or after joining a channel.

If you call this method to set the user's role as the host before joining the channel and set the local video property through the setupLocalVideo method, the local video preview is automatically enabled when the user joins the channel.

If you call this method to switch the user role after joining a channel, the SDK automatically does the following:
Attention: This method applies to the interactive live streaming profile (the profile parameter of setChannelProfile is set as channelProfileLiveBroadcasting) only.

Parameters

role
The user role in the interactive live streaming. See ClientRoleType.
options
The detailed options of a user, including the user level. See ClientRoleOptions.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setColorEnhanceOptions

Sets color enhancement.

Future<void> setColorEnhanceOptions(
      {required bool enabled,
      required ColorEnhanceOptions options,
      MediaSourceType type = MediaSourceType.primaryCameraSource});

Details

The video images captured by the camera can have color distortion. The color enhancement feature intelligently adjusts video characteristics such as saturation and contrast to enhance the video color richness and color reproduction, making the video more vivid.

You can call this method to enable the color enhancement feature and set the options of the color enhancement effect.

Attention:
  • Call this method after calling enableVideo.
  • The color enhancement feature has certain performance requirements on devices. With color enhancement turned on, Agora recommends that you change the color enhancement level to one that consumes less performance or turn off color enhancement if your device is experiencing severe heat problems.
  • Both this method and setExtensionProperty can enable color enhancement:
    • When you use the SDK to capture video, Agora recommends this method (this method only works for video captured by the SDK).
    • When you use an external video source to implement custom video capture, or send an external video source to the SDK, Agora recommends using setExtensionProperty.
  • This method relies on the image enhancement dynamic library libagora_clear_vision_extension.dll. If the dynamic library is deleted, the function cannot be enabled normally.

Parameters

enabled
Whether to enable color enhancement:
  • true Enable color enhancement.
  • false: (Default) Disable color enhancement.
options
The color enhancement options. See ColorEnhanceOptions.
type
The type of the video source. See MediaSourceType.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setDefaultAudioRouteToSpeakerphone

Sets the default audio playback route.

Future<void> setDefaultAudioRouteToSpeakerphone(bool defaultToSpeaker);

Details

Note:
  • This method applies to Android and iOS only.
  • Ensure that you call this method before joining a channel. If you need to change the audio route after joining a channel, call setEnableSpeakerphone.

Most mobile phones have two audio routes: an earpiece at the top, and a speakerphone at the bottom. The earpiece plays at a lower volume, and the speakerphone at a higher volume. When setting the default audio route, you determine whether audio playback comes through the earpiece or speakerphone when no external audio device is connected.

In different scenarios, the default audio routing of the system is also different. See the following:
  • Voice call: Earpiece.
  • Audio broadcast: Speakerphone.
  • Video call: Speakerphone.
  • Video broadcast: Speakerphone.

You can call this method to change the default audio route. After a successful method call, the SDK triggers the onAudioRoutingChanged callback.

Note:

The system audio route changes when an external audio device, such as a headphone or a Bluetooth audio device, is connected. See Audio Route for detailed change principles.

Parameters

defaultToSpeaker
Whether to set the speakerphone as the default audio route:
  • true: Set the speakerphone as the default audio route.
  • false: Set the earpiece as the default audio route.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setDualStreamMode

Sets dual-stream mode configuration on the sender side.

Future<void> setDualStreamMode(
      {required SimulcastStreamMode mode, SimulcastStreamConfig? streamConfig});

Details

The SDK defaults to enabling low-quality video stream adaptive mode (autoSimulcastStream) on the sender side, which means the sender does not actively send low-quality video stream. The receiving end with the role of the host can initiate a low-quality video stream request by calling setRemoteVideoStreamType, and upon receiving the request, the sending end automatically starts sending low-quality stream.
  • If you want to modify this behavior, you can call this method and set mode to disableSimulcastStream (never send low-quality video streams) or enableSimulcastStream (always send low-quality video streams).
  • If you want to restore the default behavior after making changes, you can call this method again with mode set to autoSimulcastStream.
Note: The difference and connection between this method and enableDualStreamMode is as follows:
  • When calling this method and setting mode to disableSimulcastStream, it has the same effect as calling enableDualStreamMode and setting enabled to false.
  • When calling this method and setting mode to enableSimulcastStream, it has the same effect as calling enableDualStreamMode and setting enabled to true.
  • Both methods can be called before and after joining a channel. If both methods are used, the settings in the method called later takes precedence.

Parameters

mode
The mode in which the video stream is sent. See SimulcastStreamMode.
streamConfig
The configuration of the low-quality video stream. See SimulcastStreamConfig.
Note: When setting mode to disableSimulcastStream, setting streamConfig will not take effect.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setEarMonitoringAudioFrameParameters

Sets the format of the in-ear monitoring raw audio data.

Future<void> setEarMonitoringAudioFrameParameters(
      {required int sampleRate,
      required int channel,
      required RawAudioFrameOpModeType mode,
      required int samplesPerCall});

Details

This method is used to set the in-ear monitoring audio data format reported by the onEarMonitoringAudioFrame callback.

Attention:
  • Before calling this method, you need to call enableInEarMonitoring, and set includeAudioFilters to earMonitoringFilterBuiltInAudioFilters or earMonitoringFilterNoiseSuppression.
  • The SDK calculates the sampling interval based on the samplesPerCall, sampleRate and channel parameters set in this method.Sample interval (sec) = samplePerCall/(sampleRate × channel). Ensure that the sample interval ≥ 0.01 (s). The SDK triggers the onEarMonitoringAudioFrame callback according to the sampling interval.

Parameters

sampleRate
The sample rate of the audio data reported in the onEarMonitoringAudioFrame callback, which can be set as 8,000, 16,000, 32,000, 44,100, or 48,000 Hz.
channel
The number of audio channels reported in the onEarMonitoringAudioFrame callback.
  • 1: Mono.
  • 2: Stereo.
mode

The use mode of the audio frame. See RawAudioFrameOpModeType.

samplesPerCall
The number of data samples reported in the onEarMonitoringAudioFrame callback, such as 1,024 for the Media Push.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

  • < 0: Failure.

setEffectPosition

Sets the playback position of an audio effect file.

Future<void> setEffectPosition({required int soundId, required int pos});

Details

After a successful setting, the local audio effect file starts playing at the specified position.

Attention: Call this method after playEffect.

Parameters

soundId
The audio effect ID. The ID of each audio effect file is unique.
pos
The playback position (ms) of the audio effect file.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setEffectsVolume

Sets the volume of the audio effects.

Future<void> setEffectsVolume(int volume);

Details

Attention: Call this method after playEffect.

Parameters

volume
The playback volume. The value range is [0, 100]. The default value is 100, which represents the original volume.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setEnableSpeakerphone

Enables/Disables the audio route to the speakerphone.

Future<void> setEnableSpeakerphone(bool speakerOn);

Details

If the default audio route of the SDK (see Set the Audio Route) or the setting in setDefaultAudioRouteToSpeakerphone cannot meet your requirements, you can call setEnableSpeakerphone to switch the current audio route. After a successful method call, the SDK triggers the onAudioRoutingChanged callback.

This method only sets the audio route in the current channel and does not influence the default audio route. If the user leaves the current channel and joins another channel, the default audio route is used.

Attention:
  • This method applies to Android and iOS only.
  • Call this method after joining a channel.
  • If the user uses an external audio playback device such as a Bluetooth or wired headset, this method does not take effect, and the SDK plays audio through the external device. When the user uses multiple external devices, the SDK plays audio through the last connected device.

Parameters

speakerOn
Sets whether to enable the speakerphone or earpiece:
  • true: Enable device state monitoring. The audio route is the speakerphone.
  • false: Disable device state monitoring. The audio route is the earpiece.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setEncryptionMode

Sets the built-in encryption mode.

Future<void> setEncryptionMode(String encryptionMode);

Details

Deprecated:
Use enableEncryption instead.

The SDK supports built-in encryption schemes, AES-128-GCM is supported by default. Call this method to use other encryption modes. All users in the same channel must use the same encryption mode and secret. Refer to the information related to the AES encryption algorithm on the differences between the encryption modes.

Attention: Before calling this method, please call setEncryptionSecret to enable the built-in encryption function.

Parameters

encryptionMode
The following encryption modes:
  • "aes-128-xts": 128-bit AES encryption, XTS mode.
  • "aes-128-ecb": 128-bit AES encryption, ECB mode.
  • "aes-256-xts": 256-bit AES encryption, XTS mode.
  • "sm4-128-ecb": 128-bit SM4 encryption, ECB mode.
  • "aes-128-gcm": 128-bit AES encryption, GCM mode.
  • "aes-256-gcm": 256-bit AES encryption, GCM mode.
  • "": When this parameter is set as null, the encryption mode is set as "aes-128-gcm" by default.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setEncryptionSecret

Enables built-in encryption with an encryption password before users join a channel.

Future<void> setEncryptionSecret(String secret);

Details

Deprecated:
Use enableEncryption instead.

Before joining the channel, you need to call this method to set the secret parameter to enable the built-in encryption. All users in the same channel should use the same secret. The secret is automatically cleared once a user leaves the channel. If you do not specify the secret or secret is set as null, the built-in encryption is disabled.

Attention:
  • Do not use this method for Media Push.
  • For optimal transmission, ensure that the encrypted data size does not exceed the original data size + 16 bytes. 16 bytes is the maximum padding size for AES encryption.

Parameters

secret
The encryption password.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setExtensionProperty

Sets the properties of the extension.

Future<void> setExtensionProperty(
    {required String provider,
    required String extension,
    required String key,
    required String value,
    MediaSourceType type = MediaSourceType.unknownMediaSource});

Details

After enabling the extension, you can call this method to set the properties of the extension.

Parameters

provider
The name of the extension provider.
extension
The name of the extension.
key
The key of the extension.
value
The value of the extension key.
type
Source type of the extension. See MediaSourceType.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setExtensionProviderProperty

Sets the properties of the extension provider.

Future<void> setExtensionProviderProperty(
    {required String provider, required String key, required String value});

Details

You can call this method to set the attributes of the extension provider and initialize the relevant parameters according to the type of the provider.

Attention:

Call this method after enableExtension, and before enabling the audio (enableAudio/enableLocalAudio) or the video (enableVideo/enableLocalVideo).

Parameters

provider
The name of the extension provider.
key
The key of the extension.
value
The value of the extension key.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setHeadphoneEQParameters

Sets the low- and high-frequency parameters of the headphone equalizer.

Future<void> setHeadphoneEQParameters(
      {required int lowGain, required int highGain});

Details

In a spatial audio effect scenario, if the preset headphone equalization effect is not achieved after calling the setHeadphoneEQPreset method, you can further adjust the headphone equalization effect by calling this method.

Parameters

lowGain
The low-frequency parameters of the headphone equalizer. The value range is [-10,10]. The larger the value, the deeper the sound.
highGain
The high-frequency parameters of the headphone equalizer. The value range is [-10,10]. The larger the value, the sharper the sound.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setHeadphoneEQPreset

Sets the preset headphone equalization effect.

Future<void> setHeadphoneEQPreset(HeadphoneEqualizerPreset preset);

Details

This method is mainly used in spatial audio effect scenarios. You can select the preset headphone equalizer to listen to the audio to achieve the expected audio experience.

Note: If the headphones you use already have a good equalization effect, you may not get a significant improvement when you call this method, and could even diminish the experience.

Parameters

preset
The preset headphone equalization effect. See HeadphoneEqualizerPreset.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setInEarMonitoringVolume

Sets the volume of the in-ear monitor.

Future<void> setInEarMonitoringVolume(int volume);

Details

Attention:
  • You can call this method either before or after joining a channel.

Parameters

volume
The volume of the in-ear monitor. The value range is [0,400].
  • 0: Mute.
  • 100: (Default) The original volume.
  • 400: Four times the original volume.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setLocalRenderMode

Updates the display mode of the local video view.

Future<void> setLocalRenderMode(
    {required RenderModeType renderMode,
    VideoMirrorModeType mirrorMode =
        VideoMirrorModeType.videoMirrorModeAuto});

Details

After initializing the local video view, you can call this method to update its rendering and mirror modes. It affects only the video view that the local user sees, not the published local video stream.

Attention:
  • Ensure that you have called the setupLocalVideo method to initialize the local video view before calling this method.
  • During a call, you can call this method as many times as necessary to update the display mode of the local video view.
  • This method only takes effect on the primary camera (primaryCameraSource). In scenarios involving custom video capture or the use of alternative video sources, you need to use setupLocalVideo instead of this method.

Parameters

renderMode

The local video display mode. See RenderModeType.

mirrorMode

The mirror mode of the local video view. See VideoMirrorModeType.

Attention: If you use a front camera, the SDK enables the mirror mode by default; if you use a rear camera, the SDK disables the mirror mode by default.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setLocalVideoMirrorMode

Sets the local video mirror mode.

Future<void> setLocalVideoMirrorMode(VideoMirrorModeType mirrorMode);

Details

Deprecated:
This method is deprecated.
Use setupLocalVideo or setLocalRenderMode instead.

Parameters

mirrorMode

The local video mirror mode. See VideoMirrorModeType.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setLocalVoiceEqualization

Sets the local voice equalization effect.

Future<void> setLocalVoiceEqualization(
  {required AudioEqualizationBandFrequency bandFrequency,
  required int bandGain});

Details

Attention: You can call this method either before or after joining a channel.

Parameters

bandFrequency
The band frequency. The value ranges between 0 and 9; representing the respective 10-band center frequencies of the voice effects, including 31, 62, 125, 250, 500, 1k, 2k, 4k, 8k, and 16k Hz. See AudioEqualizationBandFrequency.
bandGain
The gain of each band in dB. The value ranges between -15 and 15. The default value is 0.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setLocalVoicePitch

Changes the voice pitch of the local speaker.

Future<void> setLocalVoicePitch(double pitch);

Details

Attention: You can call this method either before or after joining a channel.

Parameters

pitch
The local voice pitch. The value range is [0.5,2.0]. The lower the value, the lower the pitch. The default value is 1.0 (no change to the pitch).

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setLocalVoiceReverb

Sets the local voice reverberation.

Future<void> setLocalVoiceReverb(
  {required AudioReverbType reverbKey, required int value});

Details

The SDK provides an easier-to-use method, setAudioEffectPreset, to directly implement preset reverb effects for such as pop, R&B, and KTV.

Note: You can call this method either before or after joining a channel.

Parameters

reverbKey
The reverberation key. Agora provides five reverberation keys, see AudioReverbType.
value
The value of the reverberation key.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setLogFile

Sets the log file.

Future<void> setLogFile(String filePath);

Details

Deprecated:
Use the mLogConfig parameter in initialize method instead.

Specifies an SDK output log file. The log file records all log data for the SDK’s operation. Ensure that the directory for the log file exists and is writable.

Note:

Ensure that you call initialize immediately after calling the RtcEngine method, or the output log may not be complete.

Parameters

filePath
The complete path of the log files. These log files are encoded in UTF-8.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setLogFileSize

Sets the log file size.

Future<void> setLogFileSize(int fileSizeInKBytes);

Details

Deprecated:
Use the logConfig parameter in initialize instead.

By default, the SDK generates five SDK log files and five API call log files with the following rules:

  • The SDK log files are: agorasdk.log, agorasdk.1.log, agorasdk.2.log, agorasdk.3.log, and agorasdk.4.log.
  • The API call log files are: agoraapi.log, agoraapi.1.log, agoraapi.2.log, agoraapi.3.log, and agoraapi.4.log.
  • The default size of each SDK log file and API log file is 2,048 KB. These log files are encoded in UTF-8.
  • The SDK writes the latest logs in agorasdk.log or agoraapi.log.
  • When agorasdk.log is full, the SDK processes the log files in the following order:
    1. Delete the agorasdk.4.log file (if any).
    2. Rename agorasdk.3.log to agorasdk.4.log.
    3. Rename agorasdk.2.log to agorasdk.3.log.
    4. Rename agorasdk.1.log to agorasdk.2.log.
    5. Create a new agorasdk.log file.
  • The overwrite rules for the agoraapi.log file are the same as for agorasdk.log.
Note:

This method is used to set the size of the agorasdk.log file only and does not effect the agoraapi.log file.

Parameters

fileSizeInKBytes
The size (KB) of an agorasdk.log file. The value range is [128,20480]. The default value is 2,048 KB. If you set fileSizeInKByte smaller than 128 KB, the SDK automatically adjusts it to 128 KB; if you set fileSizeInKByte greater than 20,480 KB, the SDK automatically adjusts it to 20,480 KB.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setLogFilter

Sets the log output level of the SDK.

Future<void> setLogFilter(LogFilterType filter);

Details

Deprecated:
Use logConfig in initialize instead.

This method sets the output log level of the SDK. You can use one or a combination of the log filter levels. The log level follows the sequence of logFilterOff, logFilterCritical, logFilterError, logFilterWarn, logFilterInfo, and logFilterDebug. Choose a level to see the logs preceding that level.

If, for example, you set the log level to logFilterWarn, you see the logs within levels logFilterCritical, logFilterError and logFilterWarn.

Parameters

filter

The output log level of the SDK. See LogFilterType.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setLogLevel

Sets the output log level of the SDK.

Future<void> setLogLevel(LogLevel level);

Details

Deprecated:
This method is deprecated. Use RtcEngineContext instead to set the log output level.

Choose a level to see the logs preceding that level.

Parameters

level
The log level: LogLevel.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setLowlightEnhanceOptions

Sets low-light enhancement.

Future<void> setLowlightEnhanceOptions(
      {required bool enabled,
      required LowlightEnhanceOptions options,
      MediaSourceType type = MediaSourceType.primaryCameraSource});

Details

The low-light enhancement feature can adaptively adjust the brightness value of the video captured in situations with low or uneven lighting, such as backlit, cloudy, or dark scenes. It restores or highlights the image details and improves the overall visual effect of the video.

You can call this method to enable the color enhancement feature and set the options of the color enhancement effect.

Attention:
  • Call this method after calling enableVideo.
  • Dark light enhancement has certain requirements for equipment performance. The low-light enhancement feature has certain performance requirements on devices. If your device overheats after you enable low-light enhancement, Agora recommends modifying the low-light enhancement options to a less performance-consuming level or disabling low-light enhancement entirely.
  • Both this method and setExtensionProperty can turn on low-light enhancement:
    • When you use the SDK to capture video, Agora recommends this method (this method only works for video captured by the SDK).
    • When you use an external video source to implement custom video capture, or send an external video source to the SDK, Agora recommends using setExtensionProperty.
  • This method relies on the image enhancement dynamic library libagora_clear_vision_extension.dll. If the dynamic library is deleted, the function cannot be enabled normally.

Parameters

enabled
Whether to enable low-light enhancement:
  • true: Enable low-light enhancement.
  • false: (Default) Disable low-light enhancement.
options
The low-light enhancement options. See LowlightEnhanceOptions.
type
The type of the video source. See MediaSourceType.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setMaxMetadataSize

Sets the maximum size of the media metadata.

Future<void> setMaxMetadataSize(int size);

Details

After calling registerMediaMetadataObserver, you can call this method to set the maximum size of the media metadata.

Parameters

size
The maximum size of media metadata.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

  • < 0: Failure.

setMixedAudioFrameParameters

Sets the audio data format reported by onMixedAudioFrame.

Future<void> setMixedAudioFrameParameters(
    {required int sampleRate,
    required int channel,
    required int samplesPerCall});

Parameters

sampleRate

The sample rate (Hz) of the audio data, which can be set as 8000, 16000, 32000, 44100, or 48000.

channel

The number of channels of the audio data, which can be set as 1(Mono) or 2(Stereo).

samplesPerCall

Sets the number of samples. In Media Push scenarios, set it as 1024.

Note:

The SDK triggers the onMixedAudioFrame callback according to the sample interval. Sampleinterval (sec) = samplePerCall/(sampleRate × channel) Ensure that the value of sample interval more than or equal to 0.01.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setParameters

Provides technical preview functionalities or special customizations by configuring the SDK with JSON options.

Future<void> setParameters(String parameters);

Parameters

parameters
Pointer to the set parameters in a JSON string.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setPlaybackAudioFrameBeforeMixingParameters

Sets the audio data format reported by onPlaybackAudioFrameBeforeMixing.

Future<void> setPlaybackAudioFrameBeforeMixingParameters(
      {required int sampleRate, required int channel});

Parameters

sampleRate

The sample rate (Hz) of the audio data, which can be set as 8000, 16000, 32000, 44100, or 48000.

channel

The number of channels of the audio data, which can be set as 1(Mono) or 2(Stereo).

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setPlaybackAudioFrameParameters

Sets the audio data format for playback.

Future<void> setPlaybackAudioFrameParameters(
    {required int sampleRate,
    required int channel,
    required RawAudioFrameOpModeType mode,
    required int samplesPerCall});

Details

Sets the data format for the onPlaybackAudioFrame callback.

Attention:
  • Ensure that you call this method before joining a channel.
  • The SDK calculates the sampling interval based on the samplesPerCall, sampleRate and channel parameters set in this method.Sample interval (sec) = samplePerCall/(sampleRate × channel). Ensure that the sample interval ≥ 0.01 (s). The SDK triggers the onPlaybackAudioFrame callback according to the sampling interval.

Parameters

sampleRate
The sample rate returned in the onPlaybackAudioFrame callback, which can be set as 8000, 16000, 32000, 44100, or 48000 Hz.
channel
The number of channels returned in the onPlaybackAudioFrame callback:
  • 1: Mono.
  • 2: Stereo.
mode

The use mode of the audio frame. See RawAudioFrameOpModeType.

samplesPerCall
The number of data samples returned in the onPlaybackAudioFrame callback, such as 1024 for the Media Push.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

  • < 0: Failure.

setRecordingAudioFrameParameters

Sets the format of the captured raw audio data.

Future<void> setRecordingAudioFrameParameters(
    {required int sampleRate,
    required int channel,
    required RawAudioFrameOpModeType mode,
    required int samplesPerCall});

Details

Sets the audio format for the onRecordAudioFrame callback.

Attention:
  • Ensure that you call this method before joining a channel.
  • The SDK calculates the sampling interval based on the samplesPerCall, sampleRate and channel parameters set in this method.Sample interval (sec) = samplePerCall/(sampleRate × channel). Ensure that the sample interval ≥ 0.01 (s).

Parameters

sampleRate
The sample rate returned in the onRecordAudioFrame callback, which can be set as 8000, 16000, 32000, 44100, or 48000 Hz.
channel
The number of channels returned in the onRecordAudioFrame callback:
  • 1: Mono.
  • 2: Stereo.
mode

The use mode of the audio frame. See RawAudioFrameOpModeType.

samplesPerCall
The number of data samples returned in the onRecordAudioFrame callback, such as 1024 for the Media Push.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

  • < 0: Failure.

setRemoteDefaultVideoStreamType

Sets the default video stream type to subscribe to.

Future<void> setRemoteDefaultVideoStreamType(VideoStreamType streamType);

Details

The SDK defaults to enabling low-quality video stream adaptive mode (autoSimulcastStream) on the sending end, which means the sender does not actively send low-quality video stream. The receiver with the role of the host can initiate a low-quality video stream request by calling this method, and upon receiving the request, the sending end automatically starts sending the low-quality video stream.

The SDK will dynamically adjust the size of the corresponding video stream based on the size of the video window to save bandwidth and computing resources. The default aspect ratio of the low-quality video stream is the same as that of the high-quality video stream. According to the current aspect ratio of the high-quality video stream, the system will automatically allocate the resolution, frame rate, and bitrate of the low-quality video stream.

Attention:
  • Call this method before joining a channel. The SDK does not support changing the default subscribed video stream type after joining a channel.
  • If you call both this method and setRemoteVideoStreamType, the setting of setRemoteVideoStreamType takes effect.

Parameters

streamType

The default video-stream type. See VideoStreamType.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setRemoteRenderMode

Updates the display mode of the video view of a remote user.

Future<void> setRemoteRenderMode(
    {required int uid,
    required RenderModeType renderMode,
    required VideoMirrorModeType mirrorMode});

Details

After initializing the video view of a remote user, you can call this method to update its rendering and mirror modes. This method affects only the video view that the local user sees.

Attention:
  • Call this method after initializing the remote view by calling the setupRemoteVideo method.
  • During a call, you can call this method as many times as necessary to update the display mode of the video view of a remote user.

Parameters

uid
The user ID of the remote user.
renderMode

The rendering mode of the remote user view. For details, see RenderModeType.

mirrorMode

The mirror mode of the remote user view. See VideoMirrorModeType.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

  • < 0: Failure.

setRemoteUserSpatialAudioParams

Sets the spatial audio effect parameters of the remote user.

Future<void> setRemoteUserSpatialAudioParams(
    {required int uid, required SpatialAudioParams params});

Details

Call this method after enableSpatialAudio. After successfully setting the spatial audio effect parameters of the remote user, the local user can hear the remote user with a sense of space.

Parameters

uid
The user ID. This parameter must be the same as the user ID passed in when the user joined the channel.
params
The spatial audio parameters. See SpatialAudioParams.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setRemoteVideoStreamType

Sets the video stream type to subscribe to.

Future<void> setRemoteVideoStreamType(
    {required int uid, required VideoStreamType streamType});

Details

The SDK defaults to enabling low-quality video stream adaptive mode (autoSimulcastStream) on the sending end, which means the sender does not actively send low-quality video stream. The receiver with the role of the host can initiate a low-quality video stream request by calling this method, and upon receiving the request, the sending end automatically starts sending the low-quality video stream.

The SDK will dynamically adjust the size of the corresponding video stream based on the size of the video window to save bandwidth and computing resources. The default aspect ratio of the low-quality video stream is the same as that of the high-quality video stream. According to the current aspect ratio of the high-quality video stream, the system will automatically allocate the resolution, frame rate, and bitrate of the low-quality video stream.

Attention:
  • You can call this method either before or after joining a channel.
  • If the publisher has already called setDualStreamMode and set mode to disableSimulcastStream (never send low-quality video stream), calling this method will not take effect, you should call setDualStreamMode again on the sending end and adjust the settings.
  • Calling this method on the receiving end of the audience role will not take effect.
  • If you call both setRemoteVideoStreamType and setRemoteDefaultVideoStreamType, the settings in setRemoteVideoStreamType take effect.

Parameters

uid
The user ID.
streamType

The video stream type, see VideoStreamType.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setRemoteVideoSubscriptionOptions

Options for subscribing to remote video streams.

Future<void> setRemoteVideoSubscriptionOptions(
      {required int uid, required VideoSubscriptionOptions options});

Details

When a remote user has enabled dual-stream mode, you can call this method to choose the option for subscribing to the video streams sent by the remote user.

  • If you only register one VideoFrameObserver object, the SDK subscribes to the raw video data and encoded video data by default (the effect is equivalent to setting encodedFrameOnly to false).
  • If you only register one VideoEncodedFrameObserver object, the SDK only subscribes to the encoded video data by default (the effect is equivalent to setting encodedFrameOnly to true).
  • If you register one VideoFrameObserver object and one VideoEncodedFrameObserver object successively, the SDK subscribes to the encoded video data by default (the effect is equivalent to setting encodedFrameOnly to false).
  • If you call this method first with the options parameter set, and then register one VideoFrameObserver or VideoEncodedFrameObserver object, you need to call this method again and set the options parameter as described in the above two items to get the desired results.
Note: Agora recommends the following steps:
  1. Set autoSubscribeVideo to false when calling joinChannel to join a channel.
  2. Call this method after receiving the onUserJoined callback to set the subscription options for the specified remote user's video stream.
  3. Call the muteRemoteVideoStream method to resume subscribing to the video stream of the specified remote user. If you set encodedFrameOnly to true in the previous step, the SDK triggers the onEncodedVideoFrameReceived callback locally to report the received encoded video frame information.

Parameters

uid
The user ID of the remote user.
options
The video subscription options. See VideoSubscriptionOptions.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setRemoteVoicePosition

Sets the 2D position (the position on the horizontal plane) of the remote user's voice.

Future<void> setRemoteVoicePosition(
    {required int uid, required double pan, required double gain});

Details

This method sets the 2D position and volume of a remote user, so that the local user can easily hear and identify the remote user's position.

When the local user calls this method to set the voice position of a remote user, the voice difference between the left and right channels allows the local user to track the real-time position of the remote user, creating a sense of space. This method applies to massive multiplayer online games, such as Battle Royale games.

Attention:
  • For this method to work, enable stereo panning for remote users by calling the enableSoundPositionIndication method before joining a channel.
  • For the best voice positioning, Agora recommends using a wired headset.
  • Call this method after joining a channel.

Parameters

uid
The user ID of the remote user.
pan
The voice position of the remote user. The value ranges from -1.0 to 1.0:
  • 0.0: (Default) The remote voice comes from the front.
  • -1.0: The remote voice comes from the left.
  • 1.0: The remote voice comes from the right.
gain
The volume of the remote user. The value ranges from 0.0 to 100.0. The default value is 100.0 (the original volume of the remote user). The smaller the value, the lower the volume.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setRouteInCommunicationMode

Selects the audio playback route in communication audio mode.

Future<void> setRouteInCommunicationMode(int route);

Details

This method is used to switch the audio route from Bluetooth headphones to earpiece, wired headphones or speakers in communication audio mode (). After the method is called successfully, the SDK will trigger the onAudioRoutingChanged callback to report the modified route.

Attention:

Parameters

route
The audio playback route you want to use:
  • -1: The default audio route.
  • 0: Headphones with microphone.
  • 1: Handset.
  • 2: Headphones without microphone.
  • 3: Device's built-in speaker.
  • 4: (Not supported yet) External speakers.
  • 5: Bluetooth headphones.
  • 6: USB device.

Exceptions

Without practical meaning.

setScreenCaptureContentHint

Sets the content hint for screen sharing.

Future<void> setScreenCaptureContentHint(VideoContentHint contentHint);

Details

A content hint suggests the type of the content being shared, so that the SDK applies different optimization algorithms to different types of content. If you don't call this method, the default content hint is contentHintNone.

Attention: You can call this method either before or after you start screen sharing.

Parameters

contentHint
The content hint for screen sharing. See VideoContentHint.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setScreenCaptureScenario

Sets the screen sharing scenario.

Future<void> setScreenCaptureScenario(ScreenScenarioType screenScenario);

Details

When you start screen sharing or window sharing, you can call this method to set the screen sharing scenario. The SDK adjusts the video quality and experience of the sharing according to the scenario.

Note: Agora recommends that you call this method before joining a channel.

Parameters

screenScenario
The screen sharing scenario. See ScreenScenarioType.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setSubscribeAudioBlocklist

Set the blocklist of subscriptions for audio streams.

Future<void> setSubscribeAudioBlocklist(
      {required List<int> uidList, required int uidNumber});

Details

You can call this method to specify the audio streams of a user that you do not want to subscribe to.

Attention:
  • You can call this method either before or after joining a channel.
  • The blocklist is not affected by the setting in muteRemoteAudioStream,muteAllRemoteAudioStreams, and autoSubscribeAudio in ChannelMediaOptions.
  • Once the blocklist of subscriptions is set, it is effective even if you leave the current channel and rejoin the channel.
  • If a user is added in the allowlist and blocklist at the same time, only the blocklist takes effect.

Parameters

uidList

The user ID list of users that you do not want to subscribe to.

If you want to specify the audio streams of a user that you do not want to subscribe to, add the user ID in this list. If you want to remove a user from the blocklist, you need to call the setSubscribeAudioBlocklist method to update the user ID list; this means you only add the uid of users that you do not want to subscribe to in the new user ID list.

uidNumber
The number of users in the user ID list.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setSubscribeAudioAllowlist

Sets the allowlist of subscriptions for audio streams.

Future<void> setSubscribeAudioAllowlist(
      {required List<int> uidList, required int uidNumber});

Details

You can call this method to specify the audio streams of a user that you want to subscribe to.

Note:
  • You can call this method either before or after joining a channel.
  • The allowlist is not affected by the setting in muteRemoteAudioStream, muteAllRemoteAudioStreams and autoSubscribeAudio in ChannelMediaOptions.
  • Once the allowlist of subscriptions is set, it is effective even if you leave the current channel and rejoin the channel.
  • If a user is added in the allowlist and blocklist at the same time, only the blocklist takes effect.

Parameters

uidList

The user ID list of users that you want to subscribe to.

If you want to specify the audio streams of a user for subscription, add the user ID in this list. If you want to remove a user from the allowlist, you need to call the setSubscribeAudioAllowlist method to update the user ID list; this means you only add the uid of users that you want to subscribe to in the new user ID list.

uidNumber
The number of users in the user ID list.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setSubscribeVideoBlocklist

Set the blocklist of subscriptions for video streams.

Future<void> setSubscribeVideoBlocklist(
      {required List<int> uidList, required int uidNumber});

Details

You can call this method to specify the video streams of a user that you do not want to subscribe to.

Note:
  • You can call this method either before or after joining a channel.
  • The blocklist is not affected by the setting in muteRemoteVideoStream, muteAllRemoteVideoStreams and autoSubscribeAudio in ChannelMediaOptions.
  • Once the blocklist of subscriptions is set, it is effective even if you leave the current channel and rejoin the channel.
  • If a user is added in the allowlist and blocklist at the same time, only the blocklist takes effect.

Parameters

uidList

The user ID list of users that you do not want to subscribe to.

If you want to specify the video streams of a user that you do not want to subscribe to, add the user ID of that user in this list. If you want to remove a user from the blocklist, you need to call the setSubscribeVideoBlocklist method to update the user ID list; this means you only add the uid of users that you do not want to subscribe to in the new user ID list.

uidNumber
The number of users in the user ID list.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setSubscribeVideoAllowlist

Set the allowlist of subscriptions for video streams.

Future<void> setSubscribeVideoAllowlist(
      {required List<int> uidList, required int uidNumber});

Details

You can call this method to specify the video streams of a user that you want to subscribe to.

Note:
  • You can call this method either before or after joining a channel.
  • The allowlist is not affected by the setting in muteRemoteVideoStream, muteAllRemoteVideoStreams and autoSubscribeAudio in ChannelMediaOptions.
  • Once the allowlist of subscriptions is set, it is effective even if you leave the current channel and rejoin the channel.
  • If a user is added in the allowlist and blocklist at the same time, only the blocklist takes effect.

Parameters

uidList

The user ID list of users that you want to subscribe to.

If you want to specify the video streams of a user for subscription, add the user ID of that user in this list. If you want to remove a user from the allowlist, you need to call the setSubscribeVideoAllowlist method to update the user ID list; this means you only add the uid of users that you want to subscribe to in the new user ID list.

uidNumber
The number of users in the user ID list.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setVideoDenoiserOptions

Sets video noise reduction.

Future<void> setVideoDenoiserOptions(
      {required bool enabled,
      required VideoDenoiserOptions options,
      MediaSourceType type = MediaSourceType.primaryCameraSource});

Details

Underlit environments and low-end video capture devices can cause video images to contain significant noise, which affects video quality. In real-time interactive scenarios, video noise also consumes bitstream resources and reduces encoding efficiency during encoding.

You can call this method to enable the video noise reduction feature and set the options of the video noise reduction effect.

Attention:
  • Call this method after calling enableVideo.
  • Video noise reduction has certain requirements for equipment performance. If your device overheats after you enable video noise reduction, Agora recommends modifying the video noise reduction options to a less performance-consuming level or disabling video noise reduction entirely.
  • Both this method and setExtensionProperty can turn on video noise reduction function:
    • When you use the SDK to capture video, Agora recommends this method (this method only works for video captured by the SDK).
    • When you use an external video source to implement custom video capture, or send an external video source to the SDK, Agora recommends using setExtensionProperty.
  • This method relies on the image enhancement dynamic library libagora_clear_vision_extension.dll. If the dynamic library is deleted, the function cannot be enabled normally.

Parameters

enabled
Whether to enable video noise reduction:
  • true: Enable video noise reduction.
  • false: (Default) Disable video noise reduction.
options
The video noise reduction options. See VideoDenoiserOptions.
type
The type of the video source. See MediaSourceType.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setVideoEncoderConfiguration

Sets the video encoder configuration.

Future<void> setVideoEncoderConfiguration(VideoEncoderConfiguration config);

Details

Sets the encoder configuration for the local video. Each configuration profile corresponds to a set of video parameters, including the resolution, frame rate, and bitrate.

The config specified in this method is the maximum value under ideal network conditions. If the video engine cannot render the video using the specified config due to unreliable network conditions, the parameters further down the list are considered until a successful configuration is found.

Attention: You can call this method either before or after joining a channel. If the user does not need to reset the video encoding properties after joining the channel, Agora recommends calling this method before enableVideo to reduce the time to render the first video frame.

Parameters

config
Video profile. See VideoEncoderConfiguration.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setupLocalVideo

Initializes the local video view.

Future<void> setupLocalVideo(VideoCanvas canvas);

Details

This method initializes the video view of a local stream on the local device. It affects only the video view that the local user sees, not the published local video stream. Call this method to bind the local video stream to a video view (view) and to set the rendering and mirror modes of the video view.

After initialization, call this method to set the local video and then join the channel. The local video still binds to the view after you leave the channel. To unbind the local video from the view, set the view parameter as NULL.

In real-time interactive scenarios, if you need to simultaneously view multiple preview frames in the local video preview, and each frame is at a different observation position along the video link, you can repeatedly call this method to set different views and set different observation positions for each view. For example, by setting the video source to the camera and then configuring two views with position setting to positionPostCapturerOrigin and positionPostCapturer, you can simultaneously preview the raw, unprocessed video frame and the video frame that has undergone preprocessing (image enhancement effects, virtual background, watermark) in the local video preview.

Attention:
  • You can call this method either before or after joining a channel.
  • To update the rendering or mirror mode of the local video view during a call, use the setLocalRenderMode method.

Parameters

canvas
The local video view and settings. See VideoCanvas.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

  • < 0: Failure.

setupRemoteVideo

Initializes the video view of a remote user.

Future<void> setupRemoteVideo(VideoCanvas canvas);

Details

This method initializes the video view of a remote stream on the local device. It affects only the video view that the local user sees. Call this method to bind the remote video stream to a video view and to set the rendering and mirror modes of the video view.

You need to specify the ID of the remote user in this method. If the remote user ID is unknown to the application, set it after the app receives the onUserJoined callback.

To unbind the remote user from the view, set the view parameter to NULL.

Once the remote user leaves the channel, the SDK unbinds the remote user.

In the scenarios of custom layout for mixed videos on the mobile end, you can call this method and set a separate view for rendering each sub-video stream of the mixed video stream.

Attention:
  • To update the rendering or mirror mode of the remote video view during a call, use the setRemoteRenderMode method.
  • If you use the Agora recording function, the recording client joins the channel as a placeholder client, triggering the onUserJoined callback. Do not bind the placeholder client to the app view because the placeholder client does not send any video streams. If your app does not recognize the placeholder client, bind the remote user to the view when the SDK triggers the onFirstRemoteVideoDecoded callback.

Parameters

canvas

The remote video view and settings. See VideoCanvas.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

  • < 0: Failure.

setVoiceBeautifierParameters

Sets parameters for the preset voice beautifier effects.

Future<void> setVoiceBeautifierParameters(
  {required VoiceBeautifierPreset preset,
  required int param1,
  required int param2});

Details

Call this method to set a gender characteristic and a reverberation effect for the singing beautifier effect. This method sets parameters for the local user who sends an audio stream. After setting the audio parameters, all users in the channel can hear the effect.

For better voice effects, Agora recommends that you call setAudioProfile and set scenario to audioScenarioGameStreaming(3) and profile to audioProfileMusicHighQuality(4) or audioProfileMusicHighQualityStereo(5) before calling this method.

Attention:

Parameters

preset
The option for the preset audio effect:
  • SINGING_BEAUTIFIER: The singing beautifier effect.
param1
The gender characteristics options for the singing voice:
  • 1: A male-sounding voice.
  • 2: A female-sounding voice.
param2
The reverberation effect options for the singing voice:
  • 1: The reverberation effect sounds like singing in a small room.
  • 2: The reverberation effect sounds like singing in a large room.
  • 3: The reverberation effect sounds like singing in a hall.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setVoiceBeautifierPreset

Sets a preset voice beautifier effect.

Future<void> setVoiceBeautifierPreset(VoiceBeautifierPreset preset);

Details

Call this method to set a preset voice beautifier effect for the local user who sends an audio stream. After setting a voice beautifier effect, all users in the channel can hear the effect. You can set different voice beautifier effects for different scenarios.

For better voice effects, Agora recommends that you call setAudioProfile and set scenario to audioScenarioGameStreaming(3) and profile to audioProfileMusicHighQuality(4) or audioProfileMusicHighQualityStereo(5) before calling this method.

Attention:
  • You can call this method either before or after joining a channel.
  • Do not set the profile parameter in setAudioProfile to audioProfileSpeechStandard(1) or audioProfileIot(6), or the method does not take effect.
  • This method has the best effect on human voice processing, and Agora does not recommend calling this method to process audio data containing music.
  • After calling setVoiceBeautifierPreset, Agora does not recommend calling the following methods, otherwise the effect set by setVoiceBeautifierPreset will be overwritten:
  • This method relies on the voice beautifier dynamic library libagora_audio_beauty_extension.dll. If the dynamic library is deleted, the function cannot be enabled normally.

Parameters

preset

The preset voice beautifier effect options: VoiceBeautifierPreset.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setVoiceConversionPreset

Sets a preset voice beautifier effect.

Future<void> setVoiceConversionPreset(VoiceConversionPreset preset);

Details

Call this method to set a preset voice beautifier effect for the local user who sends an audio stream. After setting an audio effect, all users in the channel can hear the effect. You can set different voice beautifier effects for different scenarios.

To achieve better audio effect quality, Agora recommends that you call setAudioProfile and set the profile to audioProfileMusicHighQuality(4) or audioProfileMusicHighQualityStereo(5) and scenario to audioScenarioGameStreaming(3) before calling this method.

Attention:
  • You can call this method either before or after joining a channel.
  • Do not set the profile parameter in setAudioProfile to audioProfileSpeechStandard(1) or audioProfileIot(6), or the method does not take effect.
  • This method has the best effect on human voice processing, and Agora does not recommend calling this method to process audio data containing music.
  • After calling setVoiceConversionPreset, Agora does not recommend you to call the following methods, otherwise the effect set by setVoiceConversionPreset will be overwritten:
  • This method relies on the voice beautifier dynamic library libagora_audio_beauty_extension.dll. If the dynamic library is deleted, the function cannot be enabled normally.

Parameters

preset

The options for the preset voice beautifier effects: VoiceConversionPreset.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

  • < 0: Failure.

setVolumeOfEffect

Sets the volume of a specified audio effect.

Future<void> setVolumeOfEffect({required int soundId, required int volume});

Parameters

soundId
The ID of the audio effect. The ID of each audio effect file is unique.
volume
The playback volume. The value range is [0, 100]. The default value is 100, which represents the original volume.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

startAudioMixing

Starts playing the music file.

Future<void> startAudioMixing(
      {required String filePath,
      required bool loopback,
      required int cycle,
      int startPos = 0});

Details

This method mixes the specified local or online audio file with the audio from the microphone, or replaces the microphone's audio with the specified local or remote audio file. A successful method call triggers the onAudioMixingStateChanged(audioMixingStatePlaying) callback. When the audio mixing file playback finishes, the SDK triggers the onAudioMixingStateChanged(audioMixingStateStopped) callback on the local client.

Attention:
  • You can call this method either before or after joining a channel. If you need to call startAudioMixing multiple times, ensure that the time interval between calling this method is more than 500 ms.
  • If the local music file does not exist, the SDK does not support the file format, or the the SDK cannot access the music file URL, the SDK reports 701.
  • For the audio file formats supported by this method, see What formats of audio files does the Agora RTC SDK support.

Parameters

filePath
File path:
  • Android: The file path, which needs to be accurate to the file name and suffix. Agora supports URL addresses, absolute paths, or file paths that start with /assets/. You might encounter permission issues if you use an absolute path to access a local file, so Agora recommends using a URI address instead. For example: content://com.android.providers.media.documents/document/audio%3A14441
  • Windows: The absolute path or URL address (including the suffixes of the filename) of the audio effect file. For example: C:\music\audio.mp4.
  • iOS or macOS: The absolute path or URL address (including the suffixes of the filename) of the audio effect file. For example: /var/mobile/Containers/Data/audio.mp4.
loopback
Whether to only play music files on the local client:
  • true: Only play music files on the local client so that only the local user can hear the music.
  • false: Publish music files to remote clients so that both the local user and remote users can hear the music.
cycle
The number of times the music file plays.
  • ≥ 0: The number of playback times. For example, 0 means that the SDK does not play the music file while 1 means that the SDK plays once.
  • -1: Play the audio file in an infinite loop.
startPos
The playback position (ms) of the music file.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

startAudioRecording

Starts audio recording on the client and sets recording configurations.

Future<void> startAudioRecording(AudioRecordingConfiguration config);

Details

The Agora SDK allows recording during a call. After successfully calling this method, you can record the audio of users in the channel and get an audio recording file. Supported formats of the recording file are as follows:
  • WAV: High-fidelity files with typically larger file sizes. For example, if the sample rate is 32,000 Hz, the file size for 10-minute recording is approximately 73 MB.
  • AAC: Low-fidelity files with typically smaller file sizes. For example, if the sample rate is 32,000 Hz and the recording quality is audioRecordingQualityMedium, the file size for 10-minute recording is approximately 2 MB.

Once the user leaves the channel, the recording automatically stops.

Attention: Call this method after joining a channel.

Parameters

config
Recording configurations. See AudioRecordingConfiguration.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

startLastmileProbeTest

Starts the last mile network probe test.

Future<void> startLastmileProbeTest(LastmileProbeConfig config);

Details

This method starts the last-mile network probe test before joining a channel to get the uplink and downlink last mile network statistics, including the bandwidth, packet loss, jitter, and round-trip time (RTT).

Once this method is enabled, the SDK returns the following callbacks:
  • onLastmileQuality: The SDK triggers this callback within two seconds depending on the network conditions. This callback rates the network conditions and is more closely linked to the user experience.
  • onLastmileProbeResult: The SDK triggers this callback within 30 seconds depending on the network conditions. This callback returns the real-time statistics of the network conditions and is more objective.

This method must be called before joining the channel, and is used to judge and predict whether the current uplink network quality is good enough.

Attention:
  • Do not call other methods before receiving the onLastmileQuality and onLastmileProbeResult callbacks. Otherwise, the callbacks may be interrupted.
  • A host should not call this method after joining a channel (when in a call).

Parameters

config
The configurations of the last-mile network probe test. See LastmileProbeConfig.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

startLocalVideoTranscoder

Starts the local video mixing.

Future<void> startLocalVideoTranscoder(LocalTranscoderConfiguration config);

Details

After calling this method, you can merge multiple video streams into one video stream locally. For example, you can merge the video streams captured by the camera, screen sharing, media player, remote video, video files, images, etc. into one video stream, and then publish the mixed video stream to the channel.

Note:
  • Local video mixing requires more CPU resources. Therefore, Agora recommends enabling this function on devices with higher performance.
  • If you need to mix locally captured video streams, the SDK supports the following capture combinations:
    • On the Windows platform, it supports up to 4 video streams captured by cameras + 4 screen sharing streams.
    • On the macOS platform, it supports up to 4 video streams captured by cameras + 1 screen sharing stream.
    • On Android and iOS platforms, it supports video streams captured by up to 2 cameras (the device itself needs to support dual cameras or supports external cameras) + 1 screen sharing stream.
  • If you need to mix the locally collected video streams, you need to call this method after startCameraCapture or startScreenCaptureBySourceType.
  • If you want to publish the mixed video stream to the channel, you need to set publishTranscodedVideoTrack in ChannelMediaOptions to true when calling joinChannel or updateChannelMediaOptions.

Applicable scenarios

You can enable the local video mixing function in scenarios such as remote conferences, live streaming, and online education, which allows users to view and manage multiple videos more conveniently, and supports portrait-in-picture effect and other functions.

The following is a typical use case for implementing the portrait-in-picture effect:
  1. Call enableVirtualBackground, and set the custom background image to backgroundNone, that is, separate the portrait and the background in the video captured by the camera.
  2. Call startScreenCaptureBySourceType to start capturing the screen sharing video stream.
  3. Call this method and set the video source for capturing portraits as one of the video sources participating in the local video mixing, and the portrait picture-invideo mixing can be added in the mixed image video.
    Note: When configuring the local video mixing, it is necessary to ensure that the layer number of the video stream capturing the portrait is greater than the layer number of the screen sharing stream. Otherwise, the portrait will be covered by the screen sharing and will not be displayed in the final mixed video stream.

Parameters

config
Configuration of the local video mixing, see LocalTranscoderConfiguration.
Attention:
  • The maximum resolution of each video stream participating in the local video mixing is 4096 × 2160. If this limit is exceeded, video mixing does not take effect.
  • The maximum resolution of the mixed video stream is 4096 × 2160.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

startPreviewWithoutSourceType

Enables the local video preview.

Future<void> startPreviewWithoutSourceType();

Details

You can call this method to enable local video preview. Call this method after the following:
Attention:
  • The local preview enables the mirror mode by default.
  • After the local video preview is enabled, if you call leaveChannel to exit the channel, the local preview remains until you call stopPreview to disable it.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

startPreview

Enables the local video preview and specifies the video source for the preview.

Future<void> startPreview(
            {VideoSourceType sourceType = VideoSourceType.videoSourceCameraPrimary});

Details

You can call this method to enable local video preview. Call this method after the following:
Attention:
  • The local preview enables the mirror mode by default.
  • After the local video preview is enabled, if you call leaveChannel to exit the channel, the local preview remains until you call stopPreview to disable it.
  • The video source type set in this method needs to be consistent with the video source type of VideoCanvas you set in setupLocalVideo.

Parameters

sourceType
The type of the video source. See VideoSourceType.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

startRhythmPlayer

Enables the virtual metronome.

Future<void> startRhythmPlayer(
      {required String sound1,
      required String sound2,
      required AgoraRhythmPlayerConfig config});

Details

In music education, physical education and other scenarios, teachers usually need to use a metronome so that students can practice with the correct beat. The meter is composed of a downbeat and upbeats. The first beat of each measure is called a downbeat, and the rest are called upbeats.

In this method, you need to set the file path of the upbeat and downbeat, the number of beats per measure, the beat speed, and whether to send the sound of the metronome to remote users.

After successfully calling this method, the SDK triggers the onRhythmPlayerStateChanged callback locally to report the status of the virtual metronome.

Attention:
  • This method is for Android and iOS only.
  • After enabling the virtual metronome, the SDK plays the specified audio effect file from the beginning, and controls the playback duration of each file according to beatsPerMinute you set in AgoraRhythmPlayerConfig. For example, if you set beatsPerMinute as 60, the SDK plays one beat every second. If the file duration exceeds the beat duration, the SDK only plays the audio within the beat duration.
  • By default, the sound of the virtual metronome is published in the channel. If you do not want the sound to be heard by the remote users, you can set publishRhythmPlayerTrack in ChannelMediaOptions as false.

Parameters

sound1
The absolute path or URL address (including the filename extensions) of the file for the downbeat. For example, C:\music\audio.mp4. For the audio file formats supported by this method, see What formats of audio files does the Agora RTC SDK support.
sound2
The absolute path or URL address (including the filename extensions) of the file for the upbeats. For example, C:\music\audio.mp4. For the audio file formats supported by this method, see What formats of audio files does the Agora RTC SDK support.
config
The metronome configuration. See AgoraRhythmPlayerConfig.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

startRtmpStreamWithoutTranscoding

Starts pushing media streams to a CDN without transcoding.

Future<void> startRtmpStreamWithoutTranscoding(String url);

Details

Agora recommends that you use the server-side Media Push function. For details, see Use RESTful API.

You can call this method to push an audio or video stream to the specified CDN address. This method can push media streams to only one CDN address at a time, so if you need to push streams to multiple addresses, call this method multiple times.

After you call this method, the SDK triggers the onRtmpStreamingStateChanged callback on the local client to report the state of the streaming.

Attention:
  • Call this method after joining a channel.
  • Only hosts in the LIVE_BROADCASTING profile can call this method.
  • If you want to retry pushing streams after a failed push, make sure to call stopRtmpStream first, then call this method to retry pushing streams; otherwise, the SDK returns the same error code as the last failed push.

Parameters

url
The address of Media Push. The format is RTMP or RTMPS. The character length cannot exceed 1024 bytes. Special characters such as Chinese characters are not supported.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

startRtmpStreamWithTranscoding

Starts Media Push and sets the transcoding configuration.

Future<void> startRtmpStreamWithTranscoding(
    {required String url, required LiveTranscoding transcoding});

Details

Agora recommends that you use the server-side Media Push function. For details, see Use RESTful API.

You can call this method to push a live audio-and-video stream to the specified CDN address and set the transcoding configuration. This method can push media streams to only one CDN address at a time, so if you need to push streams to multiple addresses, call this method multiple times.

Under one Agora project, the maximum number of concurrent tasks to push media streams is 200 by default. If you need a higher quota, contact technical support.

After you call this method, the SDK triggers the onRtmpStreamingStateChanged callback on the local client to report the state of the streaming.

Attention:
  • Call this method after joining a channel.
  • Only hosts in the LIVE_BROADCASTING profile can call this method.
  • If you want to retry pushing streams after a failed push, make sure to call stopRtmpStream first, then call this method to retry pushing streams; otherwise, the SDK returns the same error code as the last failed push.

Parameters

url
The address of Media Push. The format is RTMP or RTMPS. The character length cannot exceed 1024 bytes. Special characters such as Chinese characters are not supported.
transcoding

The transcoding configuration for Media Push. See LiveTranscoding.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

startScreenCapture

Starts screen capture.

Future<void> startScreenCapture(ScreenCaptureParameters2 captureParams);

Details

There are two options for enabling screen sharing. You can choose the one that best suits your specific scenario:
  • Call this method before joining a channel, then call joinChannel to join channel and set publishScreenCaptureVideo to true to start screen sharing.
  • Call this method after joining a channel, then call updateChannelMediaOptions and set publishScreenCaptureVideo to true to start screen sharing.
Attention:
  • This method applies to Android and iOS only.
  • On the iOS platform, screen sharing is only available on iOS 12.0 and later.
  • The billing for the screen sharing stream is based on the dimensions in ScreenVideoParameters. When you do not pass in a value, Agora bills you at 1280 × 720; when you pass a value in, Agora bills you at that value. For billing details, see Pricing.
  • If you are using the custom audio source instead of the SDK to capture audio, Agora recommends you add the keep-alive processing logic to your application to avoid screen sharing stopping when the application goes to the background.
  • This feature requires high-performance device, and Agora recommends that you use it on iPhone X and later models.
  • This method relies on the iOS screen sharing dynamic library AgoraReplayKitExtension.xcframework. If the dynamic library is deleted, screen sharing cannot be enabled normally.
  • On the Android platform, if the user has not granted the app screen capture permission, the SDK reports the onPermissionError(2) callback.
  • On Android 9 and later, to avoid the application being killed by the system after going to the background, Agora recommends you add the foreground service android.permission.FOREGROUND_SERVICE to the /app/Manifests/AndroidManifest.xml file.
  • Due to performance limitations, screen sharing is not supported on Android TV.
  • Due to system limitations, if you are using Huawei phones, do not adjust the video encoding resolution of the screen sharing stream during the screen sharing, or you could experience crashes.
  • Due to system limitations, some Xiaomi devices do not support capturing system audio during screen sharing.
  • To avoid system audio capture failure when screen sharing, Agora recommends that you set the audio application scenario to audioScenarioGameStreaming by using the setAudioScenario method before joining the channel.

Parameters

captureParams
The screen sharing encoding parameters. The default video dimension is 1920 x 1080, that is, 2,073,600 pixels. Agora uses the value of this parameter to calculate the charges. See ScreenCaptureParameters2.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

startScreenCaptureByDisplayId

Captures the screen by specifying the display ID.

Future<void> startScreenCaptureByDisplayId(
    {required int displayId,
    required Rectangle regionRect,
    required ScreenCaptureParameters captureParams});

Details

This method shares a screen or part of the screen.

There are two ways to start screen sharing, you can choose one according to your needs:
  • Call this method before joining a channel, and then call joinChannel to join a channel and set publishScreenTrack or publishSecondaryScreenTrack to true to start screen sharing.
  • Call this method after joining a channel, and then call updateChannelMediaOptions and set publishScreenTrack or publishSecondaryScreenTrack to true to start screen sharing.
Attention: This method is for Windows and macOS only.

Parameters

displayId
The display ID of the screen to be shared.
Note: For the Windows platform, if you need to simultaneously share two screens (main screen and secondary screen), you can set displayId to -1 when calling this method.
regionRect
(Optional) Sets the relative location of the region to the screen. Pass in nil to share the entire screen. See Rectangle.
If the specified region overruns the screen, the SDK shares only the region within it; if you set width or height as 0, the SDK shares the whole screen.
captureParams
Screen sharing configurations. The default video dimension is 1920 x 1080, that is, 2,073,600 pixels. Agora uses the value of this parameter to calculate the charges. See ScreenCaptureParameters.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

startScreenCaptureByScreenRect

Captures the whole or part of a screen by specifying the screen rect.

Future<void> startScreenCaptureByScreenRect(
    {required Rectangle screenRect,
    required Rectangle regionRect,
    required ScreenCaptureParameters captureParams});

Details

Deprecated:
This method is deprecated. Use startScreenCaptureByDisplayId instead. Agora strongly recommends using startScreenCaptureByDisplayId if you need to start screen sharing on a device connected to another display.

This method shares a screen or part of the screen. You need to specify the area of the screen to be shared.

There are two ways to start screen sharing, you can choose one according to your needs:
  • Call this method before joining a channel, and then call joinChannel to join a channel and set publishScreenTrack or publishSecondaryScreenTrack to true to start screen sharing.
  • Call this method after joining a channel, and then call updateChannelMediaOptions and set publishScreenTrack or publishSecondaryScreenTrack to true to start screen sharing.
Attention: This method applies to Windows only.

Parameters

screenRect
Sets the relative location of the screen to the virtual screen.
regionRect
Sets the relative location of the region to the screen. If you do not set this parameter, the SDK shares the whole screen. See Rectangle. If the specified region overruns the screen, the SDK shares only the region within it; if you set width or height as 0, the SDK shares the whole screen.
captureParams
The screen sharing encoding parameters. The default video resolution is 1920 × 1080, that is, 2,073,600 pixels. Agora uses the value of this parameter to calculate the charges. See ScreenCaptureParameters.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

startScreenCaptureByWindowId

Captures the whole or part of a window by specifying the window ID.

Future<void> startScreenCaptureByWindowId(
    {required int windowId,
    required Rectangle regionRect,
    required ScreenCaptureParameters captureParams});

Details

This method captures a window or part of the window. You need to specify the ID of the window to be captured.

There are two ways to start screen sharing, you can choose one according to your needs:
  • Call this method before joining a channel, and then call joinChannel to join a channel and set publishScreenTrack or publishSecondaryScreenTrack to true to start screen sharing.
  • Call this method after joining a channel, and then call updateChannelMediaOptions and set publishScreenTrack or publishSecondaryScreenTrack to true to start screen sharing.
Attention:
  • This method applies to the macOS and Windows only.
  • The window sharing feature of the Agora SDK relies on WGC (Windows Graphics Capture) or GDI (Graphics Device Interface) capture, and WGC cannot be set to disable mouse capture on systems earlier than Windows 10 2004. Therefore, captureMouseCursor(false) might not work when you start window sharing on a device with a system earlier than Windows 10 2004. See ScreenCaptureParameters.

This method supports window sharing of UWP (Universal Windows Platform) applications. Agora tests the mainstream UWP applications by using the lastest SDK, see details as follows:

System version Software Compatible versions Support
win10 Chrome 76.0.3809.100 No
Office Word 18.1903.1152.0 Yes
Office Excel No
Office PPT Yes
WPS Word 11.1.0.9145 Yes
WPS Excel
WPS PPT
Media Player (comes with the system) All Yes
win8 Chrome All Yes
Office Word All Yes
Office Excel
Office PPT
WPS Word 11.1.0.9098 Yes
WPS Excel
WPS PPT
Media Player (comes with the system) All Yes
win7 Chrome 73.0.3683.103 No
Office Word All Yes
Office Excel
Office PPT
WPS Word 11.1.0.9098 No
WPS Excel
WPS PPT 11.1.0.9098 Yes
Media Player (comes with the system) All No

Parameters

windowId
The ID of the window to be shared.
regionRect
(Optional) Sets the relative location of the region to the screen. If you do not set this parameter, the SDK shares the whole screen. See Rectangle. If the specified region overruns the window, the SDK shares only the region within it; if you set width or height as 0, the SDK shares the whole window.
captureParams
Screen sharing configurations. The default video resolution is 1920 × 1080, that is, 2,073,600 pixels. Agora uses the value of this parameter to calculate the charges. See ScreenCaptureParameters.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

stopAllEffects

Stops playing all audio effects.

Future<void> stopAllEffects();

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

stopAudioMixing

Stops playing and mixing the music file.

Future<void> stopAudioMixing();

Details

This method stops the audio mixing. Call this method when you are in a channel.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

stopAudioRecording

Stops the audio recording on the client.

Future<void> stopAudioRecording();

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

stopChannelMediaRelay

Stops the media stream relay. Once the relay stops, the host quits all the target channels.

Future<void> stopChannelMediaRelay();

Details

After a successful method call, the SDK triggers the onChannelMediaRelayStateChanged callback. If the callback reports relayStateIdle (0) and relayOk (0), the host successfully stops the relay.

Attention: If the method call fails, the SDK triggers the onChannelMediaRelayStateChanged callback with the relayErrorServerNoResponse (2) or relayErrorServerConnectionLost (8) status code. You can call the leaveChannel method to leave the channel, and the media stream relay automatically stops.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

  • < 0: Failure.

stopEchoTest

Stops the audio call test.

Future<void> stopEchoTest();

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

stopEffect

Stops playing a specified audio effect.

Future<void> stopEffect(int soundId);

Parameters

soundId
The ID of the audio effect. Each audio effect has a unique ID.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

stopLastmileProbeTest

Stops the last mile network probe test.

Future<void> stopLastmileProbeTest();

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

stopLocalVideoTranscoder

Stops the local video mixing.

Future<void> stopLocalVideoTranscoder();

Details

After calling startLocalVideoTranscoder, call this method if you want to stop the local video mixing.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

stopPreview

Stops the local video preview.

Future<void> stopPreview(
    {VideoSourceType sourceType = VideoSourceType.videoSourceCameraPrimary});

Details

After calling startPreview to start the preview, if you want to close the local video preview, call this method.

Note: Call this method before joining a channel or after leaving a channel.

Parameters

sourceType
The type of the video source. See VideoSourceType.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

  • < 0: Failure.

stopRhythmPlayer

Disables the virtual metronome.

Future<void> stopRhythmPlayer();

Details

After calling startRhythmPlayer, you can call this method to disable the virtual metronome.

Attention: This method is for Android and iOS only.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

stopRtmpStream

Stops pushing media streams to a CDN.

Future<void> stopRtmpStream(String url);

Details

Agora recommends that you use the server-side Media Push function. For details, see Use RESTful API.

You can call this method to stop the live stream on the specified CDN address. This method can stop pushing media streams to only one CDN address at a time, so if you need to stop pushing streams to multiple addresses, call this method multiple times.

After you call this method, the SDK triggers the onRtmpStreamingStateChanged callback on the local client to report the state of the streaming.

Parameters

url
The address of Media Push. The format is RTMP or RTMPS. The character length cannot exceed 1024 bytes. Special characters such as Chinese characters are not supported.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

switchCamera

Switches between front and rear cameras.

Future<void> switchCamera();

Details

Attention:
  • This method is for Android and iOS only.
  • This method must be called after the camera is successfully enabled, that is, after the SDK triggers the onLocalVideoStateChanged callback and returns the local video state as localVideoStreamStateCapturing (1).

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

takeSnapshot

Takes a snapshot of a video stream.

Future<void> takeSnapshot({required int uid, required String filePath});

Details

This method takes a snapshot of a video stream from the specified user, generates a JPG image, and saves it to the specified path.

The method is asynchronous, and the SDK has not taken the snapshot when the method call returns. After a successful method call, the SDK triggers the onSnapshotTaken callback to report whether the snapshot is successfully taken, as well as the details for that snapshot.

Attention:
  • Call this method after joining a channel.
  • When used for local video snapshots, this method takes a snapshot for the video streams specified in ChannelMediaOptions.
  • If the user's video has been preprocessed, for example, watermarked or beautified, the resulting snapshot includes the pre-processing effect.

Parameters

uid
The user ID. Set uid as 0 if you want to take a snapshot of the local user's video.
filePath
The local path (including filename extensions) of the snapshot. For example:
  • Windows: C:\Users\<user_name>\AppData\Local\Agora\<process_name>\example.jpg
  • iOS: /App Sandbox/Library/Caches/example.jpg
  • macOS: ~/Library/Logs/example.jpg
  • Android: /storage/emulated/0/Android/data/<package name>/files/example.jpg
Ensure that the path you specify exists and is writable.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

unloadAllEffects

Releases a specified preloaded audio effect from the memory.

Future<void> unloadAllEffects();

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

unloadEffect

Releases a specified preloaded audio effect from the memory.

Future<void> unloadEffect(int soundId);

Parameters

soundId
The ID of the audio effect. Each audio effect has a unique ID.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

unregisterAudioEncodedFrameObserver

Unregisters the encoded audio frame observer.

void unregisterAudioEncodedFrameObserver(AudioEncodedFrameObserver observer);

Parameters

observer
The encoded audio observer. See AudioEncodedFrameObserver.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

unregisterAudioSpectrumObserver

Unregisters the audio spectrum observer.

void unregisterAudioSpectrumObserver(AudioSpectrumObserver observer);

Details

After calling registerAudioSpectrumObserver, if you want to disable audio spectrum monitoring, you can call this method.

Attention: You can call this method either before or after joining a channel.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

unregisterMediaMetadataObserver

Unregisters the specified metadata observer.

void unregisterMediaMetadataObserver(
    {required MetadataObserver observer, required MetadataType type});

Parameters

observer
The metadata observer. See MetadataObserver.
type

The metadata type. The SDK currently only supports videoMetadata.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

  • < 0: Failure.

updateChannelMediaOptions

Updates the channel media options after joining the channel.

Future<void> updateChannelMediaOptions(ChannelMediaOptions options);

Parameters

options
The channel media options. See ChannelMediaOptions.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

updateLocalTranscoderConfiguration

Updates the local video mixing configuration.

Future<void> updateLocalTranscoderConfiguration(
      LocalTranscoderConfiguration config);

Details

After calling startLocalVideoTranscoder, call this method if you want to update the local video mixing configuration.

Note: If you want to update the video source type used for local video mixing, such as adding a second camera or screen to capture video, you need to call this method after startCameraCapture or startScreenCaptureBySourceType.

Parameters

config
Configuration of the local video mixing, see LocalTranscoderConfiguration.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

updatePreloadChannelToken

Updates the wildcard token for preloading channels.

Future<void> updatePreloadChannelToken(String token);

Details

You need to maintain the life cycle of the wildcard token by yourself. When the token expires, you need to generate a new wildcard token and then call this method to pass in the new token.

Applicable scenarios

In scenarios involving multiple channels, such as switching between different channels, using a wildcard token means users do not need to apply for a new token every time joinning a new channel, which can save users time for switching channels and reduce the pressure on your token server.

Parameters

token
The new token.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

updateRtmpTranscoding

Updates the transcoding configuration.

Future<void> updateRtmpTranscoding(LiveTranscoding transcoding);

Details

Agora recommends that you use the server-side Media Push function. For details, see Use RESTful API.

After you start pushing media streams to CDN with transcoding, you can dynamically update the transcoding configuration according to the scenario. The SDK triggers the onTranscodingUpdated callback after the transcoding configuration is updated.

Parameters

transcoding

The transcoding configuration for Media Push. See LiveTranscoding.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

updateScreenCapture

Updates the screen capturing parameters.

Future<void> updateScreenCapture(ScreenCaptureParameters2 captureParams);

Details

If the system audio is not captured when screen sharing is enabled, and then you want to update the parameter configuration and publish the system audio, you can refer to the following steps:
  1. Call this method, and set captureAudio to true.
  2. Call updateChannelMediaOptions, and set publishScreenCaptureAudio to true to publish the audio captured by the screen.
Attention:
  • This method applies to Android and iOS only.
  • On the iOS platform, screen sharing is only available on iOS 12.0 and later.

Parameters

captureParams
The screen sharing encoding parameters. The default video resolution is 1920 × 1080, that is, 2,073,600 pixels. Agora uses the value of this parameter to calculate the charges. See ScreenCaptureParameters2.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

updateScreenCaptureParameters

Updates the screen capturing parameters.

Future<void> updateScreenCaptureParameters(
      ScreenCaptureParameters captureParams);

Details

Attention:
  • This method is for Windows and macOS only.
  • Call this method after starting screen sharing or window sharing.

Parameters

captureParams
The screen sharing encoding parameters. The default video resolution is 1920 × 1080, that is, 2,073,600 pixels. Agora uses the value of this parameter to calculate the charges. See ScreenCaptureParameters.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

updateScreenCaptureRegion

Updates the screen capturing region.

Future<void> updateScreenCaptureRegion(Rectangle regionRect);

Details

Attention: Call this method after starting screen sharing or window sharing.

Parameters

regionRect
The relative location of the screen-share area to the screen or window. If you do not set this parameter, the SDK shares the whole screen or window. See Rectangle. If the specified region overruns the screen or window, the SDK shares only the region within it; if you set width or height as 0, the SDK shares the whole screen or window.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setRemoteSubscribeFallbackOption

Sets the fallback option for the subscribed video stream based on the network conditions.

Future<void> setRemoteSubscribeFallbackOption(StreamFallbackOptions option);

Details

An unstable network affects the audio and video quality in a video call or interactive live video streaming. If option is set as streamFallbackOptionVideoStreamLow or streamFallbackOptionAudioOnly, the SDK automatically switches the video from a high-quality stream to a low-quality stream or disables the video when the downlink network conditions cannot support both audio and video to guarantee the quality of the audio. Meanwhile, the SDK continuously monitors network quality and resumes subscribing to audio and video streams when the network quality improves.

When the subscribed video stream falls back to an audio-only stream, or recovers from an audio-only stream to an audio-video stream, the SDK triggers the