TRTCVoiceRoom
is based on Tencent Real-Time Communication (TRTC) and Tencent Cloud Chat. With TRTCVoiceRoom:TRTCVoiceRoom
is an open-source class depending on two closed-source Tencent Cloud SDKs. For the specific implementation process, see Audio Chat Room (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 profile. |
API | Description |
Creates a room (called by room owner). If the room does not exist, the system will automatically create a room. | |
Terminates a room (called by room owner). | |
Enters a room (called by listener). | |
Exits a room (called by listener). | |
Gets room list details. | |
Gets the user information of the specified userId . If the value is null , the information of all users in the room is obtained. |
API | Description |
Becomes a speaker (called by room owner or listener). | |
Changes the seat (called by speaker). | |
Becomes a listener (called by speaker). | |
Places a user in a seat (called by room owner). | |
Removes a speaker (called by room owner). | |
Mutes/Unmutes a seat (called by room owner). | |
Blocks/Unblocks a seat (called by room owner). |
API | Description |
Starts mic capturing. | |
Stops mic capturing. | |
Sets audio quality. | |
Mutes/Unmutes local audio. | |
Sets whether to play sound from the device’s speaker or receiver. | |
Sets mic capturing volume. | |
Sets playback volume. | |
Enables/Disables in-ear monitoring. |
API | Description |
Mutes/Unmutes a specified member. | |
Mutes/Unmutes all members. |
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 |
Sends an invitation. | |
Accepts an invitation. | |
Declines an invitation. | |
Cancels an invitation. |
API | Description |
Callback for error. | |
Callback for warning. | |
Callback of log. |
API | Description |
The room was terminated. | |
The room information changed. | |
User volume |
API | Description |
All seat changes | |
Someone became a speaker or was made a speaker by the room owner. | |
Someone became a listener or was moved to listeners by the room owner. | |
The room owner muted a seat. | |
Whether a user’s mic is muted | |
The room owner blocked a seat. |
API | Description |
A listener entered the room. | |
A listener exited the room. |
API | Description |
A text chat message was received. | |
A custom message was received. |
API | Description |
An invitation was received. | |
The invitee accepted the invitation. | |
The invitee declined the invitation. | |
The inviter canceled the invitation. |
public static synchronized TRTCVoiceRoom sharedInstance(Context context);
Parameter | Type | Description |
context | Context | Android context, which will be converted to ApplicationContext for the calling of system APIs |
TRTCVoiceRoom
instance can no longer be used. You need to call sharedInstance again to get a new instance.public static void destroySharedInstance();
TRTCVoiceRoomDelegate
to get different status notifications of TRTCVoiceRoom.public abstract void setDelegate(TRTCVoiceRoomDelegate delegate);
setDelegate
is the delegate callback of TRTCVoiceRoom
. public abstract void setDelegateHandler(Handler handler);
Parameter | Type | Description |
handler | Handler | The status notifications of TRTCVoiceRoom are sent to the handler thread you specify. |
public abstract void login(int sdkAppId,String userId, String userSig,TRTCVoiceRoomCallback.ActionCallback callback);
Parameter | Type | Description |
sdkAppId | int | |
userId | String | The ID of 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. |
callback | ActionCallback | The callback for login. The code is 0 if login succeeds. |
public abstract void logout(TRTCVoiceRoomCallback.ActionCallback callback);
Parameter | Type | Description |
callback | ActionCallback | The callback for logout. The code is 0 if logout succeeds. |
public abstract void setSelfProfile(String userName, String avatarURL, TRTCVoiceRoomCallback.ActionCallback callback);
Parameter | Type | Description |
userName | String | The username. |
avatar | String | The address of the profile photo. |
callback | ActionCallback | Callback for profile setting. The code is 0 if the operation succeeds. |
public abstract void createRoom(int roomId, TRTCVoiceRoomDef.RoomParam roomParam, TRTCVoiceRoomCallback.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 karaoke room list. Currently, Tencent Cloud does not provide management services for room lists. Please manage your own room lists. |
roomParam | TRTCCreateRoomParam | Room information, such as room name, seat list information, and cover information. To manage seats, you must enter the number of seats in the room. |
callback | ActionCallback | Callback for room creation. The code is 0 if the operation succeeds. |
createRoom
to create an audio chat room, passing in room attributes (e.g. room ID, whether listeners require room owner’s consent to speak, number of seats).enterSeat
to become a speaker.onSeatListChanget
notification about the change of the seat list, and can update the change to the UI.onAnchorEnterSeat
notification that someone became a speaker, and mic capturing will be enabled automatically.public abstract void destroyRoom(TRTCVoiceRoomCallback.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, TRTCVoiceRoomCallback.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 room information of multiple audio chat rooms.enterRoom
with the room ID passed in to enter the room.onRoomInfoChange
notification about room attribute change from the component. The attributes can be recorded, and corresponding changes can be made to the UI, including room name, whether room owner’s consent is required for listeners to speak, etc.onSeatListChange
notification about the change of the seat list and can update the change to the UI.onAnchorEnterSeat
notification that someone became a speaker.public abstract void exitRoom(TRTCVoiceRoomCallback.ActionCallback callback);
Parameter | Type | Description |
callback | ActionCallback | Callback for room exit. The code is 0 if the operation succeeds. |
roomInfo
when calling createRoom()
.public abstract void getRoomInfoList(List<Integer> roomIdList, TRTCVoiceRoomCallback.RoomInfoCallback callback);
Parameter | Type | Description |
roomIdList | List<Integer> | Room ID list |
callback | RoomInfoCallback | Callback of room details |
userId
.public abstract void getUserInfoList(List<String> userIdList, TRTCVoiceRoomCallback.UserListCallback userlistcallback);
Parameter | Type | Description |
userIdList | List<String> | IDs of the users to query. If this parameter is null , the information of all users in the room is queried. |
userlistcallback | UserListCallback | Callback of user details |
onSeatListChange
notification and an onAnchorEnterSeat
notification.public abstract void enterSeat(int seatIndex, TRTCVoiceRoomCallback.ActionCallback callback);
Parameter | Type | Description |
seatIndex | int | The number of the seat to take |
callback | ActionCallback | Callback for the operation |
sendInvitation
first to send a request and, after receiving onInvitationAccept
, call this API.onSeatListChange
, onAnchorLeaveSeat
, and onAnchorEnterSeat
notifications. This API will only change the user’s seat number, not the user role.public abstract int moveSeat(int seatIndex, TRTCVoiceRoomCallback.ActionCallback callback);
Parameter | Type | Description |
seatIndex | int | The number of the seat to change to |
callback | ActionCallback | Callback for the operation |
Parameter | Type | Description |
code | int | Result of seat change. 0 : operation successful; 10001 : API rate limit exceeded; other values: operation failed |
sendInvitation
first to send a request and, after receiving onInvitationAccept
, call this API.onSeatListChange
notification and an onAnchorLeaveSeat
notification.public abstract void leaveSeat(TRTCVoiceRoomCallback.ActionCallback callback);
Parameter | Type | Description |
callback | ActionCallback | Callback for the operation |
onSeatListChange
notification and an onAnchorEnterSeat
notification.public abstract void pickSeat(int seatIndex, String userId, TRTCVoiceRoomCallback.ActionCallback callback);
Parameter | Type | Description |
seatIndex | int | The number of the seat to place the listener in |
userId | String | User ID |
callback | ActionCallback | Callback for the operation |
sendInvitation
first to send a request and, after receiving onInvitationAccept
, call pickSeat
.onSeatListChange
notification and an onAnchorLeaveSeat
notification.public abstract void kickSeat(int seatIndex, TRTCVoiceRoomCallback.ActionCallback callback);
Parameter | Type | Description |
seatIndex | int | The number of the seat to remove the speaker from |
callback | ActionCallback | Callback for the operation |
onSeatListChange
notification and an onSeatMute
notification.public abstract void muteSeat(int seatIndex, boolean isMute, TRTCVoiceRoomCallback.ActionCallback callback);
Parameter | Type | Description |
seatIndex | int | The number of the seat to block/unblock |
isMute | boolean | true : mute; false : unmute |
callback | ActionCallback | Callback for the operation |
seatIndex
will call muteAudio
to mute/unmute his or her audio.onSeatListChange
notification and an onSeatClose
notification.public abstract void closeSeat(int seatIndex, boolean isClose, TRTCVoiceRoomCallback.ActionCallback callback);
Parameter | Type | Description |
seatIndex | int | The number of the seat to block/unblock |
isClose | boolean | true : block; false : unblock |
callback | ActionCallback | Callback for the operation |
seatIndex
will leave the seat.public abstract void startMicrophone();
public abstract void stopMicrophone();
public abstract void setAudioQuality(int quality);
Parameter | Type | Description |
quality | int |
public abstract void muteLocalAudio(boolean mute);
Parameter | Type | Description |
mute | boolean |
public abstract void setSpeaker(boolean useSpeaker);
Parameter | Type | Description |
useSpeaker | boolean | true : Speaker; false : Receiver |
public abstract void setAudioCaptureVolume(int volume);
Parameter | Type | Description |
volume | int | Capturing volume. Value range: 0-100 (default: 100) |
public abstract void setAudioPlayoutVolume(int volume);
Parameter | Type | Description |
volume | int | Playback volume. Value range: 0-100 (default: 100) |
public abstract void muteRemoteAudio(String userId, boolean mute);
Parameter | Type | Description |
userId | String | User ID |
mute | boolean | true : Mute; false : Unmute |
public abstract void muteAllRemoteAudio(boolean mute);
Parameter | Type | Description |
mute | boolean | true : Mute; false : Unmute |
public abstract void setVoiceEarMonitorEnable(boolean enable);
Parameter | Type | Description |
enable | boolean | true : Enable; false : Disable |
public abstract TXAudioEffectManager getAudioEffectManager();
public abstract void sendRoomTextMsg(String message, TRTCVoiceRoomCallback.ActionCallback callback);
Parameter | Type | Description |
message | String | Text message |
callback | ActionCallback | Callback for the operation |
public abstract void sendRoomCustomMsg(String cmd, String message, TRTCVoiceRoomCallback.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 String sendInvitation(String cmd, String userId, String content, TRTCVoiceRoomCallback.ActionCallback callback);
Parameter | Type | Description |
cmd | String | Custom command of business |
userId | String | Invitee’s user ID |
content | String | Invitation content |
callback | ActionCallback | Callback for the operation |
Parameter | Type | Description |
inviteId | String | Invitation ID |
public abstract void acceptInvitation(String id, TRTCVoiceRoomCallback.ActionCallback callback);
Parameter | Type | Description |
id | String | Invitation ID |
callback | ActionCallback | Callback for the operation |
public abstract void rejectInvitation(String id, TRTCVoiceRoomCallback.ActionCallback callback);
Parameter | Type | Description |
id | String | Invitation ID |
callback | ActionCallback | Callback for the operation |
public abstract void cancelInvitation(String id, TRTCVoiceRoomCallback.ActionCallback callback);
Parameter | Type | Description |
id | String | Invitation ID |
callback | ActionCallback | Callback for the operation |
void 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 |
roomInfo
is passed in by the room owner during room creation.void onRoomInfoChange(TRTCVoiceRoomDef.RoomInfo roomInfo);
Parameter | Type | Description |
roomInfo | RoomInfo | Room information |
muteLocalAudio
, all members in the room will receive this callback.void onUserMicrophoneMute(String userId, boolean mute);
Parameter | Type | Description |
userId | String | User ID |
mute | boolean | true : muted; false : unmuted |
void onUserVolumeUpdate(List<TRTCCloudDef.TRTCVolumeInfo> userVolumes, int totalVolume);
Parameter | Type | Description |
userVolumes | ListList<TRTCCloudDef.TRTCVolumeInfo> | List of user IDs |
totalVolume | int | Total volume. Value range: 0-100 |
void onSeatListChange(List<SeatInfo> seatInfoList);
Parameter | Type | Description |
seatInfoList | List<SeatInfo> | Full seat list |
void onAnchorEnterSeat(int index, TRTCVoiceRoomDef.UserInfo user);
Parameter | Type | Description |
index | int | The seat taken |
user | UserInfo | Details of the user who took the seat |
void onAnchorLeaveSeat(int index, TRTCVoiceRoomDef.UserInfo user);
Parameter | Type | Description |
index | int | The seat previously occupied by the speaker |
user | UserInfo | Details of the user who took the seat |
void onSeatMute(int index, boolean isMute);
Parameter | Type | Description |
index | int | The seat muted/unmuted |
isMute | boolean | true : muted; false : unmuted |
void onSeatClose(int index, boolean isClose);
Parameter | Type | Description |
index | int | The seat blocked/unblocked |
isClose | boolean | true : blocked; false : unblocked |
void onAudienceEnter(TRTCVoiceRoomDef.UserInfo userInfo);
Parameter | Type | Description |
userInfo | UserInfo | Information of the listener who entered the room |
void onAudienceExit(TRTCVoiceRoomDef.UserInfo userInfo);
Parameter | Type | Description |
userInfo | UserInfo | Information of the listener who exited the room |
void onRecvRoomTextMsg(String message, TRTCVoiceRoomDef.UserInfo userInfo);
Parameter | Type | Description |
message | String | Text message |
userInfo | UserInfo | Information of the sender |
void onRecvRoomCustomMsg(String cmd, String message, TRTCVoiceRoomDef.UserInfo userInfo);
Parameter | Type | Description |
cmd | String | Custom command word used to distinguish between different message types |
message | String | Text message |
userInfo | UserInfo | Information of the sender |
void onReceiveNewInvitation(String id, String inviter, String cmd, String content);
Parameter | Type | Description |
id | String | Invitation ID |
inviter | String | Inviter’s user ID |
cmd | String | Custom command word specified by business |
content | String | Content specified by business |
void onInviteeAccepted(String id, String invitee);
Parameter | Type | Description |
id | String | Invitation ID |
invitee | String | Invitee’s user ID |
void onInviteeRejected(String id, String invitee);
Parameter | Type | Description |
id | String | Invitation ID |
invitee | String | Invitee’s user ID |
void onInvitationCancelled(String id, String inviter);
Parameter | Type | Description |
id | String | Invitation ID |
inviter | String | Inviter’s user ID |
Was this page helpful?