CloudHubSDK Android
Channel management
initEngine
Initialize the SDK engine.
public static int initEngine(Context context, RtcEngineListener listener,String configs,String appId,boolean enableMultiCamera)
Parameters
Parameters | Description |
---|---|
context | Android context |
listener | Event listener of RtcEngineListener interface |
configs | Keep Parameters |
appId | The App ID provided by CloudHub for app developers. Only apps with the same App ID can enter the same channel for calls or live broadcasts. One App ID can only be used to create one RtcEngine |
enableMultiCamera | Whether to allow multiple cameras to publish at the same time |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Details
Please call the interface method of the RtcEngine class on the main thread.
When multi-camera publishing is allowed, the device id of the camera must be specified for each stream published, and the stream cannot be switched to other devices after publishing, unless republished; if multi-camera publishing is not allowed, only one video stream can be published, but this The stream can be switched to other devices, and in each API method that contains cameraIdParameters, cameraIdParameters is ignored.
Note
- This method can be called multiple times, but only when it is called for the first time, the SDK engine singleton is initialized.
initEngine3
Initialize the SDK engine.
public static int initEngine3(Context context, RtcEngineListener listener,String configs,String appId,boolean enableMultiCamera)
Parameters
Parameters | Description |
---|---|
context | Android application context |
listener | Event listener that implements the RtcEngineListener interface |
configs | Reserved Parameters |
appId | App ID provided by CloudHub for app developers. Only apps with the same App ID can enter the same channel for calls or live broadcasts. One App ID can only be used to create one RtcEngine3 |
enableMultiCamera | Whether to allow multiple cameras to be released at the same time |
Returns
- 0: The method is called successfully
- Non-zero: method call failed
Details
Please call the interface method of the RtcEngine3 class on the main thread.
When multi-camera publishing is allowed, the device id of the camera must be specified for each stream published, and the stream cannot be switched to other devices after it is published, unless it is republished; if multi-camera publishing is not allowed, only one video stream can be published, but this The stream can be switched to other devices, and in each API method that contains cameraIdParameters, cameraIdParameters is ignored.
Note
- This method can be called multiple times, but only when it is called for the first time, the SDK engine singleton is initialized.
setChannelProfile
Sets the channel profile of the CloudHub RtcEngine.
public static int setChannelProfile(int profile)
Parameters
Parameters | Description |
---|---|
profile | The channel profile of the Cloudhub RtcEngine:: * CHANNEL_PROFILE_COMMUNICATION(0), Communication. This profile applies to scenarios such as an audio call or video call, where all users can publish and subscribe to streams. * CHANNEL_PROFILE_LIVE_BROADCASTING(1), Live interactive steaming. In this profile, uses have roles, namely, host and audience (default). A host can both publish and subscribe to streams, while an audience can only subscribe to streams. This profile applies to scenarios such as a chat room or interactive video streaming. |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Details
After initialization, the SDK uses the CHANNEL_PROFILE_COMMUNICATION channel profile by default. You can call setChannelProfile to set the channel profile. The CloudHub RtcEngine differentiates channel profiles and applies different optimization algorithms accordingly. For example, it prioritizes smoothness and low latency for a video call, and prioritizes video quality for a video live interactive streaming.
Note
- Users in the same channel must use the same channel scene.
- This method must be called before joining the channel, and the channel scene cannot be set after entering the channel.
setClientRole
Sets the role of the user in interactive live streaming.
public static int setClientRole(int role)
Parameters
Parameters | Description |
---|---|
role | The role of a user in interactive live streaming: * CLIENT_ROLE_BROADCASTER(1), Host. A host can both send and receive streams. If you set this user role in the channel, the SDK automatically calls muteLocalAudioStream(false) and muteLocalVideoStream(false) * CLIENT_ROLE_AUDIENCE(2), Audience. An audience member can only receive streams. If you set this user role in the channel, the SDK automatically calls muteLocalAudioStream(true) and muteLocalVideoStream(true) |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Details
Before joining the channel, the user needs to set the audience (default) or anchor role through this method. After joining the channel, the user can switch user roles through this method. If you call this method to switch user roles after joining a channel, after the call is successful, the local onClientRoleChanged callback will be triggered; the remote will trigger onUserLeft and onUserJoined callbacks.
Note
- This method is only applicable to live broadcast scenes.
- When calling the publishStream method, the user role will be automatically switched to the anchor role.
joinChannel
Allows a user to join a channel.
public static int joinChannel(String channelId, String uid, String token, String properties,boolean autoSubscribeAudio,boolean autoSubscribeVideo)
Parameters
Parameters | Description |
---|---|
channelId | Channel number. Must be a combination of letters and numbers |
uid | The unique identifier of the user in the channel. Must be a combination of letters and numbers. If it is empty, the SDK will automatically generate a GUID as the uid and notify it through the onJoinChannelSuccess callback |
token | The token generated by the developer’s service side. If the safety requirements are not high, you can pass the null |
properties | User-defined attributes. Will be synchronized to other users in the channel. It must be a json string and can be passed empty |
autoSubscribeAudio | Subscribe to audio automatically |
autoSubscribeVideo | Subscribe to video automatically |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Details
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 AppId cannot call each other. You must call the leaveChannel method to exit the current call before joining another channel. A successful method call of joinChannel triggers the following callbacks: The local client: onJoinChannelSuccess. The remote client: onUserJoined, 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 CloudHub server is interrupted due to poor network conditions, the SDK tries reconnecting to the server. When the local client successfully rejoins the channel, the SDK triggers the onRejoinChannelSuccess callback on the local client. Once the user joins the channel (switches to another 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. If you do not want to subscribe to a specified stream or all remote streams, call the mute methods accordingly.
Note
- The uid of each user in the channel cannot be repeated. If it is repeated, when a user with the same uid later enters, it will trigger the previous user to leave the channel automatically. At this time, the previous user will receive the onLocalUserEvicted callback.
leaveChannel
Allows a user to leave a channel.
public static int leaveChannel()
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Details
After joining a channel, the user must call the leaveChannel method to end the call before joining another channel. This method returns 0 if the user leaves the channel and releases all resources related to the call. This method call is asynchronous, and the user has not exited the channel when the method call returns. Once the user leaves the channel, the SDK triggers the onLeaveChannel callback.
A successful method call of leaveChannel triggers the following callbacks:
The local client: onLeaveChannel. The remote client: onUserOffline, if the user leaving the channel is in the Communication channel, or is a host in the LIVE_BROADCASTING profile
renewToken
Renews the token when the current token expires.
public static int renewToken(String token)
Parameters
Parameters | Description |
---|---|
token | The new token. |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Details
The token expires after a period of time once the token schema is enabled when:
- onTokenWillExpire callback
- onRequestToken callback
The app should retrieve a new token from the server and call this method to renew it. Failure to do so results in the SDK disconnecting from the server.
getConnectionState
Gets the connection state of the SDK
public static int getConnectionState()
Returns
- CONNECTION_STATE_DISCONNECTED(1)
- CONNECTION_STATE_CONNECTING(2)
- CONNECTION_STATE_CONNECTED(3)
- CONNECTION_STATE_RECONNECTING(4)
- CONNECTION_STATE_FAILED(5)
setListener
Replace the event callback listener.
public static int setListener(RtcEngineListener listener)
Parameters
Parameters | Description |
---|---|
listener | The new event listener object |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Details
Replace the old listener with the new listener.
Note
The listener can be set to null, but it should be noted that if the listener is null, you cannot receive event notifications from the engine.
Audio management
enableAudio
Enables the audio module.
public static int enableAudio(boolean enable)
Parameters
Parameters | Description |
---|---|
enable | true :Start the audio engine false:Close the audio engine |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
adjustRecordingSignalVolume
Adjusts the volume of the signal captured by the microphone.
int adjustRecordingSignalVolume(int volume)
Parameters
Parameter | Description |
---|---|
volume | The volume of the signal captured by the microphone. Including the following: • 0: Mute. • 400: (Default) Original volume. |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
adjustPlaybackSignalVolume
djusts the playback signal volume of all remote users.
int adjustPlaybackSignalVolume(int volume)
Parameters
Parameter | Description |
---|---|
volume | The volume of the signal captured by the microphone. Including the following: • 0: Mute. • 400: (Default) Original volume. |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
adjustUserPlaybackSignalVolume
Adjusts the playback signal volume of a specified remote user.
int adjustUserPlaybackSignalVolume(String uid, int volume)
Parameters
Parameter | Description |
---|---|
uid | The ID of the remote user |
— | — |
volume | The volume of the signal captured by the microphone. Including the following: • 0: Mute. • 100: (Default) Original volume. |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
enableLocalAudio
Enables/Disables the local audio capture.
public static int enableLocalAudio(boolean enable)
Parameters
Parameters | Description |
---|---|
enable | * true:Turn on local voice capture * false : Stop local voice capture |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Details
The audio function is enabled by default. This method disables/re-enables the local audio function, that is, to stop or restart local audio capture and processing.
This method does not affect receiving the remote audio streams, and enableLocalAudio(false)
is applicable to scenarios where the user wants to receive remote audio streams without sending any audio stream to other users in the channel.
Note
This method is different from the muteLocalAudioStream method:
- enableLocalAudio Disables/Re-enables the local audio capture and processing. If you disable or re-enable local audio sampling using the enableLocalAudio method, the local user may hear a pause in the remote audio playback.
- muteLocalAudioStream Stops/Continues sending the local audio streams.
muteLocalAudioStream
Stops or resumes publishing the local audio stream.
public static int muteLocalAudioStream(boolean mute)
Parameters
Parameters | Description |
---|---|
mute | Sets whether to stop publishing the local audio stream. * true:Stop publishing the local audio stream. * false:Resume publishing the local audio stream. |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Details
This method is used to allow/prohibit sending local audio streams to the network. After successfully calling this method, the remote end will trigger the onRemoteAudioStateChanged callback (reason is REMOTE_VIDEO_STATE_REASON_REMOTE_MUTED / REMOTE_VIDEO_STATE_REASON_REMOTE_UNMUTED.state_reason_video.
Note
This method does not affect the recording state, and does not disable the microphone.
muteRemoteAudioStream
Stops or resumes subscribing to the audio stream of a specified user.
public static int muteRemoteAudioStream(String uid, boolean mute)
Parameters
Parameters | Description |
---|---|
uid | The user ID of the specified remote user. |
mute | Sets whether to stop subscribing to the audio stream of a specified user. true: Stop subscribing to the audio stream of a specified user. false: (Default) Resume subscribing to the audio stream of a specified user. |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Note
If you have previously called muteAllRemoteAudioStreams(true) to mute all remote audio, please make sure you have called muteAllRemoteAudioStreams before calling this API /#muteallremoteaudiostreams)(false). muteAllRemoteAudioStreams is global control, muteRemoteAudioStream is fine control.
muteAllRemoteAudioStreams
Stops or resumes subscribing to the audio streams of all remote users.
public static int muteAllRemoteAudioStreams(boolean mute)
Parameters
Parameters | Description |
---|---|
mute | Sets whether to stop subscribing to the audio streams of all remote users. true: Stop subscribing to the audio streams of all remote users. false: (Default) Resume subscribing to the audio streams of all remote users. |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
setDefaultMuteAllRemoteAudioStreams
Sets whether to receive all remote audio streams by default.
public static int setDefaultMuteAllRemoteAudioStreams(boolean mute)
Parameters
Parameters | Description |
---|---|
mute | * True:Stop subscribing to the audio streams of all remote users by default. * False:(Default) Resume subscribing to the audio streams of all remote users by default. |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Video management
enableVideo
Enable/disable the video module.
public static int enableVideo(boolean enable)
Parameters
Parameters | Description |
---|---|
enable | true: enable, false: disable |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Details
This method is used to enable/disable the video mode. It can be called before joining a channel or during a call. Call enableVideo(true) before joining a channel, then the video mode is automatically turned on, and enableVideo(true) switches from audio mode to video mode. Call enableVideo(false) to turn off the video mode.
Note
- This method sets the internal engine to be enabled, and it is still valid after leaveChannel.
- This method resets the entire engine, and the response speed is slow, so we recommend using the following methods to control the video module:
- enableLocalVideo: Whether to start camera capture and create a local video stream
- muteLocalVideoStream: whether to publish local video stream
- muteRemoteVideoStream: Whether to receive and play the remote video stream
- muteAllRemoteVideoStreams: Whether to receive and play all remote video streams
setVideoEncoderConfiguration
Sets the video encoder configuration.
java public static int setVideoEncoderConfiguration(String cameraId, int maxWidth, int maxHeight, int maxFps, int orientationMode)
Parameters
Parameters | Description |
---|---|
cameraId | Specifies the ID of the camera to be operated. If it is a single camera mode, the Parameters are ignored |
maxWidth | Allowable maximum width |
maxHeight | Allowable maximum height |
maxFps | Maximum frame rate allowed |
orientationMode | Video rotation mode, the value is as follows: * ORIENTATION_MODE_ADAPTIVE(0), default adaptive; * ORIENTATION_MODE_FIXED_LANDSCAPE(1), landscape mode * ORIENTATION_MODE_FIXED_PORTRAIT(2), portrait mode |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Details
This method sets the video encoding Parameters. All the set parameters are the maximum value under ideal conditions. When the video engine cannot reach the maximum resolution or frame rate set due to equipment, network environment, etc., it will take the value closest to the maximum.
startPlayingLocalVideo
Start playing local video.
public static int startPlayingLocalVideo(String cameraId, RtcSurfaceViewRenderer renderer, int renderMode, int mirrorMode)
Parameters
Parameters | Description |
---|---|
cameraId | Specify the camera ID to be operated. If it is a single-camera mode, this Parameters is ignored |
renderer | View window for displaying video |
renderMode | Display mode, the values are as follows: * RENDER_MODE_HIDDEN(1), fill the window, the image may be cropped * RENDER_MODE_FIT( 2), show all, the window may have black borders |
mirrorMode | Mirror mode, the value is as follows: * VIDEO_MIRROR_MODE_ENABLED(1) * VIDEO_MIRROR_MODE_DISABLED(2) |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Details
Call this method to start previewing the local video. Need to call enableVideo and enableLocalVideo in advance to start the local camera. When you leave the channel and enter again, you need to call this method again to start previewing the local video again.
Note
If you want to update the display or mirroring mode of the local video during a call, please use the setLocalVideoRenderMode / setLocalVideoMirrorMode method.
startPlayingRemoteVideo
Start playing the remote video.
public static int startPlayingRemoteVideo(String streamId, RtcSurfaceViewRenderer renderer, int renderMode, int mirrorMode)
Parameters
Parameters | Description |
---|---|
streamId | ID of the remote video stream |
mediaType | The media type of the remote stream, the values are as follows: * MEDIA_TYPE_AUDIO_ONLY(1) *MEDIA_TYPE_AUDIO_AND_VIDEO(3) *MEDIA_TYPE_ONLINE_MOVIE_VIDEO(4) *MEDIA_TYPE_OFFLINE_MOVIE_VIDEO(5) *MEDIA_TYPE_SCREEN_VIDEO(6) |
renderer | View window for displaying video |
renderMode | see startPlayingLocalVideo |
mirrorMode | see startPlayingLocalVideo |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Details Call this method to start playing the remote video. You need to call enableVideo in advance to enable the video engine.
Note
If you want to update the display or mirroring mode of the remote user’s video during a call, please use the setRemoteVideoRenderMode / setRemoteVideoMirrorMode method.
setLocalVideoRenderMode
Set the display mode of the local video.
public static int setLocalVideoRenderMode(String cameraId, int renderMode)
Parameters
Parameters | Description |
---|---|
cameraId | Specify the camera ID to be operated. If it is a single-camera mode, this Parameters is ignored |
renderMode | see startPlayingLocalVideo |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Details
After playing the local video, you can call this method to update the display mode of the local video. This method only affects the video images seen by local users, and does not affect the video images published locally.
Note
- Please call this method after calling the startPlayingLocalVideo method.
- This method can be called multiple times during a call.
setLocalVideoMirrorMode
Sets the local video mirror mode.
public static int setLocalVideoMirrorMode(String cameraId, int mirrorMode)
Parameters
Parameters | Description |
---|---|
cameraId | Specify the camera ID to be operated. If it is a single-camera mode, this Parameters is ignored |
mirrorMode | See. startPlayingLocalVideo |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Details
After playing the local video, you can call this method to update the mirror mode of the local video. This method only affects the video images seen by the local users, and does not affect the locally published video images.
Note
- Please call this method after calling the startPlayingLocalVideo method.
- This method can be called multiple times during a call.
setRemoteVideoRenderMode
Set the display mode of the remote video.
public static int setRemoteVideoRenderMode(String streamId, int renderMode)
Parameters
Parameters | Description |
---|---|
streamId | ID of the remote video stream |
renderMode | See startPlayingLocalVideo |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Details
After playing the remote user’s video, you can call this method to update the display mode of the remote user’s video when it is displayed locally. This method only affects the video images seen by local users.
Note
- Please call this method after calling the startPlayingRemoteVideo method.
- This method can be called multiple times during a call.
setRemoteVideoMirrorMode
Set the mirror mode of the remote video.
public static int setRemoteVideoMirrorMode(String streamId, int mirrorMode)
Parameters
Parameters | Description |
---|---|
streamId | ID of the remote video stream |
mirrorMode | See startPlayingLocalVideo |
Returns
- 0(ERR_OK): Success.
- <0: Failure
Details
After playing the remote user’s video, you can call this method to update the mirror mode when the remote user’s video is displayed locally. This method only affects the video images seen by local users.
Note
- Please call this method after calling the startPlayingRemoteVideo method.
- This method can be called multiple times during a call.
stopPlayingLocalVideo
Stop playing local video.
public static int stopPlayingLocalVideo(String cameraId)
Parameters
Parameters | Description |
---|---|
cameraId | Specify the camera ID to be operated. If it is a single-camera mode, this Parameters is ignored |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
stopPlayingRemoteVideo
Stop playing the remote video.
public static int stopPlayingRemoteVideo(String streamId)
Parameters
Parameters | Description |
---|---|
streamId | ID of the remote video stream |
mediaType | See startPlayingRemoteVideo |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
enableLocalVideo
Disables/Re-enables the local video capture.
public static int enableLocalVideo(String cameraId, boolean enable)
Parameters
Parameters | Description |
---|---|
cameraId | Specify the camera ID to be operated. If it is a single camera mode, the Parameters are ignored |
enable | Whether to disable/re-enable the local video, including the capturer, renderer, and sender: * true: (Default) Re-enable the local video. * false: Disable the local video. 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 other remote users. When you set enabled as false, this method does not require a local camera. |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Details
This method disables or re-enables local video capture and does not affect the reception of remote video.
muteLocalVideoStream
Stops or resumes publishing the local video stream.
public static int muteLocalVideoStream(String cameraId,boolean mute)
Parameters
Parameters | Description |
---|---|
cameraId | Specify the camera ID to be operated. If it is a single camera mode, the Parameters are ignored |
mute | * true: Stop publishing the local video stream. * false: Resume publishing the local video stream. |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Details
After the method is successfully called, the remote end will trigger the onRemoteVideoStateChanged callback, the reason is REMOTE_VIDEO_STATE_REASON_REMOTE_MUTED.
Note
When this method is called, the SDK no longer sends the local video stream, but the camera is still working. Compared with enableLocalVideo for controlling the sending of local video streams, this method has a faster response time. This method does not affect the acquisition of local video streams and does not disable the camera.
muteRemoteVideoStream
Stops or resumes subscribing to the video stream of a specified user.
public static int muteRemoteVideoStream(String streamId, boolean mute)
Parameters
Parameters | Description |
---|---|
streamId | ID of the remote video stream |
mute | * true:Stop subscribing to the video stream of a specified user. * false: (Default) Resume subscribing to the video stream of a specified user. |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Details
After the method is successfully called, the onRemoteVideoStateChanged callback will be triggered locally, and the reason is REMOTE_VIDEO_STATE_REASON_LOCAL_MUTED
muteAllRemoteVideoStreams
Stops or resumes subscribing to the video streams of all remote users.
public static int muteAllRemoteVideoStreams(boolean mute)
Parameters
Parameters | Description |
---|---|
mute | * true:Stop subscribing to the video streams of all remote users. * false:(Default) Resume subscribing to the video streams of all remote users. |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
setDefaultMuteAllRemoteVideoStreams
Sets whether to receive all remote video streams by default.
public static int setDefaultMuteAllRemoteVideoStreams (boolean mute)
Parameters
Parameters | Description |
---|---|
mute | * true:Stop subscribing to the video streams of all remote users by default. * false:(Default) Resume subscribing to the video streams of all remote users by default. |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
hookLocalVideoFrame
Allow/disable local video data callback.
public static int hookLocalVideoFrame(String cameraId,boolean hook)
Parameters
Parameters | Description |
---|---|
cameraId | Specify the camera ID to be operated. If it is a single-camera mode, this Parameters is ignored |
hook | Whether to allow local video data callbacks. * true: allowed * false: prohibited (default) |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Details
This method controls whether the original video data of the local camera is called back to the application layer, but does not control the start or stop of the collection behavior.
setLocalVideoHD
Set local video HD capture.
public static int setLocalVideoHD(String cameraId)
Parameters
Parameters | Description |
---|---|
cameraId | Specify the camera ID to be operated. If it is a single-camera mode, this Parameters is ignored |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Details
This method enables high-definition local video capture, but does not affect the size of the video sent to the remote end. The sent video will be cut, stretched, etc., controlled by setVideoEncoderConfiguration.
Video pre-process and post-process
setBeautyEffectOptions
public static int setBeautyEffectOptions(String cameraId, boolean enabled, BeautyOptions options)
Enables/Disables image enhancement and sets the options.
Parameters
Parameters | Description |
---|---|
cameraId | Specify the camera ID to be operated. If it is a single-camera mode, this Parameters is ignored |
enabled | Whether to enable image enhancement:: * true:Enables image enhancement. * false:Disables image enhancement. |
options | The image enhancement options. See BeautyOptions |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
setVideoEffectOptions
public static int setVideoEffectOptions(boolean enabled, Structs.VideoEffectOptions options, String sourceID)
Set up advanced beauty
Parameters
| Parameters | Description |
| ——– | —————————————- ——————– |
| enabled | Whether to enable the beauty function:
* true: enable
* false: (default) disable |
| options | Beauty options, see VideoEffectOptions for detailed definitions |
| sourceID | Specify the SourceID to be operated. If it is a single camera mode, this Parameters is ignored |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Multi-channel management
createChannel
Create and get an RtcChannel object
public static RtcChannel createChannel(String channelId)
Parameters | Description |
---|---|
channelId | channel id |
Returns
- Method call is successful, Returns RtcChannel object.
- Method call failed, Returns null.
Details
- You can call this method multiple times to create multiple RtcChannel objects, and then call the joinChannel method in each RtcChannel object to join multiple channels at the same time.
- After joining multiple channels, you can subscribe to the audio and video streams of each channel at the same time; however, only one audio and video stream can be released on one channel at the same time.
Music file playback
startPlayingMovie
Start playing a music file.
public static int startPlayingMovie(String mediaFile, boolean toPublish, boolean cycle, boolean paused, RtcSurfaceViewRenderer rendererOrNull)
Parameters
Parameters | Description |
---|---|
mediaFile | The path of the music file, which can be a local file or http/https path |
toPublish | Whether to publish or not |
paused | Whether to pause immediately after startup. The default is false |
cycle | Whether to automatically start from the beginning after playing. The default is false |
rendererOrNull | If it is an mp4 video file, the view window used to display the video. Can be null |
Returns
- 0(ERR_OK): Success.
- <0: Failure
stopPlayingMovie
Stop playing a music file.
public static int stopPlayingMovie(String mediaFile)
Parameters
Parameters | Description |
---|---|
mediaFile | See startPlayingMovie for details |
Returns
- 0(ERR_OK): Success.
- <0: Failure
pausePlayingMovie
Pause/resume playing a music file.
public static int pausePlayingMovie(String mediaFile, boolean pause)
Parameters
Parameters | Description |
---|---|
mediaFile | See startPlayingMovie for details |
pause | true to pause playback; false to resume playback |
Returns
- 0(ERR_OK): Success.
- <0: Failure
getMovieInfo
Get information about music files
public static int getMovieInfo(String mediaFile, Structs.LocalMovieInfo info)
Parameters
Parameters | Description |
---|---|
mediaFile | See startPlayingMovie for details |
info | Media file information. See LocalMovieInfo for details |
Returns
- 0(ERR_OK): Success.
- <0: Failure
getMovieCurrentPosition
Get the playback progress of the music file.
public static long getMovieCurrentPosition(String mediaFile)
Parameters
Parameters | Description |
---|---|
mediaFile | See startPlayingMovie for details |
Returns
Play progress (in milliseconds)
setMoviePosition
Continue to play a music file.
public static int setMoviePosition(String mediaFile, long pos)
Parameters
Parameters | Description |
---|---|
mediaFile | See startPlayingMovie for details |
pos | The target time to move, in milliseconds |
Returns
- 0(ERR_OK): Success.
- <0: Failure
Audio file playback
getEffectsVolume
Obtain the playback volume of the sound effect file.
public static int getEffectsVolume()
Returns
- The method call is successful Returns The volume value of the sound effect, the range is [0, 100]
- <0: Method call failed
setEffectsVolume
Set the playback volume of the sound effect file.
public static int setEffectsVolume(int volume)
Parameters
Parameters | Description |
---|---|
volume | Volume value, the range is [0, 100], the default is 100. |
Returns
- 0(ERR_OK): Success.
- <0: Failure
setVolumeOfEffect
Adjust the playback volume of the sound effect file in real time, the range is [0,100]
public static int setVolumeOfEffect(int soundId, int volume)
Parameters
Parameters | Description |
---|---|
soundId | The sound effect ID passed in when playEffect. |
volume | Volume value, the range is [0, 100], the default is 100. |
playEffect
Start playing a sound effect file.
public static int playEffect(int soundId, String filePath, int loopCount,double pitch,double pan, int gain, boolean toPublish, long startTimeMS, long endTimeMS)
Parameters
Parameters | Description |
---|---|
soundId | The sound effect ID set by yourself must be unique. |
filePath | The path of the sound effect file, which can be a local file or an http/https link. |
loopCount | Set the number of times the sound effect file is played in a loop: * 0: Play the sound effect file once * 1: Play the sound effect file twice in a loop * -1: Infinite loop Play the sound effect file until it stops after calling stopEffect or stopAllEffects |
pitch | The pitch of the sound effect. The value range is [0.5,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 sound effect. The value range is [-1.0,1.0] -1.0: The sound effect appears on the left. 0.0: The sound effect appears right in front. 1.0: The sound effect appears on the right. |
gain | Set the volume of the sound effect. The value range is [0.0,100.0]. The default value is 100.0. The smaller the value, the lower the volume of the sound effect. |
toPublish | Set whether to transmit the sound effect to the remote site * true: While the sound effect file is played locally, the remote user can also hear the sound effect * false: only locally Hear the sound effect |
startTimeMS | Set the time (milliseconds) to start playing, and the file will start playing from there. |
endTimeMS | Set the time (milliseconds) to end the playback, and the file will end when it is played. |
Returns
- 0(ERR_OK): Success.
- <0: Failure
Details
This method can play a designated local or online sound effect file to add sound effects to the application, such as the sound effects of specific operations in the game.
In this method, you can set the number of times and gain of the sound effect file, and whether the remote user can hear the sound effect. You can call this method multiple times. By passing in the soundID and filePath of different sound effect files, multiple sound effect files can be played at the same time to achieve sound effect superimposition. For the best user experience, we recommend that no more than 3 sound effect files are played at the same time.
After calling this method to play the sound effect, the onAudioEffectFinish callback will be triggered.
stopEffect
Stop playing a sound file.
public static int stopEffect(int soundId)
Parameters
Parameters | Description |
---|---|
soundId | The sound effect ID passed in when playEffect. |
Returns
- 0(ERR_OK): Success.
- <0: Failure
stopAllEffects
Stop playing all sound effect files.
public static int stopAllEffects()
Returns
- 0(ERR_OK): Success.
- <0: Failure
preloadEffect
Preload the specified sound effect file into the memory.
public static int preloadEffect (int soundId, String filePath)
Parameters
Parameters | Description |
---|---|
soundId | The sound effect ID set by yourself must be unique. |
filePath | The path of the sound effect file, which can be a local file or an http/https link. |
Returns
- 0(ERR_OK): Success.
- <0: Failure
unloadEffect
Release a preloaded sound effect file from the memory.
public static int unloadEffect (int soundId)
Parameters
Parameters | Description |
---|---|
soundId | The sound effect ID set by yourself must be unique. |
Returns
- 0(ERR_OK): Success.
- <0: Failure
pauseEffect
Pause playing a sound effect file.
public static int pauseEffect(int soundId)
Parameters
Parameters | Description |
---|---|
soundId | The sound effect ID passed in when playEffect. |
Returns
- 0(ERR_OK): Success.
- <0: Failure
pauseAllEffects
Pause all sound effect files.
public static int pauseAllEffects()
Returns
- 0(ERR_OK): Success.
- <0: Failure
resumeEffect
Continue to play a sound effect file.
public static int resumeEffect(int soundId)
Parameters
Parameters | Description |
---|---|
soundId | The sound effect ID passed in when playEffect. |
Returns
- 0(ERR_OK): Success.
- <0: Failure
resumeAllEffects
Resume all sound effect files.
public static int resumeAllEffects()
Returns
- 0(ERR_OK): Success.
- <0: Failure
Vocal effect
To use this feature, please contact us to help you activate
setAudioQuality
Set the audio quality of the local transmission
Parameters
Parameter | Description |
---|---|
quality | Audio quality, see AUDIO_QUALITY |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
setLocalVoicePitch
Changes the voice pitch of the local speaker.
public static int setLocalVoicePitch(double pitch)
Parameters
Parameters | Description |
---|---|
pitch | Sets the voice pitch. The value ranges between 0.5 and 2.0. The lower the value, the lower the voice pitch. The default value is 1.0 (no change to the local voice pitch). |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
setLocalVoiceEqualization
Sets the local voice equalization effect.
public static int setLocalVoiceEqualization(int bandFrequency, int gain)
Parameters
Parameters | Description |
---|---|
bandFrequency | Sets the band frequency. The value ranges between 0 and 9; representing the respective 10-band center frequencies of the voice effects, including 31, 62, 125, 250, 500, 1k, 2k, 4k, 8k, and 16k Hz.See AUDIO_EQUALIZATION_BAND_FREQUENCY. |
gain | Sets the gain of each band (dB). The value ranges between -15 and 15. The default value is 0. |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
setLocalVoiceReverb
Sets the local voice reverberation.
public static int setLocalVoiceReverb(int reverbType, double value)
Parameters
Parameters | describe |
---|---|
reverbType | The reverberation key For details. see AUDIO_REVERB_TYPE |
value | Set the effect value of the reverberation effect. For the value range of each reverberation effect, please refer to AUDIO_REVERB_TYPE |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
setAudioEffectPreset
Sets an SDK preset audio effect.
public static int setAudioEffectPreset(int preset)
Parameters | Description |
---|---|
preset | The options for SDK preset audio effects. See AUDIO_EFFECT_PRESET。 |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Details
This method sets the human voice effect preset by the SDK. This method needs to be called after enableLocalAudio. Note that calling the enableLocalAudio interface and passing false will cancel the preset sound effect. This method cannot be mixed with setLocalVoicePitch, setLocalVoiceEqualization, setLocalVoiceReverb.
enableDeepLearningDenoise
Enables or disables deep-learning noise reduction.
public static int enableDeepLearningDenoise(boolean enabled)
Parameters
Parameters | Description |
---|---|
enabled | Sets whether to enable deep-learning noise reduction.: true: (Default) Enables deep-learning noise reduction. false: Disables deep-learning noise reduction. |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Sound localization
enableSoundPositionIndication
Enables/Disables stereo panning for remote users.
public static int enableSoundPositionIndication(boolean enabled)
Parameters
Parameters | Description |
---|---|
enabled | true:Enables stereo panning. false:Disables stereo panning. |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Details
If you want to call setRemoteVoicePosition to realize the function of listening voice position recognition, please make sure to call this method to turn on the voice stereo of the remote user before enableAudio
setRemoteVoicePosition
Sets the sound position of a remote user.
public static int setRemoteVoicePosition(String uid, double pan, double gain)
Parameters
Parameters | Description |
---|---|
uid | The ID of the remote user. |
pan | The sound position of the remote user. The value ranges from -1.0 to 1.0: •0.0:the remote sound comes from the front. • -1.0:the remote sound comes from the left. • 1.0:the remote sound comes from the right. |
gain | Gain of the remote user. The value ranges from 0.0 to 100.0. The default value is 100.0 (the original gain of the remote user). The smaller the value, the less the gain. |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Details
- Ensure that you call this method after joining a channel.
- For this method to work, enable stereo panning for remote users by calling the enableSoundPositionIndication method before enableAudio.
- This method requires hardware support. For the best sound positioning, we recommend using a wired headset.
Cross-channel media stream forwarding
startChannelMediaRelay
Starts to relay media streams across channels.
public static int startChannelMediaRelay(Structs.ChannelMediaRelayConfiguration config)
Parameters
Parameters | Description |
---|---|
config | The configuration of the media stream relay: ChannelMediaRelayConfiguration |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Details
After a successful method call, the SDK triggers the onChannelMediaRelayStateChanged callbacks, and these callbacks return the state and events of the media stream relay.
- If the onChannelMediaRelayStateChanged callback returns RELAY_STATE_RUNNING(2) and RELAY_ERROR_OK(0), and the onChannelMediaRelayEvent callback returns RELAY_EVENT_PACKET_SENT_TO_DEST_CHANNEL(4), the SDK starts relaying media streams between the original and the destination channel.
- If the onChannelMediaRelayStateChanged callback returns RELAY_STATE_FAILURE(3), an exception occurs during the media stream relay.
Note
- The cross-channel media stream forwarding function needs to be activated by contacting technical support.
- Call this method after the joinChannel method.
- This method takes effect only when you are a host in a LIVE_BROADCASTING 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.
updateChannelMediaRelay
Updates the channels for media relay.
public static int updateChannelMediaRelay(Structs.ChannelMediaRelayConfiguration config)
Parameters
Parameters | Description |
---|---|
config | The media stream relay configuration: ChannelMediaRelayConfiguration |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Details
After successfully starting to forward the media stream across channels, if you want to forward the stream to multiple target channels, or exit the current forwarding channel, you can call this method.
Note
- Please call this method after the startChannelMediaRelay method.
- Cross-channel media stream forwarding supports up to 4 target channels.
stopChannelMediaRelay
Stops the media stream relay.
public static int stopChannelMediaRelay()
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Details
If the method call fails, the SDK triggers the onChannelMediaRelayStateChanged callback with the RELAY_ERROR_SERVER_NO_RESPONSE(2) or RELAY_ERROR_SERVER_CONNECTION_LOST(8) error code. You can leave the channel by calling the leaveChannel method, and the media stream relay automatically stops.
Volume indication
enableAudioVolumeIndication
Enable/disable the speaker volume prompt.
public static int enableAudioVolumeIndication(int interval)
Parameters
Parameters | Description |
---|---|
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 setting interval ≥ 200 ms. |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Switch speakers or earpieces
setEnableSpeakerphone
Enables/Disables the audio route to the speakerphone.
public static int setEnableSpeakerphone(boolean enabled)
Parameters
Parameters | Description |
---|---|
enabled | Sets whether to enable the speakerphone or earpiece true: Enable the speakerphone. The audio route is the speakerphone. false: Disable the speakerphone. The audio route is the earpiece. |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Details
This method sets whether to allow the voice to be routed to the speaker (external amplifier). This method can be called before joinChannel.
isSpeakerphoneEnabled
Checks whether the speakerphone is enabled.
public static boolean isSpeakerphoneEnabled()
Returns
- true: The speakerphone is enabled, and the audio plays from the speakerphone.
- false:The speakerphone is not enabled, and the audio plays from devices other than the speakerphone. For example, the headset or earpiece.
Details
When a wired or Bluetooth headset is connected, the sound will be automatically switched to the headset. At this time, the Returns value of isSpeakerphoneEnabled is still the setting before the headset is connected. When the headset is disconnected, the sound will also return to the playback path set before the headset is connected.
In-ear monitoring
enableInEarMonitoring
Enables in-ear monitoring.
public static int enableInEarMonitoring(boolean enabled)
Parameters
Parameters | Description |
---|---|
enabled | Sets whether to enable/disable in-ear monitoring: true: Enable false: (Default) Disable. |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Note
Users must use wired headphones to hear the ear-back effect
setInEarMonitoringVolume
Sets the volume of the in-ear monitor.
public static int setInEarMonitoringVolume(int volume)
Parameters
Parameters | Description |
---|---|
volume | Sets the volume of the in-ear monitor. The value ranges between 0 and 100 (default). |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Network test before call
startEchoTest
Starts an audio call test.
public static int startEchoTest(int intervalInSeconds)
Parameters
Parameters | Description |
---|---|
intervalInSeconds | The time interval of the test result of the voice call loop, the value range is [2,10], and the unit is second. |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Details
Need to call enableVideo and enableAudio in advance
stopEchoTest
Stops the audio call test.
public static int stopEchoTest()
Returns
- 0(ERR_OK): Success.
- < 0: Failure
startLastmileProbeTest
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).
public static int startLastmileProbeTest(Structs.LastmileProbeConfig config)
Parameters
Parameters | Description |
---|---|
config | See LastmileProbeConfig |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Details
The network quality detection before the call starts, and the bandwidth, packet loss, network jitter, and round-trip delay data of the uplink and downlink networks are fed back to the user. After enabling this method, the SDK will Returns the following 2 callbacks in turn:
- lastmileQuality, Returns once every 2 seconds depending on network conditions. This callback provides feedback on the uplink and downlink network quality through scoring, which is closer to the user’s subjective feelings.
- Lastmile, Returns within 30 seconds depending on the network situation. This callback uses specific data to feed back the quality of the uplink and downlink networks, which is more objective.
Note Please perform this test before joining the channel. Need to call enableVideo and enableAudio in advance.
stopLastmileProbeTest
Stops the last-mile network probe test.
public static int stopLastmileProbeTest()
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Server recording
When someone in the channel calls the start/stop/pause/resume server recording interface and the server recording state changes, everyone in the channel will receive the onServerRecordStateChange callback notify.
When the room is in recording/recording paused two states, new people entering the room will also receive onServerRecordStateChange callback notification.
Audio capture (Push mode only)
setExternalAudioSource
public static int setExternalAudioSourceParameters(int sampleRate, int channels)
Sets the external audio source.
This method sets the external audio format passed in pushAudioFrame.
Details This method needs to be called before joining the channel.
Parameters
Parameters | Description |
---|---|
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 channels of the external audio source:(1: Mono. 2: Stereo.) |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
pushSourceAudioFrame
public static int pushSourceAudioFrame(byte[] data)
To push external audio frames, you need to call setRecordingAudioFrameParameters first.
Parameters
Parameters | Description |
---|---|
data | Valid data of the frame |
Returns
- 0(ERR_OK): Success.
- <0: Failure
Audio self-rendering (Pull mode only)
pullPlaybackAudioFrame
Pulls the remote audio frame.
public static int pullPlaybackAudioFrame(byte[] data10ms)
Pull playback (after mixing) data (pulling 10ms data at a time) (the user needs to continue to call at 10ms intervals). Need to call setPlaybackAudioFrameParameters first.
After calling this method, the App will take an active pull method to obtain the remote-end decoded and mixed audio data for audio playback.
Parameters
Parameters | Description |
---|---|
data10ms | 10ms effective frame data |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
setExternalAudioSink
Sets the external audio sink.
public static int setExternalAudioSinkParameters(int sampleRate, int channels)
Set the data format pulled by pullAudioFrame. This method sets the audio format pulled by pullAudioFrame.
Details Ensure that you call this method before joining a channel.
Parameters
Parameters | Description |
---|---|
sampleRate | The sample rate (Hz) of the external audio sink. You can set this parameter as 16000, 32000, 44100, or 48000. |
channel | The number of audio channels of the external audio sink: (1: Mono 2: Stereo |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Original audio data
setRecordingAudioFrameParameters
Sets the audio sampling format for the onRecordAudioFrame callback.
public static int setRecordingAudioFrameParameters(int sampleRate, int channel, int samplesPerCall)
Details Ensure that you call this method before joining a channel.
Parameters
Parameters | Description |
---|---|
sampleRate | The sample rate (samplesPerSec) returned in the onRecordFrame callback, which can be set as 8000, 16000, 32000, 44100, or 48000 Hz. |
channel | The number of audio channels (channels) returned in the onRecordFrame callback: (1: Mono . 2: Stereo) |
samplesPerCall | The number of samples the onRecordFrame callback returns. In RTMP or RTMPS streaming scenarios, set it as 1024. |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
setPlaybackAudioFrameParameters
Sets the audio playback format for the OnPlaybackAudioFrame callback.
public static int setPlaybackAudioFrameParameters(int sampleRate, int channel, int samplesPerCall)
Details Ensure that you call this method before joining a channel.
Parameters
Parameters | Description |
---|---|
sampleRate | The sample rate (samplesPerSec) returned in the onPlaybackFrame callback, which can be set as 8000, 16000, 32000, 44100, or 48000 Hz. |
channel | The number of channels (channels) returned in the onPlaybackFrame callback:(1: Mono 2: Stereo |
samplesPerCall | The number of samples the onPlaybackFrame callback returns. In RTMP or RTMPS streaming scenarios, set it as 1024. |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Record sound clip
startRecordingVoiceClip
Start recording a sound clip
public static int startRecordingVoiceClip(String clipBaseName, int clipDurationSeconds, int fileType)
Parameters
Parameters | Description |
---|---|
clipBaseName | Sound clip basename |
clipDurationSeconds | Duration of each sound clip |
fileType | File Type MEDIAFILE_TYPE |
Returns
- 0(ERR_OK): Success.
- <0: Failure
Details
After the call is successful, the user will receive the onVoiceClipFileReady callback.
stopRecordingVoiceClip
Stop recording a sound clip
public static int stopRecordingVoiceClip(String clipBaseName)
Parameters
Parameters | Description |
---|---|
clipBaseName | Sound clip basename |
Returns
- 0(ERR_OK): Success.
- <0: Failure
Switch cameras
switchCamera
Switches between front and rear cameras.
public static int switchCamera()
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Details
This method is only applicable to single camera mode. Please call this method when local video capture is turned on.
isFrontFacingCameraFired
Determine whether it is a front camera
public static boolean isFrontFacingCameraFired(String cameraId)
Parameters | Description |
---|---|
cameraId | Device id |
Returns
- true Is the front camera
- false Not front camera
setCameraFlipMode
Set the flip mode of the camera.
public static int setCameraFlipMode(String cameraId, boolean horizontalFlip, boolean verticalFlip)
Parameters
Parameters | Description |
---|---|
cameraId | Specify the camera ID to be operated. If it is a single-camera mode, this Parameters is ignored |
horizontalFlip | Whether to enable horizontal flip |
verticalFlip | Whether to enable vertical flip |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Details
This method flips the data collected by the camera horizontally (and/or vertically). For the same camera, after turning off the camera, the engine will still remember the camera’s flip settings, and the previous settings will be automatically loaded when the camera is turned on next time, unless the user passes enableVideo(false) The video engine has been turned off.
correctCameraKeystoning
Correct the keystone distortion of the camera.
public static int correctCameraKeystoning(String cameraId, float fromX, float fromY, float toX, float toY)
Parameters
Parameters | Description |
---|---|
cameraId | Specify the camera ID to be operated. If it is a single-camera mode, this Parameters is ignored |
fromX,fromY | The coordinates of the starting point of the vector for this correction |
toX,toY | The vector end point coordinates of this correction |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Details
This method corrects the keystone distortion of the camera through the incremental interactive mode. The vector AB formed by the starting point A (fromX, fromY) and the end point B (toX, toY) represents the displacement of this correction, which is equivalent to the user dragging the mouse to move from A to B. The engine will automatically determine this time according to the position of the starting point A Which corner of the picture is the corrected corner point.
The coordinates of the upper left and lower right corners of the view are (0.0, 0.0) and (1.0, 1.0). The view is divided into four equally divided 1/4 areas, namely the upper left area, the upper right area, the lower right area, and the lower left area. Point A and Point B must be located in a certain equally divided area of the view, and cross-area correction is invalid.
resetCameraKeystoning
Cancel the correction of keystone distortion of the camera.
java public static int resetCameraKeystoning(String cameraId)
Parameters
Parameters | Description |
---|---|
cameraId | Specify the camera ID to be operated. If it is a single-camera mode, this Parameters is ignored |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Details
This method disables the keystone correction function of the camera and restores the default behavior.
getLocalCameraIds
Get a list of local camera IDs.
public String[] getLocalCameraIds()
Returns
- The camera ID list or null.
Details
In multi-camera mode, you can use this method to enumerate all the cameras, and then open one or more of them for publishing.
Stream message
sendStreamMessage
The SDK has the following restrictions on this method:
Up to 30 packets can be sent per second in a channel with each packet having a maximum size of 1 kB. Each client can send up to 6 kB of data per second. Each user can have up to five data channels simultaneously. A successful onStreamMessage method call triggers the onStreamMessage callback on the remote client, from which the remote user gets the stream message.
public static int sendStreamMessage( byte[] message )
Parameters
Parameters | Description |
---|---|
message | Sent data. |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Publish management
setPublishStreamInfo
setPublishStreamInfo(String streamInfo, String cameraId)
Set local video information
Parameters
Parameter | Description |
---|---|
streamInfo | Local video information (json format) |
cameraId | Specify the camera ID to be published. If it is a single camera mode, this Parameters is ignored |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Details
Bind the information describing the video stream to the device so that others can receive it. If you have this requirement, it must be called before publishStream after joinChannel succeeds. If the remote end successfully subscribes to this video stream, the information of this video stream will be reflected in the streamInfoParameters in the onRemoteVideoStateChanged callback.
publishStream
Start to publish local audio and video.
public static int publishStream(String cameraId))
Parameters
Parameters | Description |
---|---|
cameraId | Specify the camera ID to be published. If it is a single camera mode, this Parameters is ignored |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Details
Publish your own audio and video to the channel for others to watch and listen. After the release is successful, the local will receive the onLocalVideoStateChanged callback. If the remote end turns off automatic subscription (see setAutoSubscribe for details), it will receive a onUserPublished callback. At this time, if the other party decides to watch this person, they need to call subscribeStream, and after success, they will receive the onRemoteVideoStateChanged callback. If the remote end does not turn off the automatic subscription, it will directly receive the onRemoteVideoStateChanged callback.
Note
This method can only be called after joining the channel successfully.
unpublishStream
Stop publishing local audio and video.
public static int unpublishStream(String cameraId)
Parameters
Parameters | Description |
---|---|
cameraId | Specify the camera ID to be published. If it is a single camera mode, this Parameters is ignored |
Returns
- 0(ERR_OK): Success.
- <0: Failure
Details
Stop publishing your own audio and video. After you stop publishing, you will receive the onLocalVideoStateChanged callback locally. If the remote end turns off automatic subscription (see setAutoSubscribe for details), it will receive a onUserUnpublished callback. In addition, the onRemoteVideoStateChanged callback will be received regardless of whether the automatic subscription is turned off by the remote end.
Note
This method can only be called after joining the channel successfully.
Subscription management (only for manual subscription mode)
subscribeStream
Start subscribing to one audio and video.
public static int subscribeStream(String streamId)
Parameters
Parameters | Description |
---|---|
streamId | The unique ID of the audio and video stream in the channel. This ID can be obtained from the onUserPublished callback |
Returns
- 0(ERR_OK): Success.
- <0: Failure
Details
Please call after receiving the onUserPublished callback.
unsubscribeStream
Stop subscribing to one audio and video.
public static int unsubscribeStream(String streamId)
Parameters
Parameters | Description |
---|---|
streamId | The unique ID of the audio and video stream in the channel. This ID can be obtained from the onUserPublished / onUserUnpublished callback |
Returns
- 0(ERR_OK): Success.
- <0: Failure
Details
After receiving the onUserPublished callback, you can call subscribeStream / unsubscribeStream repeatedly /#unsubscribestream) method to create/remove subscription to this audio and video stream. After receiving the onUserUnpublished callback, there is no need to manually call the unsubscribe method.
setAutoSubscribe
Turn on/off the automatic subscription mode (enabled by default).
public static int setAutoSubscribe(boolean autoSubscribe)
Parameters
Parameters | Description |
---|---|
autoSubscribe | Whether to enable automatic subscription mode |
Returns
- 0(ERR_OK): Success.
- <0: Failure
Details
If the automatic subscription mode is turned on, whenever a new media stream is released in the channel, the local SDK will automatically complete the network link establishment and the decoding of audio and video data, and trigger onRemoteVideoStateChanged callback (the state is REMOTE_VIDEO_STATE_STARTING), you only need to call the corresponding playback method at this time. If the automatic subscription mode is turned off, whenever a new media stream is published in the channel, only onUserPublished callback will be received locally, and the link will not be triggered automatically The beginning of creation and data decoding. Developers can decide whether/when to subscribe.
Server recording
startServerRecord
Start server recording.
public static int startServerRecord()
Returns
- 0: The method is called successfully
- Non-zero: method call failed
stopServerRecord
Stop server recording.
public static int stopServerRecord()
Returns
- 0(ERR_OK): Success.
- <0: Failure
pauseServerRecord
Pause server recording.
public static int pauseServerRecord()
Returns
- 0(ERR_OK): Success.
- <0: Failure
resumeServerRecord
Resume server recording.
public static int resumeServerRecord()
Returns
- 0(ERR_OK): Success.
- <0: Failure
Advanced signaling method
These methods must be called after successfully joining the channel.
setProperty
Set custom attributes for a user in the channel.
public static int setProperty(String uid, String tellWhom, String properties)
Parameters
Parameters | Description |
---|---|
uid | uid of the target user |
tellWhom | The user to be notified. Empty to notify everyone in the channel. If you specify the uid of a user, only the specified user will be notified. Default is empty |
properties | Custom properties, must be a json string |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Details
There are two ways to set custom attributes:
- When a user joins a channel, specify properties in joinChannel;
- After the user joins the channel and calls setProperty, the user will receive the onSetProperty callback.
After the setting is successful, both the notified user and the set user will receive the notification. In addition, new users entering the channel will also get these attributes of the user in the onUserJoined callback.
Note
- If different attributes of the same user are specified multiple times, these attributes will be recorded and sent to the new users who enter the channel later through the onUserJoined callback.
- If the same attributes of the same user are specified multiple times, the attributes set later will overwrite the attributes set before. For example, repeat the setting twice for user A, and pass in {“test”: true} and {“test”: false} respectively, then user B who newly enters the channel will receive onUserJoined callback, you will get the attributes of user A {“test”: false}.
sendChatMsg
Send chat messages.
public static int sendChatMsg(String toId, String message, String extraData)
Parameters
Parameters | Description |
---|---|
toId | The user to be notified. Empty to notify everyone in the channel. If the uid of a certain user is specified, only the specified notification user will be notified |
message | Chat message text |
extraData | Custom attributes of this message. Must be a json string. Can be empty |
Returns
- 0(ERR_OK): Success.
- <0: Failure
Details
You can usually use extraData to transfer some information such as fonts and avatars. Users in the channel will receive the onChatMessageArrival callback.
pubMsg
Post a custom message.
public static int pubMsg(String msgId,
String msgName,
String toId,
String data,
String associatedUserId,
String associatedMsgId,
boolean save,
String extendInfo)
Parameters
Parameters | Description |
---|---|
msgId | Message id, which is the unique identifier of a message in the channel |
msgName | Message name |
toId | The user to be notified. Empty to notify everyone in the channel. If the uid of a certain user is specified, only the user specified to be notified will be notified |
data | Message content. Must be a json string. Can be empty |
associatedUserId | The uid of the associated user, once a message is associated with a user, the message will be automatically deleted when the user logs out |
associatedMsgId | The id of the associated message. Once a message is associated with another message, the associated message will be deleted automatically when the associated message is deleted. |
save | Whether to save. If saved, users who enter the channel later will receive this signaling in the onPubMsg callback until this message is deleted by the delMsg method |
extendInfo | Reserved Parameters |
Returns
- 0(ERR_OK): Success.
- <0: Failure
Details
The pubMsg mechanism is similar to a message board, which is used to save and synchronize the business status in the channel. Both users who are already in the channel or new users who join later can receive custom messages that have been published in the current channel through the onPubMsg callback.
delMsg
Delete a custom message.
public static int delMsg(String msgId, String msgName, String toId, String data)
Parameters
Parameters | Description |
---|---|
msgId | The message id to be deleted. When publishing a message through the pubMsg method, its id will be specified |
msgName | Message name |
toId | The user to be notified. Empty to notify everyone in the channel. If the uid of a certain user is specified, only the specified notification user will be notified. |
data | Reserved Parameters |
Returns
- 0(ERR_OK): Success.
- <0: Failure
Details
After the call is successful, users already in the channel will receive the message onDelMsg.
Note
Deleting a non-existent message will fail.
evictUser
Kick a user out of the channel.
public static int evictUser(String uid, int reason)
Parameters
Parameters | Description |
---|---|
uid | The uid of the kicked user |
reason | custom field |
Returns
- 0(ERR_OK): Success.
- <0: Failure
Details
After the call is successful, the kicked user will receive the onLocalUserEvicted callback. Other users will receive the onUserLeft callback.
CDN push streaming
addPublishStreamUrl
Publishes the local stream to a specified CDN streaming URL.
public static int addPublishStreamUrl(String url)
Parameters
Parameters | Description |
---|---|
url | The CDN streaming 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. |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
removePublishStreamUrl
Removes an RTMP or RTMPS stream from the CDN.
public static int removePublishStreamUrl(String url)
Parameters
Parameters | Description |
---|---|
url | The CDN streaming URL to be removed. The maximum length of this parameter is 1024 bytes. The URL address must not contain special characters, such as Chinese language characters. |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
setLiveTranscoding
Sets the video layout and audio settings for CDN live.
public static int setLiveTranscoding(Structs.LiveTranscoding transcoding)
Parameters
Parameters | Description |
---|---|
transcoding | The CDN live audio/video transcoding settings. See LiveTranscoding |
Returns
- 0(ERR_OK): Success.
- < 0: Failure
Other methods
getSdkVersion
Gets the SDK version.
public static String getSdkVersion()
Returns
The current version number.