TRTCLiveRoom
includes the following features which are based on Tencent Real-Time Communication (TRTC) and Tencent Cloud Chat.TRTCLiveRoom
is an open-source class depending on two closed-source Tencent Cloud SDKs. For the specific implementation process, please see Interactive Live Video Streaming (Android).AVChatRoom
feature of the Chat SDK is used to implement chat rooms. The attribute APIs of Chat are used to store room information such as the seat list, and invitation signaling is used to send requests to speak or invite others to speak.API | Description |
Gets a singleton object. | |
Terminates a singleton object. | |
Sets event callbacks. | |
Sets the thread where event callbacks are. | |
Logs in. | |
Logs out. | |
Sets the profile. |
API | Description |
Creates a room (called by anchor). If the room does not exist, the system will create the room automatically. | |
Terminates a room (called by anchor). | |
Enters a room (called by audience). | |
Exits a room (called by audience). | |
Gets room list details. | |
Gets the anchors in a room. This API works only if it is called after enterRoom() . | |
Gets the information of all audience members in a room. This API works only if it is called after enterRoom() . |
API | Description |
Enables preview of the local video. | |
Stops local video capturing and preview. | |
Starts live streaming (pushing streams). | |
Stops live streaming (pushing streams). | |
Plays a remote video. This API can be called in common playback and co-anchoring scenarios. | |
Stops rendering a remote video. |
API | Description |
Requests co-anchoring (called by audience). | |
Responds to a co-anchoring request (called by anchor). | |
Removes a user from co-anchoring (called by anchor). |
API | Description |
Sends a cross-room communication request (called by anchor). | |
Responds to a cross-room communication request (called by anchor). | |
Quits cross-room communication. |
API | Description |
Switches between the front and rear cameras. | |
Specifies whether to mirror video. | |
Mutes/Unmutes the local user. | |
Mutes/Unmutes a remote user. | |
Mutes/Unmutes all remote users. |
API | Description |
API | Description |
API | Description |
Broadcasts a text chat message in a room. This API is generally used for on-screen comments. | |
Sends a custom text message. |
API | Description |
Specifies whether to display debugging information on the UI. |
API | Description |
Callback for error. | |
Callback for warning. | |
Callback of log. |
API | Description |
The room was terminated. | |
The room information changed. |
API | Description |
There is a new anchor in the room. | |
An anchor left the room. | |
An audience member entered the room. | |
An audience member left the room. |
API | Description |
A co-anchoring request was received. | |
A user was removed from co-anchoring. |
API | Description |
A cross-room communication request was received. | |
Cross-room communication ended. |
API | Description |
A text chat message was received. | |
A custom message was received. |
public static synchronized TRTCLiveRoom sharedInstance(Context context);
Parameter | Type | Description |
context | Context | Android context, which will be converted to ApplicationContext for the calling of system APIs |
TRTCLiveRoom
instance can no longer be used. You need to call sharedInstance again to get a new instance.public static void destroySharedInstance();
TRTCLiveRoomDelegate
to get the callbacks.public abstract void setDelegate(TRTCLiveRoomDelegate delegate);
setDelegate
is the delegate callback of TRTCLiveRoom
. public abstract void setDelegateHandler(Handler handler);
Parameter | Type | Description |
handler | Handler | Callbacks for the events of TRTCLiveRoom are returned via this handler. Do not use it together with setDelegate . |
public abstract void login(int sdkAppId,String userId, String userSig,TRTCLiveRoomDef.TRTCLiveRoomConfig config,TRTCLiveRoomCallback.ActionCallback callback);
Parameter | Type | Description |
sdkAppId | int | |
userId | String | The ID of the current user, which is a string that can contain only letters (a-z and A-Z), digits (0-9), hyphens (-), and underscores (_) |
userSig | String | Tencent Cloud's proprietary security signature. For how to calculate and use it, see FAQs > UserSig. |
config | TRTCLiveRoomConfig | Global configuration information, which needs to be initialized during login and cannot be modified afterward. useCDNFirst : Specifies the way the audience watches live streams. true means that the audience watches live streams over CDNs, which is cost-efficient but has high latency. false means that the audience watches live streams in the low latency mode, the cost of which is between that of CDN live streaming and co-anchoring, but the latency is within 1 second. CDNPlayDomain : Specifies the domain name for CDN live streaming. It takes effect only if useCDNFirst is set to true . You can set it in Domain Management of the CSS console. |
callback | ActionCallback | The callback for login. The code is 0 if login succeeds. |
public abstract void logout(TRTCLiveRoomCallback.ActionCallback callback);
Parameter | Type | Description |
callback | ActionCallback | Callback for logout. The code is 0 if logout succeeds. |
public abstract void setSelfProfile(String userName, String avatarURL, TRTCLiveRoomCallback.ActionCallback callback);
Parameter | Type | Description |
userName | String | Username |
avatarURL | String | Profile photo URL |
callback | ActionCallback | Callback for profile setting. The code is 0 if the operation succeeds. |
public abstract void createRoom(int roomId, TRTCLiveRoomDef.TRTCCreateRoomParam roomParam, TRTCLiveRoomCallback.ActionCallback callback);
Parameter | Type | Description |
roomId | int | The room ID. You need to assign and manage the IDs in a centralized manner. Multiple roomId values can be aggregated into a live room list. Currently, Tencent Cloud does not provide list management services. Please manage your own room lists. |
roomParam | TRTCCreateRoomParam | Room information, such as room name and cover information. If both the room list and room information are managed on your server, you can ignore this parameter. |
callback | ActionCallback | Callback for room creation. The code is 0 if the operation succeeds. |
startCameraPreview()
to enable camera preview and set beauty filters. createRoom()
to create a room, the result of which is returned via the ActionCallback
callback.starPublish()
to push streams.public abstract void destroyRoom(TRTCLiveRoomCallback.ActionCallback callback);
Parameter | Type | Description |
callback | ActionCallback | Callback for room termination. The code is 0 if the operation succeeds. |
public abstract void enterRoom(int roomId, TRTCLiveRoomCallback.ActionCallback callback);
Parameter | Type | Description |
roomId | int | The room ID. |
callback | ActionCallback | Callback for room entry. The code is 0 if the operation succeeds. |
roomID
and other information of multiple rooms.enterRoom()
to enter the room.startPlay(userId)
, passing in the anchor’s userId
to start playback.userId
, the user can call startPlay(userId)
to start playback.userId
before room entry, he or she can find it in the onAnchorEnter(userId)
callback of TRTCLiveRoomDelegate
, which is returned after room entry, and can then call startPlay(userId)
to start playback.public abstract void exitRoom(TRTCLiveRoomCallback.ActionCallback callback);
Parameter | Type | Description |
callback | ActionCallback | Callback for room exit. The code is 0 if the operation succeeds. |
roomInfo
when they call createRoom()
.public abstract void getRoomInfos(List<Integer> roomIdList, TRTCLiveRoomCallback.RoomInfoCallback callback);
Parameter | Type | Description |
roomIdList | List<Integer> | Room ID list |
callback | RoomInfoCallback | Callback of room details |
enterRoom()
.public abstract void getAnchorList(TRTCLiveRoomCallback.UserListCallback callback);
Parameter | Type | Description |
callback | UserListCallback | Callback of user details |
enterRoom()
.public abstract void getAudienceList(TRTCLiveRoomCallback.UserListCallback callback);
Parameter | Type | Description |
callback | UserListCallback | Callback of user details |
public abstract void startCameraPreview(boolean isFront, TXCloudVideoView view, TRTCLiveRoomCallback.ActionCallback callback);
Parameter | Type | Description |
isFront | boolean | true : Front camera; false : Rear camera |
view | TXCloudVideoView | The control that loads video images |
callback | ActionCallback | Callback for the operation |
public abstract void stopCameraPreview();
public abstract void startPublish(String streamId, TRTCLiveRoomCallback.ActionCallback callback);
Parameter | Type | Description |
streamId | String | The streamId used to bind live streaming CDNs. You need to set it to the streamId of the anchor if you want audience to play the anchor’s stream via live streaming CDNs. |
callback | ActionCallback | Callback for the operation |
public abstract void stopPublish(TRTCLiveRoomCallback.ActionCallback callback);
Parameter | Type | Description |
callback | ActionCallback | Callback for the operation |
public abstract void startPlay(String userId, TXCloudVideoView view, TRTCLiveRoomCallback.ActionCallback callback);
Parameter | Type | Description |
userId | String | ID of the user whose video is to be played |
view | TXCloudVideoView | The control that loads video images |
callback | ActionCallback | Callback for the operation |
userId
, after entering a room, a user can call startPlay(userId)
to play the anchor's video.userId
before room entry, he or she can find it in the onAnchorEnter(userId)
callback of TRTCLiveRoomDelegate
, which is returned after room entry, and can then call startPlay(userId)
to play the anchor’s video.onAnchorEnter(userId)
callback from TRTCLiveRoomDelegate
and can call startPlay(userId)
, passing in the userId
obtained from the callback to play the co-anchoring user’s video.onAnchorExit()
callback is received.public abstract void stopPlay(String userId, TRTCLiveRoomCallback.ActionCallback callback);
Parameter | Type | Description |
userId | String | ID of the remote user |
callback | ActionCallback | Callback for the operation |
public abstract void requestJoinAnchor(String reason, int timeout, TRTCLiveRoomCallback.ActionCallback callback);
Parameter | Type | Description |
reason | String | Reason for co-anchoring |
timeout | int | Timeout period |
callback | ActionCallback | Callback of the anchor’s response |
requestJoinAnchor()
to send a co-anchoring request to the anchor.onRequestJoinAnchor()
callback of TRTCLiveRoomDelegate
.responseJoinAnchor()
to accept or reject the co-anchoring request.responseCallback
callback, which carries the anchor’s response.startCameraPreview()
to enable local camera preview.startPublish()
to push streams.onAnchorEnter()
callback of TRTCLiveRoomDelegate
.startPlay()
to play the co-anchoring viewer’s video.onAnchorEnter()
callback and can call startPlay()
to play other co-anchoring viewers’ video.onRequestJoinAnchor()
callback of TRTCLiveRoomDelegate
.public abstract void responseJoinAnchor(String userId, boolean agree, String reason);
Parameter | Type | Description |
userId | String | The user ID of the audience member. |
agree | boolean | true : accept; false : reject |
reason | String | Reason for accepting/rejecting the request |
onKickoutJoinAnchor()
callback of TRTCLiveRoomDelegate
.public abstract void kickoutJoinAnchor(String userId, TRTCLiveRoomCallback.ActionCallback callback);
Parameter | Type | Description |
userId | String | The ID of the co-anchoring user. |
callback | ActionCallback | Callback for the operation |
public abstract void requestRoomPK(int roomId, String userId, TRTCLiveRoomCallback.ActionCallback callback);
Parameter | Type | Description |
roomId | int | Room ID of the anchor to call |
userId | String | User ID of the anchor to call |
callback | ActionCallback | Callback for requesting cross-room communication. |
requestRoomPK()
to send a ccross-room communication request to anchor B.onRequestRoomPK()
callback of TRTCLiveRoomDelegate
.responseRoomPK()
to respond to the cross-room communication request.onAnchorEnter()
callback of TRTCLiveRoomDelegate
and call startPlay()
to play anchor A's video.responseCallback
callback, which carries anchor B’s response.onAnchorEnter()
callback of TRTCLiveRoomDelegate
and calls startPlay()
to play anchor B’s video.responseCallback
passed in to requestRoomPK
.public abstract void responseRoomPK(String userId, boolean agree, String reason);
Parameter | Type | Description |
userId | String | User ID of the request sending anchor |
agree | boolean | true : Accept; false : Reject |
reason | String | Reason for accepting/rejecting the request |
onQuitRoomPk()
callback of TRTCLiveRoomDelegate
.public abstract void quitRoomPK(TRTCLiveRoomCallback.ActionCallback callback);
Parameter | Type | Description |
callback | ActionCallback | Callback for the operation |
public abstract void switchCamera();
public abstract void setMirror(boolean isMirror);
Parameter | Type | Description |
isMirror | boolean | Enable/Disable mirroring |
public abstract void muteLocalAudio(boolean mute);
Parameter | Type | Description |
mute | boolean | true : Mute; false : Unmute |
public abstract void muteRemoteAudio(String userId, boolean mute);
Parameter | Type | Description |
userId | String | ID of the remote user |
mute | boolean | true : Mute; false : Unmute |
public abstract void muteAllRemoteAudio(boolean mute);
Parameter | Type | Description |
mute | boolean | true : Mute; false : Unmute |
public abstract TXAudioEffectManager getAudioEffectManager();
public abstract TXBeautyManager getBeautyManager();
TXBeautyManager
:public abstract void sendRoomTextMsg(String message, TRTCLiveRoomCallback.ActionCallback callback);
Parameter | Type | Description |
message | String | Text message |
callback | ActionCallback | Callback for the operation |
public abstract void sendRoomCustomMsg(String cmd, String message, TRTCLiveRoomCallback.ActionCallback callback);
Parameter | Type | Description |
cmd | String | A custom command word used to distinguish between different message types |
message | String | Text message |
callback | ActionCallback | Callback for the operation |
public abstract void showVideoDebugLog(boolean isShow);
Parameter | Type | Description |
isShow | boolean | Show/Hide debugging information |
TRTCLiveRoomDelegate
Event Callback APIsvoid onError(int code, String message);
Parameter | Type | Description |
code | int | Error code |
message | String | Error message |
void onWarning(int code, String message);
Parameter | Type | Description |
code | int | Error code |
message | String | Warning message |
void onDebugLog(String message);
Parameter | Type | Description |
message | String | Log information |
void onRoomDestroy(String roomId);
Parameter | Type | Description |
roomId | String | Room ID |
void onRoomInfoChange(TRTCLiveRoomDef.TRTCLiveRoomInfo roomInfo);
Parameter | Type | Description |
roomInfo | TRTCLiveRoomInfo | Room information |
startPlay()
of TRTCLiveRoom
to play the video of the anchor/co-anchoring viewer.void onAnchorEnter(String userId);
Parameter | Type | Description |
userId | String | User ID of the new anchor/co-anchoring viewer |
stopPlay()
of TRTCLiveRoom
to stop playing the video of the anchor/co-anchoring viewer.void onAnchorExit(String userId);
Parameter | Type | Description |
userId | String | ID of the user who quit |
void onAudienceEnter(TRTCLiveRoomDef.TRTCLiveUserInfo userInfo);
Parameter | Type | Description |
userInfo | TRTCLiveUserInfo | Information of the viewer who entered the room |
void onAudienceExit(TRTCLiveRoomDef.TRTCLiveUserInfo userInfo);
Parameter | Type | Description |
userInfo | TRTCLiveUserInfo | Information of the viewer who left the room |
void onRequestJoinAnchor(TRTCLiveRoomDef.TRTCLiveUserInfo userInfo, String reason, int timeOut);
Parameter | Type | Description |
userInfo | TRTCLiveUserInfo | Information of the viewer who requested co-anchoring |
reason | String | Reason for co-anchoring |
timeout | int | Timeout period for response from the anchor. If the anchor does not respond to the request within the period, it will be discarded automatically. |
stopPublish()
of TRTCLiveRoom
to quit co-anchoring.void onKickoutJoinAnchor();
onAnchorEnter()
callback of TRTCLiveRoomDelegate
and call startPlay()
to play the other anchor’s video.void onRequestRoomPK(TRTCLiveRoomDef.TRTCLiveUserInfo userInfo, int timeout);
Parameter | Type | Description |
userInfo | TRTCLiveUserInfo | Information of the anchor who requested cross-room communication. |
timeout | int | Timeout period for response from the anchor |
void onQuitRoomPK();
void onRecvRoomTextMsg(String message, TRTCLiveRoomDef.TRTCLiveUserInfo userInfo);
Parameter | Type | Description |
message | String | Text message |
userInfo | TRTCLiveUserInfo | Information of the sender |
void onRecvRoomCustomMsg(String cmd, String message, TRTCLiveRoomDef.TRTCLiveUserInfo userInfo);
Parameter | Type | Description |
command | String | A custom command word used to distinguish between different message types |
message | String | Text message |
userInfo | TRTCLiveUserInfo | Information of the sender |
void playBGM(String url, int loopTimes, int bgmVol, int micVol, TRTCCloud.BGMNotify notify);
Parameter | Type | Description |
url | String | Path of the music file |
loopTimes | int | Loop times |
bgmVol | int | Volume of background music |
micVol | int | Audio capturing volume |
notify | TRTCCloud.BGMNotify | Playback notification |
void stopBGM();
void pauseBGM();
void resumeBGM();
void setBGMVolume(int volume);
Parameter | Type | Description |
volume | int | Volume. Value range: 0-100. Default value: 100 |
int setBGMPosition(int position);
Parameter | Type | Description |
position | int | Playback progress of background music in milliseconds (ms) |
0
: successfulvoid setMicVolume(int volume);
Parameter | Type | Description |
volume | Int | Volume. Value range: 0-100. Default value: 100 |
void setReverbType(int reverbType);
Parameter | Type | Description |
reverbType | int |
void setVoiceChangerType(int type);
Parameter | Type | Description |
type | int | Voice changing effect. For details, please see the definitions of TRTC_VOICE_CHANGER_TYPE in TRTCCloudDef . |
void playAudioEffect(int effectId, String path, int count, boolean publish, int volume);
Parameter | Type | Description |
effectId | int | Audio effect ID |
path | String | Audio effect path |
count | int | Loop times |
publish | boolean | Whether to push the audio effect. true : push the effect to remote users; false : preview the effect locally only |
volume | int | Volume. Value range: 0-100. Default value: 100 |
void pauseAudioEffect(int effectId);
Parameter | Type | Description |
effectId | int | Audio effect ID |
void resumeAudioEffect(int effectId);
Parameter | Type | Description |
effectId | int | Audio effect ID |
void stopAudioEffect(int effectId);
Parameter | Type | Description |
effectId | int | Audio effect ID |
void stopAllAudioEffects();
void setAudioEffectVolume(int effectId, int volume);
Parameter | Type | Description |
effectId | int | Audio effect ID |
volume | int | Volume. Value range: 0-100. Default value: 100 |
void setAllAudioEffectsVolume(int volume);
Parameter | Type | Description |
volume | int | Volume. Value range: 0-100. Default value: 100 |
Was this page helpful?