RtcEngine
The base interface class of the RTC SDK that implements core real-time audio and video features.
RtcEngine provides the main methods for app calls. You must call createAgoraRtcEngine to create a RtcEngine object before calling other APIs.
registerEventHandler
Adds the main callback event.
void registerEventHandler(RtcEngineEventHandler eventHandler);
The interface class RtcEngineEventHandler is used by the SDK to send callback event notifications to the App. The App receives SDK event notifications by inheriting methods from this interface class. All methods in the interface class have default (empty) implementations. The App can choose to inherit only the events it cares about. In callback methods, the App should not perform time-consuming tasks or call APIs that may block (e.g., sendStreamMessage), otherwise it may affect the operation of the SDK.
Parameters
- eventHandler
- The callback event to be added. See RtcEngineEventHandler.
Return Values
No return value if the method call succeeds; if the method call fails, an AgoraRtcException is thrown, which you need to catch and handle. See Error Codes for details and troubleshooting suggestions.
addVideoWatermark
Adds a local video watermark.
Future<void> addVideoWatermark(
{required String watermarkUrl, required WatermarkOptions options});
- Deprecated
- Deprecated: This method is deprecated. Use addVideoWatermarkWithConfig instead.
- If the video orientation (OrientationMode) is fixed to landscape or adaptive landscape mode, landscape coordinates are used.
- If the video orientation (OrientationMode) is fixed to portrait or adaptive portrait mode, portrait coordinates are used.
- When setting the watermark coordinates, the image area of the watermark must not exceed the video dimensions set in the setVideoEncoderConfiguration method. Otherwise, the exceeding part will be cropped.
- You must call this method after calling enableVideo.
- If you only want to add a watermark during CDN streaming, you can use this method or startRtmpStreamWithTranscoding to set the watermark.
- The watermark image must be in PNG format. This method supports all pixel formats of PNG images: RGBA, RGB, Palette, Gray, and Alpha_gray.
- If the size of the PNG image to be added does not match the size set in this method, the SDK scales or crops the PNG image to match the settings.
- If you have set the local video to mirror mode, the local watermark will also be mirrored. To avoid mirrored watermark when local users view their own video, it is recommended not to use both mirror and watermark features on local video. Implement the local watermark feature at the application layer.
Parameters
- watermarkUrl
- The local path of the watermark image to be added. This method supports adding watermark images from local absolute/relative paths.
- options
- Settings for the watermark image to be added. See WatermarkOptions.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
addVideoWatermarkWithConfig
Adds a watermark image to the local video stream.
Future<void> addVideoWatermarkWithConfig(WatermarkConfig configs);
- Since
- Available since v4.6.2.
You can use this method to overlay a watermark image on the local video stream and configure its position, size, and visibility in the preview using WatermarkConfig.
Parameters
- configs
- Watermark configuration. See WatermarkConfig.
Return Values
- 0: The method call succeeds.
- < 0: The method call fails.
adjustAudioMixingPlayoutVolume
Adjusts the local playback volume of the music file.
Future<void> adjustAudioMixingPlayoutVolume(int volume);
Timing
You need to call this method after calling startAudioMixing and receiving the onAudioMixingStateChanged(audioMixingStatePlaying) callback.
Parameters
- volume
- Volume of the music file. The range is [0,100], where 100 (default) is the original volume.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
adjustAudioMixingPublishVolume
Adjusts the remote playback volume of the music file.
Future<void> adjustAudioMixingPublishVolume(int volume);
This method adjusts the remote playback volume of the mixed music file.
Timing
You need to call this method after calling startAudioMixing and receiving the onAudioMixingStateChanged(audioMixingStatePlaying) callback.
Parameters
- volume
- Volume of the music file. The range is [0,100], where 100 (default) is the original volume.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
adjustAudioMixingVolume
Adjusts the playback volume of the music file.
Future<void> adjustAudioMixingVolume(int volume);
This method adjusts the playback volume of the mixed music file for both local and remote playback.
Timing
This method must be called after startAudioMixing.
Parameters
- volume
- Volume range of the music file is 0~100. 100 (default) is the original file volume.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
adjustCustomAudioPlayoutVolume
Adjusts the local playback volume of a custom audio track.
Future<void> adjustCustomAudioPlayoutVolume(
{required int trackId, required int volume});
After calling this method to set the local playback volume of the audio, if you want to adjust the volume again, you can call this method again.
Parameters
- trackId
- Audio track ID. Set this parameter to the custom audio track ID returned by the createCustomAudioTrack method.
- volume
- Playback volume of the custom audio capture. Range: [0,100]. 0 means mute, 100 means original volume.
Return Values
- < 0: Method call failed. See Error Codes for details and resolution suggestions.
adjustCustomAudioPublishVolume
Adjusts the remote playback volume of a custom audio track.
Future<void> adjustCustomAudioPublishVolume(
{required int trackId, required int volume});
After calling this method to set the remote playback volume of the audio, if you want to adjust the volume again, you can call this method again.
Parameters
- trackId
- Audio track ID. Set this parameter to the custom audio track ID returned by the createCustomAudioTrack method.
- volume
- Playback volume of the custom audio capture. Range: [0,100]. 0 means mute, 100 means original volume.
Return Values
- < 0: Method call failed. See Error Codes for details and resolution suggestions.
adjustLoopbackSignalVolume
Adjusts the volume of the signal captured by the sound card.
Future<void> adjustLoopbackSignalVolume(int volume);
After calling enableLoopbackRecording to enable sound card capture, you can call this method to adjust the volume of the signal captured by the sound card.
Parameters
- volume
- The volume of the music file. The range is 0~100. 100 (default) represents the original volume of the file.
Return Values
- < 0: The method call fails. See Error Codes for details and resolution suggestions.
adjustPlaybackSignalVolume
Adjusts the signal volume of all remote users for local playback.
Future<void> adjustPlaybackSignalVolume(int volume);
This method adjusts the signal volume of all remote users after mixing for local playback. If you need to adjust the signal volume of a specific remote user for local playback, it is recommended to call adjustUserPlaybackSignalVolume.
Timing
Can be called before or after joining a channel.
Parameters
- volume
- Volume, range is [0,400].
- 0: Mute.
- 100: (Default) Original volume.
- 400: 4 times the original volume, with built-in overflow protection.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
adjustRecordingSignalVolume
Adjusts the volume of the audio recording signal.
Future<void> adjustRecordingSignalVolume(int volume);
If you only need to mute the audio signal, it is recommended to use muteRecordingSignal.
Timing
Can be called before or after joining a channel.
Parameters
- volume
- Volume. The range is [0,400].
- 0: Mute.
- 100: (Default) Original volume.
- 400: 4 times the original volume, with built-in overflow protection.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
adjustUserPlaybackSignalVolume
Adjusts the playback volume of a specified remote user locally.
Future<void> adjustUserPlaybackSignalVolume(
{required int uid, required int volume});
You can call this method during a call to adjust the playback volume of a specified remote user locally. To adjust the playback volume of multiple users, call this method multiple times.
Timing
You must call this method after joining a channel.
Parameters
- uid
- The ID of the remote user.
- volume
- The volume, with a range of [0,400].
- 0: Mute.
- 100: (Default) Original volume.
- 400: Four times the original volume, with built-in overflow protection.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
clearVideoWatermarks
Removes added video watermarks.
Future<void> clearVideoWatermarks();
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
complain
Report call quality issues.
Future<void> complain({required String callId, required String description});
This method allows users to report call quality issues. It must be called after leaving the channel.
Parameters
- callId
- Call ID. You can obtain this parameter by calling getCallId.
- description
- Description of the call. The length should be less than 800 bytes.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
configRhythmPlayer
Configures the virtual metronome.
Future<void> configRhythmPlayer(AgoraRhythmPlayerConfig config);
- Deprecated
- Deprecated since v4.6.2.
- After calling startRhythmPlayer, you can call this method to reconfigure the virtual metronome.
- After enabling the virtual metronome, the SDK starts playing the specified audio files from the beginning and controls the duration of each file based on the
beatsPerMinuteyou set in AgoraRhythmPlayerConfig. For example, ifbeatsPerMinuteis set to60, the SDK plays 1 beat per second. If the file duration exceeds the beat duration, the SDK only plays the portion that fits the beat duration. - By default, the sound of the virtual metronome is not published to remote users. If you want remote users to hear it, set
publishRhythmPlayerTrackin ChannelMediaOptions to true after calling this method.
Timing
This method can be called before or after joining a channel.
Parameters
- config
- Metronome configuration. See AgoraRhythmPlayerConfig.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
createAgoraRtcEngine
createCustomVideoTrack
Creates a custom video track.
Future<int> createCustomVideoTrack();
- Call this method to create a video track and get the video track ID.
- When calling joinChannel to join a channel, set
customVideoTrackIdin ChannelMediaOptions to the video track ID you want to publish and setpublishCustomVideoTrackto true. - Call pushVideoFrame and specify
videoTrackIdas the video track ID from step 2 to publish the corresponding custom video source in the channel.
Return Values
- If the method call succeeds, returns the video track ID as the unique identifier of the video track.
- If the method call fails, returns 0xffffffff. See Error Codes for details and resolution suggestions.
createDataStream
Creates a data stream.
Future<int> createDataStream(DataStreamConfig config);
Timing
This method can be called before or after joining a channel.
Parameters
- config
- Data stream configuration. See DataStreamConfig.
Return Values
- ID of the created data stream: method call succeeded.
- < 0: method call failed. See Error Codes for details and resolution suggestions.
createMediaPlayer
Creates a media player object.
Future<MediaPlayer> createMediaPlayer();
Before calling other APIs under the MediaPlayer class, you need to call this method to create a media player instance. If you need multiple instances, you can call this method multiple times.
Timing
This method can be called before or after joining a channel.
Parameters
- delegate
- The event handler for RtcEngine. See RtcEngineEventHandler.
Return Values
- If the method call succeeds: returns a MediaPlayer object.
- If the method call fails: returns a null pointer.
createVideoEffectObject
Creates an IVideoEffectObject video effect object.
Future<VideoEffectObject?> createVideoEffectObject(
{required String bundlePath,
MediaSourceType type = MediaSourceType.primaryCameraSource});
- Since
- Available since v4.6.2.
Parameters
- bundlePath
- Path to the video effect resource package.
- type
- Media source type. See MediaSourceType.
Return Values
- If the method call succeeds, returns a pointer to the
IVideoEffectObjectobject. SeeIVideoEffectObject. - If the method call fails, returns
NULL.
destroyCustomVideoTrack
Destroys the specified video track.
Future<void> destroyCustomVideoTrack(int videoTrackId);
Parameters
- videoTrackId
- The video track ID returned by the createCustomVideoTrack method.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
destroyMediaPlayer
Destroys the media player.
Future<void> destroyMediaPlayer(MediaPlayer mediaPlayer);
Return Values
- < 0: Failure. See Error Codes for details and resolution suggestions.
destroyVideoEffectObject
Destroys the video effect object.
Future<void> destroyVideoEffectObject(VideoEffectObject videoEffectObject);
- Since
- Available since v4.6.2.
Parameters
- videoEffectObject
- The video effect object to destroy. See VideoEffectObject.
Return Values
- 0: The method call succeeds.
- < 0: The method call fails.
disableAudio
Disables the audio module.
Future<void> disableAudio();
The audio module is enabled by default. You can call this method to disable the audio module.
- enableLocalAudio: Whether to enable microphone capture and create a local audio stream.
- enableLoopbackRecording: Whether to enable sound card capture.
- muteLocalAudioStream: Whether to publish the local audio stream.
- muteRemoteAudioStream: Whether to receive and play the remote audio stream.
- muteAllRemoteAudioStreams: Whether to receive and play all remote audio streams.
Timing
Can be called before or after joining a channel. Remains effective after leaving the channel.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
disableAudioSpectrumMonitor
Disables audio spectrum monitoring.
Future<void> disableAudioSpectrumMonitor();
After calling enableAudioSpectrumMonitor, if you want to disable audio spectrum monitoring, call this method.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
disableVideo
Disables the video module.
Future<void> disableVideo();
This method disables the video module.
- This method sets the internal engine to a disabled state and remains effective after leaving the channel.
- Calling this method resets the entire engine and may take longer to respond. You can use the following methods to control specific video functions as needed:
- enableLocalVideo: Whether to enable camera capture and create the local video stream.
- muteLocalVideoStream: Whether to publish the local video stream.
- muteRemoteVideoStream: Whether to receive and play the remote video stream.
- muteAllRemoteVideoStreams: Whether to receive and play all remote video streams.
Timing
- If called before joining, audio-only mode is enabled.
- If called after joining, switches from video mode to audio-only mode. You can call enableVideo to switch back to video mode.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
enableAudio
Enables the audio module.
Future<void> enableAudio();
The audio module is enabled by default. If you have called disableAudio to disable the audio module, you can call this method to re-enable it.
- Calling this method resets the entire engine and has a relatively slow response time. You can use the following methods to control specific audio module features based on your needs:
- enableLocalAudio: Whether to enable microphone capture and create a local audio stream.
- muteLocalAudioStream: Whether to publish the local audio stream.
- muteRemoteAudioStream: Whether to receive and play the remote audio stream.
- muteAllRemoteAudioStreams: Whether to receive and play all remote audio streams.
- When calling this method in a channel, it resets the settings of enableLocalAudio, muteRemoteAudioStream, and muteAllRemoteAudioStreams. Use with caution.
Timing
Can be called before or after joining a channel. Remains effective after leaving the channel.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
enableAudioSpectrumMonitor
Enables audio spectrum monitoring.
Future<void> enableAudioSpectrumMonitor({int intervalInMS = 100});
If you want to obtain audio spectrum data of local or remote users, register an audio spectrum observer and enable audio spectrum monitoring.
Parameters
- intervalInMS
- The time interval (in milliseconds) at which the SDK triggers the onLocalAudioSpectrum and onRemoteAudioSpectrum callbacks. The default value is 100 ms. The value must not be less than 10 ms, otherwise the method call fails.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
enableAudioVolumeIndication
Enables audio volume indication.
Future<void> enableAudioVolumeIndication(
{required int interval, required int smooth, required bool reportVad});
This method allows the SDK to periodically report volume information of the local user who is sending a stream and up to 3 remote users with the highest instantaneous volume to the app.
Timing
Can be called before or after joining a channel.
Parameters
- interval
- The time interval for volume indication:
- ≤ 0: Disables the volume indication.
- > 0: The interval in milliseconds for volume indication. It is recommended to set it greater than 100 ms. Must not be less than 10 ms, otherwise the onAudioVolumeIndication callback will not be received.
- smooth
- The smoothing factor that specifies the sensitivity of the volume indication. The range is [0,10], and the recommended value is 3. The larger the value, the more sensitive the fluctuation; the smaller the value, the smoother the fluctuation.
- reportVad
-
- true: Enables local voice activity detection. When enabled, the
vadparameter in the onAudioVolumeIndication callback reports whether voice is detected locally. - false: (Default) Disables local voice activity detection. Unless the engine automatically detects local voice, the
vadparameter in the onAudioVolumeIndication callback does not report local voice detection.
- true: Enables local voice activity detection. When enabled, the
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
enableCameraCenterStage
Enables or disables the Center Stage feature.
Future<void> enableCameraCenterStage(bool enabled);
The Center Stage feature is disabled by default. You need to call this method to enable it. To disable the feature, call this method again and set enabled to false.
- iPad:
- 12.9-inch iPad Pro (5th generation)
- 11-inch iPad Pro (3rd generation)
- iPad (9th generation)
- iPad mini (6th generation)
- iPad Air (5th generation)
- 2020 M1 MacBook Pro 13-inch + iPhone 11 (using iPhone as an external camera for MacBook)
Scenario
The Center Stage feature can be widely used in scenarios such as online meetings, live shows, and online education. Hosts can enable this feature to keep themselves centered in the frame whether they move or not, ensuring a better visual presentation.
Timing
You must call this method after the camera is successfully started, that is, after the SDK triggers the onLocalVideoStateChanged callback and returns the local video state as localVideoStreamStateCapturing (1).
Parameters
- enabled
- Whether to enable the Center Stage feature:
- true: Enable Center Stage.
- false: Disable Center Stage.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly.
enableContentInspect
Enables/disables local snapshot upload.
Future<void> enableContentInspect(
{required bool enabled, required ContentInspectConfig config});
After enabling local snapshot upload, the SDK takes and uploads snapshots of the video sent by the local user based on the module type and frequency set in ContentInspectConfig. After the snapshot is completed, the Agora server sends a callback notification to your server via HTTPS request and uploads all snapshots to your specified third-party cloud storage.
- Before calling this method, ensure that the local snapshot upload service has been enabled in the Agora Console.
- When using the Agora-developed plugin for snapshot upload (
contentInspectSupervision) in the video moderation module, you must integrate the local snapshot upload dynamic librarylibagora_content_inspect_extension.dll. Deleting this library will prevent the local snapshot upload feature from working properly.
Timing
Can be called before or after joining a channel.
Parameters
- enabled
- Sets whether to enable local snapshot upload:
- true: Enable local snapshot upload.
- false: Disable local snapshot upload.
- config
- Local snapshot upload configuration. See ContentInspectConfig.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
enableCustomAudioLocalPlayback
Sets whether to play the external audio source locally.
Future<void> enableCustomAudioLocalPlayback(
{required int trackId, required bool enabled});
After calling this method to enable local playback of the externally captured audio source, to stop local playback, you can call this method again and set enabled to false.
You can call adjustCustomAudioPlayoutVolume to adjust the local playback volume of the custom audio track.
Parameters
- trackId
- Audio track ID. Set this parameter to the custom audio track ID returned by the createCustomAudioTrack method.
- enabled
- Whether to play the external audio source locally:
- true: Play locally.
- false: (Default) Do not play locally.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
enableDualStreamMode
Enables or disables dual-stream mode on the sending end and configures the low-quality stream.
Future<void> enableDualStreamMode(
{required bool enabled, SimulcastStreamConfig? streamConfig});
- Deprecated
- Deprecated: Deprecated since v4.2.0. Use setDualStreamMode instead.
- High-quality stream: High resolution and high frame rate video stream.
- Low-quality stream: Low resolution and low frame rate video stream.
- This method applies to all types of streams sent by the sender, including but not limited to camera-captured video, screen sharing, and custom-captured video.
- To enable dual-stream mode in multi-channel scenarios, call enableDualStreamModeEx.
- This method can be called 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
- Configuration for the low-quality stream. See SimulcastStreamConfig.
Note: When
modeis set todisableSimulcastStream, settingstreamConfighas no effect.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
enableEncryption
Enable or disable built-in encryption.
Future<void> enableEncryption(
{required bool enabled, required EncryptionConfig config});
After the user leaves the channel, the SDK automatically disables encryption. To enable encryption again, you need to call this method before the user rejoins the channel.
- All users in the same channel must set the same encryption mode and key when calling this method.
- If built-in encryption is enabled, the CDN live streaming feature cannot be used.
Scenario
Scenarios with high security requirements.
Timing
This method must be called before joining the channel.
Parameters
- enabled
- Whether to enable built-in encryption:
true: Enable built-in encryption.false: (default) Disable built-in encryption.
- config
- Configure the built-in encryption mode and key. See EncryptionConfig.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
enableExtension
Enables or disables an extension.
Future<void> enableExtension(
{required String provider,
required String extension,
bool enable = true,
MediaSourceType type = MediaSourceType.unknownMediaSource});
- To enable multiple extensions, you need to call this method multiple times.
- After this method is called successfully, no other extensions can be loaded.
Timing
It is recommended to call this method after joining a channel.
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
- The media source type of the extension. See MediaSourceType.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
enableFaceDetection
Enables/disables local face detection.
Future<void> enableFaceDetection(bool enabled);
Timing
This method must be called after the camera is started (e.g., by calling startPreview or enableVideo).
Parameters
- enabled
- Whether to enable face detection:
- true: Enables face detection.
- false: (Default) Disables face detection.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
enableInEarMonitoring
Enables in-ear monitoring.
Future<void> enableInEarMonitoring(
{required bool enabled,
required EarMonitoringFilterType includeAudioFilters});
This method enables or disables in-ear monitoring.
Timing
Can be called before or after joining a channel.
Parameters
- enabled
- Enable/disable in-ear monitoring:
- true: Enable in-ear monitoring.
- false: (Default) Disable in-ear monitoring.
- includeAudioFilters
- The audio filter type for in-ear monitoring. See EarMonitoringFilterType.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
enableInstantMediaRendering
Enables accelerated rendering of audio and video frames.
Future<void> enableInstantMediaRendering();
After successfully calling this method, the SDK enables accelerated rendering mode for both video and audio, which speeds up the time to first frame and first sound after joining a channel.
Scenario
Agora recommends enabling this mode for audience users in live streaming scenarios.
Timing
This method must be called before joining a channel.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
enableLocalAudio
Enables or disables local audio capture.
Future<void> enableLocalAudio(bool enabled);
- enableLocalAudio: Enables or disables local audio capture and processing. Using enableLocalAudio to disable or enable local capture will cause a brief interruption in hearing remote playback locally.
- muteLocalAudioStream: Stops or resumes sending the local audio stream without affecting the capture status.
Scenario
This method does not affect receiving and playing remote audio streams. enableLocalAudio(false) is suitable for scenarios where you only want to receive remote audio without sending locally captured audio.
Timing
This method can be called before or after joining a channel. When called before joining, it only sets the device state and takes effect immediately after joining.
Parameters
- enabled
-
- true: Re-enables the local audio function, i.e., enables local audio capture (default);
- false: Disables the local audio function, i.e., stops local audio capture.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
enableLocalVideo
Enables or disables local video capture.
Future<void> enableLocalVideo(bool enabled);
This method disables or re-enables local video capture and does not affect receiving remote video.
After calling enableVideo, local video capture is enabled by default.
If you call enableLocalVideo(false) in a channel to disable local video capture, it also stops publishing the video stream in the channel. To re-enable, call enableLocalVideo(true), then call updateChannelMediaOptions and set the options parameter to publish the captured video stream to the channel.
After successfully enabling or disabling local video capture, the remote side receives the onRemoteVideoStateChanged callback.
- This method can be called before or after joining a channel. However, settings made before joining only take effect after joining.
- This method sets the internal engine to an enabled state and remains effective after leaving the channel.
Parameters
- enabled
- Whether to enable local video capture.
- true: (Default) Enable local video capture.
- false: Disable local video capture. After disabling, the remote user cannot receive the local video stream, but the local user can still receive the remote video stream. When set to false, this method does not require a local camera.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
enableLoopbackRecording
Enables sound card capture.
Future<void> enableLoopbackRecording(
{required bool enabled, String? deviceName});
After enabling the sound card capture function, the sound played by the sound card is mixed into the local audio stream and can be sent to the remote side.
- This method is only applicable to macOS and Windows platforms.
- This method can be called before or after joining a channel.
- If you call disableAudio to disable the audio module, the sound card capture function will also be disabled. To re-enable it, you must call enableAudio to enable the audio module, and then call enableLoopbackRecording again.
Parameters
- enabled
- Whether to enable sound card capture:
- true: Enable sound card capture; the virtual sound card name is displayed in System Sound > Output.
- false: (Default) Disable sound card capture; the virtual sound card name is not displayed in System Sound > Output.
- deviceName
-
- macOS: Device name of the virtual sound card. Default is empty, which means using the AgoraALD virtual sound card for capture.
- Windows: Device name of the sound card. Default is empty, which means using the built-in sound card of the device for capture.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
enableMultiCamera
Enables or disables multi-camera capture.
Future<void> enableMultiCamera(
{required bool enabled, required CameraCapturerConfiguration config});
- Call this method to enable multi-camera capture.
- Call startPreview to start local video preview.
- Call startCameraCapture and set
sourceTypeto specify the second camera for capture. - Call joinChannelEx and set
publishSecondaryCameraTrackto true to publish the second camera's video stream in the channel.
- Call stopCameraCapture.
- Call this method and set
enabledto false.
- iPhone XR
- iPhone XS
- iPhone XS Max
- iPad Pro (3rd generation and later)
- If called before startPreview, the local video preview will display feeds from both cameras simultaneously.
- If called after startPreview, the SDK will stop the current camera capture first, then start both the original and the second camera. The local video preview may briefly go black before automatically recovering.
Parameters
- enabled
- Whether to enable multi-camera video capture mode:
- true: Enables multi-camera capture mode. The SDK uses multiple cameras to capture video.
- false: Disables multi-camera capture mode. The SDK uses only a single camera to capture video.
- config
- Configuration for the second camera. See CameraCapturerConfiguration.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
enableSoundPositionIndication
Enables/disables stereo sound for remote users.
Future<void> enableSoundPositionIndication(bool enabled);
To enable spatial audio positioning using setRemoteVoicePosition, make sure to call this method before joining the channel to enable stereo sound for remote users.
Parameters
- enabled
- Whether to enable stereo sound for remote users:
- true: Enable stereo sound.
- false: Disable stereo sound.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
enableSpatialAudio
Enables or disables spatial audio.
Future<void> enableSpatialAudio(bool enabled);
After enabling spatial audio, you can call setRemoteUserSpatialAudioParams to set the spatial audio parameters for remote users.
- This method can be called before or after joining a channel.
- This method depends on the spatial audio dynamic library
libagora_spatial_audio_extension.dll. Deleting this library will cause the feature to fail to enable properly.
Parameters
- enabled
- Whether to enable spatial audio:
- true: Enable spatial audio.
- false: Disable spatial audio.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
enableVideo
Enables the video module.
Future<void> enableVideo();
The video module is disabled by default. You need to call this method to enable it. To disable the video module later, call the disableVideo method.
- This method sets the internal engine to an enabled state and remains effective after leaving the channel.
- Calling this method resets the entire engine and may take longer to respond. You can use the following methods to control specific video functions as needed:
- enableLocalVideo: Whether to enable camera capture and create the local video stream.
- muteLocalVideoStream: Whether to publish the local video stream.
- muteRemoteVideoStream: Whether to receive and play the remote video stream.
- muteAllRemoteVideoStreams: Whether to receive and play all remote video streams.
- When called in a channel, this method resets the settings of enableLocalVideo, muteRemoteVideoStream, and muteAllRemoteVideoStreams. Use with caution.
Timing
- If called before joining, the video module is enabled.
- If called during an audio-only call, the call automatically switches to a video call.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
enableVideoImageSource
Enables or disables the placeholder image streaming feature.
Future<void> enableVideoImageSource(
{required bool enable, required ImageTrackOptions options});
When publishing a video stream, you can call this method to use a custom image to replace the current video stream for streaming. After enabling this feature, you can customize the placeholder image using the ImageTrackOptions parameter. After disabling the placeholder feature, remote users will still see the video stream you are currently publishing.
Timing
It is recommended to call this method after joining a channel.
Parameters
- enable
- Whether to enable placeholder image streaming:
- true: Enable placeholder image streaming.
- false: (Default) Disable placeholder image streaming.
- options
- Placeholder image settings. See ImageTrackOptions.
Return Values
- < 0: The method call fails. See Error Codes for details and resolution suggestions.
enableVirtualBackground
Enables/disables virtual background.
Future<void> enableVirtualBackground(
{required bool enabled,
required VirtualBackgroundSource backgroundSource,
required SegmentationProperty segproperty,
MediaSourceType type = MediaSourceType.primaryCameraSource});
The virtual background feature allows replacing the original background of the local user with a static image, dynamic video, blurring the background, or segmenting the portrait from the background to achieve picture-in-picture effects. After successfully enabling the virtual background feature, all users in the channel can see the customized background. Call this method after enableVideo or startPreview.
- Using video as a virtual background may cause continuous memory usage growth, which can lead to app crashes. Therefore, try to reduce the resolution and frame rate of the video when using it.
- This feature has high performance requirements. The SDK automatically checks the current device capability when calling this method. It is recommended to use it on devices with the following chipsets:
- Snapdragon 700 series 750G and above
- Snapdragon 800 series 835 and above
- Dimensity 700 series 720 and above
- Kirin 800 series 810 and above
- Kirin 900 series 980 and above
- Devices with A9 and above chips:
- iPhone 6S and above
- iPad Air 3rd generation and above
- iPad 5th generation and above
- iPad Pro 1st generation and above
- iPad mini 5th generation and above
- It is recommended to use this feature under the following conditions:
- Using a high-definition camera and evenly lit environment.
- The scene contains few objects, the user's portrait is half-body and mostly unobstructed, and the background color is relatively uniform and different from the user's clothing color.
- This method depends on the virtual background dynamic library
libagora_segmentation_extension.dll. Deleting this library will cause the feature to fail to start properly.
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 the SDK's video capture resolution, the SDK scales and crops the custom background image while preserving its aspect ratio.
- segproperty
- Processing properties of the background image. See SegmentationProperty.
- type
- The media source type to which the effect is applied. See MediaSourceType.
Note: In this method, this parameter only supports the following two settings:
- When using the camera to capture local video, keep the default value
primaryCameraSource. - To use custom captured video, set this parameter to
customVideoSource.
- When using the camera to capture local video, keep the default value
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
enableVoiceAITuner
Enables or disables the AI tuner feature.
Future<void> enableVoiceAITuner(
{required bool enabled, required VoiceAiTunerType type});
The AI tuner feature enhances audio quality and adjusts voice tone style.
Scenario
Social and entertainment scenarios with high audio quality requirements, such as online karaoke, online podcasts, and live shows.
Timing
Can be called before or after joining a channel.
Parameters
- enabled
- Whether to enable the AI tuner feature:
- true: Enable the AI tuner feature.
- false: (default) Disable the AI tuner feature.
- type
- AI tuner effect type. See VoiceAiTunerType.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
enableWebSdkInteroperability
Enable interoperability with Web SDK (applicable only in live broadcast scenarios).
Future<void> enableWebSdkInteroperability(bool enabled);
- Deprecated
- Deprecated: This method is deprecated. The SDK automatically enables interoperability with the Web SDK, so you do not need to call this method.
This method enables or disables interoperability with the Web SDK. If users join the channel via Web SDK, make sure to call this method; otherwise, Web users may see a black screen when viewing the Native side. This method is only applicable in live broadcast scenarios. In communication scenarios, interoperability is enabled by default.
Parameters
- enabled
- Whether to enable interoperability with the Web SDK:
- true: Enable interoperability.
- false: (default) Disable interoperability.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
getAudioDeviceInfo
Gets audio device information.
Future<DeviceInfo> getAudioDeviceInfo();
After calling this method, you can check whether the audio device supports ultra-low latency recording and playback.
- This method is applicable to Android only.
- This method can be called before or after joining a channel.
Return Values
- Non-null: The method call succeeds.
- Null: The method call fails. See Error Codes for details and resolution suggestions.
getAudioDeviceManager
Gets the AudioDeviceManager object to manage audio devices.
AudioDeviceManager getAudioDeviceManager();
Return Values
An AudioDeviceManager object.
getAudioMixingCurrentPosition
Gets the playback progress of the music file.
Future<int> getAudioMixingCurrentPosition();
This method gets the current playback progress of the music file, in milliseconds.
- You need to call this method after calling startAudioMixing and receiving the
onAudioMixingStateChanged(audioMixingStatePlaying)callback. - If you need to call getAudioMixingCurrentPosition multiple times, ensure the interval between calls is greater than 500 ms.
Return Values
- ≥ 0: The method call succeeds and returns the current playback progress of the music file (ms). 0 indicates the music file has not started playing.
- < 0: The method call fails. See Error Codes for details and resolution suggestions.
getAudioMixingDuration
Gets the total duration of the music file.
Future<int> getAudioMixingDuration();
This method gets the total duration of the music file, in milliseconds.
Timing
You need to call this method after startAudioMixing and receiving the onAudioMixingStateChanged(audioMixingStatePlaying) callback.
Return Values
- ≥ 0: The method call succeeds and returns the duration of the music file.
- < 0: The method call fails. See Error Codes for details and resolution suggestions.
getAudioMixingPlayoutVolume
Gets the local playback volume of the music file.
Future<int> getAudioMixingPlayoutVolume();
You can call this method to get the local playback volume of the mixed music file, which helps troubleshoot volume-related issues.
Timing
You need to call this method after startAudioMixing and receiving the onAudioMixingStateChanged(audioMixingStatePlaying) callback.
Return Values
- ≥ 0: The method call succeeds and returns the volume value, range is [0,100].
- < 0: The method call fails. See Error Codes for details and resolution suggestions.
getAudioMixingPublishVolume
Gets the remote playback volume of the music file.
Future<int> getAudioMixingPublishVolume();
This interface helps developers troubleshoot volume-related issues.
onAudioMixingStateChanged(audioMixingStatePlaying) callback.Return Values
- ≥ 0: The method call succeeds and returns the volume value, range is [0,100].
- < 0: The method call fails. See Error Codes for details and resolution suggestions.
getAudioTrackCount
Gets the audio track index of the current music file.
Future<int> getAudioTrackCount();
- You need to call this method after calling startAudioMixing and receiving the
onAudioMixingStateChanged(audioMixingStatePlaying)callback.
Return Values
- When the method call succeeds, returns the audio track index of the current music file.
- < 0: The method call fails. See Error Codes for details and resolution suggestions.
getCallId
Gets the call ID.
Future<String> getCallId();
Each time the client joins a channel, a corresponding callId is generated to identify the current call. You can call this method to get the callId parameter, and then pass it in when calling methods such as rate and complain.
Timing
This method must be called after joining a channel.
Return Values
Call ID.
getCameraMaxZoomFactor
Gets the maximum zoom factor supported by the camera.
Future<double> getCameraMaxZoomFactor();
- This method is only applicable to Android and iOS.
- Call this method after the SDK triggers the onLocalVideoStateChanged callback and returns the local video state as
localVideoStreamStateCapturing(1).
Return Values
The maximum zoom factor supported by the device camera.
getConnectionState
Gets the current network connection state.
Future<ConnectionStateType> getConnectionState();
Timing
Can be called before or after joining a channel.
Return Values
Current network connection state. See ConnectionStateType.
getCurrentMonotonicTimeInMs
Gets the SDK's current monotonic time.
Future<int> getCurrentMonotonicTimeInMs();
Monotonic time refers to a monotonically increasing time sequence, whose value increases over time. The unit is milliseconds. In custom video capture and custom audio capture scenarios, to ensure audio-video synchronization, Agora recommends that you call this method to get the SDK's current monotonic time and then pass the value into the timestamp parameter of the captured VideoFrame or AudioFrame.
Timing
Can be called before or after joining a channel.
Return Values
- ≥ 0: The method call succeeds and returns the SDK's current monotonic time (milliseconds).
- < 0: The method call fails. See Error Codes for details and resolution suggestions.
getEffectCurrentPosition
Gets the playback progress of the specified sound effect file.
Future<int> getEffectCurrentPosition(int soundId);
Parameters
- soundId
- The ID of the sound effect. Each sound effect has a unique ID.
Return Values
- If the method call succeeds, returns the playback progress of the specified sound effect file (milliseconds).
- < 0: The method call fails. See Error Codes for details and resolution suggestions.
getEffectDuration
Gets the total duration of the specified sound effect file.
Future<int> getEffectDuration(String filePath);
Parameters
- filePath
- File path:
- Android: File path, must include the file name and extension. Supports URL of online files, URI of local files, absolute paths, or paths starting with
/assets/. Accessing local files via absolute path may cause permission issues. It is recommended to use URI. For example:content://com.android.providers.media.documents/document/audio%3A14441. - Windows: Absolute path or URL to the audio file, must include the file name and extension. For example:
C:\music\audio.mp4. - iOS or macOS: Absolute path or URL to the audio file, must include the file name and extension. For example:
/var/mobile/Containers/Data/audio.mp4.
- Android: File path, must include the file name and extension. Supports URL of online files, URI of local files, absolute paths, or paths starting with
Return Values
- If the method call succeeds, returns the duration of the specified sound effect file (milliseconds).
- < 0: The method call fails. See Error Codes for details and resolution suggestions.
getEffectsVolume
Gets the playback volume of audio effect files.
Future<int> getEffectsVolume();
The volume range is [0,100]. 100 (default) is the original file volume.
Return Values
- The volume of the audio effect file.
- < 0: The method call fails. See Error Codes for details and resolution suggestions.
getErrorDescription
Gets the warning or error description.
Future<String> getErrorDescription(int code);
Parameters
- code
- Error code reported by the SDK.
Return Values
Specific error description.
getExtensionProperty
Retrieves detailed information about the extension.
Future<String> getExtensionProperty(
{required String provider,
required String extension,
required String key,
required int bufLen,
MediaSourceType type = MediaSourceType.unknownMediaSource});
Timing
Can be called before or after joining a channel.
Parameters
- provider
- The name of the extension provider.
- extension
- The name of the extension.
- key
- The key of the extension property.
- type
- The media source type of the extension. See MediaSourceType.
- bufLen
- The maximum length of the extension property JSON string. The maximum value is 512 bytes.
Return Values
- If the method call succeeds, returns the extension information.
- If the method call fails, returns an empty string.
getFaceShapeAreaOptions
Gets face shaping area options.
Future<FaceShapeAreaOptions> getFaceShapeAreaOptions(
{required FaceShapeArea shapeArea,
MediaSourceType type = MediaSourceType.primaryCameraSource});
Call this method to get the current parameter settings of the face shaping area.
Scenario
When users open the facial area and intensity adjustment menu in the app, you can call this method to get the current options and update the UI accordingly.
Timing
Call this method after enableVideo.
Parameters
- shapeArea
- The face shaping area. See FaceShapeArea.
- type
- The media source type to which the effect is applied. See MediaSourceType.
Note: In this method, this parameter only supports the following two settings:
- When using the camera to capture local video, keep the default value
primaryCameraSource. - To use custom captured video, set this parameter to
customVideoSource.
- When using the camera to capture local video, keep the default value
Return Values
If the method call succeeds, returns a FaceShapeAreaOptions object; if it fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
getFaceShapeBeautyOptions
Gets face shaping effect options.
Future<FaceShapeBeautyOptions> getFaceShapeBeautyOptions(
{MediaSourceType type = MediaSourceType.primaryCameraSource});
Call this method to get the current parameter settings of the face shaping effect.
Scenario
When users open the facial beauty style and intensity menu in the app, you can call this method to get the current options and update the UI accordingly.
Timing
Call this method after enableVideo.
Parameters
- type
- The media source type to which the effect is applied. See MediaSourceType.
Note: In this method, this parameter only supports the following two settings:
- When capturing local video using the camera, keep the default value
primaryCameraSource. - To use custom captured video, set this parameter to
customVideoSource.
- When capturing local video using the camera, keep the default value
Return Values
Returns a FaceShapeBeautyOptions object if the method call succeeds; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
getLocalSpatialAudioEngine
Gets the LocalSpatialAudioEngine object.
LocalSpatialAudioEngine getLocalSpatialAudioEngine();
Return Values
The LocalSpatialAudioEngine object.
getMediaEngine
Gets the MediaEngine object.
MediaEngine getMediaEngine();
Return Values
MediaEngine object.
getNativeHandle
Gets the C++ handle of the Native SDK.
Future<int> getNativeHandle();
This method gets the C++ handle of the Native SDK engine, which is used in special scenarios including registering audio and video callbacks.
Return Values
Native handle of the SDK engine.
getNetworkType
Gets the local network connection type.
Future<int> getNetworkType();
You can call this method at any time to get the current network type in use.
Return Values
- ≥ 0: The method call succeeds and returns the local network connection type.
- 0: Network disconnected.
- 1: Network type is LAN.
- 2: Network type is Wi-Fi (including hotspot).
- 3: Network type is 2G mobile network.
- 4: Network type is 3G mobile network.
- 5: Network type is 4G mobile network.
- 6: Network type is 5G mobile network.
- < 0: The method call fails and returns an error code.
- -1: Unknown network connection type.
getNtpWallTimeInMs
Gets the current NTP (Network Time Protocol) time.
Future<int> getNtpWallTimeInMs();
In real-time chorus scenarios, especially when downlink inconsistency occurs across receiving ends due to network issues, you can call this method to get the current NTP time as the reference time to align lyrics and music across multiple receivers and achieve chorus synchronization.
Return Values
Unix timestamp (milliseconds) of the current NTP time.
getScreenCaptureSources
Gets the list of shareable screen and window objects.
Future<List<ScreenCaptureSourceInfo>> getScreenCaptureSources(
{required Size thumbSize,
required Size iconSize,
required bool includeScreen});
Before screen or window sharing, you can call this method to get a list of shareable screen and window objects, allowing users to select a screen or window to share via thumbnails in the list. The list contains important information such as window ID and screen ID. After obtaining the ID, you can call startScreenCaptureByWindowId or startScreenCaptureByDisplayId to start sharing.
Parameters
- thumbSize
- The target size (in pixels) of the thumbnail for the screen or window. The SDK scales the original image to match the longest side of the target size while maintaining the aspect ratio. For example, if the original size is 400 × 300 and
thumbSizeis 100 × 100, the actual thumbnail size is 100 × 75. If the target size is larger than the original, the thumbnail is the original image and no scaling is applied. - iconSize
- The target size (in pixels) of the icon corresponding to the application. The SDK scales the original image to match the longest side of the target size while maintaining the aspect ratio. For example, if the original size is 400 × 300 and
iconSizeis 100 × 100, the actual icon size is 100 × 75. If the target size is larger than the original, the icon is the original image and no scaling is applied. - includeScreen
- Whether the SDK returns screen information in addition to window information:
- true: SDK returns both screen and window information.
- false: SDK returns only window information.
Return Values
An array of ScreenCaptureSourceInfo.
getUserInfoByUid
Gets user information by UID.
Future<UserInfo> getUserInfoByUid(int uid);
After a remote user joins a channel, the SDK retrieves the UID and User Account of the remote user and caches a mapping table of UID and User Account. It then triggers the onUserInfoUpdated callback locally. After receiving this callback, call this method with the UID to get the UserInfo object that contains the specified user's User Account.
Timing
Call this method after receiving the onUserInfoUpdated callback.
Parameters
- uid
- User ID.
Return Values
- The UserInfo object, if the method call succeeds.
null, if the method call fails.
getUserInfoByUserAccount
Gets user information by User Account.
Future<UserInfo> getUserInfoByUserAccount(String userAccount);
After a remote user joins a channel, the SDK retrieves the UID and User Account of the remote user and caches a mapping table of UID and User Account. It then triggers the onUserInfoUpdated callback locally. After receiving this callback, call this method with the User Account to get the UserInfo object that contains the specified user's UID.
Timing
Call this method after receiving the onUserInfoUpdated callback.
Parameters
- userAccount
- User Account of the user.
Return Values
- The UserInfo object, if the method call succeeds.
null, if the method call fails.
getVersion
getVideoDeviceManager
Gets a VideoDeviceManager object to manage video devices.
VideoDeviceManager getVideoDeviceManager();
Return Values
A VideoDeviceManager object.
getVolumeOfEffect
Gets the playback volume of the specified audio effect file.
Future<int> getVolumeOfEffect(int soundId);
Parameters
- soundId
- ID of the audio effect file.
Return Values
- ≥ 0: The method call succeeds and returns the playback volume. The volume range is [0,100]. 100 is the original volume.
- < 0: The method call fails. See Error Codes for details and resolution suggestions.
initialize
Initializes the RtcEngine.
Future<void> initialize(RtcEngineContext context);
Timing
Make sure to call createAgoraRtcEngine and initialize to create and initialize the RtcEngine before calling other APIs.
Parameters
- context
- Configuration for the RtcEngine instance. See RtcEngineContext.
Return Values
- < 0: Failure.
- -1: General error (not specifically categorized).
- -2: Invalid parameter.
- -7: SDK initialization failed.
- -22: Resource allocation failed. This occurs when the App uses too many resources or system resources are exhausted.
- -101: Invalid App ID.
isCameraAutoExposureFaceModeSupported
Checks whether the device supports auto exposure.
Future<bool> isCameraAutoExposureFaceModeSupported();
Return Values
- true: The device supports auto exposure.
- false: The device does not support auto exposure.
isCameraAutoFocusFaceModeSupported
Checks whether the device supports face auto-focus.
Future<bool> isCameraAutoFocusFaceModeSupported();
- This method is only applicable to Android and iOS.
- Call this method after the SDK triggers the onLocalVideoStateChanged callback and returns the local video state as
localVideoStreamStateCapturing(1).
Return Values
- true: The device supports face auto-focus.
- false: The device does not support face auto-focus.
isCameraCenterStageSupported
Checks whether the camera supports Center Stage.
Future<bool> isCameraCenterStageSupported();
Before calling enableCameraCenterStage to enable the Center Stage feature, it is recommended to call this method to check whether the current device supports Center Stage.
Timing
You must call this method after the camera is successfully started, that is, after the SDK triggers the onLocalVideoStateChanged callback and returns the local video state as localVideoStreamStateCapturing (1).
Return Values
- true: The current camera supports Center Stage.
- false: The current camera does not support Center Stage.
isCameraExposurePositionSupported
Checks whether the device supports manual exposure.
Future<bool> isCameraExposurePositionSupported();
- This method is only applicable to Android and iOS.
- Call this method after the SDK triggers the onLocalVideoStateChanged callback and returns the local video state as
localVideoStreamStateCapturing(1).
Return Values
- true: The device supports manual exposure.
- false: The device does not support manual exposure.
isCameraExposureSupported
Checks whether the current camera supports exposure adjustment.
Future<bool> isCameraExposureSupported();
- This method is only applicable to Android and iOS.
- You must call this method after the SDK triggers the onLocalVideoStateChanged callback and the local video state returns
localVideoStreamStateCapturing(1). - It is recommended to call this method to check whether the current camera supports exposure adjustment before calling setCameraExposureFactor to adjust the exposure factor.
- This method checks whether the currently used camera supports exposure adjustment, i.e., the camera specified when calling setCameraCapturerConfiguration.
Return Values
- true: The method call succeeds.
- false: The method call fails. See Error Codes for details and resolution suggestions.
isCameraFaceDetectSupported
Checks whether the device camera supports face detection.
Future<bool> isCameraFaceDetectSupported();
- This method is only applicable to Android and iOS.
- You must call this method after the SDK triggers the onLocalVideoStateChanged callback and the local video state returns
localVideoStreamStateCapturing(1).
Return Values
- true: The device camera supports face detection.
- false: The device camera does not support face detection.
isCameraFocusSupported
Checks whether the device supports manual focus.
Future<bool> isCameraFocusSupported();
- This method is only applicable to Android and iOS.
- You must call this method after the SDK triggers the onLocalVideoStateChanged callback and the local video state returns
localVideoStreamStateCapturing(1).
Return Values
- true: The device supports manual focus.
- false: The device does not support manual focus.
isCameraTorchSupported
Checks whether the device supports keeping the flashlight on.
Future<bool> isCameraTorchSupported();
- This method is only applicable to Android and iOS.
- You must call this method after the SDK triggers the onLocalVideoStateChanged callback and the local video state returns
localVideoStreamStateCapturing(1). - Typically, the app enables the front camera by default. If your front camera does not support keeping the flashlight on, this method returns
false. If you want to check whether the rear camera supports keeping the flashlight on, you need to call switchCamera to switch the camera before using this method. - On iPads with system version 15, even if isCameraTorchSupported returns true, due to system issues, you may still fail to turn on the flashlight using setCameraTorchOn.
Return Values
- true: The device supports keeping the flashlight on.
- false: The device does not support keeping the flashlight on.
isCameraZoomSupported
Checks whether the device supports camera zoom.
Future<bool> isCameraZoomSupported();
Timing
You must call this method after the SDK triggers the onLocalVideoStateChanged callback and the local video state returns localVideoStreamStateCapturing (1).
Return Values
- 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);
Checks whether the current device meets the requirements for advanced features such as virtual background and beauty effects.
Scenario
Before using advanced audio and video features, you can check whether the current device supports them to avoid performance degradation or feature unavailability on low-end devices. Based on the return value of this method, you can decide whether to show or enable the corresponding feature buttons, or prompt users with appropriate messages when the device capability is insufficient.
Parameters
- type
- The type of advanced feature. See FeatureType.
Return Values
- true: The device supports the specified advanced feature.
- false: The device does not support the specified advanced feature.
isSpeakerphoneEnabled
Checks whether the speakerphone is enabled.
Future<bool> isSpeakerphoneEnabled();
Timing
This method can be called before or after joining a channel.
Return Values
- true: The speakerphone is enabled, and audio is routed to the speaker.
- false: The speakerphone is not enabled, and audio is routed to a non-speaker device (earpiece, headset, etc.).
joinChannel
Sets media options and joins a channel.
Future<void> joinChannel(
{required String token,
required String channelId,
required int uid,
required ChannelMediaOptions options});
This method allows you to set media options when joining a channel, such as whether to publish audio and video streams in the channel. By default, users subscribe to all remote audio and video streams in the channel, which may incur usage and affect billing. If you want to unsubscribe, you can do so by setting the options parameter or using the corresponding mute methods.
- This method only supports joining one channel at a time.
- Apps with different App IDs cannot communicate with each other.
- Before joining a channel, ensure that the App ID used to generate the Token is the same as the one used in the initialize method to initialize the engine. Otherwise, joining the channel using the Token will fail.
Timing
Call this method after initialize.
Parameters
- token
- The dynamic key generated on your server for authentication. See Token Authentication.
Note:
- (Recommended) If your project enables security mode (i.e., uses APP ID + Token for authentication), this parameter is required.
- If your project only enables debug mode (i.e., uses APP ID for authentication), you can join a channel without providing a Token. You will automatically leave the channel after 24 hours.
- If you need to join multiple channels at once or frequently switch between channels, Agora recommends using a wildcard Token to avoid requesting a new Token from your server for each new channel. See Wildcard Token.
- channelId
- The channel name. This parameter identifies the channel for real-time audio and video interaction. Users with the same App ID and channel name will join the same channel. This parameter must be a string of up to 64 bytes. Supported character set (89 characters):
- 26 lowercase letters a~z
- 26 uppercase letters A~Z
- 10 digits 0~9
- "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", "{", "}", "|", "~", ","
- uid
- User ID. This parameter identifies the user in the real-time audio and video interaction channel. You must set and manage the user ID yourself and ensure that each user ID is unique within the same channel. This parameter is a 32-bit unsigned integer. Recommended range: 1 to 2^32-1. If not specified (i.e., set to 0), the SDK automatically assigns one and returns it in the onJoinChannelSuccess callback. The application must remember and maintain this return value; the SDK does not maintain it.
- options
- Channel media options. See ChannelMediaOptions.
Return Values
- < 0: Method call failed. See Error Codes for details and resolution suggestions.
- -2: Invalid parameters. For example, an invalid Token,
uidis not an integer, or ChannelMediaOptions contains invalid values. Provide valid parameters and rejoin the channel. - -3: RtcEngine initialization failed. Reinitialize the RtcEngine object.
- -7: RtcEngine not initialized. Initialize the RtcEngine object before calling this method.
- -8: Internal state error in RtcEngine. Possible cause: startEchoTest was called but stopEchoTest was not called before joining the channel. Call stopEchoTest before this method.
- -17: Join channel rejected. Possible cause: user is already in the channel. Use onConnectionStateChanged to check if the user is in the channel. Do not call this method again unless you receive
connectionStateDisconnected(1). - -102: Invalid channel name. Provide a valid
channelIdand rejoin the channel. - -121: Invalid user ID. Provide a valid
uidand rejoin the channel.
- -2: Invalid parameters. For example, an invalid Token,
joinChannelWithUserAccount
Joins a channel using a User Account and token, and sets channel media options.
Future<void> joinChannelWithUserAccount(
{required String token,
required String channelId,
required String userAccount,
ChannelMediaOptions? options});
Before calling this method, if you have not registered a User Account using registerLocalUserAccount, the SDK automatically creates one for you when you join a channel using this method. To reduce the time it takes to join a channel, register the account first using registerLocalUserAccount, then call this method. After a user successfully joins a channel, they automatically subscribe to all audio and video streams from other users in the channel, which incurs usage and affects billing. To unsubscribe, call the corresponding mute methods.
- This method only supports joining one channel at a time.
- Apps with different App IDs cannot communicate with each other.
- Before joining a channel, make sure the App ID used to generate the token is the same as the one used in the initialize method. Otherwise, joining the channel with the token will fail.
Timing
This method must be called after initialize.
Parameters
- token
- The dynamic key generated on your server for authentication. See Use Token Authentication.
Note:
- (Recommended) If your project has enabled secure mode (using APP ID + Token for authentication), this parameter is required.
- If your project is in debug mode only (using APP ID for authentication), you can join the channel without a token. The user will automatically leave the channel after 24 hours.
- If you need to join multiple channels or frequently switch between channels, Agora recommends using a wildcard token to avoid requesting a new token from your server every time. See Use Wildcard Token.
- userAccount
- The User Account of the user. This parameter identifies the user in the real-time audio/video interaction channel. You must manage and ensure the uniqueness of each User Account within the same channel. This parameter is required, must not exceed 255 bytes, and cannot be
null. Supported character set (89 characters total):- 26 lowercase letters a–z
- 26 uppercase letters A–Z
- 10 digits 0–9
- Space
- "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", "{", "}", "|", "~", ","
- options
- Channel media configuration options. See ChannelMediaOptions.
Return Values
- < 0: The method call fails. See Error Codes for details and resolution suggestions.
- -2: Invalid parameter. For example, an illegal token is used, the
uidparameter is not an integer, or a member value of ChannelMediaOptions is invalid. Provide valid parameters and rejoin the channel. - -3: RtcEngine initialization failed. Reinitialize the RtcEngine object.
- -7: RtcEngine not initialized. Initialize RtcEngine before calling this method.
- -8: Internal state error of RtcEngine. This may occur if you call this method after starting an echo test with startEchoTest but before stopping it with stopEchoTest. Call stopEchoTest before this method.
- -17: Join channel rejected. Possibly because the user is already in the channel. Use the onConnectionStateChanged callback to check if the user is in the channel. Do not call this method again unless the state is
connectionStateDisconnected(1). - -102: Invalid channel name. Provide a valid
channelIdand rejoin the channel. - -121: Invalid user ID. Provide a valid
uidand rejoin the channel.
- -2: Invalid parameter. For example, an illegal token is used, the
joinChannelWithUserAccountEx
Joins a channel using a User Account and token, and sets channel media options.
Future<void> joinChannelWithUserAccountEx(
{required String token,
required String channelId,
required String userAccount,
required ChannelMediaOptions options});
Before calling this method, if you have not registered a User Account using registerLocalUserAccount, the SDK automatically creates one for you when you join a channel using this method. To reduce the time it takes to join a channel, register the account first using registerLocalUserAccount, then call this method.
After a user successfully joins a channel, they automatically subscribe to all audio and video streams from other users in the channel, which incurs usage and affects billing. To unsubscribe, set the options parameter or call the corresponding mute methods.
- This method only supports joining one channel at a time.
- Apps with different App IDs cannot communicate with each other.
- Before joining a channel, make sure the App ID used to generate the token is the same as the one used in the initialize method. Otherwise, joining the channel with the token will fail.
Timing
This method must be called after initialize.
Parameters
- token
- The dynamic key generated on your server for authentication. See Use Token Authentication.
Note:
- (Recommended) If your project has enabled secure mode (using APP ID + Token for authentication), this parameter is required.
- If your project is in debug mode only (using APP ID for authentication), you can join the channel without a token. The user will automatically leave the channel after 24 hours.
- If you need to join multiple channels or frequently switch between channels, Agora recommends using a wildcard token to avoid requesting a new token from your server every time. See Use Wildcard Token.
- userAccount
- The User Account of the user. This parameter identifies the user in the real-time audio/video interaction channel. You must manage and ensure the uniqueness of each User Account within the same channel. This parameter is required, must not exceed 255 bytes, and cannot be
null. Supported character set (89 characters total):- 26 lowercase letters a–z
- 26 uppercase letters A–Z
- 10 digits 0–9
- Space
- "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", "{", "}", "|", "~", ","
- options
- Channel media configuration options. See ChannelMediaOptions.
Return Values
- < 0: The method call fails. See Error Codes for details and resolution suggestions.
- -2: Invalid parameter. For example, an illegal token is used, the
uidparameter is not an integer, or a member value of ChannelMediaOptions is invalid. Provide valid parameters and rejoin the channel. - -3: RtcEngine initialization failed. Reinitialize the RtcEngine object.
- -7: RtcEngine not initialized. Initialize RtcEngine before calling this method.
- -8: Internal state error of RtcEngine. This may occur if you call this method after starting an echo test with startEchoTest but before stopping it with stopEchoTest. Call stopEchoTest before this method.
- -17: Join channel rejected. Possibly because the user is already in the channel. Use the onConnectionStateChanged callback to check if the user is in the channel. Do not call this method again unless the state is
connectionStateDisconnected(1). - -102: Invalid channel name. Provide a valid
channelIdand rejoin the channel. - -121: Invalid user ID. Provide a valid
uidand rejoin the channel.
- -2: Invalid parameter. For example, an illegal token is used, the
leaveChannel
Sets channel options and leaves the channel.
Future<void> leaveChannel({LeaveChannelOptions? options});
After calling this method, the SDK stops audio and video interaction, leaves the current channel, and releases all session-related resources. After successfully joining a channel, you must call this method to end the call; otherwise, you cannot start a new call. If you have joined multiple channels using joinChannelEx, calling this method will leave all joined channels.
Timing
This method must be called after joining a channel.
Parameters
- options
- Options for leaving the channel. See LeaveChannelOptions.
Return Values
When the method call succeeds, there is no return value; when it fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
loadExtensionProvider
Loads an extension.
Future<void> loadExtensionProvider(
{required String path, bool unloadAfterUse = false});
This method adds external SDK extensions (such as marketplace or SDK extension plugins) into the SDK.
Timing
Call this method immediately after initializing RtcEngine.
Parameters
- path
- The path and name of the extension dynamic library. For example:
/library/libagora_segmentation_extension.dll. - unloadAfterUse
- Whether to automatically unload the extension after use:
- true: Automatically unloads the extension when RtcEngine is destroyed.
- false: Does not automatically unload the extension until the process exits (recommended).
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
muteAllRemoteAudioStreams
Stops or resumes subscribing to all remote users' audio streams.
Future<void> muteAllRemoteAudioStreams(bool mute);
After this method is called successfully, the local user stops or resumes subscribing to all remote users' audio streams, including streams from users who join the channel after this method is called.
autoSubscribeAudio to false when calling joinChannel, so that no audio streams are subscribed to upon joining.
If you call enableAudio or disableAudio after this method, the later call takes effect.Timing
You must call this method after joining a channel.
Parameters
- mute
- Whether to stop subscribing to all remote users' audio streams:
- true: Stop subscribing to all remote users' audio streams.
- false: (Default) Subscribe to all remote users' audio streams.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
muteAllRemoteVideoStreams
Stops or resumes subscribing to all remote users' video streams.
Future<void> muteAllRemoteVideoStreams(bool mute);
After this method is called successfully, the local user stops or resumes subscribing to all remote users' video streams, including streams from users who join the channel after this method is called.
autoSubscribeVideo to false when calling joinChannel, so that no video streams are subscribed to upon joining.
If you call enableVideo or disableVideo after this method, the later call takes effect.Timing
You must call this method after joining a channel.
Parameters
- mute
- Whether to stop subscribing to all remote users' video streams.
- true: Stop subscribing to all users' video streams.
- false: (Default) Subscribe to all users' video streams.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
muteLocalAudioStream
Stops or resumes publishing the local audio stream.
Future<void> muteLocalAudioStream(bool mute);
This method controls whether to publish the locally captured audio stream. Not publishing the local audio stream does not disable the audio capture device, so it does not affect the audio capture status.
Timing
Can be called before or after joining a channel.
Parameters
- mute
- Whether to stop publishing the local audio stream.
- true: Stop publishing.
- false: (Default) Publish.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
muteLocalVideoStream
Stops or resumes publishing the local video stream.
Future<void> muteLocalVideoStream(bool mute);
This method controls whether to publish the locally captured video stream. Not publishing the local video stream does not disable the video capture device, so it does not affect the video capture status.
Compared to calling enableLocalVideo(false) to stop video capture and thus stop publishing, this method responds faster.
Timing
Can be called before or after joining a channel.
Parameters
- mute
- Whether to stop sending the local video stream.
- true: Stop sending the local video stream.
- false: (Default) Send the local video stream.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
muteRecordingSignal
Mutes the recording signal.
Future<void> muteRecordingSignal(bool mute);
- Record the adjusted volume.
- Mute the recording signal.
Timing
Can be called before or after joining a channel.
Parameters
- mute
-
- true: Mute.
- false: (default) Original volume.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
muteRemoteAudioStream
Stops or resumes subscribing to the audio stream of a specified remote user.
Future<void> muteRemoteAudioStream({required int uid, required bool mute});
Timing
You need to call this method after joining a channel.
Parameters
- uid
- The user ID of the specified user.
- mute
- Whether to stop subscribing to the audio stream of the specified remote user.
- true: Stop subscribing to the audio stream of the specified user.
- false: (Default) Subscribe to the audio stream of the specified user.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
muteRemoteVideoStream
Stops or resumes subscribing to the video stream of a specified remote user.
Future<void> muteRemoteVideoStream({required int uid, required bool mute});
Timing
You need to call this method after joining a channel.
Parameters
- uid
- The user ID of the specified user.
- mute
- Whether to stop subscribing to the video stream of the specified remote user.
- true: Stop subscribing to the video stream of the specified user.
- false: (Default) Subscribe to the video stream of the specified user.
Return Values
- < 0: Method call failed. See Error Codes for details and resolution suggestions.
pauseAllChannelMediaRelay
Pauses media stream relay to all destination channels.
Future<void> pauseAllChannelMediaRelay();
After starting media stream relay across channels, if you want to pause relaying to all destination channels, you can call this method. To resume relaying, call resumeAllChannelMediaRelay.
Return Values
When the method call succeeds, there is no return value; when it fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
pauseAllEffects
Pauses playback of all audio effect files.
Future<void> pauseAllEffects();
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
pauseAudioMixing
Pauses the playback of the music file.
Future<void> pauseAudioMixing();
After you call the startAudioMixing method to play a music file, call this method to pause the playback. To stop the playback, call stopAudioMixing.
Timing
You must call this method after joining a channel.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
pauseEffect
Pauses playback of the audio effect file.
Future<void> pauseEffect(int soundId);
Parameters
- soundId
- ID of the audio effect. Each audio effect has a unique ID.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
playAllEffects
Plays all audio effect files.
Future<void> playAllEffects(
{required int loopCount,
required double pitch,
required double pan,
required int gain,
bool publish = false});
After calling preloadEffect multiple times to preload multiple audio effect files, you can call this method to play all preloaded audio effect files.
Parameters
- loopCount
- Number of times the audio effect file is looped:
- -1: Loops indefinitely until stopEffect or stopAllEffects is called.
- 0: Plays once.
- 1: Plays twice.
- pitch
- Pitch of the audio effect. Value range is [0.5,2.0]. Default is 1.0, which represents the original pitch. The smaller the value, the lower the pitch.
- pan
- Spatial position of the audio effect. Value range is [-1.0,1.0]:
- -1.0: Audio effect appears on the left.
- 0: Audio effect appears in the center.
- 1.0: Audio effect appears on the right.
- gain
- Volume of the audio effect. Value range is [0,100]. 100 is the default and represents the original volume. The smaller the value, the lower the volume.
- publish
- Whether to publish the audio effect to remote users:
- true: Publishes the audio effect to remote users. Both local and remote users can hear it.
- false: (Default) Does not publish the audio effect to remote users. Only local users can hear it.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
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});
You can call this method multiple times with different soundID and filePath to play multiple audio effect files simultaneously. For optimal user experience, it is recommended to play no more than 3 audio effect files at the same time.
Timing
This method can be called before or after joining a channel.
Parameters
- soundId
- ID of the audio effect. Each audio effect has a unique ID.
Note: If you have loaded the audio effect into memory using preloadEffect, make sure this parameter matches the
soundIdset in preloadEffect. - filePath
- Path of the file to be played. Supports URL of online files or absolute path of local files. Must include file name and extension. Supported formats include MP3, AAC, M4A, MP4, WAV, 3GP, etc.
Note: If you have loaded the audio effect into memory using preloadEffect, make sure this parameter matches the
filePathset in preloadEffect. - loopCount
- Number of times the audio effect is looped.
- ≥ 0: Number of loops. For example, 1 means loop once, i.e., played twice in total.
- -1: Loops indefinitely.
- pitch
- Pitch of the audio effect. Value range is [0.5,2.0]. Default is 1.0, which represents the original pitch. The smaller the value, the lower the pitch.
- pan
- Spatial position of the audio effect. Value range is [-1.0,1.0], for example:
- -1.0: Audio effect appears on the left
- 0.0: Audio effect appears in the center
- 1.0: Audio effect appears on the right
- gain
- Volume of the audio effect. Value range is [0.0,100.0]. Default is 100.0, which represents the original volume. The smaller the value, the lower the volume.
- publish
- Whether to publish the audio effect to remote users:
- true: Publishes the audio effect to remote users. Both local and remote users can hear it.
- false: Does not publish the audio effect to remote users. Only local users can hear it.
- startPos
- Playback position of the audio effect file in milliseconds.
Return Values
- < 0: The method call fails. See Error Codes for details and resolution suggestions.
preloadChannel
Preloads a channel using token, channelId, and uid.
Future<void> preloadChannel(
{required String token, required String channelId, required int uid});
Calling this method reduces the time it takes for an audience member to join a channel when switching channels frequently, thereby shortening the time to hear the first audio frame and see the first video frame from the host, and improving the audience's video experience. If the current channel has already been successfully preloaded, and the audience leaves and rejoins the channel, as long as the Token passed during preloading is still valid, re-preloading is not required.
- When calling this method, ensure the user role is set to audience and the audio scenario is not chorus (
audioScenarioChorus), otherwise preloading will not take effect. - Ensure the channel name, user ID, and Token passed during preloading are the same as those used when joining the channel later; otherwise, preloading will not take effect.
- Currently, a single RtcEngine instance supports preloading up to 20 channels. If this limit is exceeded, only the latest 20 preloaded channels take effect.
Timing
To improve the user experience of preloading channels, Agora recommends calling this method as early as possible after confirming the channel name and user information, and before joining the channel.
Parameters
- token
- A dynamic key generated on your server for authentication. See Token Authentication.
When the Token expires, depending on the number of preloaded channels, you can pass in a new Token for preloading in different ways:
- For a single channel: call this method again with the new Token.
- For multiple channels:
- If you use a wildcard Token, call updatePreloadChannelToken to update the Token for all preloaded channels. When generating a wildcard Token, the user ID must not be set to 0. See Wildcard Token.
- If you use different Tokens: call this method and pass in your user ID, corresponding channel name, and the updated Token.
- channelId
- The name of the channel to preload. This parameter identifies the channel for real-time audio and video communication. Under the same App ID, users who enter the same channel name will join the same channel for audio and video interaction.
This parameter must be a string no longer than 64 bytes. Supported character set (89 characters total):
- 26 lowercase letters a~z
- 26 uppercase letters A~Z
- 10 digits 0~9
- "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", "{", "}", "|", "~", ","
- uid
- User ID. This parameter identifies the user in the real-time audio and video channel. You need to set and manage the user ID yourself and ensure it is unique within the same channel. This parameter is a 32-bit unsigned integer. Recommended range: 1 to 2^32-1. If not specified (i.e., set to 0), the SDK automatically assigns one and returns it in the onJoinChannelSuccess callback. The application must store and manage this return value, as the SDK does not maintain it.
Return Values
- < 0: The method call fails. See Error Codes for details and resolution suggestions.
preloadChannelWithUserAccount
Preloads a channel using token, channelId, and userAccount.
Future<void> preloadChannelWithUserAccount(
{required String token,
required String channelId,
required String userAccount});
Calling this method reduces the time it takes for an audience member to join a channel when switching channels frequently, thereby shortening the time to hear the first audio frame and see the first video frame from the host, and improving the audience's video experience. If the current channel has already been successfully preloaded, and the audience leaves and rejoins the channel, as long as the Token passed during preloading is still valid, re-preloading is not required.
- When calling this method, ensure the user role is set to audience and the audio scenario is not chorus (
audioScenarioChorus), otherwise preloading will not take effect. - Ensure the channel name, user account, and Token passed during preloading are the same as those used when joining the channel later; otherwise, preloading will not take effect.
- Currently, a single RtcEngine instance supports preloading up to 20 channels. If this limit is exceeded, only the latest 20 preloaded channels take effect.
Timing
To improve the user experience of preloading channels, Agora recommends calling this method as early as possible after confirming the channel name and user information, and before joining the channel.
Parameters
- token
- A dynamic key generated on your server for authentication. See Token Authentication.
When the Token expires, depending on the number of preloaded channels, you can pass in a new Token for preloading in different ways:
- For a single channel: call this method again with the new Token.
- For multiple channels:
- If you use a wildcard Token, call updatePreloadChannelToken to update the Token for all preloaded channels. When generating a wildcard Token, the user ID must not be set to 0. See Wildcard Token.
- If you use different Tokens: call this method and pass in your user ID, corresponding channel name, and the updated Token.
- channelId
- The name of the channel to preload. This parameter identifies the channel for real-time audio and video communication. Under the same App ID, users who enter the same channel name will join the same channel for audio and video interaction.
This parameter must be a string no longer than 64 bytes. Supported character set (89 characters total):
- 26 lowercase letters a~z
- 26 uppercase letters A~Z
- 10 digits 0~9
- "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", "{", "}", "|", "~", ","
- userAccount
- User account. This parameter identifies the user in the real-time audio and video channel. You need to set and manage the user account yourself and ensure it is unique within the same channel. This parameter is required, must not exceed 255 bytes, and cannot be
null. Supported character set (89 characters total):- 26 lowercase letters a-z
- 26 uppercase letters A-Z
- 10 digits 0-9
- Space
- "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", "{", "}", "|", "~", ","
Return Values
- < 0: The method call fails. See Error Codes for details and resolution suggestions.
- -2: Invalid parameter. For example, the user account is empty. You need to enter a valid parameter and rejoin the channel.
- -7: The RtcEngine object is not initialized. You need to initialize the RtcEngine object before calling this method.
- -102: Invalid channel name. You need to enter a valid channel name and rejoin the channel.
preloadEffect
Loads the audio effect file into memory.
Future<void> preloadEffect(
{required int soundId, required String filePath, int startPos = 0});
To ensure smooth communication, pay attention to the size of the preloaded audio effect file. Supported formats for preloading audio files are listed in What audio formats are supported by the RTC SDK.
Timing
Agora recommends calling this method before joining a channel.
Parameters
- soundId
- The ID of the audio effect. Each audio effect has a unique ID.
- filePath
- File path:
- Android: File path including file name and extension. Supports URL of online files, URI of local files, absolute paths, or paths starting with
/assets/. Accessing local files via absolute path may cause permission issues. It is recommended to use URI to access local files. For example,content://com.android.providers.media.documents/document/audio%3A14441. - Windows: Absolute path or URL of the audio file, including file name and extension. For example,
C:\music\audio.mp4. - iOS or macOS: Absolute path or URL of the audio file, including file name and extension. For example,
/var/mobile/Containers/Data/audio.mp4.
- Android: File path including file name and extension. Supports URL of online files, URI of local files, absolute paths, or paths starting with
- startPos
- The start position for loading the audio effect file, in milliseconds.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
queryCameraFocalLengthCapability
Queries the focal length capabilities supported by the camera.
Future<List<FocalLengthInfo>> queryCameraFocalLengthCapability();
To enable wide-angle or ultra-wide-angle camera modes, it is recommended to call this method first to check whether the device supports the corresponding focal length capabilities. Then, based on the result, call setCameraCapturerConfiguration to adjust the camera's focal length configuration to achieve the best capturing effect.
Return Values
Returns an array of FocalLengthInfo objects, which contain the camera's orientation and focal length type.
queryCodecCapability
Queries the video codec capabilities supported by the SDK.
Future<List<CodecCapInfo>> queryCodecCapability(int size);
Parameters
- size
- The size of CodecCapInfo.
Return Values
- If the call succeeds, returns an array of CodecCapInfo, indicating the SDK's video encoding capabilities.
- If the call times out, modify your call logic and avoid calling this method on the main thread.
queryDeviceScore
Queries the device score level.
Future<int> queryDeviceScore();
Scenario
In high-definition or ultra-high-definition video scenarios, you can first call this method to query the device score. If the returned score is low (e.g., below 60), you should lower the video resolution accordingly to avoid affecting the video experience. The minimum device score requirement varies by business scenario. For specific recommendations, please contact technical support.
Return Values
- < 0: The method call fails.
queryScreenCaptureCapability
Queries the maximum frame rate supported by the device during screen sharing.
Future<int> queryScreenCaptureCapability();
Scenario
In screen sharing scenarios, if you want to enable high frame rates (e.g., 60 fps) but are unsure whether the device supports it, you can call this method to query the maximum frame rate supported by the device. If high frame rates are not supported, you can lower the frame rate of the screen sharing stream accordingly to ensure the expected sharing experience.
Return Values
- If the method call succeeds, returns the maximum frame rate supported by the device. See ScreenCaptureFramerateCapability.
- <0: The method call fails. See Error Codes for details and resolution suggestions.
rate
Rates a call.
Future<void> rate(
{required String callId,
required int rating,
required String description});
Parameters
- callId
- The call ID. You can obtain this parameter by calling getCallId.
- rating
- The rating for the call, from 1 (lowest) to 5 (highest).
- description
- A description of the call. The length must be less than 800 bytes.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
registerAudioEncodedFrameObserver
Registers the audio encoded frame observer.
void registerAudioEncodedFrameObserver(
{required AudioEncodedFrameObserverConfig config,
required AudioEncodedFrameObserver observer});
- Call this method after joining a channel.
- Since this method and
startAudioRecordingboth configure audio content and quality, it is not recommended to use them together. Otherwise, only the one called later takes effect.
Parameters
- config
- Configuration for the encoded audio observer. See AudioEncodedFrameObserverConfig.
- observer
- Observer for encoded audio. See AudioEncodedFrameObserver.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
registerAudioSpectrumObserver
Registers an audio spectrum observer.
void registerAudioSpectrumObserver(AudioSpectrumObserver observer);
After successfully registering an audio spectrum observer and calling enableAudioSpectrumMonitor to enable audio spectrum monitoring, the SDK reports the callbacks implemented in the AudioSpectrumObserver class at the interval you set.
Parameters
- observer
- Audio spectrum observer. See AudioSpectrumObserver.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
registerExtension
Registers an extension.
Future<void> registerExtension(
{required String provider,
required String extension,
MediaSourceType type = MediaSourceType.unknownMediaSource});
For external SDK extensions (such as marketplace or SDK extension plugins), after loading the extension, you need to call this method to register it. Internal SDK extensions (those included in the SDK package) are automatically loaded and registered after initializing RtcEngine, so you do not need to call this method.
- To register multiple extensions, call this method multiple times.
- The order in which different extensions process data in the SDK is determined by the registration order. That is, extensions registered earlier process data first.
Timing
- It is recommended to call this method after initializing RtcEngine and before joining a channel.
- For video-related extensions (such as beauty filters), you need to call this method before enabling the video module (enableVideo/enableLocalVideo).
- Before calling this method, you must call loadExtensionProvider to load the extension.
Parameters
- provider
- The name of the extension provider.
- extension
- The name of the extension.
- type
- The media source type of the extension. See MediaSourceType.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
registerLocalUserAccount
Registers the local user account.
Future<void> registerLocalUserAccount(
{required String appId, required String userAccount});
- Call registerLocalUserAccount to register the account first, then call joinChannelWithUserAccount to join the channel. This can reduce the time to join the channel.
- Directly call joinChannelWithUserAccount to join the channel.
- Ensure the
userAccountset in this method is unique within the channel. - To ensure communication quality, make sure to use the same type of user identifier within a channel. That is, use either UID or user account consistently within the same channel. If users join the channel via Web SDK, ensure they use the same identifier type.
Parameters
- appId
- The App ID of your project registered in the console.
- userAccount
- User account. This parameter identifies the user in the real-time audio and video channel. You need to set and manage the user account yourself and ensure it is unique within the same channel. This parameter is required, must not exceed 255 bytes, and cannot be
null. Supported character set (89 characters total):- 26 lowercase letters a-z
- 26 uppercase letters A-Z
- 10 digits 0-9
- Space
- "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", "{", "}", "|", "~", ","
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
registerMediaMetadataObserver
Registers a media metadata observer to receive or send metadata.
void registerMediaMetadataObserver(
{required MetadataObserver observer, required MetadataType type});
You need to implement the MetadataObserver class yourself and specify the metadata type in this method. This method allows you to add synchronized metadata to the video stream for interactive live streaming scenarios such as sending shopping links, e-coupons, and online quizzes.
Parameters
- observer
- The metadata observer. See MetadataObserver.
- type
- The metadata type. Currently only
videoMetadatais supported.
Return Values
- < 0: The method call fails. See Error Codes for details and resolution suggestions.
release
Destroys the RtcEngine object.
Future<void> release({bool sync = false});
This method releases all resources used by the SDK. Some Apps only use real-time audio and video communication when needed, and release resources when not needed for other operations. This method is suitable for such cases. After calling this method, you can no longer use other SDK methods and callbacks. To use real-time audio and video communication again, you must call createAgoraRtcEngine and initialize again to create a new RtcEngine object.
- This method is a synchronous call. You must wait for the RtcEngine resources to be released before performing other operations (e.g., creating a new RtcEngine object), so it is recommended to call this method in a sub-thread to avoid blocking the main thread.
- It is not recommended to call release within SDK callbacks, as the SDK must wait for the callback to return before recycling related object resources, which may cause a deadlock.
Parameters
- sync
- Whether this method is a synchronous call:
- true: This method is synchronous.
- false: This method is asynchronous. Currently, only synchronous calls are supported. Do not set this parameter to false.
unregisterEventHandler
Removes the specified callback event.
void unregisterEventHandler(RtcEngineEventHandler eventHandler);
This method removes all previously added callback events.
Parameters
- eventHandler
- The callback event to be removed. See RtcEngineEventHandler.
Return Values
When the method call succeeds, there is no return value; when it fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
removeVideoWatermark
Removes the watermark image from the local video.
Future<void> removeVideoWatermark(String id);
- Since
- Available since v4.6.2.
This method removes the previously added watermark image from the local video stream based on the specified unique ID.
Parameters
- id
- ID of the watermark to remove. This value must match the ID used when adding the watermark.
Return Values
- 0: The method call succeeds.
- < 0: The method call fails.
renewToken
Updates the token.
Future<void> renewToken(String token);
This method is used to update the token. The token expires after a certain period, at which point the SDK cannot establish a connection with the server.
Timing
- When you receive the onTokenPrivilegeWillExpire callback indicating the token is about to expire;
- When you receive the onRequestToken callback indicating the token has expired;
- When you receive the onConnectionStateChanged callback reporting
connectionChangedTokenExpired(9);
Parameters
- token
- The newly generated token.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
resumeAllChannelMediaRelay
Resumes media stream relay to all destination channels.
Future<void> resumeAllChannelMediaRelay();
After calling the pauseAllChannelMediaRelay method, if you need to resume media stream relay to all destination channels, you can call this method.
Return Values
- < 0: Method call failed. See Error Codes for details and resolution suggestions.
- -5: This method call was rejected. There is no paused cross-channel media stream relay.
resumeAllEffects
Resumes playback of all audio effect files.
Future<void> resumeAllEffects();
After you call pauseAllEffects to pause all audio effects, you can call this method to resume playback.
Timing
This method must be called after pauseAllEffects.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
resumeAudioMixing
Resumes the playback of the music file.
Future<void> resumeAudioMixing();
After you call pauseAudioMixing to pause the music file, call this method to resume playback.
Timing
You must call this method after joining a channel.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
resumeEffect
Resumes playback of the specified audio effect file.
Future<void> resumeEffect(int soundId);
Parameters
- soundId
- The ID of the audio effect. Each audio effect has a unique ID.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
selectAudioTrack
Specifies the playback audio track of the current music file.
Future<void> selectAudioTrack(int index);
After obtaining the number of audio tracks in the music file, you can call this method to specify any track for playback. For example, if a multi-track file contains songs in different languages on different tracks, you can use this method to set the playback language of the music file.
- For supported audio file formats, see What audio formats does the RTC SDK support?.
- You must call this method after calling startAudioMixing and receiving the
onAudioMixingStateChanged(audioMixingStatePlaying)callback.
Parameters
- index
- The specified playback audio track. The value must be greater than or equal to 0 and less than the return value of getAudioTrackCount.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
sendCustomReportMessage
Sends a custom report message.
Future<void> sendCustomReportMessage(
{required String id,
required String category,
required String event,
required String label,
required int value});
Agora provides a custom data reporting and analytics service. This service is currently in a free beta period. During the beta, you can report up to 10 data entries within 6 seconds. Each custom data entry must not exceed 256 bytes, and each string must not exceed 100 bytes. To try this service, please [contact sales](mailto:support@agora.io) to enable it and agree on the custom data format.
sendMetaData
Sends media metadata.
Future<void> sendMetaData(
{required Metadata metadata, required VideoSourceType sourceType});
If the metadata is sent successfully, the receiver receives the onMetadataReceived callback.
Parameters
- metadata
- The media metadata. See Metadata.
- sourceType
- The type of video source. See VideoSourceType.
Return Values
- < 0: The method call fails. See Error Codes for details and resolution suggestions.
sendStreamMessage
Sends a data stream.
Future<void> sendStreamMessage(
{required int streamId, required Uint8List data, required int length});
- Each client in the channel can have up to 5 data channels simultaneously, with a total sending bitrate limit of 30 KB/s shared among all channels.
- Each data channel can send up to 60 packets per second, with each packet limited to 1 KB.
- This method must be called after joining the channel and after calling createDataStream to create the data channel.
- This method is only applicable to broadcaster users.
Parameters
- streamId
- The data stream ID. You can get it through createDataStream.
- data
- The data to be sent.
- length
- The length of the data.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setAINSMode
Enables or disables AI noise reduction and sets the noise reduction mode.
Future<void> setAINSMode(
{required bool enabled, required AudioAinsMode mode});
- TV noise
- Air conditioner noise
- Factory machine noise
- Thunder
- Explosions
- Cracking sounds
- This method depends on the AI noise reduction dynamic library. Deleting this library will prevent the feature from working properly. For the name of the AI noise reduction library, see Plugin List.
- Currently, it is not recommended to enable this feature on devices running Android 6.0 or lower.
Scenario
In scenarios such as voice chat, online education, and online meetings, if the surrounding environment is noisy, the AI noise reduction feature can identify and reduce both steady and non-steady noises while preserving voice quality, thereby improving audio quality and user experience.
Timing
This method can be called before or after joining a channel.
Parameters
- enabled
- Whether to enable AI noise reduction:
- true: Enable AI noise reduction.
- false: (default) Disable AI noise reduction.
- mode
- Noise reduction mode. See AudioAinsMode.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setAdvancedAudioOptions
Sets advanced audio options.
Future<void> setAdvancedAudioOptions(AdvancedAudioOptions options);
If you have advanced audio processing needs, such as collecting and sending stereo audio, you can call this method to set advanced audio options.
Parameters
- options
- Advanced audio options. See AdvancedAudioOptions.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setAudioEffectParameters
Sets the parameters for SDK preset voice effects.
Future<void> setAudioEffectParameters(
{required AudioEffectPreset preset,
required int param1,
required int param2});
- 3D voice effect: Set the surround cycle of the 3D voice effect.
- Pitch correction effect: Set the base scale and main pitch of the pitch correction effect. To allow users to adjust the pitch correction effect themselves, it is recommended to bind the base scale and main pitch configuration options to the UI elements of your app.
- Call setAudioScenario to set the audio scenario to high-quality, i.e.,
audioScenarioGameStreaming(3). - Call setAudioProfile to set the
profiletoaudioProfileMusicHighQuality(4) oraudioProfileMusicHighQualityStereo(5).
- This method can be called before and after joining a channel.
- Do not set the
profileparameter of setAudioProfile toaudioProfileSpeechStandard(1) oraudioProfileIot(6), otherwise this method will not take effect. - This method provides the best processing effect for voice. It is not recommended to use this method to process audio data that contains music.
- After calling setAudioEffectParameters, it is not recommended to call the following methods, otherwise the effect set by setAudioEffectParameters will be overridden:
- This method depends on the voice beautifier dynamic library
libagora_audio_beauty_extension.dll. Deleting this library will cause the feature to not function properly.
Parameters
- preset
- SDK preset effects. The following settings are supported:
roomAcoustics3dVoice, 3D voice effect.- Before using this enum, you need to set the
profileparameter of setAudioProfile toaudioProfileMusicStandardStereo(3) oraudioProfileMusicHighQualityStereo(5), otherwise this enum setting is invalid. - After enabling 3D voice, users need to use audio playback devices that support stereo to hear the expected effect.
- Before using this enum, you need to set the
pitchCorrection, pitch correction effect.
- param1
-
- If
presetis set toroomAcoustics3dVoice, thenparam1indicates the surround cycle of the 3D voice effect. The range is [1,60] in seconds. The default value is 10, meaning the voice surrounds 360 degrees in 10 seconds. - If
presetis set topitchCorrection, thenparam1indicates the base scale of the pitch correction effect:1: (Default) Natural major.2: Natural minor.3: Japanese scale.
- If
- param2
-
- If
presetis set toroomAcoustics3dVoice, you need to setparam2to0. - If
presetis set topitchCorrection, thenparam2indicates the main pitch of the pitch correction effect:1: A2: A#3: B4: (Default) C5: C#6: D7: D#8: E9: F10: F#11: G12: G#
- If
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setAudioEffectPreset
Sets the SDK preset voice effect.
Future<void> setAudioEffectPreset(AudioEffectPreset preset);
You can call this method to set the SDK preset voice effect for the local user who is sending the stream, without changing the gender characteristics of the original voice. After setting the effect, all users in the channel can hear it.
- Do not set the
profileparameter of setAudioProfile toaudioProfileSpeechStandard(1) oraudioProfileIot(6), otherwise this method will not take effect. - If you call setAudioEffectPreset and set an enum other than
roomAcoustics3dVoiceorpitchCorrection, do not call setAudioEffectParameters, otherwise the effect set by setAudioEffectPreset will be overridden. - After calling setAudioEffectPreset, it is not recommended to call the following methods, otherwise the effect set by setAudioEffectPreset will be overridden:
- This method depends on the voice beautifier dynamic library
libagora_audio_beauty_extension.dll. Deleting this library will cause the feature to not function properly.
Timing
- Call setAudioScenario to set the audio scenario to high-quality, i.e.,
audioScenarioGameStreaming(3). - Call setAudioProfile to set the
profiletoaudioProfileMusicHighQuality(4) oraudioProfileMusicHighQualityStereo(5).
Parameters
- preset
- Preset effect options. See AudioEffectPreset.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setAudioMixingDualMonoMode
Sets the channel mode of the current audio file.
Future<void> setAudioMixingDualMonoMode(AudioMixingDualMonoMode mode);
In stereo audio files, the left and right channels can store different audio data. Depending on your needs, you can set the channel mode to original, left channel, right channel, or mixed mode.
Scenario
- To hear only the accompaniment, set the channel mode to left.
- To hear both accompaniment and vocals, set the channel mode to mixed.
Timing
You must call this method after startAudioMixing and after receiving the onAudioMixingStateChanged(audioMixingStatePlaying) callback.
Parameters
- mode
- The channel mode. See AudioMixingDualMonoMode.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setAudioMixingPitch
Adjusts the pitch of the locally played music file.
Future<void> setAudioMixingPitch(int pitch);
When mixing local voice with a music file, call this method to adjust only the pitch of the music file.
Timing
You must call this method after startAudioMixing and after receiving the onAudioMixingStateChanged(audioMixingStatePlaying) callback.
Parameters
- pitch
- Adjusts the pitch of the locally played music file in semitone steps. The default value is 0, which means no pitch adjustment. The valid range is [-12, 12]. Each step represents a semitone difference. The greater the absolute value, the more the pitch is raised or lowered.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setAudioMixingPlaybackSpeed
Sets the playback speed of the current music file.
Future<void> setAudioMixingPlaybackSpeed(int speed);
You must call this method after startAudioMixing and after receiving the onAudioMixingStateChanged callback reporting the playback state as audioMixingStatePlaying.
Parameters
- speed
- The playback speed of the music file. The recommended range is [50, 400], where:
- 50: 0.5x speed.
- 100: Original speed.
- 400: 4x speed.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly.
setAudioMixingPosition
Sets the playback position of the music file.
Future<void> setAudioMixingPosition(int pos);
This method sets the playback position of the audio file, allowing you to play the file based on actual needs instead of playing it from start to finish.
Timing
You must call this method after startAudioMixing and after receiving the onAudioMixingStateChanged(audioMixingStatePlaying) callback.
Parameters
- pos
- Integer. The position on the progress bar, in milliseconds.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setAudioProfile
Sets the audio encoding profile and audio scenario.
Future<void> setAudioProfile(
{required AudioProfileType profile,
AudioScenarioType scenario = AudioScenarioType.audioScenarioDefault});
audioScenarioGameStreaming(3). In this scenario, the SDK switches to media volume to avoid the issue.Scenario
This method applies to various audio scenarios. You can choose as needed. For example, in scenarios that require high audio quality such as music education, it is recommended to set profile to AudioProfileMusicHighQuality (4) and scenario to AudioScenarioGameStreaming (3).
Timing
This method can be called before or after joining a channel.
Parameters
- profile
- Audio encoding profile, including sample rate, bitrate, encoding mode, and number of channels. See AudioProfileType.
- scenario
- Audio scenario. The device volume type varies under different audio scenarios. See AudioScenarioType.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setAudioScenario
Sets the audio scenario.
Future<void> setAudioScenario(AudioScenarioType scenario);
audioScenarioGameStreaming(3). In this scenario, the SDK switches to media volume to avoid the issue.Scenario
This method applies to various audio scenarios. You can choose as needed. For example, in scenarios that require high audio quality such as music education, it is recommended to set scenario to AudioScenarioGameStreaming (3).
Timing
This method can be called before or after joining a channel.
Parameters
- scenario
- Audio scenario. The device volume type varies under different audio scenarios. See AudioScenarioType.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setAudioSessionOperationRestriction
Sets the SDK's permission to operate the Audio Session.
Future<void> setAudioSessionOperationRestriction(
AudioSessionOperationRestriction restriction);
By default, both the SDK and the App have permission to operate the Audio Session. If you only want the App to operate the Audio Session, you can call this method to restrict the SDK's permission. This method can be called before or after joining a channel. Once called, the restriction takes effect when the SDK needs to modify the Audio Session.
- This method is applicable to iOS only.
- This method does not restrict the App's permission to operate the Audio Session.
Parameters
- restriction
- SDK's permission to operate the Audio Session. See AudioSessionOperationRestriction. This parameter is a bit mask, where each bit corresponds to a permission.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setBeautyEffectOptions
Sets beauty effect options.
Future<void> setBeautyEffectOptions(
{required bool enabled,
required BeautyOptions options,
MediaSourceType type = MediaSourceType.primaryCameraSource});
Enables local beauty effects and sets the beauty effect options.
- This method depends on the video enhancement dynamic library
libagora_clear_vision_extension.dll. Deleting this library will cause the feature to fail to start. - This feature requires high device performance. When calling this method, the SDK automatically checks the current device capabilities.
Timing
Call this method after enableVideo or startPreview.
Parameters
- enabled
- Whether to enable the beauty effect:
- true: Enable the beauty effect.
- false: (Default) Disable the beauty effect.
- options
- Beauty options. See BeautyOptions for details.
- type
- The media source type to which the effect is applied. See MediaSourceType.
Note: In this method, this parameter only supports the following two settings:
- When capturing local video using the camera, keep the default value
primaryCameraSource. - To use custom captured video, set this parameter to
customVideoSource.
- When capturing local video using the camera, keep the default value
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setCameraAutoExposureFaceModeEnabled
Enables or disables the auto exposure feature.
Future<void> setCameraAutoExposureFaceModeEnabled(bool enabled);
Parameters
- enabled
- Whether to enable auto exposure:
- true: Enable auto exposure.
- false: Disable auto exposure.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setCameraAutoFocusFaceModeEnabled
Sets whether to enable face auto-focus.
Future<void> setCameraAutoFocusFaceModeEnabled(bool enabled);
By default, the SDK disables face auto-focus on Android and enables it on iOS. If you want to manually set face auto-focus, call this method.
Timing
You must call this method after the SDK triggers the onLocalVideoStateChanged callback and the local video state is localVideoStreamStateCapturing (1).
Parameters
- enabled
- Whether to enable face auto-focus:
- true: Enable face auto-focus.
- false: Disable face auto-focus.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setCameraCapturerConfiguration
Sets the camera capture configuration.
Future<void> setCameraCapturerConfiguration(
CameraCapturerConfiguration config);
Timing
You must call this method before starting local camera capture, such as before calling startPreview and joinChannel.
Parameters
- config
- Camera capture configuration. See CameraCapturerConfiguration.
Note: You do not need to set the
deviceIdparameter in this method.
Return Values
- < 0: Method call failed. See Error Codes for details and resolution suggestions.
setCameraDeviceOrientation
Sets the rotation angle of the captured video.
Future<void> setCameraDeviceOrientation(
{required VideoSourceType type, required VideoOrientation orientation});
- This method is applicable to Windows only.
- You must call this method after enableVideo. The setting takes effect after the camera is successfully turned on, i.e., after the SDK triggers the onLocalVideoStateChanged callback and the local video state is
localVideoStreamStateCapturing(1). - When the video capture device does not have a gravity sensor, you can call this method to manually adjust the rotation angle of the captured video frame.
Parameters
- type
- Video source type. See VideoSourceType.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setCameraExposureFactor
Sets the exposure factor of the current camera.
Future<void> setCameraExposureFactor(double factor);
When the lighting in the shooting environment is insufficient or too bright, it affects the quality of video capture. To achieve better video effects, you can use this method to adjust the camera's exposure factor.
- This method is applicable to Android and iOS only.
- You must call this method after enableVideo. The setting takes effect after the camera is successfully turned on, i.e., after the SDK triggers the onLocalVideoStateChanged callback and the local video state is
localVideoStreamStateCapturing(1). - It is recommended to call isCameraExposureSupported before using this method to check whether the current camera supports adjusting the exposure factor.
- When you call this method, it sets the exposure factor for the currently used camera, which is the one specified in setCameraCapturerConfiguration.
Parameters
- factor
- Exposure factor of the camera. The default value is 0, which means using the camera's default exposure level. The larger the value, the higher the exposure. When the video image is overexposed, you can reduce the exposure factor; when the image is underexposed and dark details are lost, you can increase the exposure factor. If the specified exposure factor exceeds the supported range of the device, the SDK automatically adjusts it to the supported range. On Android, the range is [-20.0, 20.0]; on iOS, the range is [-8.0, 8.0].
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setCameraExposurePosition
Sets the manual exposure position.
Future<void> setCameraExposurePosition(
{required double positionXinView, required double positionYinView});
- This method is applicable to Android and iOS only.
- You must call this method after enableVideo. The setting takes effect after the camera is successfully turned on, i.e., after the SDK triggers the onLocalVideoStateChanged callback and the local video state is
localVideoStreamStateCapturing(1). - After this method is successfully called, the local client triggers the onCameraExposureAreaChanged callback.
Parameters
- positionXinView
- The horizontal coordinate of the touch point relative to the view.
- positionYinView
- The vertical coordinate of the touch point relative to the view.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setCameraFocusPositionInPreview
Sets the manual focus position and triggers focusing.
Future<void> setCameraFocusPositionInPreview(
{required double positionX, required double positionY});
- This method is applicable to Android and iOS only.
- You must call this method after enableVideo. The setting takes effect after the camera is successfully turned on, i.e., after the SDK triggers the onLocalVideoStateChanged callback and the local video state is
localVideoStreamStateCapturing(1). - After this method is successfully called, the local client triggers the onCameraFocusAreaChanged callback.
Parameters
- positionX
- The horizontal coordinate of the touch point relative to the view.
- positionY
- The vertical coordinate of the touch point relative to the view.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setCameraStabilizationMode
Sets the camera stabilization mode.
Future<void> setCameraStabilizationMode(CameraStabilizationMode mode);
Camera stabilization mode is disabled by default. You need to call this method to enable it and set the appropriate stabilization mode.
- Camera stabilization only takes effect when the video resolution is greater than 1280 × 720.
- The higher the stabilization level, the narrower the camera's field of view and the greater the camera delay. To ensure user experience, it is recommended to set the
modeparameter tocameraStabilizationModeLevel1.
Scenario
In scenarios such as mobile shooting, low-light environments, or handheld shooting, you can set the camera stabilization mode to reduce the impact of camera shake and obtain more stable and clearer images.
Timing
This method must be called after the camera is successfully started, i.e., after the SDK triggers the onLocalVideoStateChanged callback and returns the local video state as localVideoStreamStateCapturing (1).
Parameters
- mode
- Camera stabilization mode. See CameraStabilizationMode.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly.
setCameraTorchOn
Sets whether to turn on the flashlight.
Future<void> setCameraTorchOn(bool isOn);
- This method is applicable to Android and iOS only.
- You must call this method after enableVideo. The setting takes effect after the camera is successfully turned on, i.e., after the SDK triggers the onLocalVideoStateChanged callback and the local video state is
localVideoStreamStateCapturing(1).
Parameters
- isOn
- Whether to turn on the flashlight:
- true: Turn on the flashlight.
- false: (default) Turn off the flashlight.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setCameraZoomFactor
Sets the camera zoom factor.
Future<void> setCameraZoomFactor(double factor);
Some iOS devices use a composite rear camera consisting of multiple lenses, such as dual cameras (wide-angle and ultra-wide-angle) or triple cameras (wide-angle, ultra-wide-angle, and telephoto). For such composite lenses with ultra-wide-angle capability, you can call setCameraCapturerConfiguration to set cameraFocalLengthType to cameraFocalLengthDefault (0) (standard lens), and then call this method to set the camera zoom factor to a value less than 1.0 to achieve an ultra-wide-angle shooting effect.
- This method is applicable only to Android and iOS.
- You must call this method after enableVideo. The setting takes effect after the camera is successfully started, that is, when the SDK triggers the onLocalVideoStateChanged callback and returns the local video state as
localVideoStreamStateCapturing(1).
Parameters
- factor
- Camera zoom factor. For devices that do not support ultra-wide-angle, the value ranges from 1.0 to the maximum zoom factor; for devices that support ultra-wide-angle, the value ranges from 0.5 to the maximum zoom factor. You can call getCameraMaxZoomFactor to get the maximum zoom factor supported by the device.
Return Values
- Failure: return value < 0.
setChannelProfile
Sets the channel profile.
Future<void> setChannelProfile(ChannelProfileType profile);
You can call this method to set the channel profile. The SDK adopts different optimization strategies for different use cases, such as prioritizing video quality in live streaming scenarios. The default channel profile after SDK initialization is live streaming.
Timing
This method must be called before joining a channel.
Parameters
- profile
- Channel profile. See ChannelProfileType.
Return Values
- < 0: Failure. See Error Codes for details and resolution suggestions.
- -2: Invalid parameter.
- -7: SDK not initialized.
setClientRole
Sets the user role and audience latency level in live streaming.
Future<void> setClientRole(
{required ClientRoleType role, ClientRoleOptions? options});
By default, the SDK sets the user role to audience. You can call this method to set the user role to broadcaster. The user role (role) determines the user's privileges at the SDK level, such as whether they can publish streams.
audienceLatencyLevelUltraLowLatency (ultra-low latency).
If you call this method before joining a channel and set role to BROADCASTER, the local user will not receive the onClientRoleChanged callback.Timing
This method can be called either before or after joining a channel. If you call this method before joining a channel to set the user role to broadcaster and set local video properties using setupLocalVideo, the local video preview will start automatically when the user joins the channel. If you call this method after joining a channel to switch user roles, upon success, the SDK automatically calls muteLocalAudioStream and muteLocalVideoStream to update the publishing state of audio and video streams.
Parameters
- role
- User role. See ClientRoleType.
Note: Users with the audience role cannot publish audio or video streams in the channel. When publishing in live streaming, make sure the user role is switched to broadcaster.
- options
- User-specific settings, including user level. See ClientRoleOptions.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setCloudProxy
Sets the cloud proxy service.
Future<void> setCloudProxy(CloudProxyType proxyType);
When the user's network is restricted by a firewall, you need to add the IP and port provided by Agora to the firewall whitelist, then call this method to enable the cloud proxy and set the proxy type via the proxyType parameter.
After successfully connecting to the cloud proxy, the SDK triggers the onConnectionStateChanged (connectionStateConnecting, connectionChangedSettingProxyServer) callback.
To disable an already set Force UDP or Force TCP cloud proxy, call setCloudProxy(noneProxy).
To change the cloud proxy type, first call setCloudProxy(noneProxy), then call setCloudProxy with the desired proxyType value.
- It is recommended to call this method outside the channel.
- If the user is in an intranet firewall environment, the features of CDN streaming and cross-channel media relay are not available when using Force UDP cloud proxy.
- When using Force UDP cloud proxy, the startAudioMixing method cannot play online audio files via HTTP. CDN streaming and cross-channel media relay use cloud proxy over TCP.
Parameters
- proxyType
- The cloud proxy type. See CloudProxyType. This parameter is required. If you do not assign a value, the SDK will report an error.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setColorEnhanceOptions
Sets the color enhancement feature.
Future<void> setColorEnhanceOptions(
{required bool enabled,
required ColorEnhanceOptions options,
MediaSourceType type = MediaSourceType.primaryCameraSource});
The video captured by the camera may suffer from color distortion. The color enhancement feature can intelligently adjust video characteristics such as saturation and contrast to improve color richness and accuracy, making the video more vivid. You can call this method to enable color enhancement and set the enhancement effect.
- Call this method after enableVideo.
- Color enhancement requires a certain level of device performance. After enabling it, if the device overheats or encounters other issues, it is recommended to lower the enhancement level or disable the feature.
- This method depends on the video enhancement dynamic library
libagora_clear_vision_extension.dll. Deleting this library will cause the feature to fail to start.
Parameters
- enabled
- Whether to enable the color enhancement feature:
- true: Enable color enhancement.
- false: (Default) Disable color enhancement.
- options
- Color enhancement options used to configure the enhancement effect. See ColorEnhanceOptions.
- type
- The media source type to which the effect is applied. See MediaSourceType.
Note: In this method, this parameter only supports the following two settings:
- When capturing local video using the camera, keep the default value
primaryCameraSource. - To use custom captured video, set this parameter to
customVideoSource.
- When capturing local video using the camera, keep the default value
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setDefaultAudioRouteToSpeakerphone
Sets the default audio route.
Future<void> setDefaultAudioRouteToSpeakerphone(bool defaultToSpeaker);
- Voice call: Earpiece
- Voice live broadcast: Speaker
- Video call: Speaker
- Video live broadcast: Speaker
Timing
This method must be called before joining a channel. To switch the audio route after joining a channel, call setEnableSpeakerphone.
Parameters
- defaultToSpeaker
- Whether to use the speaker as the default audio route:
- true: Set the default audio route to speaker.
- false: Set the default audio route to earpiece.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setDirectCdnStreamingAudioConfiguration
Sets the audio encoding configuration when the host pushes the stream directly to the CDN.
Future<void> setDirectCdnStreamingAudioConfiguration(
AudioProfileType profile);
- Deprecated
- Deprecated since v4.6.2.
This method only takes effect for audio captured by the microphone or custom audio sources, that is, when publishMicrophoneTrack or publishCustomAudioTrack is set to true in DirectCdnStreamingMediaOptions.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setDirectCdnStreamingVideoConfiguration
Sets the video encoding properties when the host pushes streams directly to the CDN.
Future<void> setDirectCdnStreamingVideoConfiguration(
VideoEncoderConfiguration config);
- Deprecated
- Deprecated since v4.6.2.
This method only applies to video captured by the camera, screen sharing, or custom video sources. That is, it applies to video captured when publishCameraTrack or publishCustomVideoTrack is set to true in DirectCdnStreamingMediaOptions.
If the video resolution you set exceeds the range supported by your camera device, the SDK adapts based on your settings and captures, encodes, and streams using the closest resolution with the same aspect ratio as your setting. You can get the actual resolution of the pushed video stream through the onDirectCdnStreamingStats callback.
Parameters
- config
- Video encoding configuration. See VideoEncoderConfiguration.
Note: When pushing streams directly to the CDN, the SDK currently only supports setting OrientationMode to landscape mode (
orientationModeFixedLandscape) or portrait mode (orientationModeFixedPortrait).
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setDualStreamMode
Sets the dual-stream mode on the sender and configures the low-quality video stream.
Future<void> setDualStreamMode(
{required SimulcastStreamMode mode, SimulcastStreamConfig? streamConfig});
autoSimulcastStream) by default on the sender, meaning the sender does not actively send low-quality streams. Receivers with host roles can call setRemoteVideoStreamType to request low-quality streams. After receiving the request, the sender automatically starts sending low-quality streams.
- If you want to change this behavior, you can call this method and set
modetodisableSimulcastStream(never send low-quality streams) orenableSimulcastStream(always send low-quality streams). - If you want to revert to the default behavior after modification, call this method again and set
modetoautoSimulcastStream.
- Calling this method and setting
modetodisableSimulcastStreamhas the same effect as calling enableDualStreamMode withenabledset to false. - Calling this method and setting
modetoenableSimulcastStreamhas the same effect as calling enableDualStreamMode withenabledset to true. - Both methods can be called before or after joining a channel. If both are used, the settings in the later call take effect.
Parameters
- mode
- The mode for sending video streams. See SimulcastStreamMode.
- streamConfig
- The configuration of the low-quality video stream. See SimulcastStreamConfig.
Note: When
modeis set todisableSimulcastStream, settingstreamConfighas no effect.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setEarMonitoringAudioFrameParameters
Sets the data format for the onEarMonitoringAudioFrame callback.
Future<void> setEarMonitoringAudioFrameParameters(
{required int sampleRate,
required int channel,
required RawAudioFrameOpModeType mode,
required int samplesPerCall});
This method sets the data format for the onEarMonitoringAudioFrame callback.
- Before calling this method, you need to call enableInEarMonitoring and set
includeAudioFilterstoearMonitoringFilterBuiltInAudioFiltersorearMonitoringFilterNoiseSuppression. - The SDK calculates the sampling interval using the
samplesPerCall,sampleRate, andchannelparameters in this method. The formula is: sampling interval =samplesPerCall/ (sampleRate×channel). Ensure the sampling interval is no less than 0.01 seconds. The SDK triggers the onEarMonitoringAudioFrame callback based on this interval.
Parameters
- sampleRate
- Sampling rate (Hz) of the audio reported in onEarMonitoringAudioFrame, can be set to 8000, 16000, 32000, 44100, or 48000.
- channel
- Number of audio channels reported in onEarMonitoringAudioFrame, can be set to 1 or 2:
- 1: Mono.
- 2: Stereo.
- mode
- Usage mode of the audio frame. See RawAudioFrameOpModeType.
- samplesPerCall
- Number of audio samples reported in onEarMonitoringAudioFrame, typically 1024 in applications like push streaming.
Return Values
- < 0: The method call fails. See Error Codes for details and resolution suggestions.
setEffectPosition
Sets the playback position of the specified audio effect file.
Future<void> setEffectPosition({required int soundId, required int pos});
After successful setting, the local audio effect file will start playing from the specified position.
Parameters
- soundId
- The ID of the audio effect. Each audio effect has a unique ID.
- pos
- The playback position of the audio effect file, in milliseconds.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setEffectsVolume
Sets the playback volume of audio effect files.
Future<void> setEffectsVolume(int volume);
Timing
This method must be called after playEffect.
Parameters
- volume
- Playback volume. The range is [0,100]. The default value is 100, representing the original volume.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setEnableSpeakerphone
Enables or disables speakerphone playback.
Future<void> setEnableSpeakerphone(bool speakerOn);
For the SDK's default audio routes in different scenarios.
- This method only sets the audio route used by the user in the current channel and does not affect the SDK's default audio route. If the user leaves the current channel and joins a new one, the SDK's default audio route will still be used.
- If the user uses external audio playback devices such as Bluetooth or wired headsets, this method has no effect. Audio will only be played through external devices. If multiple external devices are connected, audio is played through the last connected device.
Scenario
If the SDK's default audio route or the setting of setDefaultAudioRouteToSpeakerphone does not meet your needs, you can call this method to switch the current audio route.
Timing
This method must be called after joining a channel.
Parameters
- speakerOn
- Whether to enable speakerphone playback:
- true: Enable. Audio is routed to the speaker.
- false: Disable. Audio is routed to the earpiece.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setExtensionProperty
Sets an extension property.
Future<void> setExtensionProperty(
{required String provider,
required String extension,
required String key,
required String value,
MediaSourceType type = MediaSourceType.unknownMediaSource});
After enabling the extension, you can call this method to set its properties.
Timing
Call this method after calling enableExtension to enable the extension.
Parameters
- provider
- The name of the extension provider.
- extension
- The name of the extension.
- key
- The key of the extension property.
- value
- The value corresponding to the extension property key.
- type
- The media source type of the extension. See MediaSourceType.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setExtensionProviderProperty
Sets a property for the extension provider.
Future<void> setExtensionProviderProperty(
{required String provider, required String key, required String value});
You can call this method to set the properties of the extension provider and initialize related parameters based on the provider type.
Timing
Call this method after registerExtension and before enableExtension.
Parameters
- provider
- The name of the extension provider.
- key
- The key of the extension property.
- value
- The value corresponding to the extension property key.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setExternalMediaProjection
Sets an external MediaProjection to capture screen video stream.
Future<void> setExternalMediaProjection(int mediaProjection);
After this method is successfully called, the external MediaProjection you set will replace the one applied by the SDK to capture the screen video stream.
When screen sharing is stopped or RtcEngine is destroyed, the SDK automatically releases the MediaProjection.
MediaProjection permission before calling this method.Scenario
MediaProjection yourself, you can use your own MediaProjection to replace the one obtained by the SDK. Here are two usage scenarios:
- On customized system devices, you can avoid system pop-ups (which require user permission for screen capture) and directly start screen capture.
- In a screen sharing process with one or more subprocesses, this avoids errors caused by creating objects in subprocesses that may lead to capture failure.
Timing
This method must be called before startScreenCapture.
Parameters
- mediaProjection
- A MediaProjection object used to capture screen video stream.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setExternalRemoteEglContext
Sets the EGL context for rendering remote video streams.
Future<void> setExternalRemoteEglContext(int eglContext);
By setting this method, developers can replace the SDK's default internal remote EGL context to facilitate unified EGL context management. When the engine is destroyed, the SDK automatically releases the EGL context.
Scenario
This method is applicable in scenarios where remote video rendering is done using video data in Texture format.
Timing
This method must be called before joining the channel.
Parameters
- eglContext
- The EGL context object used for rendering remote video streams.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setFaceShapeAreaOptions
Sets face shaping area options and specifies the media source.
Future<void> setFaceShapeAreaOptions(
{required FaceShapeAreaOptions options,
MediaSourceType type = MediaSourceType.primaryCameraSource});
If the preset face shaping effects set with setFaceShapeBeautyOptions do not meet expectations, you can use this method to configure face shaping area options and fine-tune individual facial areas for more refined results.
- On Android, this method is only supported on Android 4.4 and above.
- This method depends on the video enhancement dynamic library
libagora_clear_vision_extension.dll. Deleting this library will cause the feature to fail to start. - This feature requires high device performance. When calling this method, the SDK automatically checks the current device capabilities.
Timing
Call this method after setFaceShapeBeautyOptions.
Parameters
- options
- Face shaping area options. See FaceShapeAreaOptions.
- type
- The media source type to which the effect is applied. See MediaSourceType.
Note: In this method, this parameter only supports the following two settings:
- When capturing local video using the camera, keep the default value
primaryCameraSource. - To use custom captured video, set this parameter to
customVideoSource.
- When capturing local video using the camera, keep the default value
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setFaceShapeBeautyOptions
Sets face shaping effect options and specifies the media source.
Future<void> setFaceShapeBeautyOptions(
{required bool enabled,
required FaceShapeBeautyOptions options,
MediaSourceType type = MediaSourceType.primaryCameraSource});
Call this method to enhance facial features such as slimming the face, enlarging eyes, slimming the nose, etc., using preset parameters in one go. You can also adjust the overall intensity of the effect.
- On Android, this method is only supported on Android 4.4 and above.
- This method depends on the video enhancement dynamic library
libagora_clear_vision_extension.dll. Deleting this library will cause the feature to fail to start. - This feature requires high device performance. When calling this method, the SDK automatically checks the current device capabilities.
Timing
Call this method after enableVideo.
Parameters
- enabled
- Whether to enable the face shaping effect:
- true: Enable face shaping.
- false: (Default) Disable face shaping.
- options
- Face shaping style options. See FaceShapeBeautyOptions.
- type
- The media source type to which the effect is applied. See MediaSourceType.
Note: In this method, this parameter only supports the following two settings:
- When capturing local video using the camera, keep the default value
primaryCameraSource. - To use custom captured video, set this parameter to
customVideoSource.
- When capturing local video using the camera, keep the default value
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setFilterEffectOptions
Sets filter effect options and specifies the media source.
Future<void> setFilterEffectOptions(
{required bool enabled,
required FilterEffectOptions options,
MediaSourceType type = MediaSourceType.primaryCameraSource});
- This method depends on the video enhancement dynamic library
libagora_clear_vision_extension.dll. If this library is removed, the feature cannot be enabled properly. - This feature has high performance requirements. When this method is called, the SDK automatically checks the current device capabilities.
Timing
Call this method after enableVideo.
Parameters
- enabled
- Whether to enable the filter effect:
- true: Enables the filter feature.
- false: (Default) Disables the filter feature.
- options
- Filter options. See FilterEffectOptions.
- type
- The type of media source to which the effect is applied. See MediaSourceType.
Note: In this method, this parameter only supports the following two settings:
- When using the camera to capture local video, keep the default value
primaryCameraSource. - If you want to use custom captured video, set this parameter to
customVideoSource.
- When using the camera to capture local video, keep the default value
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setHeadphoneEQParameters
Sets the low-frequency and high-frequency parameters of the headphone equalizer.
Future<void> setHeadphoneEQParameters(
{required int lowGain, required int highGain});
In spatial audio scenarios, if the preset headphone equalizer effect set by calling setHeadphoneEQPreset does not meet expectations, you can call this method to further adjust the headphone equalizer effect.
Parameters
- lowGain
- Low-frequency parameter of the headphone equalizer. Value range is [-10,10]. The higher the value, the deeper the sound.
- highGain
- High-frequency parameter of the headphone equalizer. Value range is [-10,10]. The higher the value, the sharper the sound.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setHeadphoneEQPreset
Sets the preset headphone equalizer effect.
Future<void> setHeadphoneEQPreset(HeadphoneEqualizerPreset preset);
This method is mainly used in spatial audio scenarios. You can select a preset headphone equalizer to listen to audio and achieve the desired audio experience.
Parameters
- preset
- Preset headphone equalizer effect. See HeadphoneEqualizerPreset.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setInEarMonitoringVolume
Sets the in-ear monitoring volume.
Future<void> setInEarMonitoringVolume(int volume);
Timing
Can be called before or after joining a channel.
Parameters
- volume
- Volume, range is [0,400].
- 0: Mute.
- 100: (default) Original volume.
- 400: 4 times the original volume, with overflow protection.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setLocalRenderMode
Updates the local view display mode.
Future<void> setLocalRenderMode(
{required RenderModeType renderMode,
VideoMirrorModeType mirrorMode =
VideoMirrorModeType.videoMirrorModeAuto});
After initializing the local user view, you can call this method to update the rendering and mirror mode of the local user view. This method only affects the video seen by the local user and does not affect the published video.
(primaryCameraSource). In scenarios with custom video capture or other types of video sources, you need to use the setupLocalVideo method instead.Timing
- Call this method after initializing the local view using the setupLocalVideo method.
- You can call this method multiple times during a call to update the display mode of the local user view.
Parameters
- renderMode
- Local view display mode. See RenderModeType.
- mirrorMode
- Mirror mode for the local view. See VideoMirrorModeType.
Note: If you use the front camera, the local user view mirror mode is enabled by default; if you use the rear camera, the mirror mode is disabled by default.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setLocalRenderTargetFps
Sets the maximum frame rate for local video rendering.
Future<void> setLocalRenderTargetFps(
{required VideoSourceType sourceType, required int targetFps});
Scenario
In scenarios with low frame rate requirements for video rendering (e.g., screen sharing, online education), you can call this method to set the maximum frame rate for local video rendering. The SDK will try to match the actual rendering frame rate to this value to reduce CPU usage and improve system performance.
Timing
This method can be called before or after joining a channel.
Parameters
- sourceType
- Type of video source. See VideoSourceType.
- targetFps
- Maximum rendering frame rate (fps). Supported values: 1, 7, 10, 15, 24, 30, 60.
Note: You should set this parameter to a rendering frame rate lower than the actual video frame rate; otherwise, the setting will not take effect.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setLocalVideoMirrorMode
Sets the local video mirror mode.
Future<void> setLocalVideoMirrorMode(VideoMirrorModeType mirrorMode);
- Deprecated
- Deprecated: This method is deprecated.
Parameters
- mirrorMode
- Local video mirror mode. See VideoMirrorModeType.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setLocalVoiceEqualization
Sets the local voice equalization.
Future<void> setLocalVoiceEqualization(
{required AudioEqualizationBandFrequency bandFrequency,
required int bandGain});
Timing
Can be called before and after joining a channel.
Parameters
- bandFrequency
- Index of the frequency band. The range is [0,9], representing 10 frequency bands. The corresponding center frequencies are [31, 62, 125, 250, 500, 1k, 2k, 4k, 8k, 16k] Hz. See AudioEqualizationBandFrequency.
- bandGain
- Gain of each band in dB. The range for each value is [-15,15], with a default value of 0.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setLocalVoiceFormant
Sets the formant ratio to change the voice timbre.
Future<void> setLocalVoiceFormant(double formantRatio);
Formant ratio is a parameter that affects the timbre of the voice. The smaller the formant ratio, the deeper the voice; the larger the value, the sharper the voice. After setting the formant ratio, all users in the channel can hear the effect. If you want to change both timbre and pitch, Agora recommends using it together with setLocalVoicePitch.
Scenario
In scenarios like voice live streaming, voice chat rooms, and karaoke rooms, you can call this method to set the local voice's formant ratio to change the timbre.
Timing
Can be called before and after joining a channel.
Parameters
- formantRatio
- Formant ratio. The range is [-1.0, 1.0]. The default value is 0.0, meaning the original timbre is not changed.
Note: Agora recommends using values in the range [-0.4, 0.6]. Effects outside this range may not sound ideal.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setLocalVoicePitch
Sets the local voice pitch.
Future<void> setLocalVoicePitch(double pitch);
Timing
Can be called before and after joining a channel.
Parameters
- pitch
- Voice frequency. Can be set in the range [0.5, 2.0]. The smaller the value, the lower the pitch. The default value is 1.0, meaning no pitch change.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setLocalVoiceReverb
Sets the local voice reverb effect.
Future<void> setLocalVoiceReverb(
{required AudioReverbType reverbKey, required int value});
The SDK provides an easier method setAudioEffectPreset to directly apply preset reverb effects such as pop, R&B, KTV, etc.
Parameters
- reverbKey
- Reverb effect key. This method supports 5 reverb effect keys. See AudioReverbType.
- value
- The value corresponding to each reverb effect key.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setLogFile
Sets the log file.
Future<void> setLogFile(String filePath);
- Deprecated
- Deprecated: This method is deprecated. Set the log file path via the
contextparameter when calling initialize.
Sets the output log file of the SDK. All logs generated during SDK runtime will be written to this file.
Timing
You need to call this method immediately after initialize, otherwise the output logs may be incomplete.
Parameters
- filePath
- The full path of the log file. The log file is encoded in UTF-8.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setLogFileSize
Sets the size of the SDK log file output.
Future<void> setLogFileSize(int fileSizeInKBytes);
- Deprecated
- Deprecated: This method is deprecated. Use the
logConfigparameter in initialize instead to set the log file size.
- SDK log file names:
agorasdk.log,agorasdk.1.log,agorasdk.2.log,agorasdk.3.log,agorasdk.4.log. - API call log file names:
agoraapi.log,agoraapi.1.log,agoraapi.2.log,agoraapi.3.log,agoraapi.4.log. - Each SDK log file has a default size of 2,048 KB; API call log files also have a default size of 2,048 KB. All log files are UTF-8 encoded.
- The latest logs are always written to
agorasdk.logandagoraapi.log. - When
agorasdk.logis full, the SDK performs the following operations:- Deletes
agorasdk.4.log(if exists). - Renames
agorasdk.3.logtoagorasdk.4.log. - Renames
agorasdk.2.logtoagorasdk.3.log. - Renames
agorasdk.1.logtoagorasdk.2.log. - Creates a new
agorasdk.logfile.
- Deletes
- The overwrite rule for
agoraapi.logis the same as that ofagorasdk.log.
agorasdk.log file and does not affect agoraapi.log.Parameters
- fileSizeInKBytes
- The size of a single
agorasdk.logfile in KB. The valid range is [128, 20480], and the default value is 2,048 KB. If you setfileSizeInKByteto less than 128 KB, the SDK automatically adjusts it to 128 KB; if you set it to more than 20,480 KB, the SDK automatically adjusts it to 20,480 KB.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setLogFilter
Sets the log output level.
Future<void> setLogFilter(LogFilterType filter);
- Deprecated
- Deprecated: Use
logConfigin initialize instead.
This method sets the log output level of the SDK. Different output levels can be used individually or in combination. The log levels in order are logFilterOff, logFilterCritical, logFilterError, logFilterWarn, logFilterInfo, and logFilterDebug.
By selecting a level, you can see all logs at that level and above.
For example, if you choose logFilterWarn, you will see logs at logFilterCritical, logFilterError, and logFilterWarn levels.
Parameters
- filter
- Log filter level. See LogFilterType.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setLogLevel
Sets the SDK log output level.
Future<void> setLogLevel(LogLevel level);
- Deprecated
- Deprecated: This method is deprecated. Set the log output level via the
contextparameter when calling initialize.
By selecting a level, you can see the logs at that level.
Parameters
- level
- Log level. See LogLevel.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setLowlightEnhanceOptions
Sets the low-light enhancement feature.
Future<void> setLowlightEnhanceOptions(
{required bool enabled,
required LowlightEnhanceOptions options,
MediaSourceType type = MediaSourceType.primaryCameraSource});
You can call this method to enable the low-light enhancement feature and configure its effects.
- This method depends on the video enhancement dynamic library
libagora_clear_vision_extension.dll. If this library is removed, the feature cannot be enabled properly. - Low-light enhancement has certain performance requirements. After enabling it, if the device experiences severe overheating, it is recommended to lower the enhancement level to a less performance-intensive one or disable the feature.
- To achieve high-quality low-light enhancement (
lowLightEnhanceLevelHighQuality), you must first call setVideoDenoiserOptions to enable video denoising. The corresponding settings are:- For automatic mode (
LowLightEnhanceAuto), video denoising must be set to high quality (videoDenoiserLevelHighQuality) and automatic mode (videoDenoiserAuto). - For manual mode (
LowLightEnhanceManual), video denoising must be set to high quality (videoDenoiserLevelHighQuality) and manual mode (videoDenoiserManual).
- For automatic mode (
Scenario
Low-light enhancement can adaptively adjust the video brightness in low-light conditions (such as backlight, cloudy days, or dark scenes) and uneven lighting environments to restore or highlight image details and improve the overall visual quality.
Timing
Call this method after enableVideo.
Parameters
- enabled
- Whether to enable the low-light enhancement feature:
- true: Enables low-light enhancement.
- false: (Default) Disables low-light enhancement.
- options
- Low-light enhancement options for configuring the effect. See LowlightEnhanceOptions.
- type
- The type of media source to which the effect is applied. See MediaSourceType.
Note: In this method, this parameter only supports the following two settings:
- When using the camera to capture local video, keep the default value
primaryCameraSource. - If you want to use custom captured video, set this parameter to
customVideoSource.
- When using the camera to capture local video, keep the default value
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setMaxMetadataSize
Sets the maximum size of media metadata.
Future<void> setMaxMetadataSize(int size);
After calling registerMediaMetadataObserver, you can call this method to set the maximum size of media metadata.
Parameters
- size
- The maximum size of media metadata.
Return Values
- < 0: Failure. See Error Codes for details and resolution suggestions.
setMixedAudioFrameParameters
Sets the format of the raw audio data after audio mixing for capture and playback.
Future<void> setMixedAudioFrameParameters(
{required int sampleRate,
required int channel,
required int samplesPerCall});
The SDK calculates the sampling interval using the samplesPerCall, sampleRate, and channel parameters in this method. The formula is: sampling interval = samplesPerCall / (sampleRate × channel). Ensure the sampling interval is no less than 0.01 seconds. The SDK triggers the onMixedAudioFrame callback based on this interval.
Timing
You must call this method before joining a channel.
Parameters
- sampleRate
- The sample rate (Hz) of the audio data. You can set it to 8000, 16000, 32000, 44100, or 48000.
- channel
- The number of audio channels. You can set it to 1 or 2:
- 1: Mono.
- 2: Stereo.
- samplesPerCall
- The number of audio samples per call. Typically 1024 in scenarios like RTMP streaming.
Return Values
This method returns no value if the call succeeds. If the method call fails, it throws an AgoraRtcException, which you need to catch and handle. See Error Codes for details and troubleshooting suggestions.
setParameters
JSON configuration information for the SDK, used to provide technical preview or customized features.
Future<void> setParameters(String parameters);
Parameters
- parameters
- Parameters in JSON string format.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setPlaybackAudioFrameBeforeMixingParameters
Sets the format of the raw audio playback data before mixing.
Future<void> setPlaybackAudioFrameBeforeMixingParameters(
{required int sampleRate, required int channel
{required int sampleRate, required int samplesPerCall});
The SDK triggers the onPlaybackAudioFrameBeforeMixing callback based on the sampling interval.
Timing
You must call this method before joining a channel.
Parameters
- sampleRate
- The sample rate (Hz) of the audio data. You can set it to 8000, 16000, 32000, 44100, or 48000.
- channel
- The number of audio channels. You can set it to 1 or 2:
- 1: Mono.
- 2: Stereo.
- samplesPerCall
- Sets the number of audio samples returned in the onPlaybackAudioFrameBeforeMixing callback. In RTMP streaming scenarios, it is recommended to set this to 1024.
Return Values
This method returns no value if the call succeeds. If the method call fails, it throws an AgoraRtcException, which you need to catch and handle. See Error Codes for details and troubleshooting suggestions.
setPlaybackAudioFrameParameters
Sets the format of the raw audio data for playback.
Future<void> setPlaybackAudioFrameParameters(
{required int sampleRate,
required int channel,
required RawAudioFrameOpModeType mode,
required int samplesPerCall});
The SDK calculates the sampling interval using the samplesPerCall, sampleRate, and channel parameters in this method. The formula is: sampling interval = samplesPerCall / (sampleRate × channel). Ensure the sampling interval is no less than 0.01 seconds. The SDK triggers the onPlaybackAudioFrame callback based on this interval.
Timing
You must call this method before joining a channel.
Parameters
- sampleRate
- The sample rate (Hz) of the audio data. You can set it to 8000, 16000, 24000, 32000, 44100, or 48000.
- channel
- The number of audio channels. You can set it to 1 or 2:
- 1: Mono.
- 2: Stereo.
- mode
- The usage mode of the audio frame. See RawAudioFrameOpModeType.
- samplesPerCall
- The number of audio samples per call. Typically 1024 in scenarios like RTMP streaming.
Return Values
- < 0: Failure. See Error Codes for details and troubleshooting suggestions.
setRecordingAudioFrameParameters
Sets the format of the raw audio data for capture.
Future<void> setRecordingAudioFrameParameters(
{required int sampleRate,
required int channel,
required RawAudioFrameOpModeType mode,
required int samplesPerCall});
The SDK calculates the sampling interval using the samplesPerCall, sampleRate, and channel parameters in this method. The formula is: sampling interval = samplesPerCall / (sampleRate × channel). Ensure the sampling interval is no less than 0.01 seconds. The SDK triggers the onRecordAudioFrame callback based on this interval.
Timing
You must call this method before joining a channel.
Parameters
- sampleRate
- The sample rate (Hz) of the audio data. You can set it to 8000, 16000, 32000, 44100, or 48000.
- channel
- The number of audio channels. You can set it to 1 or 2:
- 1: Mono.
- 2: Stereo.
- mode
- The usage mode of the audio frame. See RawAudioFrameOpModeType.
- samplesPerCall
- The number of audio samples per call. Typically 1024 in scenarios like RTMP streaming.
Return Values
- < 0: Failure. See Error Codes for details and troubleshooting suggestions.
setRemoteDefaultVideoStreamType
Sets the default video stream type to subscribe to.
Future<void> setRemoteDefaultVideoStreamType(VideoStreamType streamType);
- By default, the SDK enables the small stream adaptive mode (
autoSimulcastStream) on the sender side, meaning the sender only sends the high-quality stream. Only receivers with host role can call this method to request the low-quality stream. Once the sender receives the request, it starts sending the low-quality stream. All users in the channel can then call this method to switch to low-quality stream subscription mode. - If the sender calls setDualStreamMode and sets
modetodisableSimulcastStream(never send low-quality stream), this method has no effect. - If the sender calls setDualStreamMode and sets
modetoenableSimulcastStream(always send low-quality stream), both hosts and audience can call this method to switch to low-quality stream subscription mode.
Timing
This method can only be called before joining a channel. The SDK does not support modifying the default video stream type after joining a channel.
Parameters
- streamType
- The default video stream type to subscribe to: VideoStreamType.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setRemoteRenderMode
Updates the display mode of the remote view.
Future<void> setRemoteRenderMode(
{required int uid,
required RenderModeType renderMode,
required VideoMirrorModeType mirrorMode});
After initializing the remote user view, you can call this method to update the rendering and mirror mode of the remote user view displayed locally. This method only affects the video seen by the local user.
- Call this method after initializing the remote view using the setupRemoteVideo method.
- You can call this method multiple times during a call to update the display mode of the remote user view.
Parameters
- uid
- Remote user ID.
- renderMode
- Rendering mode of the remote user view. See RenderModeType.
- mirrorMode
- Mirror mode of the remote user view. See VideoMirrorModeType.
Return Values
- < 0: Failure. See Error Codes for details and resolution suggestions.
setRemoteRenderTargetFps
Sets the maximum frame rate for remote video rendering.
Future<void> setRemoteRenderTargetFps(int targetFps);
Scenario
In scenarios where high video rendering frame rate is not required (e.g., screen sharing, online education), or when the remote user is using mid- to low-end devices, you can call this method to set the maximum frame rate for remote video rendering. The SDK will try to match the actual rendering frame rate to this value to reduce CPU usage and improve system performance.
Timing
This method can be called before or after joining a channel.
Parameters
- targetFps
- Maximum rendering frame rate (fps). Supported values: 1, 7, 10, 15, 24, 30, 60.
Note: You should set this parameter to a rendering frame rate lower than the actual video frame rate; otherwise, the setting will not take effect.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setRemoteSubscribeFallbackOption
Sets the fallback option for subscribed audio and video streams under poor network conditions.
Future<void> setRemoteSubscribeFallbackOption(StreamFallbackOptions option);
In poor network conditions, the quality of real-time audio and video communication may degrade. You can call this method and set option to streamFallbackOptionVideoStreamLow or streamFallbackOptionAudioOnly. The SDK will switch the video stream to a lower stream or disable the video stream when the downlink network is poor and audio/video quality is severely affected, to ensure audio quality. The SDK continuously monitors network quality and resumes the audio and video stream subscription when the network improves.
When the subscription falls back to audio only or recovers to audio and video, the SDK triggers the onRemoteSubscribeFallbackToAudioOnly callback.
Parameters
- option
- Fallback option for the subscribed stream. See StreamFallbackOptions.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setRemoteUserSpatialAudioParams
Sets the spatial audio parameters for a remote user.
Future<void> setRemoteUserSpatialAudioParams(
{required int uid, required SpatialAudioParams params});
This method must be called after enableSpatialAudio. After successfully setting the spatial audio parameters for the remote user, the local user will perceive spatial sound from the remote user.
Parameters
- uid
- User ID. Must match the user ID used when joining the channel.
- params
- Spatial audio parameters. See SpatialAudioParams.
Return Values
When the method call succeeds, there is no return value; when it fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setRemoteVideoStreamType
Sets the video stream type to subscribe to.
Future<void> setRemoteVideoStreamType(
{required int uid, required VideoStreamType streamType});
- By default, the SDK enables the small stream adaptive mode (
autoSimulcastStream) on the sender side, meaning the sender only sends the high-quality stream. Only receivers with host role can call this method to request the low-quality stream. Once the sender receives the request, it starts sending the low-quality stream. All users in the channel can then call this method to switch to low-quality stream subscription mode. - If the sender calls setDualStreamMode and sets
modetodisableSimulcastStream(never send low-quality stream), this method has no effect. - If the sender calls setDualStreamMode and sets
modetoenableSimulcastStream(always send low-quality stream), both hosts and audience can call this method to switch to low-quality stream subscription mode.
- This method can be called before or after joining a channel.
- If you call both this method and setRemoteDefaultVideoStreamType, the SDK uses the settings in this method.
Parameters
- uid
- User ID.
- streamType
- Video stream type: VideoStreamType.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setRemoteVideoSubscriptionOptions
Sets the subscription options for the remote video stream.
Future<void> setRemoteVideoSubscriptionOptions(
{required int uid, required VideoSubscriptionOptions options});
- If VideoFrameObserver is registered, the SDK subscribes to both raw and encoded data by default.
- If VideoEncodedFrameObserver is registered, the SDK subscribes to encoded data only by default.
- If both observers are registered, the SDK follows the most recently registered one. For example, if VideoFrameObserver is registered later, the SDK subscribes to both raw and encoded data by default.
uids, you can call this method.Parameters
- uid
- Remote user ID.
- options
- Video stream subscription settings. See VideoSubscriptionOptions.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setRemoteVoicePosition
Sets the 2D position of a remote user's voice on the horizontal plane.
Future<void> setRemoteVoicePosition(
{required int uid, required double pan, required double gain});
Sets the 2D position and volume of a remote user's voice to help the local user determine the direction of the sound. By calling this API to set the position of the remote user's voice, the difference between the left and right audio channels creates a sense of direction, allowing you to determine the real-time position of the remote user. In multiplayer online games, such as battle royale games, this method can effectively enhance the spatial awareness of game characters and simulate real-world scenarios.
- You must call enableSoundPositionIndication to enable remote voice stereo before joining the channel.
- For the best audio experience, it is recommended to use wired headphones when using this method.
- This method must be called after joining the channel.
Parameters
- uid
- The ID of the remote user.
- pan
- Sets the 2D position of the remote user's voice. The range is [-1.0, 1.0]:
- (Default) 0.0: Voice appears in front.
- -1.0: Voice appears on the left.
- 1.0: Voice appears on the right.
- gain
- Sets the volume of the remote user's voice. The range is [0.0, 100.0], with a default value of 100.0, representing the original volume of the user. The smaller the value, the lower the volume.
Return Values
When the method call succeeds, there is no return value; when it fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setRouteInCommunicationMode
Selects the audio route in communication volume mode.
Future<void> setRouteInCommunicationMode(int route);
This method is used in communication volume mode (MODE_IN_COMMUNICATION) to switch the audio route from a Bluetooth headset to the earpiece, wired headset, or speaker.
Timing
Can be called before or after joining a channel.
Parameters
- route
- The desired audio route:
- -1: System default audio route.
- 0: Headset with microphone.
- 1: Earpiece.
- 2: Headset without microphone.
- 3: Built-in speaker.
- 4: (Not supported) External speaker.
- 5: Bluetooth headset.
- 6: USB device.
Return Values
No practical meaning.
setScreenCaptureContentHint
Sets the content type for screen sharing.
Future<void> setScreenCaptureContentHint(VideoContentHint contentHint);
The SDK uses different algorithms to optimize the sharing effect based on the content type. If you do not call this method, the SDK defaults the screen sharing content type to contentHintNone, meaning no specific content type is set.
Parameters
- contentHint
- The content type of the screen sharing. See VideoContentHint.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setScreenCaptureScenario
Sets the screen sharing scenario.
Future<void> setScreenCaptureScenario(ScreenScenarioType screenScenario);
When starting screen or window sharing, you can call this method to set the screen sharing scenario. The SDK adjusts the quality of the shared screen based on the scenario you set.
Parameters
- screenScenario
- The screen sharing scenario. See ScreenScenarioType.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setSubscribeAudioAllowlist
Sets the audio subscription allowlist.
Future<void> setSubscribeAudioAllowlist(
{required List<int> uidList, required int uidNumber});
You can call this method to specify the audio streams you want to subscribe to.
- This method can be called before or after joining a channel.
- The audio subscription allowlist is not affected by muteRemoteAudioStream, muteAllRemoteAudioStreams, or
autoSubscribeAudioin ChannelMediaOptions. - After setting the allowlist, if you leave and rejoin the channel, the allowlist remains effective.
- If a user appears in both the audio subscription allowlist and blocklist, only the blocklist takes effect.
Parameters
- uidList
- The list of user IDs in the audio subscription allowlist.
If you want to subscribe to a specific user's audio stream, add that user's ID to this list. If you want to remove a user from the allowlist, call the setSubscribeAudioAllowlist method again and update the list of user IDs so that it no longer contains the
uidof the user you want to remove. - uidNumber
- The number of users in the allowlist.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setSubscribeAudioBlocklist
Sets the audio subscription blocklist.
Future<void> setSubscribeAudioBlocklist(
{required List<int> uidList, required int uidNumber});
You can call this method to specify the audio streams you do not want to subscribe to.
- This method can be called before or after joining a channel.
- The audio subscription blocklist is not affected by muteRemoteAudioStream, muteAllRemoteAudioStreams, or
autoSubscribeAudioin ChannelMediaOptions. - After setting the blocklist, if you leave and rejoin the channel, the blocklist remains effective.
- If a user appears in both the audio subscription allowlist and blocklist, only the blocklist takes effect.
Parameters
- uidList
- The list of user IDs in the audio subscription blocklist.
If you want to exclude a specific user's audio stream from being subscribed to, add that user's ID to this list. If you want to remove a user from the blocklist, call the setSubscribeAudioBlocklist method again and update the list of user IDs so that it no longer contains the
uidof the user you want to remove. - uidNumber
- The number of users in the blocklist.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setSubscribeVideoAllowlist
Sets the video subscription allowlist.
Future<void> setSubscribeVideoAllowlist(
{required List<int> uidList, required int uidNumber});
You can call this method to specify the video streams you want to subscribe to.
- This method can be called before or after joining a channel.
- The video subscription allowlist is not affected by muteRemoteVideoStream, muteAllRemoteVideoStreams, or
autoSubscribeVideoin ChannelMediaOptions. - After setting the allowlist, if you leave and rejoin the channel, the allowlist remains effective.
- If a user appears in both the audio subscription allowlist and blocklist, only the blocklist takes effect.
Parameters
- uidList
- The list of user IDs in the video subscription allowlist.
If you want to subscribe only to a specific user's video stream, add that user's ID to this list. If you want to remove a user from the allowlist, call the setSubscribeVideoAllowlist method again and update the list of user IDs so that it no longer contains the
uidof the user you want to remove. - uidNumber
- The number of users in the allowlist.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setSubscribeVideoBlocklist
Sets the video subscription blocklist.
Future<void> setSubscribeVideoBlocklist(
{required List<int> uidList, required int uidNumber});
You can call this method to specify the video streams you do not want to subscribe to.
- You can call this method either before or after joining a channel.
- The video subscription blocklist is not affected by muteRemoteVideoStream, muteAllRemoteVideoStreams, or the
autoSubscribeVideosetting in ChannelMediaOptions. - After setting the blocklist, it remains effective even if you leave and rejoin the channel.
- If a user is in both the audio subscription blocklist and allowlist, only the blocklist takes effect.
Parameters
- uidList
- The user ID list of the video subscription blocklist.
If you want to unsubscribe from the video stream of a specific publishing user, add that user's ID to this list. If you want to remove a user from the blocklist, you need to call the setSubscribeVideoBlocklist method again to update the user ID list of the subscription blocklist so that it no longer contains the
uidof the user you want to remove. - uidNumber
- The number of users in the blocklist.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setVideoDenoiserOptions
Sets the video denoising feature.
Future<void> setVideoDenoiserOptions(
{required bool enabled,
required VideoDenoiserOptions options,
MediaSourceType type = MediaSourceType.primaryCameraSource});
You can call this method to enable the video denoising feature and configure its effects.
lighteningContrastLevel: lighteningContrastNormallighteningLevel: 0.0smoothnessLevel: 0.5rednessLevel: 0.0sharpnessLevel: 0.1- This method depends on the video enhancement dynamic library
libagora_clear_vision_extension.dll. If this library is removed, the feature cannot be enabled properly. - Video denoising has certain performance requirements. After enabling it, if the device experiences severe overheating, it is recommended to lower the denoising level to a less performance-intensive one or disable the feature.
Scenario
Poor lighting and low-end video capture devices can cause noticeable noise in video images, affecting video quality. In real-time interactive scenarios, video noise can also consume bitrate resources during encoding and reduce encoding efficiency.
Timing
Call this method after enableVideo.
Parameters
- enabled
- Whether to enable the video denoising feature:
- true: Enables video denoising.
- false: (Default) Disables video denoising.
- options
- Video denoising options for configuring the effect. See VideoDenoiserOptions.
- type
- The type of media source to which the effect is applied. See MediaSourceType.
Note: In this method, this parameter only supports the following two settings:
- When using the camera to capture local video, keep the default value
primaryCameraSource. - If you want to use custom captured video, set this parameter to
customVideoSource.
- When using the camera to capture local video, keep the default value
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setVideoEncoderConfiguration
Sets the video encoding attributes.
Future<void> setVideoEncoderConfiguration(VideoEncoderConfiguration config);
Sets the encoding attributes for the local video. Each video encoding profile corresponds to a set of video parameters, including resolution, frame rate, and bitrate.
- The
configparameter of this method defines the maximum values achievable under ideal network conditions. If the network condition is poor, the video engine will not use thisconfigto render the local video and will automatically downgrade to a more appropriate video configuration.
Timing
This method can be called before or after joining a channel. If you do not need to reset the video encoding configuration after joining the channel, it is recommended to call this method before enableVideo to speed up the time to render the first frame.
Parameters
- config
- Video encoding configuration. See VideoEncoderConfiguration.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setVideoScenario
Sets the video application scenario.
Future<void> setVideoScenario(VideoApplicationScenarioType scenarioType);
After successfully calling this method to set the video application scenario, the SDK enables best practice strategies based on the specified scenario, automatically adjusting key performance indicators to optimize video experience quality.
Parameters
- scenarioType
- Video application scenario. See VideoApplicationScenarioType.
applicationScenarioMeeting(1) is for meeting scenarios. If you have called setDualStreamMode to set the low stream to always off (disableSimulcastStream), the dynamic switching of the low stream does not take effect in meeting scenarios. This enum value applies only to broadcaster vs. broadcaster scenarios. The SDK enables the following strategies for this scenario:- For meeting scenarios that require higher bitrate for the low stream, multiple anti-weak network technologies are automatically enabled to enhance the low stream's resistance to poor networks and ensure smoothness when multiple streams are subscribed.
- Real-time monitoring of the number of subscribers to the high stream on the receiving end, and dynamically adjusting the high stream configuration accordingly:
- When no one subscribes to the high stream, the bitrate and frame rate of the high stream are automatically reduced to save uplink bandwidth and consumption.
- When someone subscribes to the high stream, the high stream is reset to the VideoEncoderConfiguration set in the most recent call to setVideoEncoderConfiguration. If no configuration was previously set, the following values are used:
- Video resolution: 1280 × 720 for desktop; 960 × 540 for mobile
- Frame rate: 15 fps
- Bitrate: 1600 Kbps for desktop; 1000 Kbps for mobile
- Real-time monitoring of the number of subscribers to the low stream on the receiving end, and dynamically enabling or disabling the low stream:
- When no one subscribes to the low stream, the low stream is automatically disabled to save uplink bandwidth and consumption.
- When someone subscribes to the low stream, it is enabled and reset to the SimulcastStreamConfig set in the most recent call to setDualStreamMode. If no configuration was previously set, the following values are used:
- Video resolution: 480 × 272
- Frame rate: 15 fps
- Bitrate: 500 Kbps
applicationScenario1v1(2) is for 1v1 video call scenarios. The SDK optimizes strategies for low latency and high-quality experience in this scenario, improving performance such as image quality, first frame rendering time, latency on mid- to low-end devices, and smoothness under poor network conditions.applicationScenarioLiveshow(3) is for showroom live streaming scenarios. The SDK optimizes strategies for fast first frame rendering and high image clarity, such as enabling audio/video frame accelerated rendering by default to improve first frame experience (no need to call enableInstantMediaRendering separately), and enabling B-frames by default to ensure high image quality and transmission efficiency. It also enhances image quality and smoothness under poor network and low-end device conditions.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setVoiceBeautifierParameters
Sets the parameters for the preset voice beautifier effect.
Future<void> setVoiceBeautifierParameters(
{required VoiceBeautifierPreset preset,
required int param1,
required int param2});
- Call setAudioScenario to set the audio scenario to high-quality, i.e.,
audioScenarioGameStreaming(3). - Call setAudioProfile to set the
profiletoaudioProfileMusicHighQuality(4) oraudioProfileMusicHighQualityStereo(5).
- This method can be called before or after joining a channel.
- Do not set the
profileparameter of setAudioProfile toaudioProfileSpeechStandard(1) oraudioProfileIot(6), otherwise this method will not take effect. - This method provides optimal processing for vocals and is not recommended for audio data containing music.
- After calling setVoiceBeautifierParameters, do not call the following methods, or the effect set by setVoiceBeautifierParameters will be overridden:
- This method depends on the voice beautifier dynamic library
libagora_audio_beauty_extension.dll. If this library is deleted, the feature will not work properly.
Parameters
- preset
- The preset audio effect:
SINGING_BEAUTIFIER: Singing beautifier.
- param1
- Gender characteristics of the singing voice:
1: Male voice.2: Female voice.
- param2
- Reverb effect of the singing voice:
1: Reverb effect in a small room.2: Reverb effect in a large room.3: Reverb effect in a hall.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setVoiceBeautifierPreset
Sets the preset voice beautifier effect.
Future<void> setVoiceBeautifierPreset(VoiceBeautifierPreset preset);
Call this method to set a preset voice beautifier effect for the local user who is sending the stream. After setting the beautifier effect, all users in the channel can hear it. You can set different beautifier effects for users depending on the scenario.
- Do not set the
profileparameter of setAudioProfile toaudioProfileSpeechStandard(1) oraudioProfileIot(6), otherwise this method will not take effect. - This method provides optimal processing for vocals and is not recommended for audio data containing music.
- After calling setVoiceBeautifierPreset, do not call the following methods, or the effect set by setVoiceBeautifierPreset will be overridden:
- This method depends on the voice beautifier dynamic library
libagora_audio_beauty_extension.dll. If this library is deleted, the feature will not work properly.
Timing
- Call setAudioScenario to set the audio scenario to high-quality, i.e.,
audioScenarioGameStreaming(3). - Call setAudioProfile to set the
profiletoaudioProfileMusicHighQuality(4) oraudioProfileMusicHighQualityStereo(5).
Parameters
- preset
- The preset voice beautifier option. See VoiceBeautifierPreset.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setVoiceConversionPreset
Sets the preset voice conversion effect.
Future<void> setVoiceConversionPreset(VoiceConversionPreset preset);
Call this method to set a preset voice conversion effect provided by the SDK for the local user who is sending the stream. After setting the effect, all users in the channel can hear it. You can set different voice conversion effects for users depending on the scenario.
- Do not set the
profileparameter of setAudioProfile toaudioProfileSpeechStandard(1) oraudioProfileIot(6), otherwise this method will not take effect. - This method provides optimal processing for vocals and is not recommended for audio data containing music.
- After calling setVoiceConversionPreset, do not call the following methods, or the effect set by setVoiceConversionPreset will be overridden:
- This method depends on the voice beautifier dynamic library
libagora_audio_beauty_extension.dll. If this library is deleted, the feature will not work properly.
Timing
- Call setAudioScenario to set the audio scenario to high-quality, i.e.,
audioScenarioGameStreaming(3). - Call setAudioProfile to set the
profiletoaudioProfileMusicHighQuality(4) oraudioProfileMusicHighQualityStereo(5).
Parameters
- preset
- The preset voice conversion option: VoiceConversionPreset.
Return Values
- < 0: Failure. See Error Codes for details and resolution suggestions.
setVolumeOfEffect
Sets the playback volume of the specified audio effect file.
Future<void> setVolumeOfEffect({required int soundId, required int volume});
Timing
This method must be called after playEffect.
Parameters
- soundId
- The ID of the specified audio effect. Each audio effect has a unique ID.
- volume
- Playback volume. The range is [0,100]. The default value is 100, representing the original volume.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
setupLocalVideo
Initializes the local view.
Future<void> setupLocalVideo(VideoCanvas canvas);
This method initializes the local view and sets the display properties of the local user's video. It only affects the video seen by the local user and does not affect the publishing of the local video. Call this method to bind the display window (view) of the local video stream and set the rendering and mirror mode of the local user view.
The binding remains effective after leaving the channel. To stop rendering or unbind, you can call this method and set the view parameter to NULL to stop rendering and clear the rendering cache.
- In Flutter, you do not need to call this method manually. Use AgoraVideoView to render local and remote views.
- If you only want to update the rendering or mirror mode of the local user view during a call, use the setLocalRenderMode method.
Scenario
In app development, this method is typically called after initialization to configure local video, and then join the channel.
If you want to display multiple preview views in the local video preview, each showing different observation points in the video pipeline, you can call this method multiple times with different view values and set different observation positions for each. For example, set the video source to camera and assign two view values with position set to PositionPostCapturerOrigin and PositionPostCapturer respectively, to simultaneously preview the raw video and the processed video (beauty effects, virtual background, watermark) locally.
Timing
This method can be called before or after joining the channel.
Parameters
- canvas
- Display properties of the local video. See VideoCanvas.
Return Values
- < 0: Failure. See Error Codes for details and resolution suggestions.
setupRemoteVideo
Initializes the remote user view.
Future<void> setupRemoteVideo(VideoCanvas canvas);
This method binds a remote user to a display view and sets the rendering and mirror mode of the remote user view displayed locally. It only affects the video seen by the local user.
You need to specify the remote user's ID when calling this method. Typically, you can set this before joining the channel. If the remote user ID is not available before joining, call this method upon receiving the onUserJoined callback.
To unbind a view from a remote user, call this method and set view to null.
After leaving the channel, the SDK clears the binding of the remote user view.
In mobile custom composite layout scenarios, you can call this method to set a separate view for each sub-video stream of the composite video stream for rendering.
- In Flutter, you do not need to call this method manually. Use AgoraVideoView to render local and remote views.
- If you want to update the rendering or mirror mode of the remote user view during a call, use the setRemoteRenderMode method.
- When using the recording service, since it does not send video streams, the app does not need to bind a view for it. If the app cannot identify the recording service, bind the remote user view upon receiving the onFirstRemoteVideoDecoded callback.
Parameters
- canvas
- Display properties of the remote video. See VideoCanvas.
Return Values
- < 0: Failure. See Error Codes for details and resolution suggestions.
startAudioMixing
Starts playing a music file.
Future<void> startAudioMixing(
{required String filePath,
required bool loopback,
required int cycle,
int startPos = 0});
See Supported audio file formats for the audio formats supported by this method. If the local music file does not exist, the file format is not supported, or the online music file URL cannot be accessed, the SDK reports audioMixingReasonCanNotOpen.
- Using this method to play short sound effects may cause playback failure. To play sound effects, use playEffect instead.
- If you need to call this method multiple times, make sure the interval between calls is more than 500 ms.
- When calling this method on Android, note the following:
- Make sure to use a device with Android 4.2 or above and API level no lower than 16.
- If playing online music files, avoid using redirect URLs. Redirect URLs may not work on some devices.
- If calling this method on an emulator, make sure the music file is under the
/sdcard/directory and in MP3 format.
Timing
This method can be called before or after joining a channel.
Parameters
- filePath
- File path:
- Android: File path, must include the file name and extension. Supports URL of online files, URI of local files, absolute paths, or paths starting with
/assets/. Accessing local files via absolute path may cause permission issues. It is recommended to use URI. For example:content://com.android.providers.media.documents/document/audio%3A14441. - Windows: Absolute path or URL to the audio file, must include the file name and extension. For example:
C:\music\audio.mp4. - iOS or macOS: Absolute path or URL to the audio file, must include the file name and extension. For example:
/var/mobile/Containers/Data/audio.mp4.
- Android: File path, must include the file name and extension. Supports URL of online files, URI of local files, absolute paths, or paths starting with
- loopback
- Whether to play the music file locally only:
- true: Play the music file locally only. Only the local user can hear the music.
- false: Publish the locally played music file to remote users. Both local and remote users can hear the music.
- cycle
- Number of times to play the music file.
- > 0: Number of times to play. For example, 1 means play once.
- -1: Play in an infinite loop.
- startPos
- The playback position of the music file, in milliseconds.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
startCameraCapture
Starts video capture using the camera.
Future<void> startCameraCapture(
{required VideoSourceType sourceType,
required CameraCapturerConfiguration config});
Call this method to start multiple camera captures simultaneously by specifying sourceType.
enabled to true before calling this method.Parameters
- sourceType
- Type of video source. See VideoSourceType.
Note:
- iOS devices support up to 2 video streams from camera capture (requires multi-camera or external camera support).
- Android devices support up to 4 video streams from camera capture (requires multi-camera or external camera support).
- Desktop supports up to 4 video streams from camera capture.
- config
- Video capture configuration. See CameraCapturerConfiguration.
Note: On iOS, this parameter has no effect. Use the
configparameter in enableMultiCamera to configure video capture settings.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
startDirectCdnStreaming
Starts pushing streams directly from the host to the CDN.
Future<void> startDirectCdnStreaming(
{required DirectCdnStreamingEventHandler eventHandler,
required String publishUrl,
required DirectCdnStreamingMediaOptions options});
- Deprecated
- Deprecated since v4.6.2.
publishCameraTrack and publishCustomVideoTrack being true at the same time, nor does it support publishMicrophoneTrack and publishCustomAudioTrack being true at the same time. You can set the media options (DirectCdnStreamingMediaOptions) based on your scenario. For example:
If you want to push custom audio and video streams from the host:
- Set
publishCustomAudioTrackto true and call pushAudioFrame - Set
publishCustomVideoTrackto true and call pushVideoFrame - Ensure
publishCameraTrackis false (default) - Ensure
publishMicrophoneTrackis false (default)
publishCustomAudioTrack or publishMicrophoneTrack to true in DirectCdnStreamingMediaOptions, and call pushAudioFrame to push audio-only streams.Parameters
- eventHandler
- See onDirectCdnStreamingStateChanged and onDirectCdnStreamingStats.
- publishUrl
- CDN streaming URL.
- options
- Media options for the host. See DirectCdnStreamingMediaOptions.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
startEchoTest
Starts an audio and video call loop test.
Future<void> startEchoTest(EchoTestConfiguration config);
To test whether the user's local stream sending and receiving works properly, you can call this method to perform an audio and video call loop test, which checks whether the system's audio and video devices and the user's uplink and downlink networks are functioning correctly. After the test starts, the user needs to speak or face the camera. The audio or video will play back after about 2 seconds. If audio plays back correctly, it indicates that the system audio devices and the user's uplink and downlink networks are working properly; if video plays back correctly, it indicates that the system video devices and the user's uplink and downlink networks are working properly.
- When calling this method in a channel, ensure that no audio or video stream is being published.
- After calling this method, you must call stopEchoTest to end the test. Otherwise, the user cannot perform another loop test or join a channel.
- In a live broadcast scenario, only hosts can call this method.
Timing
This method can be called before or after joining a channel.
Parameters
- config
- Configuration for the audio and video call loop test. See EchoTestConfiguration.
Return Values
- 0: Success.
- < 0: Failure. See Error Codes for details and resolution suggestions.
startLastmileProbeTest
Starts the last-mile network probe test before a call.
Future<void> startLastmileProbeTest(LastmileProbeConfig config);
Starts the last-mile network probe test to report the uplink and downlink bandwidth, packet loss, jitter, and round-trip time to the user.
Timing
You must call this method before joining a channel, and do not call other methods before receiving the onLastmileQuality and onLastmileProbeResult callbacks. Otherwise, this method may fail due to frequent API calls.
Parameters
- config
- Configuration for the last-mile network probe. See LastmileProbeConfig.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
startLocalAudioMixer
Starts local audio mixing.
Future<void> startLocalAudioMixer(LocalAudioMixerConfiguration config);
- If you want to mix local captured audio, you can set
publishMixedAudioTrackin ChannelMediaOptions to true to publish the mixed audio stream to the channel. - If you want to mix remote audio streams, make sure the remote audio streams are published in the channel and subscribed.
Scenario
- Used with local video compositing, to synchronize and publish the audio streams related to the composed video.
- In live streaming, users receive audio streams from the channel, mix them locally, and forward them to another channel.
- In education, teachers can mix audio from interactions with students locally and forward the mixed stream to another channel.
Timing
This method can be called before or after joining a channel.
Parameters
- config
- Configuration for local audio mixing. See LocalAudioMixerConfiguration.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
startLocalVideoTranscoder
Starts local video mixing.
Future<void> startLocalVideoTranscoder(LocalTranscoderConfiguration config);
After calling this method, you can merge multiple video streams locally into one stream. For example: merge video streams from camera capture, screen sharing, media player, remote video, video files, images, etc., into one stream, and then publish the mixed video stream to the channel.
- Local video mixing consumes high CPU resources. Agora recommends enabling this feature on high-performance devices.
- If you need to mix locally captured video streams, the SDK supports the following combinations:
- On Windows, up to 4 camera video streams + 4 screen sharing streams can be mixed.
- On macOS, up to 4 camera video streams + 1 screen sharing stream can be mixed.
- On Android and iOS, up to 2 camera video streams (requires dual camera support or external camera support) + 1 screen sharing stream can be mixed.
- When configuring mixing, ensure that the layer index of the camera video stream capturing the portrait is higher than that of the screen sharing stream, otherwise the portrait will be covered and not appear in the final mixed video stream.
Scenario
- Call
enableVirtualBackgroundand set the custom background toBackgroundNone, i.e., separate the portrait from the background in the camera-captured video. - Call
startScreenCaptureBySourceTypeto start capturing the screen sharing video stream. - Call this method and set the portrait video source as one of the sources in the local mixing configuration to achieve picture-in-picture in the final mixed video.
Timing
- If you need to mix locally captured video streams, call this method after startCameraCapture or startScreenCaptureBySourceType.
- If you want to publish the mixed video stream to the channel, set
publishTranscodedVideoTrackto true in ChannelMediaOptions when calling joinChannel or updateChannelMediaOptions.
Parameters
- config
- The configuration for local video mixing. See LocalTranscoderConfiguration.
Note:
- The maximum resolution for each video stream involved in local mixing is 4096 × 2160. Exceeding this limit will cause mixing to fail.
- The maximum resolution of the mixed video stream is 4096 × 2160.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
startMediaRenderingTracing
Starts video frame rendering tracing.
Future<void> startMediaRenderingTracing();
After this method is successfully called, the SDK uses the time of the call as the starting point and reports information related to video frame rendering through the onVideoRenderingTracingResult callback.
- If you do not call this method, the SDK uses the time of calling joinChannel to join the channel as the starting point to begin tracing video rendering events automatically. You can call this method at an appropriate time based on your actual business scenario to customize the tracing.
- After leaving the current channel, the SDK automatically resets the starting point to the time of the next channel join.
Scenario
Agora recommends using this method together with UI elements in your app (such as buttons or sliders) to measure the time to first frame rendering from the user's perspective. For example, call this method when the user clicks the Join Channel button, and then use the onVideoRenderingTracingResult callback to obtain the duration of each stage in the video rendering process, allowing you to optimize each stage accordingly.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
startOrUpdateChannelMediaRelay
Starts or updates cross-channel media stream relay.
Future<void> startOrUpdateChannelMediaRelay(
ChannelMediaRelayConfiguration configuration);
- If the onChannelMediaRelayStateChanged callback reports
relayStateRunning(2) andrelayOk(0), it indicates that the SDK has started relaying media streams between the source and destination channels. - If the onChannelMediaRelayStateChanged callback reports
relayStateFailure(3), it indicates an exception occurred in the cross-channel media stream relay.
- Call this method after successfully joining a channel.
- In a live broadcast scenario, only users with the broadcaster role can call this method.
- The cross-channel media stream relay feature requires contacting technical support to enable.
- This feature does not support String-type UIDs.
Parameters
- configuration
- Configuration for cross-channel media stream relay. See ChannelMediaRelayConfiguration.
Return Values
- < 0: Method call failed. See Error Codes for details and resolution suggestions.
- -1: General error (not specifically classified).
- -2: Invalid parameter.
- -8: Internal state error. Possibly because the user role is not broadcaster.
startPreviewWithoutSourceType
Starts video preview.
Future<void> startPreviewWithoutSourceType();
This method starts the local video preview.
- Local preview enables mirror mode by default.
- After leaving the channel, local preview remains active. You need to call stopPreview to stop the local preview.
Timing
This method must be called after enableVideo.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
startPreview
Starts video preview and specifies the video source.
Future<void> startPreview(
{VideoSourceType sourceType = VideoSourceType.videoSourceCameraPrimary});
This method starts the local video preview and specifies the video source to appear in the preview.
- Local preview enables mirror mode by default.
- After leaving the channel, local preview remains active. You need to call stopPreview to stop the local preview.
Timing
This method must be called after enableVideo.
Parameters
- sourceType
- Type of the video source. See VideoSourceType.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
startRhythmPlayer
Starts the virtual metronome.
Future<void> startRhythmPlayer(
{required String sound1,
required String sound2,
required AgoraRhythmPlayerConfig config});
- Deprecated
- Deprecated since v4.6.2.
- After enabling the virtual metronome, the SDK starts playing the specified audio files from the beginning and controls the duration of each file based on the
beatsPerMinuteyou set in AgoraRhythmPlayerConfig. For example, ifbeatsPerMinuteis set to60, the SDK plays 1 beat per second. If the file duration exceeds the beat duration, the SDK only plays the portion that fits the beat duration. - By default, the sound of the virtual metronome is not published to remote users. If you want remote users to hear it, set
publishRhythmPlayerTrackin ChannelMediaOptions to true after calling this method.
Scenario
In music or physical education scenarios, instructors often use a metronome to help students practice with the correct rhythm. A measure consists of strong and weak beats, with the first beat of each measure being the strong beat and the rest being weak beats.
Timing
This method can be called before or after joining a channel.
Parameters
- sound1
- The absolute path or URL of the strong beat file, including the file name and extension. For example,
C:\music\audio.mp4. Supported audio formats: see Supported audio formats for RTC SDK. - sound2
- The absolute path or URL of the weak beat file, including the file name and extension. For example,
C:\music\audio.mp4. Supported audio formats: see Supported audio formats for RTC SDK. - config
- Metronome configuration. See AgoraRhythmPlayerConfig.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
startRtmpStreamWithTranscoding
Starts pushing streams with transcoding settings.
Future<void> startRtmpStreamWithTranscoding(
{required String url, required LiveTranscoding transcoding});
Agora recommends using the more comprehensive server-side streaming feature. See Implement Server-Side Streaming. You can call this method to push live audio and video streams to a specified CDN streaming URL with transcoding settings. This method can only push to one URL at a time. To push to multiple URLs, you must call this method multiple times. Each stream push represents a streaming task. The default maximum number of concurrent tasks is 200, meaning you can run up to 200 streaming tasks simultaneously under one Agora project. For higher quotas, please contact technical support. After calling this method, the SDK triggers the onRtmpStreamingStateChanged callback locally to report the streaming status.
- Call this method after joining a channel.
- Only hosts in live streaming scenarios can call this method.
- If the stream fails to start and you want to restart it, you must call stopRtmpStream before calling this method again. Otherwise, the SDK returns the same error code as the previous failure.
Parameters
- url
- The CDN streaming URL. The format must be RTMP or RTMPS. The character length must not exceed 1024 bytes. Special characters such as Chinese are not supported.
- transcoding
- The transcoding settings for the CDN stream. See LiveTranscoding.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
startRtmpStreamWithoutTranscoding
Starts pushing streams without transcoding.
Future<void> startRtmpStreamWithoutTranscoding(String url);
Agora recommends using the more comprehensive server-side streaming feature. See Implement Server-Side Streaming. You can call this method to push live audio and video streams to a specified CDN streaming URL. This method can only push to one URL at a time. To push to multiple URLs, you must call this method multiple times. After calling this method, the SDK triggers the onRtmpStreamingStateChanged callback locally to report the streaming status.
- Call this method after joining a channel.
- Only hosts in live streaming scenarios can call this method.
- If the stream fails to start and you want to restart it, you must call stopRtmpStream before calling this method again. Otherwise, the SDK returns the same error code as the previous failure.
Parameters
- url
- The CDN streaming URL. The format must be RTMP or RTMPS. The character length must not exceed 1024 bytes. Special characters such as Chinese are not supported.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
startScreenCapture
Starts screen capture.
Future<void> startScreenCapture(ScreenCaptureParameters2 captureParams);
- This method is only applicable to Android and iOS platforms.
- Screen sharing stream billing is based on the
dimensionsvalue in ScreenVideoParameters:- If not specified, billing is based on 1280 × 720.
- If specified, billing is based on the provided value.
- On iOS, screen sharing is only supported on iOS 12.0 and above.
- On iOS, if you use external audio capture instead of SDK audio capture, to prevent screen sharing from stopping when the app goes to the background, it is recommended to implement keep-alive logic.
- On iOS, this feature requires high device performance. It is recommended to use it on iPhone X or later.
- On iOS, this method depends on the screen sharing dynamic library
AgoraReplayKitExtension.xcframework. Removing this library will cause screen sharing to fail. - On Android, if the user does not grant screen capture permission to the app, the SDK reports the
onPermissionError(2)callback. - On Android 9 and above, to prevent the app from being killed when it goes to the background, add the foreground service permission
android.permission.FOREGROUND_SERVICEin/app/Manifests/AndroidManifest.xml. - Due to Android performance limitations, screen sharing is not supported on Android TV.
- Due to Android system limitations, avoid changing the screen sharing stream's video encoding resolution during sharing on Huawei devices to prevent crashes.
- Due to Android system limitations, some Xiaomi devices do not support capturing system audio during screen sharing.
- To improve the success rate of capturing system audio during screen sharing, it is recommended to call setAudioScenario and set the audio scenario to
audioScenarioGameStreamingbefore joining the channel.
Scenario
In screen sharing scenarios, you need to call this method to start capturing screen video streams. For implementation details, see Screen Sharing.
Timing
- If called before joining a channel, then call joinChannel and set
publishScreenCaptureVideoto true, screen sharing starts. - If called after joining a channel, then call updateChannelMediaOptions and set
publishScreenCaptureVideoto true, screen sharing starts.
Parameters
- captureParams
- Encoding parameter configuration for screen sharing. See ScreenCaptureParameters2.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
startScreenCaptureBySourceType
Starts screen capture and specifies the video source.
Future<void> startScreenCaptureBySourceType(
{required VideoSourceType sourceType,
required ScreenCaptureConfiguration config});
- If you use this method to start screen capture, you must call stopScreenCaptureBySourceType to stop it.
- On Windows, up to 4 screen capture video streams are supported.
- On macOS, only 1 screen capture video stream is supported.
Scenario
startScreenCaptureByDisplayId/startScreenCaptureByWindowId: Supports capturing a single screen or window, suitable for sharing a single screen.startScreenCaptureBySourceType: Supports specifying multiple video sources to capture multiple screen sharing streams, used for local compositing or multi-channel publishing scenarios.
Timing
- If called before joining a channel, then call joinChannel and set
publishScreenCaptureVideoto true, screen sharing starts. - If called after joining a channel, then call updateChannelMediaOptions and set
publishScreenCaptureVideoto true, screen sharing starts.
Parameters
- sourceType
- The type of video source. See VideoSourceType.
Note: On macOS, only
videoSourceScreen (2)is supported for this parameter. - config
- Screen capture configuration. See ScreenCaptureConfiguration.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
startScreenCaptureByDisplayId
Starts capturing the video stream of the specified screen.
Future<void> startScreenCaptureByDisplayId(
{required int displayId,
required Rectangle regionRect,
required ScreenCaptureParameters captureParams});
Captures the video stream of a screen or a specific region of the screen.
Scenario
In screen sharing scenarios, you need to call this method to start capturing screen video streams. For implementation details, see Screen Sharing.
Timing
- If you call this method before joining a channel, then call joinChannel to join the channel and set
publishScreenTrackorpublishSecondaryScreenTrackto true, screen sharing will start. - If you call this method after joining a channel, then call updateChannelMediaOptions to update the channel media options and set
publishScreenTrackorpublishSecondaryScreenTrackto true, screen sharing will start.
Parameters
- displayId
- Specifies the ID of the screen to be shared.
Note: On Windows, if you want to share two screens (primary + secondary) simultaneously, you can set
displayIdto-1when calling this method. - regionRect
- (Optional) Specifies the position of the region to be shared relative to the entire screen. To share the entire screen, set to
nil. See Rectangle. - captureParams
- Configuration parameters for screen sharing. The default video encoding resolution is 1920 × 1080, i.e., 2,073,600 pixels. This pixel count is used for billing. See ScreenCaptureParameters.
Note: The video properties of the screen sharing stream only need to be configured through this parameter and are unrelated to setVideoEncoderConfiguration.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
startScreenCaptureByScreenRect
Starts capturing the video stream of a specified screen region.
Future<void> startScreenCaptureByScreenRect(
{required Rectangle screenRect,
required Rectangle regionRect,
required ScreenCaptureParameters captureParams});
- Deprecated
- Deprecated: This method is deprecated. Use startScreenCaptureByDisplayId instead. If you need to enable screen sharing with external displays, it is strongly recommended to use startScreenCaptureByDisplayId.
- If you call this method before joining a channel, then call joinChannel to join the channel and set
publishScreenTrackorpublishSecondaryScreenTrackto true, screen sharing will start. - If you call this method after joining a channel, then call updateChannelMediaOptions to update the channel media options and set
publishScreenTrackorpublishSecondaryScreenTrackto true, screen sharing will start.
Parameters
- screenRect
- Specifies the position of the screen to be shared relative to the virtual screen.
- regionRect
- Specifies the position of the region to be shared relative to the entire screen. If not set, the entire screen is shared. See Rectangle. If the specified region exceeds the screen boundary, only the content within the screen is shared. If width or height is set to 0, the entire screen is shared.
- captureParams
- Configuration parameters for screen sharing encoding. The default resolution is 1920 x 1080, i.e., 2,073,600 pixels. This pixel count is used for billing. See ScreenCaptureParameters.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
startScreenCaptureByWindowId
Starts capturing the video stream of a specified window.
Future<void> startScreenCaptureByWindowId(
{required int windowId,
required Rectangle regionRect,
required ScreenCaptureParameters captureParams});
| OS Version | Application | Compatible Version | Supported |
|---|---|---|---|
| Windows 10 | Chrome | 76.0.3809.100 | No |
| Office Word | 18.1903.1152.0 | Yes | |
| Office Excel | 18.1903.1152.0 | No | |
| Office PPT | 18.1903.1152.0 | Yes | |
| WPS Word | 11.1.0.9145 | Yes | |
| WPS Excel | 11.1.0.9145 | Yes | |
| WPS PPT | 11.1.0.9145 | Yes | |
| Built-in Media Player | All versions | Yes | |
| Windows 8 | Chrome | All versions | Yes |
| Office Word | All versions | Yes | |
| Office Excel | All versions | Yes | |
| Office PPT | All versions | Yes | |
| WPS Word | 11.1.0.9098 | Yes | |
| WPS Excel | 11.1.0.9098 | Yes | |
| WPS PPT | 11.1.0.9098 | Yes | |
| Built-in Media Player | All versions | Yes | |
| Windows 7 | Chrome | 73.0.3683.103 | No |
| Office Word | All versions | Yes | |
| Office Excel | All versions | Yes | |
| Office PPT | All versions | Yes | |
| WPS Word | 11.1.0.9098 | No | |
| WPS Excel | 11.1.0.9098 | No | |
| WPS PPT | 11.1.0.9098 | Yes | |
| Built-in Media Player | All versions | No |
captureMouseCursor(false) may not work as expected. See ScreenCaptureParameters.Scenario
In screen sharing scenarios, you need to call this method to start capturing the screen video stream. For implementation details, see Screen Sharing.
Timing
- If you call this method before joining a channel, then call joinChannel to join the channel and set
publishScreenTrackorpublishSecondaryScreenTrackto true, screen sharing will start. - If you call this method after joining a channel, then call updateChannelMediaOptions to update the channel media options and set
publishScreenTrackorpublishSecondaryScreenTrackto true, screen sharing will start.
Parameters
- windowId
- Specifies the ID of the window to be shared.
- regionRect
- (Optional) Specifies the position of the region to be shared relative to the entire screen. If not set, the entire screen is shared. See Rectangle. If the specified region exceeds the window boundary, only the content within the window is shared. If width or height is 0, the entire window is shared.
- captureParams
- Configuration parameters for screen sharing. The default resolution is 1920 x 1080, i.e., 2,073,600 pixels. This pixel count is used for billing. See ScreenCaptureParameters.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
stopAllEffects
Stops playback of all audio effect files.
Future<void> stopAllEffects();
If you no longer need to play audio effect files, you can call this method to stop playback. If you only need to pause playback, call pauseAllEffects.
Timing
This method must be called after playEffect.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
stopAudioMixing
Stops playing the music file.
Future<void> stopAudioMixing();
After calling startAudioMixing to play a music file, you can call this method to stop playback. If you only want to pause playback, call pauseAudioMixing instead.
Timing
This method must be called after joining a channel.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
stopCameraCapture
Stops video capture using the camera.
Future<void> stopCameraCapture(VideoSourceType sourceType);
After calling startCameraCapture to start one or more camera capture streams, you can call this method with sourceType to stop one or more camera video captures.
enabled to false after calling this method.
If you are using local video mixing, stopping video capture from the first camera using this method will interrupt the local video mixing.Parameters
- sourceType
- Type of video source. See VideoSourceType.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
stopChannelMediaRelay
Stops cross-channel media stream relay. Once stopped, the broadcaster leaves all destination channels.
Future<void> stopChannelMediaRelay();
After the method is successfully called, the SDK triggers the onChannelMediaRelayStateChanged callback. If it reports relayStateIdle (0) and relayOk (0), it indicates that media stream relay has been stopped.
relayErrorServerNoResponse (2) or relayErrorServerConnectionLost (8). You can call the leaveChannel method to leave the channel, and the cross-channel media stream relay will stop automatically.Return Values
- < 0: Method call failed. See Error Codes for details and resolution suggestions.
- -5: This method call was rejected. There is no ongoing cross-channel media stream relay.
stopDirectCdnStreaming
Stops pushing streams directly from the host to the CDN.
Future<void> stopDirectCdnStreaming();
- Deprecated
- Deprecated since v4.6.2.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
stopEchoTest
Stops the audio call loopback test.
Future<void> stopEchoTest();
After calling startEchoTest, you must call this method to end the test. Otherwise, the user cannot perform another audio/video loopback test or join a channel.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
stopEffect
Stops playback of the specified audio effect file.
Future<void> stopEffect(int soundId);
If you no longer need to play a specific audio effect file, you can call this method to stop playback. If you only need to pause playback, call pauseEffect.
Timing
This method must be called after playEffect.
Parameters
- soundId
- The ID of the specified audio effect file. Each audio effect file has a unique ID.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
stopLastmileProbeTest
Stops the last-mile network probe test before a call.
Future<void> stopLastmileProbeTest();
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
stopLocalAudioMixer
Stops local audio mixing.
Future<void> stopLocalAudioMixer();
After calling startLocalAudioMixer, if you want to stop local audio mixing, call this method.
Timing
This method must be called after startLocalAudioMixer.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
stopLocalVideoTranscoder
Stops local video mixing.
Future<void> stopLocalVideoTranscoder();
After calling startLocalVideoTranscoder, call this method if you want to stop local video mixing.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
stopPreview
Stops video preview.
Future<void> stopPreview(
{VideoSourceType sourceType = VideoSourceType.videoSourceCameraPrimary});
Scenario
After calling startPreview to start preview, if you want to stop the local video preview, call this method.
Timing
Call this method before joining or after leaving a channel.
Parameters
- sourceType
- Type of the video source. See VideoSourceType.
Return Values
- < 0: Failure. See Error Codes for details and resolution suggestions.
stopRhythmPlayer
Stops the virtual metronome.
Future<void> stopRhythmPlayer();
After calling startRhythmPlayer, you can call this method to stop the virtual metronome.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
stopRtmpStream
Stops the CDN stream.
Future<void> stopRtmpStream(String url);
Agora recommends using the more comprehensive server-side streaming feature. See Implement Server-Side Streaming. You can call this method to stop live streaming to a specified CDN streaming URL. This method can only stop one stream at a time. To stop multiple streams, you must call this method multiple times. After calling this method, the SDK triggers the onRtmpStreamingStateChanged callback locally to report the streaming status.
Parameters
- url
- The CDN streaming URL. The format must be RTMP or RTMPS. The character length must not exceed 1024 bytes. Special characters such as Chinese are not supported.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
stopScreenCapture
Stops screen capture.
Future<void> stopScreenCapture();
Scenario
If you call startScreenCaptureBySourceType, startScreenCaptureByWindowId, or startScreenCaptureByDisplayId to start screen capture, you need to call this method to stop it.
Timing
This method can be called before or after joining a channel.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
stopScreenCaptureBySourceType
Stops screen capture for the specified video source.
Future<void> stopScreenCaptureBySourceType(VideoSourceType sourceType);
Scenario
If you call startScreenCaptureBySourceType to start one or more screen captures, you need to call this method to stop screen capture and specify the screen via the sourceType parameter.
Timing
This method can be called before or after joining a channel.
Parameters
- sourceType
- The type of video source. See VideoSourceType.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
switchCamera
Switches between front and rear cameras.
Future<void> switchCamera();
You can call this method during app runtime to dynamically switch cameras based on the actual availability of cameras, without restarting the video stream or reconfiguring the video source.
videoSourceCamera (0) when calling startCameraCapture.Timing
You must call this method after the camera is successfully started, that is, when the SDK triggers the onLocalVideoStateChanged callback and returns the local video state as localVideoStreamStateCapturing (1).
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
takeSnapshot
Takes a snapshot of the video.
Future<void> takeSnapshot({required int uid, required String filePath});
This method takes a snapshot of the specified user's video stream, generates a JPG image, and saves it to the specified path.
- This method is asynchronous. When the call returns, the SDK has not actually captured the snapshot.
- When used for local video snapshot, it captures the video stream specified in ChannelMediaOptions.
- If the user's video has undergone preprocessing, such as watermarking or beautification, the snapshot will include these effects.
Timing
You must call this method after joining a channel.
Parameters
- uid
- User ID. Set to 0 to capture the local user's video.
- filePath
-
Note: Make sure the directory exists and is writable.The local path to save the snapshot. The path must include the file name and format, 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
- Windows:
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
takeSnapshotWithConfig
Takes a video snapshot at the specified observation point.
Future<void> takeSnapshotWithConfig(
{required int uid, required SnapshotConfig config});
This method takes a snapshot of the specified user's video stream, generates a JPG image, and saves it to the specified path.
- This method is asynchronous. When the call returns, the SDK has not actually captured the snapshot.
- When used for local video snapshot, it captures the video stream specified in ChannelMediaOptions.
Timing
You must call this method after joining a channel.
Parameters
- uid
- User ID. Set to 0 to capture the local user's video.
- config
- Snapshot configuration. See SnapshotConfig.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
unloadAllEffects
Releases all preloaded audio effect files from memory.
Future<void> unloadAllEffects();
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
unloadEffect
Releases a specific preloaded audio effect file from memory.
Future<void> unloadEffect(int soundId);
After loading the audio effect file into memory using preloadEffect, call this method to release the audio effect file.
Timing
This method can be called before or after joining a channel.
Parameters
- soundId
- The ID of the specified audio effect file. Each audio effect file has a unique ID.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
unregisterAudioEncodedFrameObserver
Unregisters the audio encoded frame observer.
void unregisterAudioEncodedFrameObserver(AudioEncodedFrameObserver observer);
Parameters
- observer
- Audio encoded frame observer. See AudioEncodedFrameObserver.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
unregisterAudioSpectrumObserver
Unregisters the audio spectrum observer.
void unregisterAudioSpectrumObserver(AudioSpectrumObserver observer);
After calling registerAudioSpectrumObserver, if you want to unregister the audio spectrum observer, call this method.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
unregisterMediaMetadataObserver
Unregisters the media metadata observer.
void unregisterMediaMetadataObserver(
{required MetadataObserver observer, required MetadataType type});
Parameters
- observer
- The metadata observer. See MetadataObserver.
- type
- The metadata type. Currently, only
videoMetadatais supported.
Return Values
- < 0: Failure. See Error Codes for details and resolution suggestions.
updateChannelMediaOptions
Updates channel media options after joining the channel.
Future<void> updateChannelMediaOptions(ChannelMediaOptions options);
Parameters
- options
- Channel media options. See ChannelMediaOptions.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
updateLocalAudioMixerConfiguration
Updates the configuration of local audio mixing.
Future<void> updateLocalAudioMixerConfiguration(
LocalAudioMixerConfiguration config);
After calling startLocalAudioMixer, if you want to update the configuration of local audio mixing, call this method.
Timing
This method must be called after startLocalAudioMixer.
Parameters
- config
- Configuration for local audio mixing. See LocalAudioMixerConfiguration.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
updateLocalTranscoderConfiguration
Updates local video mixing configuration.
Future<void> updateLocalTranscoderConfiguration(
LocalTranscoderConfiguration config);
After calling startLocalVideoTranscoder, call this method if you want to update the local video mixing configuration.
Parameters
- config
- The configuration for local video mixing. See LocalTranscoderConfiguration.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
updatePreloadChannelToken
Updates the wildcard token for the preloaded channel.
Future<void> updatePreloadChannelToken(String token);
You need to manage the lifecycle of the wildcard token yourself. When the wildcard token expires, you need to generate a new one on your server and pass it in using this method.
Scenario
In scenarios where frequent channel switching or multiple channels are needed, using a wildcard token avoids repeated token requests when switching channels, which speeds up the switching process and reduces the load on your token server.
Parameters
- token
- The new token.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
updateRtmpTranscoding
Updates the RTMP transcoding configuration.
Future<void> updateRtmpTranscoding(LiveTranscoding transcoding);
Agora recommends using the more comprehensive server-side streaming feature. See Implement Server-Side RTMP Streaming. After enabling transcoding streaming, you can dynamically update the transcoding configuration based on your scenario needs. After the transcoding configuration is updated, the SDK triggers the onTranscodingUpdated callback.
Parameters
- transcoding
- The transcoding configuration for RTMP streaming. See LiveTranscoding.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
updateScreenCapture
Updates the parameter configuration for screen capture.
Future<void> updateScreenCapture(ScreenCaptureParameters2 captureParams);
- Call this method and set
captureAudioto true. - Call updateChannelMediaOptions and set
publishScreenCaptureAudioto true to publish the screen capture audio.
- This method is applicable to Android and iOS only.
- On iOS, screen sharing is supported only on iOS 12.0 and later.
Parameters
- captureParams
- Encoding parameter configuration for screen sharing. See ScreenCaptureParameters2.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
updateScreenCaptureParameters
Updates the parameter configuration for screen capture.
Future<void> updateScreenCaptureParameters(
ScreenCaptureParameters captureParams);
- This method is applicable to Windows and macOS only.
- Call this method after screen or window sharing is enabled.
Parameters
- captureParams
- Encoding parameter configuration for screen sharing. See ScreenCaptureParameters.
Note: The video properties of the screen sharing stream should be set only through this parameter and are not related to setVideoEncoderConfiguration.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.
updateScreenCaptureRegion
Updates the region for screen capture.
Future<void> updateScreenCaptureRegion(Rectangle regionRect);
Parameters
- regionRect
- The position of the region to be shared relative to the entire screen or window. If not specified, the entire screen or window is shared. See Rectangle. If the set region exceeds the screen or window boundary, only the content within the screen or window is shared; if width or height is set to 0, the entire screen or window is shared.
Return Values
When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.