TRTCKaraokeRoom
includes the following features, which are based on Tencent Real-Time Communication (TRTC) and Tencent Cloud Chat.TRTCKaraokeRoom
is an open-source class that depends on two closed-source Tencent Cloud SDKs. For the specific implementation process, see Karaoke (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.TRTCKaraokeRoom
API OverviewAPI | 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 |
Starts music. | |
Stops music. | |
Pauses music. | |
Resumes music. |
API | Description |
Becomes a speaker (called by room owner or listener). | |
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 use the device speaker or receiver to play audio. | |
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. |
TRTCKaraokeRoomDelegate
API OverviewAPI | Description |
Callback for error. | |
Callback for warning. | |
Callback of log. |
API | Description |
The room was terminated. | |
The room information changed. | |
The user volume. |
API | Description |
All seat changes. | |
A user became a speaker or was made a speaker by the room owner. | |
A user became a listener or was made a listener 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 |
Receipt of an invitation. | |
Invitation accepted by invitee. | |
Invitation declined by invitee. | |
The inviter canceled the invitation. |
API | Description |
Music playback progress. | |
Music playback is ready. | |
Music playback was completed. |
public static synchronized TRTCKaraokeRoom sharedInstance(Context context);
Parameter | Type | Description |
context | Context | Android context, which will be converted to ApplicationContext for the calling of system APIs. |
TRTCKaraokeRoom
instance can no longer be used. You need to call sharedInstance again to get a new instance.public static void destroySharedInstance();
TRTCKaraokeRoomDelegate
to get different status notifications of TRTCKaraokeRoom.public abstract void setDelegate(TRTCKaraokeRoomDelegate delegate);
setDelegate
is the delegate callback of TRTCKaraokeRoom
. public abstract void setDelegateHandler(Handler handler);
Parameter | Type | Description |
handler | Handler | The status notifications of TRTCKaraokeRoom are sent to the handler thread you specify. |
public abstract void login(int sdkAppId,String userId, String userSig,TRTCKaraokeRoomCallback.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. |
callback | ActionCallback | The callback for login. The code is 0 if login succeeds. |
public abstract void logout(TRTCKaraokeRoomCallback.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, TRTCKaraokeRoomCallback.ActionCallback callback);
Parameter | Type | Description |
userName | String | The username. |
avatar | String | The address of the profile photo. |
callback | ActionCallback | The callback for profile configuration. The code is 0 if the operation succeeds. |
public abstract void createRoom(int roomId, TRTCKaraokeRoomDef.RoomParam roomParam, TRTCKaraokeRoomCallback.ActionCallback callback);
Parameter | Type | Description |
roomId | int | The room ID. You need to assign and manage room 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 karaoke 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 | The callback for room creation. The code is 0 if the operation succeeds. |
createRoom
to create a karaoke room, passing in room attributes (i.e., room ID, whether listeners need room owner’s permission 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(TRTCKaraokeRoomCallback.ActionCallback callback);
Parameter | Type | Description |
callback | ActionCallback | The callback for room termination. The code is 0 if the operation succeeds. |
public abstract void enterRoom(int roomId, TRTCKaraokeRoomCallback.ActionCallback callback);
Parameter | Type | Description |
roomId | int | The room ID. |
callback | ActionCallback | The callback for room entry. The code is 0 if the operation succeeds. |
roomId
and room information of multiple karaoke rooms.enterRoom
with the room ID passed in.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 permission 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(TRTCKaraokeRoomCallback.ActionCallback callback);
Parameter | Type | Description |
callback | ActionCallback | The callback for room exit. The code is 0 if the operation succeeds. |
roomInfo
when calling createRoom()
.public abstract void getRoomInfoList(List<Integer> roomIdList, TRTCKaraokeRoomCallback.RoomInfoCallback callback);
Parameter | Type | Description |
roomIdList | List<Integer> | The list of room IDs. |
callback | RoomInfoCallback | The callback of room details. |
userId
.public abstract void getUserInfoList(List<String> userIdList, TRTCKaraokeRoomCallback.UserListCallback userlistcallback);
Parameter | Type | Description |
userIdList | List<String> | The IDs of the users to query. If this parameter is null , the information of all users in the room is queried. |
userlistcallback | UserListCallback | The callback of user details. |
onMusicPrepareToPlay
notification.onMusicProgressUpdate
notification.onMusicCompletePlaying
notification.public abstract void startPlayMusic(int musicID, String originalUrl, String accompanyUrl);
Parameter | Type | Description |
musicID | int | The music ID. |
originalUrl | String | The absolute path of the vocal track. |
accompanyUrl | String | The absolute path of the instrumental track. |
onMusicCompletePlaying
notification.public abstract void stopPlayMusic();
onMusicProgressUpdate
notification will be paused.onMusicCompletePlaying
notification will be received.public abstract void pausePlayMusic();
onMusicPrepareToPlay
notification will be received.public abstract void resumePlayMusic();
onSeatListChange
notification and an onAnchorEnterSeat
notification.public abstract void enterSeat(int seatIndex, TRTCKaraokeRoomCallback.ActionCallback callback);
Parameter | Type | Description |
seatIndex | int | The number of the seat to be taken. |
callback | ActionCallback | The callback for the operation. |
sendInvitation
first to send a request and, after receiving onInvitationAccept
, call this API.onSeatListChange
notification and an onAnchorLeaveSeat
notification.public abstract void leaveSeat(TRTCKaraokeRoomCallback.ActionCallback callback);
Parameter | Type | Description |
callback | ActionCallback | The callback for the operation. |
onSeatListChange
notification and an onAnchorEnterSeat
notification.public abstract void pickSeat(int seatIndex, String userId, TRTCKaraokeRoomCallback.ActionCallback callback);
Parameter | Type | Description |
seatIndex | int | The number of the seat to place the listener in. |
userId | String | The user ID. |
callback | ActionCallback | The 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, TRTCKaraokeRoomCallback.ActionCallback callback);
Parameter | Type | Description |
seatIndex | int | The number of the seat to remove the speaker from. |
callback | ActionCallback | The callback for the operation. |
onSeatListChange
notification and an onSeatMute
notification.public abstract void muteSeat(int seatIndex, boolean isMute, TRTCKaraokeRoomCallback.ActionCallback callback);
Parameter | Type | Description |
seatIndex | int | The number of the seat to mute/unmute. |
isMute | boolean | true : Mute; false : Unmute |
callback | ActionCallback | The 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, TRTCKaraokeRoomCallback.ActionCallback callback);
Parameter | Type | Description |
seatIndex | int | The number of the seat to block/unblock. |
isClose | boolean | true : Block; false : Unblock |
callback | ActionCallback | The 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 | The capturing volume. Value range: 0-100 (default: 100) |
public abstract void setAudioPlayoutVolume(int volume);
Parameter | Type | Description |
volume | int | The playback volume. Value range: 0-100 (default: 100) |
public abstract void muteRemoteAudio(String userId, boolean mute);
Parameter | Type | Description |
userId | String | The 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, TRTCKaraokeRoomCallback.ActionCallback callback);
Parameter | Type | Description |
message | String | A text chat message. |
callback | ActionCallback | The callback for the operation. |
public abstract void sendRoomCustomMsg(String cmd, String message, TRTCKaraokeRoomCallback.ActionCallback callback);
Parameter | Type | Description |
cmd | String | A custom command word used to distinguish between different message types. |
message | String | A text chat message. |
callback | ActionCallback | The callback for the operation. |
public abstract String sendInvitation(String cmd, String userId, String content, TRTCKaraokeRoomCallback.ActionCallback callback);
Parameter | Type | Description |
cmd | String | Custom command of business |
userId | String | The user ID of the invitee. |
content | String | The content of the invitation. |
callback | ActionCallback | The callback for the operation. |
Parameter | Type | Description |
inviteId | String | The invitation ID. |
public abstract void acceptInvitation(String id, TRTCKaraokeRoomCallback.ActionCallback callback);
Parameter | Type | Description |
id | String | The invitation ID. |
callback | ActionCallback | The callback for the operation. |
public abstract void rejectInvitation(String id, TRTCKaraokeRoomCallback.ActionCallback callback);
Parameter | Type | Description |
id | String | Invitation ID |
callback | ActionCallback | The callback for the operation. |
public abstract void cancelInvitation(String id, TRTCKaraokeRoomCallback.ActionCallback callback);
Parameter | Type | Description |
id | String | The invitation ID. |
callback | ActionCallback | The callback for the operation. |
TRTCKaraokeRoomDelegate
Event Callback APIsvoid onError(int code, String message);
Parameter | Type | Description |
code | int | The error code. |
message | String | The error message. |
void onWarning(int code, String message);
Parameter | Type | Description |
code | int | The error code. |
message | String | The warning message. |
void onDebugLog(String message);
Parameter | Type | Description |
message | String | Log information. |
void onRoomDestroy(String roomId);
Parameter | Type | Description |
roomId | String | The room ID. |
roomInfo
is passed in by the room owner during room creation.void onRoomInfoChange(TRTCKaraokeRoomDef.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 | The user ID. |
mute | boolean | The volume level. Value range: 0-100 |
void onUserVolumeUpdate(List<TRTCCloudDef.TRTCVolumeInfo> userVolumes, int totalVolume);
Parameter | Type | Description |
userVolumes | List | List of user volumes. |
totalVolume | int | The total volume. Value range: 0-100 |
void onSeatListChange(List<SeatInfo> seatInfoList);
Parameter | Type | Description |
seatInfoList | List<SeatInfo> | The full seat list. |
void onAnchorEnterSeat(int index, TRTCKaraokeRoomDef.UserInfo user);
Parameter | Type | Description |
index | int | The seat taken. |
user | UserInfo | The details of the user who took the seat. |
void onAnchorLeaveSeat(int index, TRTCKaraokeRoomDef.UserInfo user);
Parameter | Type | Description |
index | int | The seat previously occupied by the speaker. |
user | UserInfo | The details of the user who became a listener. |
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(TRTCKaraokeRoomDef.UserInfo userInfo);
Parameter | Type | Description |
userInfo | UserInfo | The information of the listener who entered the room. |
void onAudienceExit(TRTCKaraokeRoomDef.UserInfo userInfo);
Parameter | Type | Description |
userInfo | UserInfo | The information of the listener who exited the room. |
void onRecvRoomTextMsg(String message, TRTCKaraokeRoomDef.UserInfo userInfo);
Parameter | Type | Description |
message | String | A text chat message. |
userInfo | UserInfo | Information of the sender. |
void onRecvRoomCustomMsg(String cmd, String message, TRTCKaraokeRoomDef.UserInfo userInfo);
Parameter | Type | Description |
command | String | A custom command word used to distinguish between different message types. |
message | String | A text chat message. |
userInfo | UserInfo | Information of the sender. |
void onReceiveNewInvitation(String id, String inviter, String cmd, String content);
Parameter | Type | Description |
id | String | The invitation ID. |
inviter | String | The user ID of the inviter. |
cmd | String | A custom command word specified by business. |
content | String | Content specified by business |
void onInviteeAccepted(String id, String invitee);
Parameter | Type | Description |
id | String | The invitation ID. |
invitee | String | The user ID of the invitee. |
void onInviteeRejected(String id, String invitee);
Parameter | Type | Description |
id | String | The invitation ID. |
invitee | String | The user ID of the invitee. |
void onInvitationCancelled(String id, String inviter);
Parameter | Type | Description |
id | String | The invitation ID. |
inviter | String | The user ID of the inviter. |
void onMusicPrepareToPlay(int musicID);
Parameter | Type | Description |
musicID | int | The musicID passed in for playback. |
void onMusicProgressUpdate(int musicID, long progress, long total);
Parameter | Type | Description |
musicID | int | The musicID passed in for playback. |
progress | long | The current playback progress in ms. |
total | long | The total duration in ms. |
void onMusicCompletePlaying(int musicID);
Parameter | Type | Description |
musicID | int | The musicID passed in for playback. |
Was this page helpful?