AgoraRtcEngineKit
The basic interface of the Agora SDK that implements the core functions of real-time communication.
AgoraRtcEngineKit provides the main methods that your app can call.
addPublishStreamUrl
Publishes the local stream to a specified CDN live streaming URL.
- (int)addPublishStreamUrl:(NSString* _Nonnull)url transcodingEnabled:(BOOL)transcodingEnabled;
After calling this method, you can push media streams in RTMP or RTMPS protocol to the CDN. The SDK triggers the rtmpStreamingChangedToState callback on the local client to report the state of adding a local stream to the CDN.
- Call this method after joining a channel.
- Ensure that the media push function is enabled.
- This method takes effect only when you are a host in live interactive streaming.
- This method adds only one streaming URL to the CDN each time it is called. To push multiple URLs, call this method multiple times.
- Agora only supports pushing media streams to the CDN in RTMPS protocol when you enable transcoding.
Parameters
- url
- The media push URL in the RTMP or RTMPS format. The maximum length of this parameter is 1024 bytes. The URL address must not contain special characters, such as Chinese language characters.
- transcodingEnabled
-
Whether to enable transcoding. Transcoding in a CDN live streaming converts the audio and video streams before pushing them to the CDN server. It applies to scenarios where a channel has multiple broadcasters and composite layout is needed.
YES
: Enable transcoding.NO
: Disable transcoding.
Attention: If you set this parameter asYES
, ensure that you call the setLiveTranscoding method before calling this method.
Returns
- 0: Success.
-
< 0: Failure.
- -2: Invalid parameter, usually an empty URL or a string with a length of 0.
- -7: The engine is not initialized when streaming.
addVideoWatermark [1/2]
Adds a watermark image to the local video.
- (int)addVideoWatermark:(AgoraImage * _Nonnull)watermark
- Deprecated:
- This method is deprecated. Use addVideoWatermark [2/2] instead.
This method adds a PNG watermark image to the local video stream in a live streaming session. Once the watermark image is added, all the users in the channel (CDN audience included) and the video capturing device can see and capture it. If you only want to add a watermark to the CDN live streaming, see descriptions in setLiveTranscoding.
- The URL descriptions are different for the local video and CDN live streaming: In a local video stream, URL refers to the absolute path of the added watermark image file in the local video stream. In a CDN live stream, URL refers to the URL address of the added watermark image in the CDN live streaming.
- The source file of the watermark image must be in the PNG file format. If the width and height of the PNG file differ from your settings in this method, the PNG file will be cropped to conform to your settings.
- The Agora SDK supports adding only one watermark image onto a local video or CDN live stream. The newly added watermark image replaces the previous one.
Parameters
- watermark
- The watermark image to be added to the local live streaming: AgoraImage.
Returns
- 0: Success.
- < 0: Failure.
addVideoWatermark [2/2]
Adds a watermark image to the local video.
- (int)addVideoWatermark:(NSURL* _Nonnull)url options:(WatermarkOptions* _Nonnull)options;
This method adds a PNG watermark image to the local video in the live streaming. Once the watermark image is added, all the audience in the channel (CDN audience included), and the capturing device can see and capture it. Agora supports adding only one watermark image onto the local video, and the newly watermark image replaces the previous one.
- If the orientation mode of the encoding video (AgoraVideoOutputOrientationMode) is fixed landscape mode or the adaptive landscape mode, the watermark uses the landscape orientation.
- If the orientation mode of the encoding video (AgoraVideoOutputOrientationMode) is fixed portrait mode or the adaptive portrait mode, the watermark uses the portrait orientation.
- When setting the watermark position, the region must be less than the dimensions set in the setVideoEncoderConfiguration method; otherwise, the watermark image will be cropped.
- Ensure that call this method after enableVideo.
- If you only want to add a watermark to the media push, you can call this method or the setLiveTranscoding method.
- This method supports adding a watermark image in the PNG file format only. Supported pixel formats of the PNG image are RGBA, RGB, Palette, Gray, and Alpha_gray.
- If the dimensions of the PNG image differ from your settings in this method, the image will be cropped or zoomed to conform to your settings.
- If you have enabled the local video preview by calling the startPreview method, you can use the
visibleInPreview
member to set whether or not the watermark is visible in the preview. - If you have enabled the mirror mode for the local video, the watermark on the local video is also mirrored. To avoid mirroring the watermark, Agora recommends that you do not use the mirror and watermark functions for the local video at the same time. You can implement the watermark function in your application layer.
Parameters
- url
- The local file path of the watermark image to be added. This method supports adding a watermark image from the local absolute or relative file path.
- options
- The options of the watermark image to be added. For details, see WatermarkOptions.
Returns
- 0: Success.
- < 0: Failure.
adjustAudioMixingPlayoutVolume
Adjusts the volume of audio mixing for local playback.
- (int)adjustAudioMixingPlayoutVolume:(NSInteger)volume;
- Since
- v2.3.2
PLAY
) callback.Parameters
- volume
- Audio mixing volume for local playback. The value range is [0,100]. The default value is 100, the original volume.
Returns
- 0: Success.
- < 0: Failure.
adjustAudioMixingPublishVolume
Adjusts the volume of audio mixing for publishing.
- (int)adjustAudioMixingPublishVolume:(NSInteger)volume;
- Since
- v2.3.2
This method adjusts the volume of audio mixing for publishing (sending to other users).
PLAY
) callback.Parameters
- volume
- Audio mixing volume. The value range is [0,100]. The default value is 100, the original volume.
Returns
- 0: Success.
- < 0: Failure.
adjustAudioMixingVolume
Adjusts the volume during audio mixing.
- (int)adjustAudioMixingVolume:(NSInteger)volume;
This method adjusts the audio mixing volume on both the local client and remote clients.
- Call this method after startAudioMixing [2/2].
- Calling this method does not affect the volume of audio effect file playback invoked by the playEffect [3/3] method.
Parameters
- volume
- Audio mixing volume. The value ranges between 0 and 100. The default value is 100, the original volume.
Returns
- 0: Success.
- < 0: Failure.
adjustAudioMixingPublishVolume
Adjusts the volume of audio mixing for publishing.
- (int)adjustAudioMixingPublishVolume:(NSInteger)volume;
- Since
- v2.3.2
This method adjusts the volume of audio mixing for publishing (sending to other users).
PLAY
) callback.Parameters
- volume
- Audio mixing volume. The value range is [0,100]. The default value is 100, the original volume.
Returns
- 0: Success.
- < 0: Failure.
adjustLoopbackRecordingVolume
Adjusts the volume of the signal captured by the sound card.
- (int)adjustLoopbackRecordingVolume:(NSInteger)volume;
After calling enableLoopbackRecording to enable loopback audio capturing, you can call this method to adjust the volume of the signal captured by the sound card.
Parameters
- volume
- Audio mixing volume. The value ranges between 0 and 100. The default value is 100, the original volume.
Returns
- 0: Success.
- < 0: Failure.
adjustPlaybackSignalVolume
Adjusts the playback signal volume of all remote users.
- (int)adjustPlaybackSignalVolume:(NSInteger)volume;
- This method adjusts the playback volume that is the mixed volume of all remote users.
- You can call this method either before or after joining a channel.
Parameters
- volume
-
Integer only. The value range is [0,400].
- 0: Mute.
- 100: (Default) The original volume.
- 400: Four times the original volume (amplifying the audio signals by four times).
Returns
- 0: Success.
- < 0: Failure.
adjustRecordingSignalVolume
Adjusts the capturing signal volume.
- (int)adjustRecordingSignalVolume:(NSInteger)volume;
You can call this method either before or after joining a channel.
Parameters
- volume
-
Integer only. The value range is [0,400].
- 0: Mute.
- 100: (Default) The original volume.
- 400: Four times the original volume (amplifying the audio signals by four times).
Returns
- 0: Success.
- < 0: Failure.
adjustUserPlaybackSignalVolume
Adjusts the playback signal volume of a specified remote user.
- (int)adjustUserPlaybackSignalVolume:(NSUInteger)uid volume:(int)volume;
You can call this method to adjust the playback volume of a specified remote user. To adjust the playback volume of different remote users, call the method as many times, once for each remote user.
- Call this method after joining a channel.
- The playback volume here refers to the mixed volume of a specified remote user.
Parameters
- uid
- The ID of the remote user.
- volume
- Audio mixing volume. The value ranges between 0 and 100. The default value is 100, the original volume.
Returns
- 0: Success.
- < 0: Failure.
clearVideoWatermarks
Removes the watermark image from the video stream.
- (int)clearVideoWatermarks;
Returns
- 0: Success.
- < 0: Failure.
complain
Allows a user to complain about the call quality after a call ends.
- (int)complain:(NSString * _Nonnull)callId description:(NSString * _Nullable)description;
This method allows users to complain about the quality of the call. Call this method after the user leaves the channel.
Parameters
- callId
- The current call ID. You can get the call ID by calling getCallId.
- description
- (Optional) A description of the call. The string length should be less than 800 bytes.
Returns
- 0: Success.
- < 0: Failure.
- -2 (
ERR_INVALID_ARGUMENT
). - -3 (
ERR_NOT_READY
)。
- -2 (
sharedEngineWithAppId
Creates and initializes AgoraRtcEngineKit.
+ (instancetype _Nonnull)sharedEngineWithAppId:(NSString * _Nonnull)appId delegate:(id<AgoraRtcEngineDelegate> _Nullable)delegate;
All called methods provided by the AgoraRtcEngineKit class are executed asynchronously. We recommend calling these methods in the same thread.
- Before calling other APIs, you must call this method to create an AgoraRtcEngineKit object.
- You can create an AgoraRtcEngineKit instance either by calling this method or by calling sharedEngineWithConfig. The difference between sharedEngineWithConfig and this method is that sharedEngineWithConfig supports more configurations when creating the AgoraRtcEngineKit instance, for example, specifying the region for connection and setting the log files.
- The SDK supports creating only one AgoraRtcEngineKit instance for an app.
Parameters
- appId
- The App ID issued by Agora for your project. Only users in apps with the same App ID can join the same channel and communicate with each other. An App ID can only be used to create one AgoraRtcEngineKit instance. To change your App ID, call destroy to destroy the current AgoraRtcEngineKit instance, and then create a new one.
- delegate
- The event handler for AgoraRtcEngineKit. See AgoraRtcEngineDelegate.
Returns
- The AgoraRtcEngineKit instance, if the method call succeeds.
- An error code, if the call fails.
sharedEngineWithConfig
Creates and initializes AgoraRtcEngineKit.
+ (instancetype _Nonnull)sharedEngineWithConfig:(AgoraRtcEngineConfig * _Nonnull)config delegate:(id<AgoraRtcEngineDelegate> _Nullable)delegate;
All called methods provided by the AgoraRtcEngineKit class are executed asynchronously. Agora recommends calling these methods in the same thread.
- Before calling other APIs, you must call this method to create the AgoraRtcEngineKit object.
- You can create the AgoraRtcEngineKit instance either by calling this method or by calling sharedEngineWithAppId. The difference between sharedEngineWithAppId and this method is that this method supports more configurations when creating the AgoraRtcEngineKit instance, for example, specifying the region for connection and setting the log files.
- The SDK supports creating only one AgoraRtcEngineKitinstance for an app.
Parameters
- config
-
Configurations for the AgoraRtcEngineKit instance. See AgoraRtcEngineConfig.
- delegate
- The event handler for AgoraRtcEngineKit. See AgoraRtcEngineDelegate.
createDataStream [1/2]
Creates a data stream.
- (int)createDataStream:(NSInteger * _Nonnull)streamId reliable:(BOOL)reliable ordered:(BOOL)ordered;
Each user can create up to five data streams during the lifecycle of AgoraRtcEngineKit.
- Call this method after joining a channel.
- Agora does not support setting reliable as
YES
and ordered asYES
.
Parameters
- reliable
- Whether or not the data stream is reliable:
YES
: The recipients receive the data from the sender within five seconds. If the recipient does not receive the data within five seconds, the SDK triggers the didOccurStreamMessageErrorFromUid callback and returns an error code.NO
: There is no guarantee that the recipients receive the data stream within five seconds and no error message is reported for any delay or missing data stream.
- ordered
- Whether or not the recipients receive the data stream in the sent order:
YES
: The recipients receive the data in the sent order.NO
: The recipients do not receive the data in the sent order.
Returns
- ID of the created data stream, if the method call succeeds.
- < 0: Failure.
createDataStream [2/2]
Creates a data stream.
- (int)createDataStream:(NSInteger * _Nonnull)streamId config:(AgoraDataStreamConfig * _Nonnull)config;
Creates a data stream. Each user can create up to five data streams in a single channel.
Compared with createDataStream [1/2][1/2], this method does not support data reliability. If a data packet is not received five seconds after it was sent, the SDK directly discards the data.
Parameters
- config
- The configurations for the data stream. For details, see AgoraDataStreamConfig.
Returns
- ID of the created data stream, if the method call succeeds.
- < 0: Failure.
createMediaPlayerWithDelegate
Creates a media player instance.
- (id<AgoraRtcMediaPlayerProtocol>_Nullable)createMediaPlayerWithDelegate: (id<AgoraRtcMediaPlayerDelegate>_Nullable)delegate;
Parameters
- delegate
- The event handler for AgoraRtcEngineKit. See AgoraRtcEngineDelegate.
Returns
- The AgoraRtcMediaPlayerProtocol instance, if the method call succeeds.
- An empty pointer , if the method call fails.
delegate
Sets and retrieves AgoraRtcEngineDelegate.
@property(nonatomic, weak) id<AgoraRtcEngineDelegate> _Nullable delegate;
The SDK uses AgoraRtcEngineDelegate to inform the app on engine runtime events. All methods defined in the delegate are optional implementation methods.
destroy
Releases the AgoraRtcEngineKit instance.
+ (void)destroy;
This method releases all resources used by the Agora SDK. Use this method for apps in which users occasionally make voice or video calls. When users do not make calls, you can free up resources for other operations.
After a successful method call, you can no longer use any method or callback in the SDK anymore. If you want to use the real-time communication functions again, you must call sharedEngineWithConfig to create a new AgoraRtcEngineKit instance.
disableAudio
Disables the audio module.
- (int)disableAudio;
- This method disables the internal engine and can be called anytime after initialization. It is still valid after one leaves channel.
- This method resets the internal engine and takes some time to take effect. Agora recommends using the following API methods to control the audio modules separately:
- enableLocalAudio: Whether to enable the microphone to create the local audio stream.
- muteLocalAudioStream: Whether to publish the local audio stream.
- muteRemoteAudioStream: Whether to subscribe and play the remote audio stream.
- muteAllRemoteAudioStreams: Whether to subscribe to and play all remote audio streams.
Returns
- 0: Success.
- < 0: Failure.
disableAudioSpectrumMonitor
Disables audio spectrum monitoring.
- (int)disableAudioSpectrumMonitor;
After calling enableAudioSpectrumMonitor, if you want to disable audio spectrum monitoring, you can call this method.
You can call this method either before or after joining a channel.
Returns
- 0: Success.
- < 0: Failure.
disableVideo
Disables the video module.
- (int)disableVideo;
This method disables video. You can call this method either before or after joining a channel. If you call it before joining a channel, an audio call starts when you join the channel. If you call it after joining a channel, a video call switches to an audio call. Call enableVideo to enable video.
A successful call of this method triggers the didVideoEnabled(NO
) callback on the remote client.
- This method affects the internal engine and can be called after leaving the channel.
- This method resets the internal engine and takes some time to take effect. Agora recommends using the following API methods to control the video engine modules separately:
- enableLocalVideo: Whether to enable the camera to create the local video stream.
- muteLocalVideoStream: Whether to publish the local video stream.
- muteRemoteVideoStream: Whether to subscribe to and play the remote video stream.
- muteAllRemoteVideoStreams: Whether to subscribe to and play all remote video streams.
Returns
- 0: Success.
- < 0: Failure.
enableAudio
Enables the audio module.
- (int)enableAudio;
The audio mode is enabled by default.
- This method enables the internal engine and can be called anytime after initialization. It is still valid after one leaves channel.
- This method enables the audio module and takes some time to take effect. Agora recommends using the following API methods to control the audio module separately:
- enableLocalAudio: Whether to enable the microphone to create the local audio stream.
- muteLocalAudioStream: Whether to publish the local audio stream.
- muteRemoteAudioStream: Whether to subscribe and play the remote audio stream.
- muteAllRemoteAudioStreams: Whether to subscribe to and play all remote audio streams.
Returns
- 0: Success.
- < 0: Failure.
enableAudioSpectrumMonitor
Turn on audio spectrum monitoring.
- (int)enableAudioSpectrumMonitor:(int)intervalInMS;
If you want to obtain the audio spectrum data of local or remote users, please register the audio spectrum observer and enable audio spectrum monitoring.
You can call this method either before or after joining a channel.
Parameters
- intervalInMS
-
The interval (in milliseconds) at which the SDK triggers the onLocalAudioSpectrum and onRemoteAudioSpectrum callbacks. The default value is 100. Do not set this parameter to less than 10 milliseconds, otherwise the callback will not be triggered.
Returns
- 0: Success.
- < 0: Failure.
-2 (ERR_INVALID_ARGUMENT)
: The parameter is invalid.
enableAudioVolumeIndication
Enables the reporting of users' volume indication.
- (int)enableAudioVolumeIndication:(NSInteger)interval smooth:(NSInteger)smooth reportVad:(BOOL)reportVad;
This method enables the SDK to regularly report the volume information of the local user who sends a stream and remote users (up to three) whose instantaneous volumes are the highest to the app. Once you call this method and users send streams in the channel, the SDK triggers the reportAudioVolumeIndicationOfSpeakers callback at the time interval set in this method.
Parameters
- interval
- Sets the time interval between two consecutive volume indications:
- ≤ 0: Disables the volume indication.
- > 0: Time interval (ms) between two consecutive volume indications. We recommend a setting greater than 200 ms. Do not set this parameter to less than 10 milliseconds, otherwise the reportAudioVolumeIndicationOfSpeakers callback will not be triggered.
- smooth
- The smoothing factor sets the sensitivity of the audio volume indicator. The value ranges between 0 and 10. The recommended value is 3. The greater the value, the more sensitive the indicator.
- reportVad
-
YES
: Enable the voice activity detection of the local user. Once it is enabled, the vad parameter of the reportAudioVolumeIndicationOfSpeakers callback reports the voice activity status of the local user.NO
: (Default) Disable the voice activity detection of the local user. Once it is disabled, the vad parameter of the reportAudioVolumeIndicationOfSpeakers callback does not report the voice activity status of the local user, except for the scenario where the engine automatically detects the voice activity of the local user.
Returns
- 0: Success.
- < 0: Failure.
enableDualStreamMode [1/3]
Enables/Disables dual-stream mode.
- (int)enableDualStreamMode:(BOOL)enabled;
- High-quality video stream: High bitrate, high resolution.
- Low-quality video stream: Low bitrate, low resolution.
After you enable the dual-stream mode, you can call setRemoteVideoStream to choose to receive the high-quality video stream or low-quality video stream on the subscriber side.
- This method only takes effect for the video stream captured by the SDK through the camera. If you use video streams from the custom video source or captured by the SDK through the screen, you need to call enableDualStreamMode [2/3] or enableDualStreamMode [3/3] to enable dual-stream mode.
- You can call this method either before or after joining a channel.
Parameters
- enabled
-
Whether to enable dual-stream mode.
YES
: Enable dual-stream mode.NO
: Disable dual-stream mode.
Returns
- 0: Success.
- < 0: Failure.
enableDualStreamMode [2/3]
Enables/Disables dual-stream mode.
- (int)enableDualStreamMode:(AgoraVideoSourceType)sourceType enabled:(BOOL)enabled;
- High-quality video stream: High bitrate, high resolution.
- Low-quality video stream: Low bitrate, low resolution.
After you enable the dual-stream mode, you can call setRemoteVideoStream to choose to receive the high-quality video stream or low-quality video stream on the subscriber side.
You can call this method either before or after joining a channel.
Parameters
- sourceType
-
The capture type of the custom video source. For details, see AgoraVideoSourceType.
- enabled
-
Enables dual-stream mode.
YES
: Enables dual-stream mode.NO
: Disables dual-stream mode.
Returns
- 0: Success.
- < 0: Failure.
enableDualStreamMode [3/3]
Enables/Disables dual-stream mode.
- (int)enableDualStreamMode:(AgoraVideoSourceType)sourceType enabled:(BOOL)enabled streamConfig:(AgoraSimulcastStreamConfig* _Nonnull)streamConfig;
- High-quality video stream: High bitrate, high resolution.
- Low-quality video stream: Low bitrate, low resolution.
After you enable the dual-stream mode, you can call setRemoteVideoStream to choose to receive the high-quality video stream or low-quality video stream on the subscriber side.
You can call this method either before or after joining a channel.
Parameters
- sourceType
-
The capture type of the custom video source. For details, see AgoraVideoSourceType.
- enabled
-
Enables dual-stream mode.
YES
: Enables dual-stream mode.NO
: Disables dual-stream mode.
- streamConfig
-
The configuration of the low-quality video stream. See AgoraSimulcastStreamConfig.
Returns
- 0: Success.
- < 0: Failure.
enableEncryption
Enables/Disables the built-in encryption.
- (int)enableEncryption:(bool)enabled encryptionConfig:(AgoraEncryptionConfig * _Nonnull)config;
In scenarios requiring high security, Agora recommends calling this method to enable the built-in encryption before joining a channel.
All users in the same channel must use the same encryption mode and encryption key. After the user leaves the channel, the SDK automatically disables the built-in encryption. To enable the built-in encryption, call this method before the user joins the channel again.
Parameters
- enabled
-
Whether to enable built-in encryption:
- YES: Enable the built-in encryption.
- NO: Disable the built-in encryption.
- config
- Built-in encryption configurations. See AgoraEncryptionConfig for details.
Returns
- 0: Success.
- < 0: Failure.
- -2: An invalid parameter is used. Set the parameter with a valid value.
- -4: The encryption mode is incorrect or the SDK fails to load the external encryption library. Check the enumeration or reload the external encryption library.
- -7: The SDK is not initialized. Initialize the AgoraRtcEngineKit instance before calling this method.
enableExtensionWithVendor
Enables/Disables extensions.
- (int)enableExtensionWithVendor:(NSString * __nonnull)provider extension:(NSString * __nonnull)extension enabled:(BOOL)enabled;
Ensure that you call this method before joining a channel.
- If you want to enable multiple extensions, you need to call this method multiple times.
- The data processing order of different extensions in the SDK is determined by the order in which the extensions are enabled. That is, the extension that is enabled first will process the data first.
Parameters
- provider
- The name of the extension provider.
- extension
- The name of the extension.
- enabled
-
Whether to enable the extension:
YES
: Enable the extension.NO
: Disable the extension.
Returns
- 0: Success.
- < 0: Failure.
enableLocalAudio
Enables/Disables the local audio capture.
- (int)enableLocalAudio:(BOOL)enabled;
The audio function is enabled by default. This method disables or re-enables the local audio function to stop or restart local audio capturing.
This method does not affect receiving or playing the remote audio streams, and enableLocalAudio(NO
) applies to scenarios where the user wants to receive remote audio streams without sending any audio stream to other users in the channel.
- This method is different from the muteLocalAudioStream method:
- enableLocalVideo: Disables/Re-enables the local audio capturing and processing. If you disable or re-enable local audio capturing using the
enableLocalAudio
method, the local user might hear a pause in the remote audio playback. - muteLocalAudioStream: Sends/Stops sending the local audio streams.
- enableLocalVideo: Disables/Re-enables the local audio capturing and processing. If you disable or re-enable local audio capturing using the
- You can call this method either before or after joining a channel.
Parameters
- enabled
YES
: (Default) Re-enable the local audio function, that is, to start the local audio capturing device (for example, the microphone).NO
: Disable the local audio function, that is, to stop local audio capturing.
Returns
- 0: Success.
- < 0: Failure.
enableLocalVideo
Enables/Disables the local video capture.
- (int)enableLocalVideo:(BOOL)enabled;
This method disables or re-enables the local video capturer, and does not affect receiving the remote video stream.
After calling enableVideo, the local video capturer is enabled by default. You can call enableLocalVideo(NO
) to disable the local video capturer. If you want to re-enable the local video, call enableLocalVideo(YES
).
After the local video capturer is successfully disabled or re-enabled, the SDK triggers the callback on the remote clientremoteVideoStateChangedOfUid.
- You can call this method either before or after joining a channel.
- This method enables the internal engine and is valid after .
Parameters
- enabled
-
Whether to enable the local video capture.
YES
: (Default) Enable the local video capture.NO
: Disables the local video capture. Once the local video is disabled, the remote users can no longer receive the video stream of this user, while this user can still receive the video streams of the other remote users. When set toNO
, this method does not require a local camera.
Returns
- 0: Success.
- < 0: Failure.
enableLoopbackRecording
Enables loopback audio capturing.
- (int)enableLoopbackRecording:(BOOL)enabled;
If you enable loopback audio capturing, the output of the sound card is mixed into the audio stream sent to the other end.
- You can call this method either before or after joining a channel.
Parameters
- enabled
- Sets whether to enable loopback capturing.
YES
: Enable loopback audio capturing.NO
: (Default) Disable loopback capturing.
- deviceName
- The device name of the sound card. The default value is nil (the default sound card). If you use a virtual sound card like "Soundflower", set this parameter as the name of the sound card, "Soundflower". The SDK will find the corresponding sound card and start capturing.
Returns
- 0: Success.
- < 0: Failure.
enableSoundPositionIndication
Enables/Disables stereo panning for remote users.
- (int)enableSoundPositionIndication:(BOOL)enabled;
Ensure that you call this method before joining a channel to enable stereo panning for remote users so that the local user can track the position of a remote user by calling setRemoteVoicePosition.
Parameters
- enabled
- Whether to enable stereo panning for remote users:
YES
: Enable stereo panning.NO
: Disable stereo panning.
Returns
- 0: Success.
- < 0: Failure.
enableVideo
Enables the video module.
- (int)enableVideo;
Call this method either before joining a channel or during a call. If this method is called before joining a channel, the call starts in the video mode. Call disableVideo to disable the video mode.
A successful call of this method triggers the remoteVideoStateChangedOfUid callback on the remote client.
- This method enables the internal engine and is valid after leaving the channel.
- This method resets the internal engine and takes some time to take effect. Agora recommends using the following API methods to control the video engine modules separately:
- enableLocalVideo: Whether to enable the camera to create the local video stream.
- muteLocalVideoStream: Whether to publish the local video stream.
- muteRemoteVideoStream: Whether to subscribe to and play the remote video stream.
- muteAllRemoteVideoStreams: Whether to subscribe to and play all remote video streams.
Returns
- 0: Success.
- < 0: Failure.
enableVirtualBackground
Enables/Disables the virtual background. (beta feature)
- (int)enableVirtualBackground:(BOOL)enable backData:(AgoraVirtualBackgroundSource* _Nullable)backData NS_SWIFT_NAME(enableVirtualBackground(_:backData:));
The virtual background function allows you to replace the original background image of the local user or to blur the background. After successfully enabling the virtual background function, all users in the channel can see the customized background.
- Link the extension library in the project file:
AgoraVideoSegmentationExtension.framework
- Call
enableExtensionWithVendor(
to enable the extension.agora_segmentation
,PortraitSegmentation
,YES
) - Call enableVideo to enable the video module.
- Call this method to enable the virtual background function.
- This function requires a high-performance device. Agora recommends that you use this function on devices with the following chips:
- Devices with an i5 CPU and better
- Agora recommends that you use this function in scenarios that meet the following conditions:
- A high-definition camera device is used, and the environment is uniformly lit.
- There are few objects in the captured video. Portraits are half-length and unobstructed. Ensure that the background is a solid color that is different from the color of the user's clothing.
Parameters
- enable
- Whether to enable virtual background:
YES
: Enable virtual background.NO
: Disable virtual background.
- backData
- The custom background image. See AgoraVirtualBackgroundSource for details. To adapt the resolution of the custom background image to that of the video captured by the SDK, the SDK scales and crops the custom background image while ensuring that the content of the custom background image is not distorted.
Returns
- 0: Success.
- < 0: Failure.
- -1: The custom background image does not exist. Please check the value of source in AgoraVirtualBackgroundSource.
- -2: The color format of the custom background image is invalid. Please check the value of color in AgoraVirtualBackgroundSource.
- -3: The device does not support using the virtual background.
enableWebSdkInteroperability
Enables interoperability with the Agora Web SDK (applicable only in the live streaming scenarios).
- (int)enableWebSdkInteroperability:(BOOL)enabled;
- Deprecated:
- The SDK automatically enables interoperability with the Web SDK, so you no longer need to call this method.
This method enables or disables interoperability with the Agora Web SDK. If the channel has Web SDK users, ensure that you call this method, or the video of the Native user will be a black screen for the Web user.
This method is only applicable in live streaming scenarios, and interoperability is enabled by default in communication scenarios.
Parameters
- enabled
- Whether to enable interoperability with the Agora Web SDK.
YES
: Enable interoperability.NO
: (Default) Disable interoperability.
Returns
- 0: Success.
- < 0: Failure.
enumerateDevices
Enumerates all the audio and video devices in the system.
- (NSArray<AgoraRtcDeviceInfo *> * _Nullable)enumerateDevices:(AgoraMediaDeviceType)type;
This method returns an NSArray object that includes all audio and video devices in the system. Apps can enumerate devices with the AgoraRtcDeviceInfo NSArray object.
Parameters
- type
The device type, which includes the audio capturing, audio playback, video capturing, or video playback device. See AgoraMediaDeviceType.
Returns
An AgoraRtcDeviceInfo NSArray object that includes all audio and video devices if the method succeeds.
getAudioMixingCurrentPosition
Retrieves the playback position (ms) of the music file.
- (int)getAudioMixingCurrentPosition;
Retrieves the playback position (ms) of the audio.
PLAY
) callback.Returns
- ≥ 0: The current playback position of the audio mixing, if this method call succeeds.
- < 0: Failure.
getAudioMixingDuration
Retrieves the duration (ms) of the music file.
- (int)getAudioMixingDuration;
Retrieves the total duration (ms) of the audio.
Returns
- ≥ 0: The audio mixing duration, if this method call succeeds.
- < 0: Failure.
getAudioMixingPlayoutVolume
Retrieves the audio mixing volume for local playback.
- (int)getAudioMixingPlayoutVolume;
This method helps troubleshoot audio volume‑related issues.
PLAY
) callback.Returns
- ≥ 0: The audio mixing volume, if this method call succeeds. The value range is [0,100].
- < 0: Failure.
getAudioMixingPublishVolume
Retrieves the audio mixing volume for publishing.
- (int)getAudioMixingPublishVolume;
- Since
- v2.4.1
This method helps troubleshoot audio volume‑related issues.
PLAY
) callback.Returns
- ≥ 0: The audio mixing volume, if this method call succeeds. The value range is [0,100].
- < 0: Failure.
getCallId
Retrieves the call ID.
- (NSString * _Nullable)getCallId;
When a user joins a channel on a client, a callId is generated to identify the call from the client. Some methods, such as rate and complain, must be called after the call ends to submit feedback to the SDK. These methods require the callId parameter.
Returns
The current call ID.
getConnectionState
Gets the current connection state of the SDK.
- (AgoraConnectionState)getConnectionState;
You can call this method either before or after joining a channel.
Returns
The current connection state. For details, see AgoraConnectionState.
getDeviceInfo
Retrieves the name of the current device.
- (AgoraRtcDeviceInfo * _Nullable)getDeviceInfo:(AgoraMediaDeviceType)type;
This method retrieves the current audio and video capturing device based on your settings in the type parameter.
Parameters
- type
The device type, which includes the audio capturing, audio playback, video capturing, or video playback device. See AgoraMediaDeviceType.
Returns
- Returns AgoraRtcDeviceInfo when the method succeeds.
- Returns
nil
when the method fails.
getDeviceVolume
Retrieves the volume of the current device.
- (int)getDeviceVolume:(AgoraMediaDeviceType)type;
Parameters
- type
The device type, which includes the audio capturing, audio playback, video capturing, or video playback device. See AgoraMediaDeviceType.
Returns
- Returns the volume of the current device, if the method succeeds.
- < 0: Failure.
getEffectsVolume
Retrieves the volume of the audio effects.
- (int)getEffectsVolume;
The volume is an integer ranging from 0 to 100. The default value is 100, the original volume.
Returns
- Volume of the audio effects, if this method call succeeds.
- < 0: Failure.
getErrorDescription
Gets the warning or error description.
+ (NSString* _Nonnull)getErrorDescription: (NSInteger)error;
Parameters
- error
- The error code or warning code reported by the SDK.
Returns
The specific error or warning description.
getNativeHandle
Gets the C++ handle of the Native SDK.
- (void* _Nullable)getNativeHandle;
This method is used to retrieve the native C++ handle of the SDK engine used in special scenarios, such as registering the audio and video frame observer.
Returns
The native handle of the SDK.
getSdkVersion
Gets the SDK version.
+ (NSString * _Nonnull)getSdkVersion;
Returns
The SDK version number. The format is a string.
getUserInfoWithUserId
Gets the user information by passing in the user ID.
After a remote user joins the channel, the SDK gets the UID and user account of the remote user, caches them in a mapping table object, and triggers the didUserInfoUpdatedWithUserId callback on the local client. After receiving the callback, you can call this method to get the user account of the remote user from the AgoraUserInfo object by passing in the user ID.
Parameters
- uid
- User ID.
- error
- Error code.
Returns
- The AgoraUserInfo instance, if the method call succeeds.
- If the call fails, returns nil.
getUserInfoWithUserAccount
Gets the user information by passing in the user account.
After a remote user joins the channel, the SDK gets the UID and user account of the remote user, caches them in a mapping table object, and triggers the didUserInfoUpdatedWithUserId callback on the local client. After receiving the callback, you can call this method to get the user account of the remote user from the AgoraUserInfo object by passing in the user ID.
Parameters
- userAccount
- The user account.
- error
- Error code.
Returns
- The AgoraUserInfo instance, if the method call succeeds.
- If the call fails, returns nil.
getVolumeOfEffect
Gets the volume of a specified audio effect.
- (int)getVolumeOfEffect:(int)soundId;
Parameters
- soundId
- The ID of the audio effect.
Returns
- ≥ 0: Returns the volume of the specified audio effect, if the method call is successful. The value ranges between 0 and 100. 100 represents the original volume.
- < 0: Failure.
joinChannelByToken [1/2]
Joins a channel.
- (int)joinChannelByToken:(NSString * _Nullable)token channelId:(NSString * _Nonnull)channelId info:(NSString * _Nullable)info uid:(NSUInteger)uid joinSuccess:(void(^ _Nullable)(NSString * _Nonnull channel, NSUInteger uid, NSInteger elapsed))joinSuccessBlock;
This method enables users to join a channel. Users in the same channel can talk to each other, and multiple users in the same channel can start a group chat. Users with different App IDs cannot call each other.
- The local client: The didJoinChannel and connectionChangedToState callbacks.
- The remote client: didJoinedOfUid, if the user joining the channel is in the Communication profile or is a host in the Live-broadcasting profile.
When the connection between the client and Agora's server is interrupted due to poor network conditions, the SDK tries reconnecting to the server. When the local client successfully rejoins the channel, the SDK triggers the didRejoinChannel callback on the local client.
Parameters
- token
-
The token generated on your server for authentication. See Authenticate Your Users with Token.
- channelId
-
The channel name. This parameter signifies the channel in which users engage in real-time audio and video interaction. Under the premise of the same App ID, users who fill in the same channel ID enter the same channel for audio and video interaction. The string length must be less than 64 bytes. Supported character scopes are:
- All lowercase English letters: a to z.
- All uppercase English letters: A to Z.
- All numeric characters: 0 to 9.
- Space
- "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "= ", ".", ">", "?", "@", "[", "]", "^", "_", "{", "}", "|", "~", ","
- info
- (Optional) Reserved for future use.
- uid
- User ID. This parameter is used to identify the user in the channel for real-time audio and video interaction. You need to set and manage user IDs yourself, and ensure that each user ID in the same channel is unique. This parameter is a 32-bit unsigned integer. The value range is 1 to 232-1. If the user ID is not assigned (or set to 0), the SDK assigns a random user ID and returns it in the didJoinChannel callback. Your app must maintain the returned user ID, because the SDK does not do so.
- joinSuccessBlock
- The block of a user joining the specified channel.
joinSuccessBlock
takes higher priority than didJoinChannel. If you implement both callbacks, onlyblock
is triggered. Agora recommends settingjoinSuccessBlock
asnil
to use the AgoraRtcEngineDelegate callback.
Returns
- 0: Success.
- < 0: Failure.
joinChannelByToken [2/2]
Joins a channel with media options.
- (int)joinChannelByToken:(NSString * _Nullable)token channelId:(NSString * _Nonnull)channelId uid:(NSUInteger)uid mediaOptions:(AgoraRtcChannelMediaOptions * _Nonnull)mediaOptions joinSuccess:(void(^ _Nullable)(NSString * _Nonnull channel, NSUInteger uid, NSInteger elapsed))joinSuccessBlock;
This method enables users to join a channel. Users in the same channel can talk to each other, and multiple users in the same channel can start a group chat. Users with different App IDs cannot call each other.
- The local client: The didJoinChannel and connectionChangedToState callbacks.
- The remote client: didJoinedOfUid, if the user joining the channel is in the Communication profile or is a host in the Live-broadcasting profile.
When the connection between the client and Agora's server is interrupted due to poor network conditions, the SDK tries reconnecting to the server. When the local client successfully rejoins the channel, the SDK triggers the didRejoinChannel callback on the local client.
Compared to joinChannelByToken [1/2], this method adds the options parameter to configure whether to automatically subscribe to all remote audio and video streams in the channel when the user joins the channel. By default, the user subscribes to the audio and video streams of all the other users in the channel, giving rise to usage and billings. To unsubscribe, set the options parameter or call the mute methods accordingly.
- This method allows users to join only one channel at a time.
- Ensure that the app ID you use to generate the token is the same app ID that you pass in the sharedEngineWithConfig method; otherwise, you may fail to join the channel by token.
Parameters
- token
-
The token generated on your server for authentication. See Authenticate Your Users with Token.
- channelId
-
The channel name. This parameter signifies the channel in which users engage in real-time audio and video interaction. Under the premise of the same App ID, users who fill in the same channel ID enter the same channel for audio and video interaction. The string length must be less than 64 bytes. Supported character scopes are:
- All lowercase English letters: a to z.
- All uppercase English letters: A to Z.
- All numeric characters: 0 to 9.
- Space
- "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "= ", ".", ">", "?", "@", "[", "]", "^", "_", "{", "}", "|", "~", ","
- uid
- The user ID. This parameter is used to identify the user in the channel for real-time audio and video interaction. You need to set and manage user IDs yourself, and ensure that each user ID in the same channel is unique. This parameter is a 32-bit unsigned integer. The value range is 1 to 232-1. If the user ID is not assigned (or set to 0), the SDK assigns a random user ID and returns it in the didJoinChannel callback. Your application must record and maintain the returned user ID, because the SDK does not do so.
- mediaOptions
The channel media options. See AgoraRtcChannelMediaOptions for details.
- joinSuccessBlock
- The block of a user joining the specified channel.
joinSuccessBlock
takes higher priority than didJoinChannel. If you implement both callbacks, onlyblock
is triggered. Agora recommends settingjoinSuccessBlock
asnil
to use the AgoraRtcEngineDelegate callback.
Returns
- 0: Success.
- < 0: Failure.
joinChannelByToken [1/2]
Joins the channel with a user account.
- (int)joinChannelByToken:(NSString * _Nullable)token channelId:(NSString * _Nonnull)channelId userAccount:(NSString * _Nonnull)userAccount joinSuccess:(void(^ _Nullable)(NSString * _Nonnull channel, NSUInteger uid, NSInteger elapsed))joinSuccessBlock;
- The local client: didLocalUserRegisteredWithUserId, didJoinChannel and connectionChangedToState callbacks.
- The remote client: didJoinedOfUid and didUserInfoUpdatedWithUserId, if the user joining the channel is in the communication profile or is a host in the live streaming profile.
Once a user joins the channel, the user subscribes to the audio and video streams of all the other users in the channel by default, giving rise to usage and billing calculation. To stop subscribing to a specified stream or all remote streams, call the corresponding mute methods.
Parameters
- token
-
The token generated on your server for authentication. See Authenticate Your Users with Token.
- channelId
-
The channel name. This parameter signifies the channel in which users engage in real-time audio and video interaction. Under the premise of the same App ID, users who fill in the same channel ID enter the same channel for audio and video interaction. The string length must be less than 64 bytes. Supported character scopes are:
- All lowercase English letters: a to z.
- All uppercase English letters: A to Z.
- All numeric characters: 0 to 9.
- Space
- "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "= ", ".", ">", "?", "@", "[", "]", "^", "_", "{", "}", "|", "~", ","
- userAccount
-
The user account. This parameter is used to identify the user in the channel for real-time audio and video engagement. You need to set and manage user accounts yourself and ensure that each user account in the same channel is unique. The maximum length of this parameter is 255 bytes. Ensure that you set this parameter and do not set it as nil. Supported characters are (89 in total):
- The 26 lowercase English letters: a to z.
- The 26 uppercase English letters: A to Z.
- All numeric characters: 0 to 9.
- Space
- "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", "{", "}", "|", "~", ","
- joinSuccessBlock
- The block of a user joining the specified channel.
joinSuccessBlock
takes higher priority than didJoinChannel. If you implement both callbacks, onlyblock
is triggered. Agora recommends settingjoinSuccessBlock
asnil
to use the AgoraRtcEngineDelegate callback.
Returns
- 0: Success.
- < 0: Failure.
joinChannelByToken [2/2]
Joins the channel with a user account, and configures whether to automatically subscribe to audio or video streams after joining the channel.
- (int)joinChannelByToken:(NSString * _Nullable)token channelId:(NSString * _Nonnull)channelId userAccount:(NSString * _Nonnull)userAccount mediaOptions:(AgoraRtcChannelMediaOptions * _Nonnull)mediaOptions joinSuccess:(void(^ _Nullable)(NSString * _Nonnull channel, NSUInteger uid, NSInteger elapsed))joinSuccessBlock;
- The local client: didLocalUserRegisteredWithUserId, didJoinChannel and connectionChangedToState callbacks.
- The remote client: The didJoinedOfUid callback if the user is in the COMMUNICATION profile, and the didUserInfoUpdatedWithUserId callback if the user is a host in the LIVE_BROADCASTING profile.
Once a user joins the channel, the user subscribes to the audio and video streams of all the other users in the channel by default, giving rise to usage and billing calculation. To stop subscribing to a specified stream or all remote streams, call the corresponding mute methods.
Compared to joinChannelByToken [1/2], this method adds the options parameter to configure whether to automatically subscribe to all remote audio and video streams in the channel when the user joins the channel. By default, the user subscribes to the audio and video streams of all the other users in the channel, giving rise to usage and billings. To unsubscribe, set the options parameter or call the mute methods accordingly.
Parameters
- token
-
The token generated on your server for authentication. See Authenticate Your Users with Token.
- channelId
-
The channel name. This parameter signifies the channel in which users engage in real-time audio and video interaction. Under the premise of the same App ID, users who fill in the same channel ID enter the same channel for audio and video interaction. The string length must be less than 64 bytes. Supported character scopes are:
- All lowercase English letters: a to z.
- All uppercase English letters: A to Z.
- All numeric characters: 0 to 9.
- Space
- "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "= ", ".", ">", "?", "@", "[", "]", "^", "_", "{", "}", "|", "~", ","
- userAccount
-
The user account. This parameter is used to identify the user in the channel for real-time audio and video engagement. You need to set and manage user accounts yourself and ensure that each user account in the same channel is unique. The maximum length of this parameter is 255 bytes. Ensure that you set this parameter and do not set it as nil. Supported characters are (89 in total):
- The 26 lowercase English letters: a to z.
- The 26 uppercase English letters: A to Z.
- All numeric characters: 0 to 9.
- Space
- "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", "{", "}", "|", "~", ","
- mediaOptions
The channel media options. See AgoraRtcChannelMediaOptions for details.
- joinSuccessBlock
- The block of a user joining the specified channel.
joinSuccessBlock
takes higher priority than didJoinChannel. If you implement both callbacks, onlyblock
is triggered. Agora recommends settingjoinSuccessBlock
asnil
to use the AgoraRtcEngineDelegate callback.
Returns
- 0: Success.
- < 0: Failure.
leaveChannel [1/2]
Leaves a channel.
- (int)leaveChannel:(void(^ _Nullable)(AgoraChannelStats * _Nonnull stat))leaveChannelBlock;
This method releases all resources related to the session. This method call is asynchronous. When this method returns, it does not necessarily mean that the user has left the channel.
After joining the channel, you must call this method or leaveChannel [2/2] to end the call; otherwise, you cannot join the next call.
- The local client: didLeaveChannelWithStats.
- The remote client: didOfflineOfUid, if the user joining the channel is in the Communication profile, or is a host in the Live-broadcasting profile.
- If you call destroy immediately after calling this method, the SDK does not trigger the didLeaveChannelWithStats callback.
- If you call this method during a CDN live streaming, the SDK automatically calls the removePublishStreamUrl method.
Parameters
- leaveChannelBlock
-
This callback indicates that a user leaves a channel, and provides the statistics of the call in AgoraChannelStats.
Returns
- 0(ERR_OK): Success.
- < 0: Failure.
- -1(ERR_FAILED): A general error occurs (no specified reason).
- -2 (ERR_INVALID_ARGUMENT): The parameter is invalid.
- -7(ERR_NOT_INITIALIZED): The SDK is not initialized.
leaveChannel [2/2]
Leaves a channel.
- (int)leaveChannel:(AgoraLeaveChannelOptions * _Nonnull)options leaveChannelBlock:(void (^ _Nullable)(AgoraChannelStats * _Nonnull))leaveChannelBlock;
This method lets the user leave the channel, for example, by hanging up or exiting the call.
After joining the channel, you must call this method or leaveChannel [1/2] to end the call, otherwise, the next call cannot be started.
No matter whether you are currently in a call or not, you can call this method without side effects. This method releases all resources related to the session.
This method call is asynchronous, and the user has not left the channel when the method call returns. After you leave the channel, the SDK triggers the didLeaveChannelWithStats callback. A successful call of this method triggers the following callbacks: The local client: didLeaveChannelWithStats.The remote client: didOfflineOfUid, if the user joining the channel is in the COMMUNICATION profile, or is a host in the LIVE_BROADCASTING profile.
- If you call destroy immediately after calling this method, the SDK does not trigger the didLeaveChannelWithStats callback.
- If you call this method during a CDN live streaming, the SDK automatically calls the removePublishStreamUrl method.
Parameters
- options
- The options for leaving the channel. See AgoraLeaveChannelOptions.
- leaveChannelBlock
-
This callback indicates that a user leaves a channel, and provides the statistics of the call in AgoraChannelStats.
Returns
- 0: Success.
- < 0: Failure.
monitorDeviceChange
Monitors the change of the device state.
- (void)monitorDeviceChange:(BOOL)enabled;
Use this method to monitor the plugging and swapping of external audio or video devices, for example, an external camera.
Parameters
- enabled
- Whether to monitor the change of the device state:
YES
: Monitor the device state change.NO
: Do not monitor the device state change.
muteAllRemoteAudioStreams
Stops or resumes subscribing to the audio streams of all remote users.
- (int)muteAllRemoteAudioStreams:(BOOL)mute;
As of v3.3.0, after successfully calling this method, the local user stops or resumes subscribing to the audio streams of all remote users, including all subsequent users.
- Call this method after joining a channel.
Parameters
- mute
- Whether to subscribe to the audio streams of all remote users:
YES
: Do not subscribe to the audio streams of all remote users.NO
: (Default) Subscribe to the audio streams of all remote users by default.
Returns
- 0: Success.
- < 0: Failure.
muteAllRemoteVideoStreams
Stops or resumes subscribing to the video streams of all remote users.
- (int)muteAllRemoteVideoStreams:(BOOL)mute;
As of v3.3.0, after successfully calling this method, the local user stops or resumes subscribing to the video streams of all remote users, including all subsequent users.
- Call this method after joining a channel.
Parameters
- mute
-
Whether to stop subscribing to the video streams of all remote users.
YES
: Stop subscribing to the video streams of all remote users.NO
: (Default) Subscribe to the audio streams of all remote users by default.
Returns
- 0: Success.
- < 0: Failure.
muteLocalAudioStream
Stops or resumes publishing the local audio stream.
- (int)muteLocalAudioStream:(BOOL)mute;
- This method does not affect any ongoing audio recording, because it does not disable the microphone.
Parameters
- mute
- Whether to stop publishing the local audio stream.
YES
: Stop publishing the local audio stream.NO
: (Default) Resumes publishing the local audio stream.
Returns
- 0: Success.
- < 0: Failure.
muteLocalVideoStream
Stops or resumes publishing the local video stream.
- (int)muteLocalVideoStream:(BOOL)mute;
A successful call of this method triggers the didVideoMuted callback on the remote client.
- This method executes faster than the enableLocalVideo(
NO
) method, which controls the sending of the local video stream. - This method does not affect any ongoing video recording, because it does not disable the camera.
Parameters
- mute
-
Whether to stop publishing the local video stream.
YES
: Stop publishing the local video stream.NO
: (Default) Publish the local video stream.
Returns
- 0: Success.
- < 0: Failure.
muteRecordingSignal
Whether to mute the recording signal.
-(int)muteRecordingSignal:(BOOL)muted;
Parameters
- muted
-
YES
: Mute the recording signal.NO
: (Default) Unmute the recording signal.
Returns
- 0: Success.
- < 0: Failure.
muteRemoteAudioStream
Stops or resumes subscribing to the audio stream of a specified user.
- (int)muteRemoteAudioStream:(NSUInteger)uid mute:(BOOL)mute;
- Call this method after joining a channel.
- See recommended settings in Set the Subscribing State.
Parameters
- uid
- The user ID of the specified user.
- mute
- Whether to stop subscribing to the audio stream of the specified user.
YES
: Stop subscribing to the audio stream of the specified user.NO
: (Default) Subscribe to the audio stream of the specified user.
Returns
- 0: Success.
- < 0: Failure.
muteRemoteVideoStream
Stops or resumes subscribing to the video stream of a specified user.
- (int)muteRemoteVideoStream:(NSUInteger)uid mute:(BOOL)mute;
- Call this method after joining a channel.
- See recommended settings in Set the Subscribing State.
Parameters
- The ID of the specified user.
- mute
- Whether to stop subscribing to the video stream of the specified user.
YES
: Stop subscribing to the video streams of the specified user.NO
: (Default) Subscribe to the video stream of the specified user.
Returns
- 0: Success.
- < 0: Failure.
pauseAllChannelMediaRelay
Pauses the media stream relay to all destination channels.
- (int)pauseAllChannelMediaRelay;
After the cross-channel media stream relay starts, you can call this method to pause relaying media streams to all destination channels; after the pause, if you want to resume the relay, call resumeAllChannelMediaRelay.
After a successful method call, the SDK triggers the didReceiveChannelMediaRelayEvent callback to report whether the media stream relay is successfully paused.
Returns
- 0: Success.
- < 0: Failure.
pauseAudioMixing
Pauses playing and mixing the music file.
- (int)pauseAudioMixing;
Call this method when you are in a channel.
Returns
- 0: Success.
- < 0: Failure.
pauseAllEffects
Pauses all audio effects.
- (int)pauseAllEffects;
Returns
- 0: Success.
- < 0: Failure.
pauseEffect
Pauses a specified audio effect.
- (int)pauseEffect:(int)soundId;
Parameters
- soundId
- The audio effect ID. The ID of each audio effect file is unique.
Returns
- 0: Success.
- < 0: Failure.
playEffect [1/3]
Plays the specified local or online audio effect file.
- (int)playEffect:(int)soundId filePath:(NSString* _Nonnull)filePath loopCount:(NSInteger)loopCount pitch:(double)pitch pan:(double)pan gain:(NSInteger)gain;
Parameters
- soundId
- The audio effect ID. The ID of each audio effect file is unique.Attention: If you have preloaded an audio effect into memory by calling preloadEffect, ensure that this parameter is set to the same value as soundId in preloadEffect.
- filePath
-
The absolute path or URL address (including the suffixes of the filename) of the audio effect file. For example:
/var/mobile/Containers/Data/audio.mp4
. Supported audio formats include MP3, AAC, M4A, MP4, WAV, and 3GP. See supported audio formats. - loopCount
- The number of times the audio effect loops:
- ≥ 0: The number of playback times. For example, 1 means loop one time, which means play the audio effect two times in total.
- -1: Play the music effect in an infinite loop.
- pitch
- The pitch of the audio effect. The value range is 0.5 to 2.0. The default value is 1.0, which means the original pitch. The lower the value, the lower the pitch.
- pan
- The spatial position of the audio effect. The value range is 1 to10000.
- -1.0: The audio effect displays to the left.
- 0.0: The audio effect displays ahead.
- 1.0: The audio effect displays to the right.
- gain
- The volume of the audio effect. The value range is 1 to10000. The default value is 100.0, which means the original volume. The smaller the value, the lower the volume.
Returns
- 0: Success.
- < 0: Failure.
playEffect [2/3]
Plays the specified local or online audio effect file.
- (int)playEffect:(int)soundId filePath:(NSString* _Nonnull)filePath loopCount:(NSInteger)loopCount pitch:(double)pitch pan:(double)pan gain:(NSInteger)gain publish:(BOOL)publish;
- Call this method after joining a channel.
- Supported audio formats include MP3, AAC, M4A, MP4, WAV, and 3GP. See supported audio formats.
Parameters
- soundId
- The audio effect ID. The ID of each audio effect file is unique.Attention: If you have preloaded an audio effect into memory by calling preloadEffect, ensure that this parameter is set to the same value as soundId in preloadEffect.
- filePath
-
Attention: If you have preloaded an audio effect into memory by calling preloadEffect, ensure that this parameter is set to the same value as filePath in preloadEffect.
- loopCount
- The number of times the audio effect loops:
- ≥ 0: The number of playback times. For example, 1 means loop one time, which means play the audio effect two times in total.
- -1: Play the audio effect in an infinite loop.
- pitch
- The pitch of the audio effect. The value range is 0.5 to 2.0. The default value is 1.0, which means the original pitch. The smaller the value, the lower the pitch.
- pan
- The spatial position of the audio effect. The value ranges between -1.0 and 1.0, where:
- -1.0: The audio effect displays to the left.
- 0.0: The audio effect displays ahead.
- 1.0: The audio effect displays to the right.
- gain
- The volume of the audio effect. The value range is 0.0 to 100.0. The default value is 100.0, which means the original volume. The smaller the value, the lower the volume.
- publish
- Whether to publish the audio effect to the remote users.
YES
: Publish the audio effect to the remote users. Both the local user and remote users can hear the audio effect.NO
: Do not publish the audio effect to the remote users. Only the local user can hear the audio effect.
Returns
- 0: Success.
- < 0: Failure.
playEffect [3/3]
Plays the specified local or online audio effect file.
- (int)playEffect:(int)soundId filePath:(NSString* _Nonnull)filePath loopCount:(NSInteger)loopCount pitch:(double)pitch pan:(double)pan gain:(NSInteger)gain publish:(BOOL)publish startPos:(int)startPos;
Parameters
- soundId
- The audio effect ID. The ID of each audio effect file is unique.Attention: If you have preloaded an audio effect into memory by calling preloadEffect, ensure that this parameter is set to the same value as soundId in preloadEffect.
- filePath
The absolute path or URL address (including the suffixes of the filename) of the audio effect file. For example:
/var/mobile/Containers/Data/audio.mp4
. Supported audio formats include MP3, AAC, M4A, MP4, WAV, and 3GP. See supported audio formats.Attention: If you have preloaded an audio effect into memory by calling preloadEffect, ensure that this parameter is set to the same value as filePath in preloadEffect.- loopCount
- The number of times the audio effect loops:
- ≥ 0: The number of playback times. For example, 1 means loop one time, which means play the audio effect two times in total.
- -1: Play the music effect in an infinite loop.
- pitch
- The pitch of the audio effect. The value range is 0.5 to 2.0. The default value is 1.0, which means the original pitch. The lower the value, the lower the pitch.
- pan
- The spatial position of the audio effect. The value range is 1 to10000.
- -1.0: The audio effect displays to the left.
- 0.0: The audio effect displays ahead.
- 1.0: The audio effect displays to the right.
- gain
- The volume of the audio effect. The value range is 1 to10000. The default value is 100.0, which means the original volume. The smaller the value, the lower the volume.
- publish
- Whether to publish the audio effect to the remote users.
YES
: Publish the audio effect to the remote users. Both the local user and remote users can hear the audio effect.NO
: Do not publish the audio effect to the remote users. Only the local user can hear the audio effect.
- startPos
-
The playback position (ms) of the audio effect file.
Returns
- 0: Success.
- < 0: Failure.
preloadEffect
Preloads a specified audio effect file into the memory.
- (int)preloadEffect:(int)soundId filePath:(NSString* _Nonnull)filePath;
To ensure smooth communication, limit the size of the audio effect file. We recommend using this method to preload the audio effect before calling joinChannelByToken [2/2].
- This method does not support online audio effect files.
- For the audio file formats supported by this method, see What formats of audio files does the Agora RTC SDK support.
Parameters
- soundId
- The audio effect ID. The ID of each audio effect file is unique.
- filePath
- File path:
- iOS or macOS: The absolute path or URL address (including the suffixes of the filename) of the audio effect file. For example: /var/mobile/Containers/Data/audio.mp4.
Returns
- 0: Success.
- < 0: Failure.
pushExternalAudioFrameRawData
Pushes the external audio frame.
- (int)pushExternalAudioFrameRawData:(void * _Nonnull)data samples:(NSInteger)samples sourceId:(NSInteger)sourceId timestamp:(NSTimeInterval)timestamp;
Parameters
- data
- External audio data.
- samples
- Number of samples for the push.
- timestamp
- The timestamp (ms) of the external audio frame. It is mandatory. You can use this parameter for the following purposes: restore the order of the captured audio frame; and synchronize audio and video frames in video-related scenarios, including scenarios where external video sources are used.
- sourceId
- The ID of external audio source. If you want to publish a custom external audio source, set this parameter to the ID of the corresponding custom audio track you want to publish.
Returns
- 0: Success.
- < 0: Failure.
pushExternalAudioFrameNSData
Pushes the external audio frame to the SDK.
- (int)pushExternalAudioFrameNSData:(NSData * _Nonnull)data sourceId:(NSInteger)sourceId timestamp:(NSTimeInterval)timestamp;
Parameters
- data
- External audio data.
- timestamp
- The timestamp (ms) of the external audio frame. It is mandatory. You can use this parameter for the following purposes: restore the order of the captured audio frame; and synchronize audio and video frames in video-related scenarios, including scenarios where external video sources are used.
- sourceId
- The ID of external audio source. If you want to publish a custom external audio source, set this parameter to the ID of the corresponding custom audio track you want to publish.
Returns
- 0: Success.
- < 0: Failure.
pushExternalAudioFrameSampleBuffer
Pushes the external CMSampleBuffer audio frame to the SDK.
- (int)pushExternalAudioFrameSampleBuffer:(CMSampleBufferRef _Nonnull)sampleBuffer;
Parameters
- sampleBuffer
- The sample buffer.
Returns
- 0: Success.
- < 0: Failure.
pushExternalVideoFrame
Pushes the external raw video frame to the SDK.
- (BOOL)pushExternalVideoFrame:(AgoraVideoFrame * _Nonnull)frame;
If you call setExternalVideoSource and set the enabled parameter as YES
and the encodedFrame parameter as NO
, you can call this method to push the external raw video frame to the SDK.
Parameters
- frame
-
The external raw video frame to be pushed. See AgoraVideoFrame for details.
Returns
YES
: Pushes the external raw video frame to the SDK successfully.NO
: Fails to push external raw video frame to the SDK.
rate
Allows a user to rate a call after the call ends.
- (int)rate:(NSString * _Nonnull)callId rating:(NSInteger)rating description:(NSString * _Nullable)description;
Parameters
- callId
- The current call ID. You can get the call ID by calling getCallId.
- rating
- The rating of the call. The value is between 1 (lowest score) and 5 (highest score). If you set a value out of this range, the SDK returns the -2 (
ERR_INVALID_ARGUMENT
) error. - description
- (Optional) A description of the call. The string length should be less than 800 bytes.
Returns
- 0: Success.
- < 0: Failure.
- -2 (
ERR_INVALID_ARGUMENT
). - -3 (
ERR_NOT_READY
)。
- -2 (
registerAudioEncodedFrameObserver
Registers an encoded audio observer.
- (int)setAudioEncodedFrameDelegate:(id<AgoraAudioEncodedFrameDelegate> _Nonnull)delegate config:(AgoraAudioEncodedFrameDelegateConfig * _Nonnull) config;
- Call this method after joining a channel.
- This method and startAudioRecording [2/2] both set the audio content and audio quality. Agora recommends not using this method and startAudioRecording [2/2] together; otherwise, only the method called later will take effect.
Parameters
- config
-
Observer settings for the encoded audio. For details, see AgoraAudioEncodedFrameDelegateConfig.
- delegate
-
The encoded audio observer. For details, see AgoraAudioEncodedFrameDelegate.
Returns
- 0: Success.
- < 0: Failure.
setAudioFrameDelegate
Registers an audio frame observer object.
- (BOOL)setAudioFrameDelegate:(id<AgoraAudioFrameDelegate> _Nullable)delegate;
Call this method to register an audio frame observer object (register a callback). When you need the SDK to trigger onRecordAudioFrame or onPlaybackAudioFrame callback, you need to use this method to register the callbacks.
Parameters
- delegate
-
The observer object instance. For details, see AgoraAudioFrameDelegate. Set the value as nil to release the observer object. Agora recommends releasing the observer object after receiving the didLeaveChannelWithStats callback.
Returns
- 0: Success.
- < 0: Failure.
registerAudioSpectrumDelegate
Register an audio spectrum observer.
- (int)registerAudioSpectrumDelegate:(id<AgoraAudioSpectrumDelegate> _Nullable )delegate;
After successfully registering the audio spectrum observer and calling enableAudioSpectrumMonitor to enable the audio spectrum monitoring, the SDK reports the callback that you implement in the AgoraAudioSpectrumDelegate class at the time interval you set.
Parameters
- delegate
-
The Audio spectrum observer. For details, see AgoraAudioSpectrumDelegate.
Returns
- 0: Success.
- < 0: Failure.
registerLocalUserAccountWithAppID
Registers a user account.
- (int)registerLocalUserAccountWithAppID:(NSString * _Nonnull)appID userAccount:(NSString * _Nonnull)userAccount;
Once registered, the user account can be used to identify the local user when the user joins the channel. After the registration is successful, the user account can identify the identity of the local user, and the user can use it to join the channel.
After the user successfully registers a user account, the SDK triggers the didLocalUserRegisteredWithUserId callback on the local client, reporting the user ID and user account of the local user.
- Call registerLocalUserAccountWithAppID to to create a user account, and then call joinChannelByToken [2/2] to join the channel.
- Call the joinChannelByToken [2/2] method to join the channel.
The difference between the two ways is that the time elapsed between calling the registerLocalUserAccountWithAppID method and joining the channel is shorter than directly calling joinChannelByToken [2/2].
- Ensure that you set the userAccount parameter; otherwise, this method does not take effect.
- Ensure that the userAccount is unique in the channel.
- To ensure smooth communication, use the same parameter type to identify the user. For example, if a user joins the channel with a user ID, then ensure all the other users use the user ID too. The same applies to the user account. If a user joins the channel with the Agora Web SDK, ensure that the ID of the user is set to the same parameter type.
Parameters
- appID
- The App ID of your project on Agora Console.
- userAccount
- The user account. This parameter is used to identify the user in the channel for real-time audio and video engagement. You need to set and manage user accounts yourself and ensure that each user account in the same channel is unique. The maximum length of this parameter is 255 bytes. Ensure that you set this parameter and do not set it as nil. Supported characters are (89 in total):
- The 26 lowercase English letters: a to z.
- The 26 uppercase English letters: A to Z.
- All numeric characters: 0 to 9.
- Space
- "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", "{", "}", "|", "~", ","
Returns
- 0: Success.
- < 0: Failure.
setMediaMetadataDelegate
Registers the metadata observer.
- (BOOL)setMediaMetadataDelegate:(id<AgoraMediaMetadataDelegate> _Nullable)metadataDelegate withType:(AgoraMetadataType)type;
You need to implement the AgoraMediaMetadataDelegate class and specify the metadata type in this method. This method enables you to add synchronized metadata in the video stream for more diversified live interactive streaming, such as sending shopping links, digital coupons, and online quizzes.
A successful call of this method triggers the metadataMaxSize callback.
- Call this method before joinChannelByToken [2/2].
- This method applies only to interactive live streaming.
Parameters
- observer
- The metadata observer. See AgoraMediaMetadataDelegate.
- type
- The metadata type. The SDK currently only supports AgoraMetadataTypeVideo. See AgoraMetadataType.
Returns
- 0: Success.
- < 0: Failure.
setVideoFrameDelegate
Registers a video frame observer object.
- (BOOL)setVideoFrameDelegate:(id<AgoraVideoFrameDelegate> _Nullable)delegate;
You need to implement the class in this method AgoraVideoFrameDelegate and register callbacks according to your scenarios. After you successfully register the video frame observer, the SDK triggers the registered callbacks each time a video frame is received.
- When handling the video data returned in the callbacks, pay attention to the changes in the width and height parameters, which may be adapted under the following circumstances:
- When the network condition deteriorates, the video resolution decreases incrementally.
- If the user adjusts the video profile, the resolution of the video returned in the callbacks also changes.
- Ensure that you call this method before joining a channel.
Parameters
- delegate
-
The observer object instance. To release the instance, set the value as nil. For details, see AgoraVideoFrameDelegate.
Returns
- 0: Success.
- < 0: Failure.
resumeAllChannelMediaRelay
Resumes the media stream relay to all destination channels.
- (int)resumeAllChannelMediaRelay;
After calling the pauseAllChannelMediaRelay method, you can call this method to resume relaying media streams to all destination channels.
After a successful method call, the SDK triggers the didReceiveChannelMediaRelayEvent callback to report whether the media stream relay is successfully resumed.
Returns
- 0: Success.
- < 0: Failure.
resumeAllEffects
Resumes playing all audio effects.
- (int)resumeAllEffects;
Returns
- 0: Success.
- < 0: Failure.
resumeEffect
Resumes playing a specified audio effect.
- (int)resumeEffect:(int)soundId;
Parameters
- soundId
- The audio effect ID. The ID of each audio effect file is unique.
Returns
- 0: Success.
- < 0: Failure.
setEffectsVolume
Sets the volume of the audio effects.
- (int)setEffectsVolume:(NSInteger)volume;
Parameters
- volume
- The playback volume. The value ranges from 0 to 100. The default value is 100, which represents the original volume.
Returns
- 0: Success.
- < 0: Failure.
setVolumeOfEffect
Sets the volume of a specified audio effect.
- (int)setVolumeOfEffect:(int)soundId withVolume:(int)volume;
Parameters
- soundId
- The audio effect ID. The ID of each audio effect file is unique.
- volume
- The playback volume. The value ranges from 0 to 100. The default value is 100, which represents the original volume.
Returns
- 0: Success.
- < 0: Failure.
stopAllEffects
Stops playing all audio effects.
- (int)stopAllEffects;
Returns
- 0: Success.
- < 0: Failure.
stopEffect
Stops playing a specified audio effect.
- (int)stopEffect:(int)soundId;
Parameters
- soundId
- The audio effect ID. The ID of each audio effect file is unique.
Returns
- 0: Success.
- < 0: Failure.
unloadEffect
Releases a specified preloaded audio effect from the memory.
- (int)unloadEffect:(int)soundId;
Parameters
- soundId
- The audio effect ID. The ID of each audio effect file is unique.
Returns
- 0: Success.
- < 0: Failure.
removePublishStreamUrl
Removes an RTMP or RTMPS stream from the CDN.
- (int)removePublishStreamUrl:(NSString * _Nonnull)url;
After a successful method call, the SDK triggers rtmpStreamingChangedToState on the local client to report the result of deleting the URL.
- Before calling this method, make sure that the media push function has been enabled. .
- This method takes effect only when you are a host in live interactive streaming.
- Call this method after joining a channel.
- This method removes only one media push URL each time it is called. To remove multiple URLs, call this method multiple times.
Parameters
- url
- The media push URL to be removed. The maximum length of this parameter is 1024 bytes. The media push URL must not contain special characters, such as Chinese characters.
Returns
- 0: Success.
- < 0: Failure.
renewToken
Gets a new token when the current token expires after a period of time.
- (int)renewToken:(NSString * _Nonnull)token;
- The SDK triggers the tokenPrivilegeWillExpire callback.
- The connectionChangedToState callback reports AgoraConnectionChangedReasonTokenExpired(9).
Parameters
- token
- The new token.
Returns
- 0(ERR_OK): Success.
- < 0: Failure.
- -1(ERR_FAILED): A general error occurs (no specified reason).
- -2 (ERR_INVALID_ARGUMENT): The parameter is invalid.
- -7(ERR_NOT_INITIALIZED): The SDK is not initialized.
resumeAudioMixing
Resumes playing and mixing the music file.
- (int)resumeAudioMixing;
This method resumes playing and mixing the music file. Call this method when you are in a channel.
Returns
- 0: Success.
- < 0: Failure.
sendCustomReportMessage
Reports customized messages.
- (int)sendCustomReportMessage:(NSString * _Nullable)messageId category:(NSString * _Nullable)category event:(NSString * _Nullable)event label:(NSString * _Nullable)label value:(NSInteger)value;
Agora supports reporting and analyzing customized messages. This function is in the beta stage with a free trial. The ability provided in its beta test version is reporting a maximum of 10 message pieces within 6 seconds, with each message piece not exceeding 256 bytes and each string not exceeding 100 bytes. To try out this function, contact support@agora.io and discuss the format of customized messages with us.
sendStreamMessage
Sends data stream messages.
- (int)sendStreamMessage:(NSInteger)streamId data:(NSData * _Nonnull)data;
- Up to 30 packets can be sent per second in a channel with each packet having a maximum size of 1 KB.
- Each client can send up to 6 KB of data per second.
- Each user can have up to five data streams simultaneously.
A successful method call triggers the receiveStreamMessageFromUid callback on the remote client, from which the remote user gets the stream message. A failed method call triggers the didOccurStreamMessageErrorFromUid callback on the remote client.
- Ensure that you call createDataStream [2/2] to create a data channel before calling this method.
- In live streaming scenarios, this method only applies to hosts.
Parameters
- streamId
- The data stream ID. You can get the data stream ID by calling createDataStream [2/2].
- data
- The message to be sent.
Returns
- 0: Success.
- < 0: Failure.
setAudioEffectParameters
Sets parameters for SDK preset audio effects.
- (int)setAudioEffectParameters:(AgoraAudioEffectPreset)preset param1:(int)param1 param2:(int)param2;
Detailed Description
- 3D voice effect: Sets the cycle period of the 3D voice effect.
- Pitch correction effect: Sets the basic mode and tonic pitch of the pitch correction effect. Different songs have different modes and tonic pitches. Agora recommends bounding this method with interface elements to enable users to adjust the pitch correction interactively.
After setting the audio parameters, all users in the channel can hear the effect.
- You can call this method either before or after joining a channel.
- To get better audio effect quality, Agora recommends calling and setting scenario in setAudioProfile [1/2] as AgoraAudioScenarioGameStreaming(3) before calling this method.
- Do not set the profile parameter in setAudioProfile [1/2] to AgoraAudioProfileSpeechStandard (1), or the method does not take effect.
- This method works best with the human voice. Agora does not recommend using this method for audio containing music.
- After calling setAudioEffectParameters, Agora recommends not calling the following methods, or the settings in setAudioEffectParameters are overridden :
Parameters
- preset
- The options for SDK preset audio effects:
- AgoraAudioEffectPresetRoomAcous3DVoice, 3D voice effect:
- Call and set the profile parameter in setAudioProfile [1/2] to AgoraAudioProfileMusicStandardStereo (3) or AgoraAudioProfileMusicHighQualityStereo(5) before setting this enumerator; otherwise, the enumerator setting does not take effect.
- If the 3D voice effect is enabled, users need to use stereo audio playback devices to hear the anticipated voice effect.
- AgoraAudioEffectPresetPitchCorrection, Pitch correction effect: To achieve better audio effect quality, Agora recommends calling setAudioProfile [1/2] and setting the profile parameter to AgoraAudioProfileMusicHighQuality (4) or AgoraAudioProfileMusicHighQualityStereo(5) before setting this enumerator.
- AgoraAudioEffectPresetRoomAcous3DVoice, 3D voice effect:
- param1
-
- If you set preset to AgoraAudioEffectPresetRoomAcous3DVoice , param1 sets the cycle period of the 3D voice effect. The value range is [1,60] and the unit is seconds. The default value is 10, indicating that the voice moves around you every 10 seconds.
- If you set preset to AgoraAudioEffectPresetPitchCorrection , param1 sets the basic mode of the pitch correction effect:
1
: (Default) Natural major scale.2
: Natural minor scale.3
: Japanese pentatonic scale.
- param2
-
- If you set preset to AgoraAudioEffectPresetRoomAcous3DVoice, you need to set param2 to
0
. - If you set preset to AgoraAudioEffectPresetPitchCorrection, param2 sets the tonic 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 you set preset to AgoraAudioEffectPresetRoomAcous3DVoice, you need to set param2 to
Returns
- 0: Success.
- < 0: Failure.
setAudioEffectPreset
Sets an SDK preset audio effect.
- (int)setAudioEffectPreset:(AgoraAudioEffectPreset)preset;
Detailed Description
Call this method to set an SDK preset audio effect for the local user who sends an audio stream. This audio effect does not change the gender characteristics of the original voice. After setting an audio effect, all users in the channel can hear the effect.
To get better audio effect quality, Agora recommends calling setAudioProfile [1/2] and setting the scenario parameter as AgoraAudioScenarioGameStreaming (3) before calling this method.
- You can call this method either before or after joining a channel.
- Do not set the profile parameter in setAudioProfile [1/2] to AgoraAudioProfileSpeechStandard (1), or the method does not take effect.
- This method works best with the human voice. Agora does not recommend using this method for audio containing music.
- If you call setAudioEffectPreset and set enumerators except for AgoraAudioEffectPresetRoomAcous3DVoice or AgoraAudioEffectPresetPitchCorrection, do not call setAudioEffectParameters; otherwise, setAudioEffectPreset is overridden.
- After calling setAudioEffectPreset, Agora recommends not calling the following methods, because they can override setAudioEffectPreset:
Parameters
- preset
- The options for SDK preset audio effects. See AgoraAudioEffectPreset.
Returns
- 0: Success.
- < 0: Failure.
setAudioMixingPosition
Sets the audio mixing position.
- (int)setAudioMixingPosition:(NSInteger)pos;
Call this method to set the playback position of the music file to a different starting position (the default plays from the beginning).
PLAY
) callback.Parameters
- pos
- Integer. The playback position (ms).
Returns
- 0: Success.
- < 0: Failure.
setAudioProfile [1/2]
Sets the audio profile and audio scenario.
- (int)setAudioProfile:(AgoraAudioProfile)profile scenario:(AgoraAudioScenario)scenario;
- You can call this method either before or after joining a channel.
- In scenarios requiring high-quality audio, such as online music tutoring, Agora recommends you set profile as AgoraAudioProfileMusicHighQuality (4), and scenario as AgoraAudioScenarioGameStreaming (3) or AgoraAudioScenarioHighDefinition(6).
Parameters
- profile
-
The audio profile, including the sampling rate, bitrate, encoding mode, and the number of channels. See AgoraAudioProfile.
- scenario
- The audio scenario. See AgoraAudioScenario. Under different audio scenarios, the device uses different volume types.
Returns
- 0: Success.
- < 0: Failure.
setAudioProfile [2/2]
Sets the audio parameters and application scenarios.
- (int)setAudioProfile:(AgoraAudioProfile)profile;
- You can call this method either before or after joining a channel.
- In scenarios requiring high-quality audio, such as online music tutoring, Agora recommends you set
profile
asAgoraAudioProfileMusicHighQuality (4)
. - If you want to set the audio scenario, call sharedEngineWithConfig and set audioScenario in the AgoraRtcEngineConfig struct.
Parameters
- profile
-
The audio profile, including the sampling rate, bitrate, encoding mode, and the number of channels. See AgoraAudioProfile.
Returns
- 0: Success.
- < 0: Failure.
setBeautyEffectOptions
Sets the image enhancement options.
- (int)setBeautyEffectOptions:(BOOL)enable options:(AgoraBeautyOptions* _Nullable)options;
Enables or disables image enhancement, and sets the options.
- Link the extension library in the project file:
AgoraVideoProcessExtension.framework
- Call
enableExtensionWithVendor(
to enable the extension.agora
,beauty
,YES
) - Call enableVideo to enable the video module.
- Call this method to enable the image enhancement function.
Parameters
- enable
- Whether to enable the image enhancement function:
YES
: Enable the image enhancement function.NO
: (Default) Disable the image enhancement function.
- options
The image enhancement options. See AgoraBeautyOptions.
Returns
- 0: Success.
- < 0: Failure.
setChannelProfile
Sets the channel profile.
- (int)setChannelProfile:(AgoraChannelProfile)profile;
After initializing the SDK, the default channel profile is the live streaming profile. You can call this method to set the usage scenario of Agora channel. The Agora SDK differentiates channel profiles and applies optimization algorithms accordingly. For example, it prioritizes smoothness and low latency for a video call and prioritizes video quality for interactive live video streaming.
- To ensure the quality of real-time communication, Agora recommends that all users in a channel use the same channel profile.
- This method must be called and set before joinChannelByToken [2/2], and cannot be set again after joining the channel.
Parameters
- profile
-
The channel profile. See AgoraChannelProfile for details.
Returns
- 0(ERR_OK): Success.
- < 0: Failure.
- -2(ERR_INVALID_ARGUMENT): The parameter is invalid.
- -7(ERR_NOT_INITIALIZED): The SDK is not initialized.
setCloudProxy
Sets the Agora cloud proxy service.
- (int)setCloudProxy:(AgoraCloudProxyType)proxyType NS_SWIFT_NAME(setCloudProxy(_:));
When users' network access is restricted by a firewall, , configure the firewall to allow specific IP addresses and ports provided by Agora; then, call this method to enable the cloud proxy and set the cloud proxy type with the proxyType parameter.
After successfully connecting to the cloud proxy, the SDK triggers the connectionChangedToState (AgoraConnectionStateConnecting, AgoraConnectionChangedReasonSettingProxyServer) callback.
To disable the cloud proxy that has been set, call the setCloudProxy(AgoraNoneProxy)
.
To change the cloud proxy type that has been set, call the setCloudProxy(AgoraNoneProxy)
first, and then call the setCloudProxy to set the proxyType you want.
- Agora recommends that you call this method before joining the channel or after leaving the channel.
- When a user is behind a firewall and uses the Force UDP cloud proxy, the services for Media Push and cohosting across channels are not available.
- When you use the Force TCP cloud proxy, note that an error would occur when calling the startAudioMixing [2/2] method to play online music files in the HTTP protocol. The services for Media Push and cohosting across channels use the cloud proxy with the TCP protocol.
Parameters
- proxyType
The type of the cloud proxy. See AgoraCloudProxyType.
This parameter is mandatory. The SDK reports an error if you do not pass in a value.
Returns
- 0: Success.
- < 0: Failure.
- -2: The parameter is invalid.
- -7: The SDK is not initialized.
setClientRole [1/2]
Sets the client role.
- (int)setClientRole:(AgoraClientRole)role;
You can call this method either before or after joining the channel to set the user role as audience or host.
If you call this method to set the user's role as the host before joining the channel and set the local video property through the setupLocalVideo method, the local video preview is automatically enabled when the user joins the channel.
- The local client: didClientRoleChanged.
- The remote client: didJoinedOfUid or
didOfflineOfUid(AgoraUserOfflineReasonBecomeAudience)
.
Parameters
- role
-
The user role. See AgoraClientRole for details.
Returns
- 0: Success.
- < 0: Failure.
- -1: A general error occurs (no specified reason).
- -2: The parameter is invalid.
- -7: The SDK is not initialized.
setClientRole [2/2]
Sets the user role and level in an interactive live streaming channel.
- (int)setClientRole:(AgoraClientRole)role options:(AgoraClientRoleOptions * _Nullable)options;
In the interactive live streaming profile, the SDK sets the user role as audience by default. You can call this method to set the user role as host.
You can call this method either before or after joining a channel.
If you call this method to set the user's role as the host before joining the channel and set the local video property through the setupLocalVideo method, the local video preview is automatically enabled when the user joins the channel.
- Calls muteLocalAudioStream and muteLocalVideoStream to change the publishing state.
- Triggers didClientRoleChanged on the local client.
- Triggers didJoinedOfUid or didOfflineOfUid on the remote client.
- The user role (role) determines the permissions that the SDK grants to a user, such as permission to send local streams, receive remote streams, and push streams to a CDN address.
- The user level (level) determines the level of services that a user can enjoy within the permissions of the user's role. For example, an audience member can choose to receive remote streams with low latency or ultra-low latency. User level affects the pricing of services.
Parameters
- role
- The user role in the interactive live streaming. For details, see AgoraClientRole.
- options
- The detailed options of a user, including the user level. See AgoraClientRoleOptions for details.
Returns
- 0: Success.
- < 0: Failure.
- -1: A general error occurs (no specified reason).
- -2: The parameter is invalid.
- -5: The request is rejected.
- -7: The SDK is not initialized.
setDefaultMuteAllRemoteAudioStreams
Stops or resumes subscribing to the audio streams of all remote users by default.
- (int)setDefaultMuteAllRemoteAudioStreams:(BOOL)mute;
Call this method after joining a channel. After successfully calling this method, the local user stops or resumes subscribing to the audio streams of all subsequent users.
- To resume subscribing to the audio stream of a specified user, call muteRemoteAudioStream(
NO
), and specify the user ID. - To resume subscribing to the audio streams of multiple remote users, call muteRemoteAudioStream (
NO
)multiple times.
Parameters
- mute
- Whether to stop subscribing to the audio streams of all remote users by default.
YES
: Stop subscribing to the audio streams of all remote users by default.NO
: (Default) Subscribe to the audio streams of all remote users by default.
Returns
- 0: Success.
- < 0: Failure.
setDefaultMuteAllRemoteVideoStreams
Stops or resumes subscribing to the video streams of all remote users by default.
- (int)setDefaultMuteAllRemoteVideoStreams:(BOOL)mute;
Call this method after joining a channel. After successfully calling this method, the local user stops or resumes subscribing to the audio streams of all subsequent users.
- To resume subscribing to the audio stream of a specified user, call muteRemoteVideoStream(
NO
), and specify the user ID. - To resume subscribing to the audio streams of multiple remote users, call muteRemoteVideoStream(
NO
)multiple times.
Parameters
- mute
-
Whether to stop subscribing to the audio streams of all remote users by default.
YES
: Stop subscribing to the audio streams of all remote users by default.NO
: (Default) Resume subscribing to the audio streams of all remote users by default.
Returns
- 0: Success.
- < 0: Failure.
setDevice
Specifies a device with the device ID.
- (int)setDevice:(AgoraMediaDeviceType)type deviceId:(NSString * _Nonnull)deviceId;
Parameters
- type
The device type, which includes the audio capturing, audio playback, video capturing, or video playback device. See AgoraMediaDeviceType.
- deviceId
- The device ID. You can get the device ID by calling enumerateDevices.Plugging or unplugging the audio device does not change the value of deviceId.
Returns
- 0: Success.
- < 0: Failure.
setDeviceVolume
Sets the volume of the specified device.
- (int)setDeviceVolume:(AgoraMediaDeviceType)type volume:(int)volume;
Sets the volume of audio or video capture or playback devices.
Parameters
- type
The device type, which includes the audio capturing, audio playback, video capturing, or video playback device. See AgoraMediaDeviceType.
- volume
- The volume of the specified device. The value ranges between 0 (lowest volume) and 255 (highest volume).
Returns
- 0: Success.
- < 0: Failure.
setEncryptionMode
Sets the built-in encryption mode.
- (int)setEncryptionMode:(NSString * _Nullable)encryptionMode;
- Deprecated:
- Use enableEncryption instead.
The Agora SDK supports built-in encryption, which is set to the AES-128-GCM mode by default. Call this method to use other encryption modes. All users in the same channel must use the same encryption mode and secret. Refer to the information related to the AES encryption algorithm on the differences between the encryption modes.
Parameters
- encryptionMode
-
Encryption mode.
- "
aes-128-xts
": 128-bit AES encryption, XTS mode. - "
aes-128-ecb
": 128-bit AES encryption, ECB mode. - "
aes-256-xts
": 256-bit AES encryption, XTS mode. - "
sm4-128-ecb
": 128-bit SM4 encryption, ECB mode. - "
aes-128-gcm
": 128-bit AES encryption, GCM mode. - "
aes-256-gcm
": 256-bit AES encryption, GCM mode. - "": When this parameter is set as null, the encryption mode is set as "
aes-128-gcm
" by default.
- "
Returns
- 0: Success.
- < 0: Failure.
setEncryptionSecret
Enables built-in encryption with an encryption password before users join a channel.
- (int)setEncryptionSecret:(NSString * _Nullable)secret;
- Deprecated:
- This method is deprecated from v3.2.0. Please use enableEncryption instead.
Before joining the channel, you need to call this method to set the secret parameter to enable the built-in encryption. All users in the same channel should use the same secret. The secret is automatically cleared once a user leaves the channel. If you do not specify the secret or secret is set as null, the built-in encryption is disabled.
- Do not use this method for CDN live streaming.
- For optimal transmission, ensure that the encrypted data size does not exceed the original data size + 16 bytes. 16 bytes is the maximum padding size for AES encryption.
Parameters
- secret
- The encryption password.
Returns
- 0: Success.
- < 0: Failure.
setExtensionPropertyWithVendor
Sets the properties of the extension.
- (int)setExtensionPropertyWithVendor:(NSString * __nonnull)provider extension:(NSString * __nonnull)extension key:(NSString * __nonnull)key value:(NSString * __nonnull)value;
After enabling the extension, you can call this method to set the properties of the extension.
Parameters
- provider
- The name of the extension provider.
- extension
- The name of the extension.
- key
- The key of the extension.
- value
- The value of the extension key.
Returns
- 0: Success.
- < 0: Failure.
setExtensionProviderPropertyWithVendor
Sets the properties of the extension provider.
- (int) setExtensionProviderPropertyWithVendor:(NSString * __nonnull)provider key:(NSString * __nonnull)key value:(NSString * __nonnull)value;
You can call this method to set the attributes of the extension provider and initialize the relevant parameters according to the type of the provider.
Call this method after enableExtensionWithVendor, and before enabling the audio (enableAudio/enableLocalAudio) or the video (enableVideo/enableLocalVideo).
Parameters
- provider
- The name of the extension provider.
- key
- The key of the extension.
- value
- The value of the extension key.
Returns
- 0: Success.
- < 0: Failure.
setExternalAudioSource [1/2]
Sets the external audio source.
- (int)setExternalAudioSource:(BOOL)enabled sampleRate:(NSInteger)sampleRate channels:(NSInteger)channels;
Call this method before calling joinChannelByToken [1/2] and startPreview.
Parameters
- enabled
-
YES
: Enable the external audio source.NO
: (Default) Disable the external audio source.
- sampleRate
- The sample rate (Hz) of the external audio source, which can be set as 8000, 16000, 32000, 44100, or 48000 Hz.
- channels
-
The number of audio channels of the external audio source:
- 1: Mono.
- 2: Stereo.
Returns
- 0: Success.
- < 0: Failure.
setExternalAudioSource [2/2]
Sets the external audio source parameters.
- (int)setExternalAudioSource:(BOOL)enabled sampleRate:(NSInteger)sampleRate channels:(NSInteger)channels sourceNumber:(NSInteger)sourceNumber localPlayback:(BOOL)localPlayback publish:(BOOL)publish;
Parameters
- enabled
-
Whether to enable the external audio source:
YES
: Enable the external audio source.NO
: (Default) Disable the external audio source.
- sampleRate
- The sample rate (Hz) of the external audio source, which can be set as
8000
,16000
,32000
,44100
, or48000
. - channels
- The number of channels of the external audio source, which can be set as
1
(Mono) or2
(Stereo). - sourceNumber
- The number of external audio sources. The value of this parameter should be larger than 0. The SDK creates a corresponding number of custom audio tracks based on this parameter value and names the audio tracks starting from 0. In AgoraRtcChannelMediaOptions, you can set publishCustomAudioSourceId to the ID of the audio track you want to publish.
- localPlayback
-
Whether to play the external audio source:
YES
: Play the external audio source.NO
: (Default) Do not play the external source.
- publish
-
Whether to publish audio to the remote users:
YES
: (Default) Publish audio to the remote users.NO
: Do not publish audio to the remote users
Returns
- 0: Success.
- < 0: Failure.
setExternalVideoSource
Configures the external video source.
- (void)setExternalVideoSource:(BOOL)enable useTexture:(BOOL)useTexture sourceType:(AgoraExternalVideoSourceType)sourceType;
Parameters
- enable
- Determines whether to use the external video source:
YES
: Use the external video source. The SDK prepares to accept the external video frame.NO
: (Default) Do not use the external video source.
- useTexture
- Determines whether to use the external video frame in the Texture format.
YES
: Use the external video frame in the Texture format.NO
: (Default) Do not use the external video frame in the Texture format.
- sourceType
- Whether to encode the external video frame, see AgoraExternalVideoSourceType.
Returns
- 0: Success.
- < 0: Failure.
setLiveTranscoding
Sets the transcoding configurations for media push.
- (int)setLiveTranscoding:(AgoraLiveTranscoding *_Nullable)transcoding;
This method sets the video layout and audio settings for media push. The SDK triggers the rtcEngineTranscodingUpdated callback when you call this method to update the transcoding settings.
- This method takes effect only when you are a host in live interactive streaming.
- Ensure that you enable the Media Push service before using this function. See Prerequisites in the advanced guide Media Push.
- If you call this method to set the transcoding configuration for the first time, the SDK does not trigger the rtcEngineTranscodingUpdated callback.
- Call this method after joining a channel.
- Agora only supports pushing media streams to the CDN in RTMPS protocol when you enable transcoding.
Parameters
- transcoding
-
The transcoding configurations for the media push. See AgoraLiveTranscoding for details.
Returns
- 0: Success.
- < 0: Failure.
setLocalRenderMode [1/2]
Sets the local video display mode.
- (int)setLocalRenderMode:(NSUInteger)uid mode:(AgoraVideoRenderMode) mode;
- Deprecated:
- This method is deprecated. Use setLocalRenderMode [2/2] instead.
Call this method to set the local video display mode. This method can be called multiple times during a call to change the display mode.
Parameters
- mode
-
The local video display mode. For details, see AgoraVideoRenderMode.
- uid
-
User ID
Returns
- 0: Success.
- < 0: Failure.
setLocalRenderMode [2/2]
Updates the display mode of the local video view.
- (int)setLocalRenderMode:(AgoraVideoRenderMode)mode mirror:(AgoraVideoMirrorMode)mirror;
After initializing the local video view, you can call this method to update its rendering and mirror modes. It affects only the video view that the local user sees, not the published local video stream.
- Ensure that you have called the setupLocalVideo method to initialize the local video view before calling this method.
- During a call, you can call this method as many times as necessary to update the display mode of the local video view.
Parameters
- mode
-
The local video display mode. For details, see AgoraVideoRenderMode.
- mirror
The rendering mode of the local video view. See AgoraVideoMirrorMode.
Attention: If you use a front camera, the SDK enables the mirror mode by default; if you use a rear camera, the SDK disables the mirror mode by default.
Returns
- 0: Success.
- < 0: Failure.
setLocalVideoMirrorMode
Sets the local video mirror mode.
- (int)setLocalVideoMirrorMode:(AgoraVideoMirrorMode)mode;
- Deprecated:
- Deprecated as of v3.0.0.
Parameters
- mode
-
The local video mirror mode. For details, see AgoraVideoMirrorMode.
Returns
- 0: Success.
- < 0: Failure.
setLocalVoiceChanger
Sets the local voice changer option.
- (int) setLocalVoiceChanger:(AgoraAudioVoiceChanger)voiceChanger;
- Deprecated:
- Deprecated from v3.2.0. Use the following methods instead:
- setAudioEffectPreset : Audio effects.
- setVoiceBeautifierPreset : Voice beautifier effects.
- setVoiceConversionPreset : Voice conversion effects.
VOICE_CHANGER_XXX
: Changes the local voice to an old man, a little boy, or the Hulk. Applies to the voice talk scenario.VOICE_BEAUTY_XXX
: Beautifies the local voice by making it sound more vigorous, resounding, or adding spacial resonance. Applies to the voice talk and singing scenario.GENERAL_VOICE_BEAUTY_XXX
: Adds gender-based beautification effect to the local voice. Applies to the voice talk scenario. For a male voice: Adds magnetism to the voice. For a male voice: Adds magnetism to the voice. For a female voice: Adds freshness or vitality to the voice.
- To achieve better voice effect quality, Agora recommends setting the setAudioProfile [1/2]profile parameter in asAgoraAudioProfileMusicHighQuality (4) orAgoraAudioProfileMusicHighQualityStereo (5).
- This method works best with the human voice, and Agora does not recommend using it for audio containing music and a human voice.
- Do not use this method with setLocalVoiceReverbPreset, because the method called later overrides the one called earlier. For detailed considerations, see the advanced guide Set the Voice Effect.
- You can call this method either before or after joining a channel.
Parameters
- voiceChanger
-
The local voice changer option. The default value is AgoraAudioVoiceChangerOff , which means the original voice. For more details, see AgoraAudioVoiceChanger. The gender-based beatification effect works best only when assigned a proper gender. Use AgoraAudioGeneralBeautyVoiceMaleMagnetic for male and use AgoraAudioGeneralBeautyVoiceFemaleFresh and AgoraAudioGeneralBeautyVoiceFemaleVitality for female. Failure to do so can lead to voice distortion.
Returns
- 0: Success.
- < 0: Failure.
setLocalVoiceEqualizationOfBandFrequency
Sets the local voice equalization effect.
- (int)setLocalVoiceEqualizationOfBandFrequency:(AgoraAudioEqualizationBandFrequency)bandFrequency withGain:(NSInteger)gain;
Parameters
- bandFrequency
- The band frequency. The value ranges between 0 and 9; representing the respective 10-band center frequencies of the voice effects, including 31, 62, 125, 250, 500, 1k, 2k, 4k, 8k, and 16k Hz. For more details, see AgoraAudioEqualizationBandFrequency.
- gain
- The gain of each band in dB. The value ranges between -15 and 15. The default value is 0.
Returns
- 0: Success.
- < 0: Failure.
setLocalVoicePitch
Changes the voice pitch of the local speaker.
- (int)setLocalVoicePitch:(double)pitch;
Parameters
- pitch
- The local voice pitch. The value range is [0.5,2.0]. The lower the value, the lower the pitch. The default value is 1 (no change to the pitch).
Returns
- 0: Success.
- < 0: Failure.
setLocalVoiceReverbOfType
Sets the local voice reverberation.
- (int)setLocalVoiceReverbOfType:(AgoraAudioReverbType)reverbType withValue:(NSInteger)value;
You can call this method either before or after joining a channel.
Parameters
- reverbType
- The reverberation key. Agora provides 5 reverberation keys: AgoraAudioReverbType.
- value
- The value of the reverberation key.
Returns
- 0: Success.
- < 0: Failure.
setLocalVoiceReverbPreset
Sets the local voice reverberation option, including the virtual stereo.
- (int) setLocalVoiceReverbPreset:(AgoraAudioReverbPreset)reverbPreset;
This method sets the local voice reverberation for users in a COMMUNICATION channel or hosts in a LIVE_BROADCASTING channel. After successfully calling this method, all users in the channel can hear the voice with reverberation.
- When using the enumeration value prefixed with
AUDIO_REVERB_FX
, ensure that you set the profile parameter in setAudioProfile [1/2] toAgoraAudioProfileMusicHighQuality(4) or AgoraAudioProfileMusicHighQualityStereo(5) before calling this method. Otherwise, the method setting is invalid. - When calling the AUDIO_VIRTUAL_STEREO method, Agora recommends setting the profile parameter in setAudioProfile [1/2] as AgoraAudioProfileMusicHighQualityStereo(5).
- This method works best with the human voice, and Agora does not recommend using it for audio containing music and a human voice.
- Do not use this method with setLocalVoiceChanger, because the method called later overrides the one called earlier. For detailed considerations, see the advanced guide Set the Voice Effect.
- You can call this method either before or after joining a channel.
Parameters
- reverbPreset
The local voice reverberation option. The default value is AgoraAudioReverbPresetOff, which means the original voice. For more details, see AgoraAudioReverbPreset. To achieve better voice effects, Agora recommends the enumeration whose name begins with
AUDIO_REVERB_FX
.
Returns
- 0: Success.
- < 0: Failure.
setLogFile
Set the log file
- (int)setLogFile:(NSString * _Nonnull)filePath;
- Deprecated:
- Use the
mLogConfig
parameter in sharedEngineWithConfig method instead.
Specifies an SDK output log file. The log file records all log data for the SDK’s operation. Ensure that the directory for the log file exists and is writable.
Ensure that you call this method immediately after calling the sharedEngineWithConfigAgoraRtcEngineKit method, or the output log may not be complete.
Parameters
- filePath
- The absolute path of the log files. These log files are encoded in UTF-8.
Returns
- 0: Success.
- < 0: Failure.
setLogFileSize
Sets the log file size.
- (int)setLogFileSize:(NSUInteger)fileSizeInKBytes;
- Deprecated:
- Use the
logConfig
parameter in sharedEngineWithConfig instead.
By default, the SDK generates five SDK log files and five API call log files with the following rules:
- The SDK log files are:
agorasdk.log
,agorasdk.1.log
,agorasdk.2.log
,agorasdk.3.log
, andagorasdk.4.log
. - The API call log files are:
agoraapi.log
,agoraapi.1.log
,agoraapi.2.log
,agoraapi.3.log
, andagoraapi.4.log
. - The default size for each SDK log file is 1,024 KB; the default size for each API call log file is 2,048 KB. These log files are encoded in UTF-8.
- The SDK writes the latest logs in
agorasdk.log
oragoraapi.log
. - When
agorasdk.log
is full, the SDK processes the log files in the following order:- Delete the
agorasdk.4.log
file (if any). - Rename
agorasdk.3.log
toagorasdk.4.log
. - Rename
agorasdk.2.log
toagorasdk.3.log
. - Rename
agorasdk.1.log
toagorasdk.2.log
. - Create a new
agorasdk.log
file.
- Delete the
- The overwrite rules for the
agoraapi.log
file are the same as foragorasdk.log
.
This method is used to set the size of the agorasdk.log
file only and does not effect the agoraapi.log file
.
Parameters
- fileSizeInKBytes
-
The size (KB) of an
agorasdk.log
file. The value range is [128,20480]. The default value is 1,024 KB. If you setfileSizeInKByte
smaller than 128 KB, the SDK automatically adjusts it to 128 KB; if you setfileSizeInKByte
greater than 20,480 KB, the SDK automatically adjusts it to 20,480 KB.
Returns
- 0: Success.
- < 0: Failure.
setLogFilter
Sets the log output level of the SDK.
- (int)setLogFilter:(NSUInteger)filter;
This method sets the output log level of the SDK. You can use one or a combination of the log filter levels. The log level follows the sequence of OFF, CRITICAL, ERROR, WARNING, INFO, and DEBUG. Choose a level to see the logs preceding that level.
If, for example, you set the log level to WARNING, you see the logs within levels CRITICAL, ERROR, and WARNING.
Parameters
- filter
- The output log level of the SDK. For details, see AgoraLogFilter.
Returns
- 0: Success.
- < 0: Failure.
setLogLevel
Sets the output log level of the SDK.
- (int)setLogLevel:(AgoraLogLevel)level;
- Deprecated:
- This method is deprecated. Use AgoraRtcEngineConfig instead to set the log output level.
Choose a level to see the logs preceding that level.
Parameters
- level
- The log level: AgoraLogLevel.
Returns
- 0: Success.
- < 0: Failure.
setMediaMetadataDataSource
Sets the data source of the metadata.
- (BOOL)setMediaMetadataDataSource:(id<AgoraMediaMetadataDataSource> _Nullable)metadataDataSource withType:(AgoraMetadataType)type;
You need to implement the AgoraMediaMetadataDataSource protocol in this method and specify the data format of the metadata. After a successful method call, the SDK triggers the metadataMaxSize callback.
This method can be used with setMediaMetadataDelegate to add synchronized metadata in the video stream for more diversified live interactions, such as sending shopping links, digital coupons, and online quizzes.
- Call this method before joining a channel.
- This method applies only to interactive live streaming.
Parameters
- metadataDataSource
- The AgoraMediaMetadataDataSource protocal.
- type
- The data type of the metadata. See AgoraMetadataType. We only support video metadata for now.
Returns
YES
: Success.NO
: Failure.
setMixedAudioFrameParametersWithSampleRate
Sets the audio data format reported by onMixedAudioFrame.
- (int)setMixedAudioFrameParametersWithSampleRate:(NSInteger)sampleRate channel:(NSInteger)channel samplesPerCall:(NSInteger)samplesPerCall;
Parameters
- sampleRate
-
The sample rate (Hz) of the audio data, which can be set as
8000
,16000
,32000
,44100
, or48000
.
- channel
-
The number of channels of the audio data, which can be set as
1
(Mono) or2
(Stereo).
- samplesPerCall
-
Sets the number of samples. In media push scenarios, set it as
1024
.
The SDK triggers the onMixedAudioFrame callback according to the sample interval. Sample interval (sec) = samplePerCall
/(sampleRate
× channel
). Ensure that the value of sample interval more than or equal to 0.01.
Returns
- 0: Success.
- < 0: Failure.
setPlaybackAudioFrameBeforeMixingParametersWithSampleRate
Sets the audio data format reported by onPlaybackAudioFrameBeforeMixing.
- (int)setPlaybackAudioFrameBeforeMixingParametersWithSampleRate:(NSInteger)sampleRate channel:(NSInteger)channel;
Sets the audio data format reported by onPlaybackAudioFrameBeforeMixing.
Parameters
- sampleRate
-
The sample rate returned in the callback, which can be set as
8000
,16000
,32000
,44100
, or48000
Hz.
- channel
-
The number of channels of the external audio source, which can be set as
1
(Mono) or2
(Stereo).
Returns
- 0: Success.
- < 0: Failure.
setPlaybackAudioFrameParametersWithSampleRate
Sets the audio data format for playback.
- (int)setPlaybackAudioFrameParametersWithSampleRate:(NSInteger)sampleRate channel:(NSInteger)channel mode:(AgoraAudioRawFrameOperationMode)mode samplesPerCall:(NSInteger)samplesPerCall;
Sets the data format for the onPlaybackAudioFrame callback.
- Ensure that you call this method before joining a channel.
- The SDK calculates the sampling interval based on the samplesPerCall, sampleRate and channel parameters set in this method.Sample interval (sec) = samplePerCall/(sampleRate × channel). Ensure that the sample interval ≥ 0.01 (s). The SDK triggers the onPlaybackAudioFrame callback according to the sampling interval.
Parameters
- sampleRate
- The sample rate returned in the onPlaybackAudioFrame callback, which can be set as 8000, 16000, 32000, 44100, or 48000 Hz.
- channel
-
The number of channels returned in the onPlaybackAudioFrame callback:
- 1: Mono.
- 2: Stereo.
- mode
The use mode of the audio frame. See AgoraAudioRawFrameOperationMode.
- samplesPerCall
- The number of data samples returned in the onPlaybackAudioFrame callback, such as 1024 for the media push.
Returns
- 0: Success.
- < 0: Failure.
setRecordingAudioFrameParametersWithSampleRate
Sets the format of the captured raw audio data.
- (int)setRecordingAudioFrameParametersWithSampleRate:(NSInteger)sampleRate channel:(NSInteger)channel mode:(AgoraAudioRawFrameOperationMode)mode samplesPerCall:(NSInteger)samplesPerCall;
Sets the audio format for the onRecordAudioFrame callback.
- Ensure that you call this method before joining a channel.
- The SDK calculates the sampling interval based on the samplesPerCall, sampleRate and channel parameters set in this method.Sample interval (sec) = samplePerCall/(sampleRate × channel). Ensure that the sample interval ≥ 0.01 (s). The SDK triggers the callback according to the sampling intervalonRecordAudioFrame.
Parameters
- sampleRate
- The sample rate returned in the onRecordAudioFrame callback, which can be set as 8000, 16000, 32000, 44100, or 48000 Hz.
- channel
-
The number of channels returned in the onRecordAudioFrame callback:
- 1: Mono.
- 2: Stereo.
- mode
-
The use mode of the audio frame. See AgoraAudioRawFrameOperationMode.
- samplesPerCall
- The number of data samples returned in the onRecordAudioFrame callback, such as 1024 for the media push.
Returns
- 0: Success.
- < 0: Failure.
setRemoteDefaultVideoStreamType
Sets the default stream type of remote video streams.
- (int)setRemoteVideoStream:(NSUInteger)uid type:(AgoraVideoStreamType)streamType;
Under limited network conditions, if the publisher has not disabled the dual-stream mode using (),the receiver can choose to receive either the high-quality video stream or the low-quality video stream. The high-quality video stream has a higher resolution and bitrate, and the low-quality video stream has a lower resolution and bitrate.enableDualStreamMode [1/3]NO
By default, users receive the high-quality video stream. Call this method if you want to switch to the low-quality video stream. This method allows the app to adjust the corresponding video stream type based on the size of the video window to reduce the bandwidth and resources. The aspect ratio of the low-quality video stream is the same as the high-quality video stream. Once the resolution of the high-quality video stream is set, the system automatically sets the resolution, frame rate, and bitrate of the low-quality video stream.
The result of this method returns in the didApiCallExecute callback.
Parameters
- streamType
-
The default stream type of the remote video, see AgoraVideoStreamType.
Returns
- 0: Success.
- < 0: Failure.
setRemoteRenderMode [1/2]
Sets the video display mode of a specified remote user.
- (int)setRemoteRenderMode:(NSUInteger)uid mode:(AgoraVideoRenderMode) mode;
- Deprecated:
- This method is deprecated. Use setRemoteRenderMode [2/2] instead.
Call this method to set the video display mode of a specified remote user. This method can be called multiple times during a call to change the display mode.
Parameters
- userId
- The ID of the remote user.
- renderMode
-
The rendering mode of the remote user view. For details, see AgoraVideoRenderMode.
Returns
- 0: Success.
- < 0: Failure.
setRemoteRenderMode [2/2]
Updates the display mode of the video view of a remote user.
- (int)setRemoteRenderMode:(NSUInteger)uid mode:(AgoraVideoRenderMode)mode mirror:(AgoraVideoMirrorMode)mirror;
After initializing the video view of a remote user, you can call this method to update its rendering and mirror modes. This method affects only the video view that the local user sees.
- Please call this method after initializing the remote view by calling the setupRemoteVideo method.
- During a call, you can call this method as many times as necessary to update the display mode of the video view of a remote user.
Parameters
- userId
-
The ID of the remote user.
- renderMode
-
The rendering mode of the remote user view. For details, see AgoraVideoRenderMode.
- mirrorMode
The mirror mode of the remote user view. For details, see AgoraVideoMirrorMode.
Returns
- 0: Success.
- < 0: Failure.
setRemoteVideoStream
Sets the stream type of the remote video.
- (int)setRemoteVideoStream:(NSUInteger)uid type:(AgoraVideoStreamType)streamType;
Under limited network conditions, if the publisher has not disabled the dual-stream mode using enableDualStreamMode [1/3](NO), the receiver can choose to receive either the high-quality video stream (the high resolution, and high bitrate video stream) or the low-quality video stream (the low resolution, and low bitrate video stream). The high-quality video stream has a higher resolution and bitrate, and the low-quality video stream has a lower resolution and bitrate.
By default, users receive the high-quality video stream. Call this method if you want to switch to the low-quality video stream. This method allows the app to adjust the corresponding video stream type based on the size of the video window to reduce the bandwidth and resources. The aspect ratio of the low-quality video stream is the same as the high-quality video stream. Once the resolution of the high-quality video stream is set, the system automatically sets the resolution, frame rate, and bitrate of the low-quality video stream.
The method result returns in the didApiCallExecute callback.
Parameters
- uid
- User ID.
- streamType
-
The video stream type: AgoraVideoStreamType.
Returns
- 0: Success.
- < 0: Failure.
setRemoteVoicePosition
Sets the 2D position (the position on the horizontal plane) of the remote user's voice.
- (int)setRemoteVoicePosition:(NSUInteger)uid pan:(double)pan gain:(double)gain;
This method sets the 2D position and volume of a remote user, so that the local user can easily hear and identify the remote user's position.
When the local user calls this method to set the voice position of a remote user, the voice difference between the left and right channels allows the local user to track the real-time position of the remote user, creating a sense of space. This method applies to massive multiplayer online games, such as Battle Royale games.
- For this method to work, enable stereo panning for remote users by calling the enableSoundPositionIndication method before joining a channel.
- For the best voice positioning, Agora recommends using a wired headset.
- Call this method after joining a channel.
Parameters
- uid
- The user ID of the remote user.
- pan
- The voice position of the remote user. The value ranges from -1.0 to 1.0:
- 0.0: (Default) The remote voice comes from the front.
- -1.0: The remote voice comes from the left.
- 1.0: The remote voice comes from the right.
- gain
- The volume of the remote user. The value ranges from 0.0 to 100.0. The default value is 100.0 (the original volume of the remote user). The smaller the value, the lower the volume.
Returns
- 0: Success.
- < 0: Failure.
setupLocalVideo
Initializes the local video view.
- (int)setupLocalVideo:(AgoraRtcVideoCanvas * _Nullable)local;
This method initializes the video view of a local stream on the local device. It affects only the video view that the local user sees, not the published local video stream. Call this method to bind the local video stream to a video view and to set the rendering and mirror modes of the video view.
After initialization, call this method to set the local video and then join the channel. The local video still binds to the view after you leave the channel. To unbind the local video from the view, set the view parameter as nil.
- You can call this method either before or after joining a channel.
- To update the rendering or mirror mode of the local video view during a call, use the setLocalRenderMode [2/2] method.
Parameters
- local
- The local video view and settings. For details, see AgoraRtcVideoCanvas.
Returns
- 0: Success.
- < 0: Failure.
setupRemoteVideo
Initializes the video view of a remote user.
- (int)setupRemoteVideo:(AgoraRtcVideoCanvas * _Nonnull)remote;
This method initializes the video view of a remote stream on the local device. It affects only the video view that the local user sees. Call this method to bind the remote video stream to a video view and to set the rendering and mirror modes of the video view.
You need to specify the ID of the remote user in this method. If the remote user ID is unknown to the application, set it after the app receives the didJoinedOfUid callback.
To unbind the remote user from the view, set the view parameter to NULL.
Once the remote user leaves the channel, the SDK unbinds the remote user.
- To update the rendering or mirror mode of the remote video view during a call, use the setRemoteRenderMode [2/2] method.
- If you use the Agora recording feature, the recording client joins the channel as a dummy client, triggering the didJoinedOfUid callback. Do not bind the dummy client to the app view because the dummy client does not send any video streams. If your app does not recognize the dummy client, bind the remote user to the view when the SDK triggers the firstRemoteVideoDecodedOfUid callback.
Parameters
- remote
-
The remote video view and settings. For details, see AgoraRtcVideoCanvas.
Returns
- 0: Success.
- < 0: Failure.
setVideoEncoderConfiguration
Sets the video encoder configuration.
- (int)setVideoEncoderConfiguration:(AgoraVideoEncoderConfiguration * _Nonnull)config;
Sets the encoder configuration for the local video.
Parameters
- config
- Video profile. See AgoraVideoEncoderConfiguration.
Returns
- 0: Success.
- < 0: Failure.
setVideoProfile [1/2]
Sets the video encoder configuration.
- (int)setVideoProfile:(AgoraVideoProfile)profile swapWidthAndHeight:(BOOL)swapWidthAndHeight
- Deprecated:
- This method is deprecated as of v2.3. Please use setVideoEncoderConfiguration instead.
This method sets the video encoder configuration. You can call this method either before or after joining a channel. If the user does not need to reset the video encoding properties after joining the channel, Agora recommends calling this method before enableVideo to reduce the time to render the first video frame.
Parameters
- profile
- Video profile. For details, see AgoraVideoProfile.
- swapWidthAndHeight
The SDK outputs video with a fixed width and height according to the video profile (profile) you selected. This parameter sets whether to swap width and height of the video:
YES
: Swap the width and height.NO
: (Default) Do not swap the width and height.
Returns
- 0: Success.
- < 0: Failure.
setVideoProfile [2/2]
Sets the video encoder configuration.
- (int)setVideoResolution:(CGSize)size andFrameRate:(NSInteger)frameRate bitrate:(NSInteger)bitrate;
- Deprecated:
- This method is deprecated as of v2.3. Please use setVideoEncoderConfiguration instead.
This method sets the video encoder configuration. You can call this method either before or after joining a channel. If the user does not need to reset the video encoding properties after joining the channel, Agora recommends calling this method before enableVideo to reduce the time to render the first video frame.
Parameters
- width
- The width of the video. The maximum value of width × height is 1280 × 720.
- height
- The height of the video. The maximum value of width × height is 1280 × 720.
- frameRate
- The frame rate of the video. The highest value is 30. You can set the parameter as 5, 10, 15, 24, and 30.
- bitrate
- The bitrate of the video. You need to manually work out the bitrate according to the width, height, and frame rate. With the same width and height, the bitrate varies with the frame rate:
- If the frame rate is 5 fps, divide the recommended bitrate by 2.
- If the frame rate is 15 fps, use the recommended bitrate.
- If the frame rate is 30 fps, multiply the recommended bitrate by 1.5.
- Calculate the bitrate according to the ratio if you choose other frame rates.
- If you set a bitrate beyond the proper range, the SDK automatically adjusts the bitrate to a value within the proper range.
setVideoQualityParameters
Sets the preferences for high-quality video. (LIVE_BROADCASTING only).
- (int)setVideoQualityParameters:(BOOL)preferFrameRateOverImageQuality;
- Deprecated:
- Deprecated as of v2.4.0. Agora recommends using the degradationPreference parameter in the AgoraVideoEncoderConfiguration class to set the video quality preference.
Parameters
- preferFrameRateOverImageQuality
-
Whether to prioritize smoothness or image quality.
YES
: Prioritizes smoothness.NO
: (Default) Prioritizes the image quality.
Returns
- 0: Success.
- < 0: Failure.
setVoiceBeautifierParameters
Sets parameters for the preset voice beautifier effects.
- (int)setVoiceBeautifierParameters:(AgoraVoiceBeautifierPreset)preset param1:(int)param1 param2:(int)param2;
Call this method to set a gender characteristic and a reverberation effect for the singing beautifier effect. This method sets parameters for the local user who sends an audio stream. After setting the audio parameters, all users in the channel can hear the effect.
For better voice effects, Agora recommends that you call setAudioProfile [1/2] and setscenario to AgoraAudioScenarioGameStreaming(3) and profile to AgoraAudioProfileMusicHighQuality(4) or AgoraAudioProfileMusicHighQualityStereo(5) before calling this method.
- You can call this method either before or after joining a channel.
- Do not set the profile parameter of setAudioProfile [1/2] to AgoraAudioProfileSpeechStandard(1). Otherwise, the method does not take effect.
- This method works best with the human voice. Agora does not recommend using this method for audio containing music.
- After calling setVoiceBeautifierParameters, Agora recommends not calling the following methods, because they can override settings in setVoiceBeautifierParameters:
Parameters
- preset
- The option for the preset audio effect:
SINGING_BEAUTIFIER
: The singing beautifier effect.
- param1
- The gender characteristics options for the singing voice:
1
: A male-sounding voice.2
: A female-sounding voice.
- param2
- The reverberation effect options for the singing voice:
1
: The reverberation effect sounds like singing in a small room.2
: The reverberation effect sounds like singing in a large room.3
: The reverberation effect sounds like singing in a hall.
Returns
- 0: Success.
- < 0: Failure.
setVoiceBeautifierPreset
Sets a preset voice beautifier effect.
- (int)setVoiceBeautifierPreset:(AgoraVoiceBeautifierPreset)preset;
Call this method to set a preset voice beautifier effect for the local user who sends an audio stream. After setting a voice beautifier effect, all users in the channel can hear the effect. You can set different voice beautifier effects for different scenarios.
For better voice effects, Agora recommends that you call setAudioProfile [1/2] and set scenario to AgoraAudioScenarioGameStreaming (3) and profile to AgoraAudioProfileMusicHighQuality (4) or AgoraAudioProfileMusicHighQualityStereo (5) before calling this method.
- You can call this method either before or after joining a channel.
- Do not set the profile parameter in setAudioProfile [1/2] to AgoraAudioProfileSpeechStandard(1), or the method does not take effect.
- This method works best with the human voice. Agora does not recommend using this method for audio containing music.
- After calling setVoiceBeautifierPreset, Agora recommends not calling the following methods, because they can override setVoiceBeautifierPreset:
Parameters
- preset
-
The preset voice beautifier effect options: AgoraVoiceBeautifierPreset.
Returns
- 0: Success.
- < 0: Failure.
setVoiceConversionPreset
Sets a preset voice beautifier effect.
- (int)setVoiceConversionPreset:(AgoraVoiceConversionPreset)preset;
Call this method to set a preset voice beautifier effect for the local user who sends an audio stream. After setting an audio effect, all users in the channel can hear the effect. You can set different audio effects for different scenarios. See Set the Voice Beautifier and Audio Effects.
To achieve better audio effect quality, Agora recommends that you call setAudioProfile [1/2] and set the profile to AgoraAudioProfileMusicHighQuality(4) or AgoraAudioProfileMusicHighQualityStereo(5) and scenario to AgoraAudioScenarioGameStreaming(3) before calling this method.
- You can call this method either before or after joining a channel.
- Do not setsetAudioProfile [1/2] the profile parameter in to AgoraAudioProfileSpeechStandard(1), or the method does not take effect.
- This method works best with the human voice. Agora does not recommend using this method for audio containing music.
- After calling setVoiceConversionPreset, Agora recommends not calling the following methods, or the settings in setVoiceConversionPreset are overridden :
Parameters
- preset
The options for the preset voice beautifier effects: AgoraVoiceConversionPreset.
Returns
- 0: Success.
- < 0: Failure.
startAudioDeviceLoopbackTest
Starts an audio device loopback test.
-(int)startAudioDeviceLoopbackTest:(int)indicationInterval;
This method tests whether the local audio capture device and playback device are working properly. After starting the test, the audio capture device records the local audio, and the audio playback device plays the captured audio. The SDK triggers two independent reportAudioVolumeIndicationOfSpeakers callbacks at the time interval set in this method, which reports the volume information of the capture device (uid = 0) and the volume information of the playback device (uid = 1) respectively.
- Ensure that you call this method before joining a channel.
- This method tests local audio devices and does not report the network conditions.
Parameters
- indicationInterval
- The time interval (ms) at which the SDK triggers the reportAudioVolumeIndicationOfSpeakers callback. Agora recommends a setting greater than 200 ms. This value must not be less than 10 ms; otherwise, you can not receive the reportAudioVolumeIndicationOfSpeakers callback.
Returns
- 0: Success.
- < 0: Failure.
startAudioMixing [1/2]
Starts playing the music file.
- (int)startAudioMixing:(NSString * _Nonnull)filePath loopback:(BOOL)loopback replace:(BOOL)replace cycle:(NSInteger)cycle;
- Deprecated:
- Please use startAudioMixing [2/2] instead.
This method mixes the specified local or online audio file with the audio from the microphone, or replaces the microphone's audio with the specified local or remote audio file. A successful method call triggers the audioMixingStateChanged (AgoraAudioMixingStateTypePlaying) callback. When the audio mixing file playback finishes, the SDK triggers the audioMixingStateChanged (AgoraAudioMixingStateTypeStopped) callback on the local client.
- Call this method after joining a channel. If you need to call startAudioMixing [1/2] multiple times, ensure that the time interval between calling this method is more than 500 ms.
- If the local audio mixing file does not exist, or if the SDK does not support the file format or cannot access the music file URL, the SDK returns
WARN_AUDIO_MIXING_OPEN_ERROR
(701).
Parameters
- filePath
The absolute path or URL address (including the suffixes of the filename) of the audio effect file. For example:
/var/mobile/Containers/Data/audio.mp4
. Supported audio formats include MP3, AAC, M4A, MP4, WAV, and 3GP. See supported audio formats.- loopback
- Whether to only play music files on the local client:
YES
: Only play music files on the local client so that only the local user can hear the music.NO
: Publish music files to remote clients so that both the local user and remote users can hear the music.
- replace
- Whether to replace the audio captured by the microphone with a music file:
YES
: Replace the audio captured by the microphone with a music file. Users can only hear the music.NO
: Do not replace the audio captured by the microphone with a music file. Users can hear both music and audio captured by the microphone.
- cycle
- The number of times the music file plays.
- ≥ 0: The number of playback times. For example, 0 means that the SDK does not play the music file while 1 means that the SDK plays once.
- -1: Play the audio effect in an infinite loop.
Returns
- 0: Success.
- < 0: Failure.
startAudioMixing [2/2]
Starts playing the music file.
- (int)startAudioMixing:(NSString* _Nonnull)filePath loopback:(BOOL)loopback replace:(BOOL)replace cycle:(NSInteger)cycle startPos:(NSInteger)startPos;
This method mixes the specified local or online audio file with the audio from the microphone, or replaces the microphone's audio with the specified local or remote audio file. A successful method call triggers the audioMixingStateChanged (PLAY
) callback. When the audio mixing file playback finishes, the SDK triggers the audioMixingStateChanged (STOPPED
) callback on the local client.
- Call this method after joining a channel. If you need to call startAudioMixing [2/2] multiple times, ensure that the time interval between calling this method is more than 500 ms.
- If the local audio mixing file does not exist, or if the SDK does not support the file format or cannot access the music file URL, the SDK returns
WARN_AUDIO_MIXING_OPEN_ERROR
(701).
Parameters
- filePath
- The absolute path or URL address (including the suffixes of the filename) of the audio effect file. For example:
/var/mobile/Containers/Data/audio.mp4
. Supported audio formats include MP3, AAC, M4A, MP4, WAV, and 3GP. See supported audio formats. - loopcount
- Whether to only play music files on the local client:
YES
: Only play music files on the local client so that only the local user can hear the music.NO
: Publish music files to remote clients so that both the local user and remote users can hear the music.
- replace
- Whether to replace the audio captured by the microphone with a music file:
YES
: Replace the audio captured by the microphone with a music file. Users can only hear the music.NO
: Do not replace the audio captured by the microphone with a music file. Users can hear both music and audio captured by the microphone.
- cycle
- The number of times the music file plays.
- ≥ 0: The number of playback times. For example, 0 means that the SDK does not play the music file while 1 means that the SDK plays once.
- -1: Play the music effect in an infinite loop.
- startPos
- The playback position (ms) of the music file.
Returns
- 0: Success.
- < 0: Failure.
startAudioRecording [1/2]
Starts audio recording on the client.
- (int)startAudioRecording:(NSString * _Nonnull)filePath quality:(AgoraAudioRecordingQuality)quality;
- Deprecated:
- This method is deprecated as of v2.9.1. It has a fixed recording sample rate of 32 kHz. Please use the startAudioRecording [2/2] method instead.
.wav
: Large file size with high fidelity..aac
: Small file size with low fidelity.
Ensure that the directory for the recording file exists and is writable. This method should be called after the joinChannelByToken [1/2] method. The recording automatically stops when you call the leaveChannel [1/2] method.
Parameters
- filePath
- The absolute path (including the filename extensions) of the recording file. For example:
/var/mobile/Containers/Data/audio.mp4
.Attention:Ensure that the directory for the log files exists and is writable.
- quality
- Audio recording quality. See AgoraAudioRecordingQuality.
Returns
- 0: Success.
- < 0: Failure.
startAudioRecording [2/2]
Starts audio recording on the client.
- (int)startAudioRecordingWithConfig:(AgoraAudioRecordingConfiguration * _Nonnull)config;
- WAV: High-fidelity files with typically larger file sizes. For example, if the sample rate is 32,000 Hz, the file size for 10-minute recording is approximately 73 MB.
- AAC: Low-fidelity files with typically smaller file sizes. For example, if the sample rate is 32,000 Hz and the recording quality is AgoraAudioRecordingQualityMedium, the file size for 10-minute recording is approximately 2 MB.
Once the user leaves the channel, the recording automatically stops.
Parameters
- config
- Recording configuration. See AgoraAudioRecordingConfiguration.
Returns
- 0: Success.
- < 0: Failure.
startChannelMediaRelay
Starts relaying media streams across channels. This method can be used to implement scenarios such as co-host across channels.
- (int)startChannelMediaRelay:(AgoraChannelMediaRelayConfiguration * _Nonnull)config;
- If the channelMediaRelayStateDidChange callback returns AgoraChannelMediaRelayStateRunning (2) and AgoraChannelMediaRelayErrorNone (0), and the didReceiveChannelMediaRelayEvent callback returns AgoraChannelMediaRelayEventSentToDestinationChannel (4), it means that the SDK starts relaying media streams between the source channel and the destination channel.
- If the channelMediaRelayStateDidChange callback returns AgoraChannelMediaRelayStateFailure (3), an exception occurs during the media stream relay.
- Call this method after joining the channel.
- This method takes effect only when you are a host in a live streaming channel.
- After a successful method call, if you want to call this method again, ensure that you call the stopChannelMediaRelay method to quit the current relay.
- You need to submit a ticket before implementing this function.
- We do not support string user accounts in this API.
Parameters
- config
- The configuration of the media stream relay. See AgoraChannelMediaRelayConfiguration for details.
Returns
- Success.
- <Failure.
startEchoTest
Starts an audio call test.
- (int)startEchoTest:(void(^ _Nullable) (NSString * _Nonnull channel, NSUInteger uid, NSInteger elapsed))successBlock;
- Deprecated:
- This method is deprecated as of v2.4.0. Use startEchoTestWithInterval instead.
This method starts an audio call test to determine whether the audio devices (for example, headset and speaker) and the network connection are working properly. To conduct the test, the user speaks, and the recording is played back within 10 seconds. If the user can hear the recording within the interval, the audio devices and network connection are working properly.
- Call this method before joining a channel.
- After calling stopEchoTest, you must call startEchoTest to end the test. Otherwise, the app cannot perform the next echo test, and you cannot join the channel.
- In the live streaming channels, only a host can call this method.
Parameters
- successBlock
- The SDK triggers the successBlock callback if this method call is successful.
Returns
- 0: Success.
- < 0: Failure.
startEchoTestWithInterval
Starts an audio call test.
- (int)startEchoTestWithInterval:(NSInteger)interval successBlock:(void(^ _Nullable) (NSString * _Nonnull channel, NSUInteger uid, NSInteger elapsed))successBlock;
This method starts an audio call test to determine whether the audio devices (for example, headset and speaker) and the network connection are working properly. To conduct the test, let the user speak for a while, and the recording is played back within the set interval. If the user can hear the recording within the interval, the audio devices and network connection are working properly.
- Call this method before joining a channel.
- After calling stopEchoTest, you must call startEchoTestWithInterval to end the test. Otherwise, the app cannot perform the next echo test, and you cannot join the channel.
- In the live streaming channels, only a host can call this method.
Parameters
- interval
- The time interval (s) between when you speak and when the recording plays back.
- successBlock
- The SDK triggers the successBlock callback if this method call is successful.
Returns
- 0: Success.
- < 0: Failure.
startLastmileProbeTest
Starts the last mile network probe test.
- (int)startLastmileProbeTest:(AgoraLastmileProbeConfig *_Nullable)config;
This method starts the last-mile network probe test before joining a channel to get the uplink and downlink last mile network statistics, including the bandwidth, packet loss, jitter, and round-trip time (RTT).
- lastmileQuality: The SDK triggers this callback within two seconds depending on the network conditions. This callback rates the network conditions and is more closely linked to the user experience.
- lastmileProbeTestResult: The SDK triggers this callback within 30 seconds depending on the network conditions. This callback returns the real-time statistics of the network conditions and is more objective.
- Before a user joins a channel, call this method to check the uplink network quality.
- In a live streaming channel, call this method to check the uplink network quality before an audience member switches to a host.
- Do not call other methods before receiving the lastmileQuality and lastmileProbeTestResult callbacks. Otherwise, the callbacks may be interrupted.
- A host should not call this method after joining a channel (when in a call).
Parameters
- config
- The configurations of the last-mile network probe test. See AgoraLastmileProbeConfig.
Returns
- 0: Success.
- < 0: Failure.
startPlaybackDeviceTest
Starts the audio playback device test.
- (int)startPlaybackDeviceTest:(NSString * _Nonnull)audioFileName;
This method tests whether the audio playback device works properly. Once a user starts the test, the SDK plays an audio file specified by the user. If the user can hear the audio, the playback device works properly.
After calling this method, the SDK triggers the reportAudioVolumeIndicationOfSpeakers callback every 100 ms, reporting uid = 1 and the volume information of the playback device.
Parameters
- audioFileName
-
The path of the audio file for the audio playback device test in UTF-8.
Returns
- 0: Success.
- < 0: Failure.
startPreview
Enables the local video preview.
- (int)startPreview;
This method starts the local video preview before joining the channel. Before calling this method, ensure that you do the following:
- Call setupLocalVideo to set the local preview window.
- Call enableVideo to enable the video.
- The local preview enables the mirror mode by default.
- After the local video preview is enabled, if you call leaveChannel [1/2] to exit the channel, the local preview remains until you call stopPreview to disable it.
Returns
- 0: Success.
- < 0: Failure.
startRecordingDeviceTest
Starts the audio capture device test.
- (int)startRecordingDeviceTest:(int)indicationInterval;
This method tests whether the audio capture device works properly. After calling this method, the SDK triggers the reportAudioVolumeIndicationOfSpeakers callback at the time interval set in this method, which reports uid = 0 and the volume information of the capturing device.
Parameters
- indicationInterval
- The time interval (ms) at which the SDK triggers the reportAudioVolumeIndicationOfSpeakers callback. Agora recommends a setting greater than 200 ms. This value must not be less than 10 ms; otherwise, you can not receive the reportAudioVolumeIndicationOfSpeakers callback.
Returns
- 0: Success.
- < 0: Failure.
startScreenCaptureByDisplayId
Shares the screen by specifying the display ID.
- (int)startScreenCaptureByDisplayId:(UInt32)displayId regionRect:(CGRect)regionRect captureParams:(AgoraScreenCaptureParameters *_Nonnull)captureParams;
This method shares a screen or part of the screen. You need to specify the ID of the screen to be shared in this method.
Call this method after joining a channel.
Parameters
- displayId
- The display ID of the screen to be shared. This parameter specifies which screen you want to share.
For more information on how to get the display ID, see https://docs.agora.io/en/live-streaming-4.x-beta/screensharing_ios_ng?platform=macOS.
- regionRect
- (Optional) Sets the relative location of the region to the screen. If you do not set this parameter, the SDK shares the whole screen. It consists of the following parameters:
- x: The horizontal offset from the top-left corner.
- y: The vertical offset from the top-left corner.
- width: The width of the region.
- height: The height of the region.
If the specified region overruns the screen, the SDK shares only the region within it; if you set width or height as 0, the SDK shares the whole screen.
- captureParams
- Screen sharing configurations. The default video dimension is 1920 x 1080, that is, 2,073,600 pixels. Agora uses the value of this parameter to calculate the charges. See AgoraScreenCaptureParameters for details.
Returns
- 0: Success.
- < 0: Failure.
startScreenCaptureByWindowId
Shares the whole or part of a window by specifying the window ID.
- (int)startScreenCaptureByWindowId:(UInt32)windowId regionRect:(CGRect)regionRect captureParams:(AgoraScreenCaptureParameters *_Nonnull)captureParams;
This method shares a window or part of the window. You need to specify the ID of the window to be shared.
Call this method after joining a channel.
Parameters
- windowId
- The ID of the window to be shared.
- regionRect
- (Optional) The relative location of the region to the window. If you do not set this parameter, the SDK shares the whole window. It consists of the following parameters:
- x: The horizontal offset from the top-left corner.
- y: The vertical offset from the top-left corner.
- width: The width of the region.
- height: The height of the region.
If the specified region overruns the window, the SDK shares only the region within it; if you set width or height as 0, the SDK shares the whole window.
- captureParams
- Screen sharing configurations. The default video dimension is 1920 x 1080, that is, 2,073,600 pixels. Agora uses the value of this parameter to calculate the charges. For details, see AgoraScreenCaptureParameters.
Returns
- 0: Success.
- < 0: Failure.
updateScreenCaptureParameters
Updates the screen sharing parameters.
- (int)updateScreenCaptureParameters:(AgoraScreenCaptureParameters * _Nonnull)captureParams;
Parameters
- captureParams
- The screen sharing encoding parameters. The default video dimension is 1920 x 1080, that is, 2,073,600 pixels. Agora uses the value of this parameter to calculate the charges. For details, see AgoraScreenCaptureParameters.
Returns
- 0: Success.
- < 0: Failure.
updateScreenCaptureRegion
Updates the screen sharing region.
- (int)updateScreenCaptureRegion:(CGRect)rect;
Parameters
- rect
- The relative location of the region to the screen or window. If you do not set this parameter, the SDK shares the whole screen. If the specified region overruns the screen or window, the SDK shares only the region within it; if you set width or height as 0, the SDK shares the whole screen or window.
Returns
- 0: Success.
- < 0: Failure.
startRtmpStreamWithoutTranscoding
Starts pushing media streams to a CDN without transcoding.
- (int)startRtmpStreamWithoutTranscoding:(NSString* _Nonnull)url;
You can call this method to push a live audio-and-video stream to the specified CDN address and set the transcoding configuration. This method can push media streams to only one CDN address at a time, so if you need to push streams to multiple addresses, call this method multiple times.
After you call this method, the SDK triggers the rtmpStreamingChangedToState callback on the local client to report the state of the streaming.
- Ensure that you enable the Media Push service before using this function.
- Call this method after joining a channel.
- Only hosts in the LIVE_BROADCASTING profile can call this method.
- If you want to retry pushing streams after a failed push, make sure to call stopRtmpStream first, then call this method to retry pushing streams; otherwise, the SDK returns the same error code as the last failed push.
Parameters
- url
- The address of Media Push. The format is RTMP or RTMPS. The character length cannot exceed 1024 bytes. Special characters such as Chinese characters are not supported.
Returns
- 0: Success.
- < 0: Failure.
- -2: url is null or the string length is 0.
- -7: The SDK is not initialized before calling this method.
startRtmpStreamWithTranscoding
Starts Media Push and sets the transcoding configuration.
- (int)startRtmpStreamWithTranscoding:(NSString* _Nonnull)url transcoding:(AgoraLiveTranscoding* _Nullable)transcoding;
You can call this method to push a live audio-and-video stream to the specified CDN address and set the transcoding configuration. This method can push media streams to only one CDN address at a time, so if you need to push streams to multiple addresses, call this method multiple times.
After you call this method, the SDK triggers the rtmpStreamingChangedToState callback on the local client to report the state of the streaming.
- Ensure that you enable the Media Push service before using this function.
- Call this method after joining a channel.
- Only hosts in the LIVE_BROADCASTING profile can call this method.
- If you want to retry pushing streams after a failed push, make sure to call stopRtmpStream first, then call this method to retry pushing streams; otherwise, the SDK returns the same error code as the last failed push.
Parameters
- url
- The address of Media Push. The format is RTMP or RTMPS. The character length cannot exceed 1024 bytes. Special characters such as Chinese characters are not supported.
- transcoding
-
The transcoding configuration for Media Push. See AgoraLiveTranscoding.
Returns
- 0: Success.
- < 0: Failure.
- -2: url is null or the string length is 0.
- -7: The SDK is not initialized before calling this method.
stopScreenCapture
Stops screen sharing.
- (int)stopScreenCapture;
Returns
- 0: Success.
- < 0: Failure.
stopAudioDeviceLoopbackTest
Stops the audio device loopback test.
-(int)stopAudioDeviceLoopbackTest;
- Ensure that you call this method before joining a channel.
- Ensure that you call this method to stop the loopback test after calling the startAudioDeviceLoopbackTest method.
Returns
- 0: Success.
- < 0: Failure.
stopAudioMixing
Stops playing and mixing the music file.
- (int)stopAudioMixing;
This method stops the audio mixing. Call this method when you are in a channel.
Returns
- 0: Success.
- < 0: Failure.
stopAudioRecording
Stops the audio recording on the client.
- (int)stopAudioRecording;
If you call startAudioRecording [2/2] to start recording, you can call this method to stop the recording.
Returns
- 0: Success.
- < 0: Failure.
stopChannelMediaRelay
Stops the media stream relay. Once the relay stops, the host quits all the destination channels.
- (int)stopChannelMediaRelay;
After a successful method call, the SDK triggers the channelMediaRelayStateDidChange callback. If the callback reports AgoraChannelMediaRelayStateIdle (0) and AgoraChannelMediaRelayErrorNone (0), the host successfully stops the relay.
Returns
- 0: Success.
- < 0: Failure.
stopEchoTest
Stops the audio call test.
- (int)stopEchoTest;
Returns
- 0: Success.
-
< 0: Failure.
- -5(ERR_REFUSED): Failed to stop the echo test. The echo test may not be running.
stopLastmileProbeTest
Stops the last mile network probe test.
- (int)stopLastmileProbeTest;
Returns
- 0: Success.
- < 0: Failure.
stopPreview
Stops the local video preview.
- (int)stopPreview;
Returns
- 0: Success.
- < 0: Failure.
stopPlaybackDeviceTest
Stops the audio playback device test.
- (int)stopPlaybackDeviceTest;
This method stops the audio playback device test. You must call this method to stop the test after calling the startPlaybackDeviceTest method.
Returns
- 0: Success.
- < 0: Failure.
stopRecordingDeviceTest
Stops the audio capture device test.
- (int)stopRecordingDeviceTest;
This method stops the audio capture device test. You must call this method to stop the test after calling the startRecordingDeviceTest method.
Returns
- 0: Success.
- < 0: Failure.
stopRtmpStream
Stops pushing media streams to a CDN.
- (int)stopRtmpStream:(NSString* _Nonnull)url;
You can call this method to stop the live stream on the specified CDN address. This method can stop pushing media streams to only one CDN address at a time, so if you need to stop pushing streams to multiple addresses, call this method multiple times.
After you call this method, the SDK triggers the rtmpStreamingChangedToState callback on the local client to report the state of the streaming.
Parameters
- url
- The address of Media Push. The format is RTMP or RTMPS. The character length cannot exceed 1024 bytes. Special characters such as Chinese characters are not supported.
Returns
- 0: Success.
- < 0: Failure.
takeSnapshot
Takes a snapshot of a video stream.
- (NSInteger)takeSnapshot:(NSString* _Nonnull)channel uid:(NSInteger)uid filePath:(NSString* _Nonnull)filePath;
This method takes a snapshot of a video stream from the specified user, generates a JPG image, and saves it to the specified path.
- Call this method after joining a channel.
- If the video of the specified user is pre-processed, for example, added with watermarks or image enhancement effects, the generated snapshot also includes the pre-processing effects.
Parameters
- channel
- The channel name.
- uid
- The user ID. Set uid as 0 if you want to take a snapshot of the local user's video.
- filePath
- The local path (including the filename extensions) of the snapshot. For example,
- macOS: ~/Library/Logs/example.jpg
Returns
- 0: Success.
- < 0: Failure.
unregisterAudioSpectrumDelegate
Unregisters the audio spectrum observer.
- (int) unregisterAudioSpectrumDelegate:(id<AgoraAudioSpectrumDelegate> _Nullable)delegate;
After calling registerAudioSpectrumDelegate, if you want to disable audio spectrum monitoring, you can call this method.
Parameters
- delegate
- The Audio spectrum observer. For details, see AgoraAudioSpectrumDelegate.
Returns
- 0: Success.
- < 0: Failure.
updateChannelWithMediaOptions
Updates the channel media options after joining the channel.
- (int)updateChannelWithMediaOptions:(AgoraRtcChannelMediaOptions* _Nonnull)mediaOptions;
Parameters
- mediaOptions
- The channel media options. See AgoraRtcChannelMediaOptions.
Returns
- 0: Success.
- < 0: Failure.
updateChannelMediaRelay
Updates the channels for media stream relay.
- (int)updateChannelMediaRelay:(AgoraChannelMediaRelayConfiguration * _Nonnull)config;
After the media relay starts, if you want to relay the media stream to more channels, or leave the current relay channel, you can call the updateChannelMediaRelay method.
After a successful method call, the SDK triggers the didReceiveChannelMediaRelayEvent callback with the AgoraChannelMediaRelayEventUpdateDestinationChannel (7) state code.
Parameters
- config
- The configuration of the media stream relay. For more details, see AgoraChannelMediaRelayConfiguration.
Returns
- 0: Success.
- < 0: Failure.
updateRtmpTranscoding
Updates the transcoding configuration.
- (int)updateRtmpTranscoding:(AgoraLiveTranscoding* _Nullable)transcoding;
After you start pushing media streams to CDN with transcoding, you can dynamically update the transcoding configuration according to the scenario. The SDK triggers the rtcEngineTranscodingUpdated callback after the transcoding configuration is updated.
Parameters
- transcoding
-
The transcoding configuration for Media Push. See AgoraLiveTranscoding.
Returns
- 0: Success.
- < 0: Failure.