TRTCMeeting (Android)

Last updated: 2021-09-30 12:02:33

    TRTCMeeting has the following features based on Tencent Real-Time Communication (TRTC) and Instant Messaging (IM):

    • The host can create a meeting room, and the attendees can enter the room ID to join the meeting.
    • The attendees can share their screens with each other.
    • All users can send various text and custom messages.

    TRTCMeeting is an open-source class depending on two closed-source Tencent Cloud SDKs. For the specific implementation process, please see Video Conferencing (Android).

    • TRTC SDK: the TRTC SDK is used as the low-latency video conferencing component.
    • IM SDK: the MeetingRoom feature of the IM SDK is used to implement chat rooms in meetings.

    TRTCMeeting API Overview

    Basic SDK APIs

    API Description
    sharedInstance Gets a singleton object.
    destroySharedInstance Terminates a singleton object.
    setDelegate Sets event callback.
    setDelegateHandler Sets the thread where the event callback is.
    login Logs in.
    logout Logs out.
    setSelfProfile Modifies personal information.

    Meeting room APIs

    API Description
    createMeeting Creates meeting room (called by host).
    destroyMeeting Terminates meeting room (called by host).
    enterMeeting Enters meeting room (called by attendee).
    leaveMeeting Leaves meeting room (called by attendee).

    Remote user APIs

    API Description
    getUserInfoList Gets the list of all users in room. This API will take effect only if it is called after enterMeeting() succeeds.
    getUserInfo Gets the details of specified user in room. This API will take effect only if it is called after enterMeeting() succeeds.
    startRemoteView Plays back the remote video image of specified member.
    stopRemoteView Stops playing back remote video image.
    setRemoteViewFillMode Sets the rendering mode of remote image based on user ID.
    setRemoteViewRotation Sets the clockwise rotation angle of remote image.
    muteRemoteAudio Mutes specified member.
    muteRemoteVideoStream Blocks the video stream of specified member.

    Local video operation APIs

    API Description
    startCameraPreview Enables the preview image of local video.
    stopCameraPreview Stops local video capturing and preview.
    switchCamera Switches between front and rear cameras.
    setVideoResolution Sets resolution.
    setVideoFps Sets frame rate.
    setVideoBitrate Sets bitrate.
    setLocalViewMirror Sets the mirroring preview mode of local image.

    Local audio APIs

    API Description
    startMicrophone Enables mic capturing.
    stopMicrophone Stops mic capturing.
    setAudioQuality Sets audio quality.
    muteLocalAudio Mutes local audio.
    setSpeaker Enables speaker.
    setAudioCaptureVolume Sets mic capturing volume.
    setAudioPlayoutVolume Sets playback volume.
    startFileDumping Starts audio recording.
    stopFileDumping Stops audio recording.
    enableAudioEvaluation Enables volume reminder.

    Screen sharing APIs

    API Description
    startScreenCapture Starts screen sharing.
    stopScreenCapture Stops screen sharing.
    pauseScreenCapture Pauses screen sharing.
    resumeScreenCapture Resumes screen sharing.

    Beauty filter APIs

    API Description
    getBeautyManager Gets the beauty filter management object TXBeautyManager.

    Sharing APIs

    API Description
    getLiveBroadcastingURL Gets CDN sharing link.

    Message sending APIs

    API Description
    sendRoomTextMsg Broadcasts text message in room. This API is generally used for chat.
    sendRoomCustomMsg Sends custom (signaling) message.

    TRTCMeetingDelegate API Overview

    Common event callback APIs

    API Description
    onError Callback for error.

    Meeting room event callbacks

    API Description
    onRoomDestroy Callback for meeting room termination.
    onNetworkQuality Callback for network status.
    onUserVolumeUpdate Callback for user call volume.

    Member entry/exit event callbacks

    API Description
    onUserEnterRoom Notification of new member's room entry.
    onUserLeaveRoom Notification of member's room exit.

    Member audio/video event callbacks

    API Description
    onUserVideoAvailable Notification of member enabling/disabling camera.
    onUserAudioAvailable Notification of member enabling/disabling mic.

    Message event callback APIs

    API Description
    onRecvRoomTextMsg Receipt of text message.
    onRecvRoomCustomMsg Receipt of custom message.

    Screen sharing event callbacks

    API Description
    onScreenCaptureStarted Notification of screen sharing start.
    onScreenCapturePaused Callback for screen sharing pause.
    onScreenCaptureResumed Callback for screen sharing resumption.
    onScreenCaptureStoped Callback for screen sharing stop.

    Basic SDK APIs

    sharedInstance

    This API is used to get the TRTCMeeting singleton object.

    public static synchronized TRTCMeeting sharedInstance(Context context);
    

    The parameters are as detailed below:

    Parameter Type Description
    context Context Android context, which will be converted to ApplicationContext for the calling of system APIs

    destroySharedInstance

    This API is used to terminate the TRTCMeeting singleton object.

    Note:

    After the instance is terminated, the externally cached TRTCMeeting instance cannot be used, and you need to call sharedInstance again to get a new instance.

    public static void destroySharedInstance();
    

    setDelegate

    This API is used to get the event callback of TRTCMeeting. You can use TRTCMeetingDelegate to get various status notifications of TRTCMeeting.

    public abstract void setDelegate(TRTCMeetingDelegate delegate);
    
    Note:

    setDelegate is the delegation callback of TRTCMeeting.

    setDelegateHandler

    This API is used to set the thread where the event callback is.

    public abstract void setDelegateHandler(Handler handler);
    

    The parameters are as detailed below:

    Parameter Type Description
    handler Handler Notifies various status notification callbacks in TRTCMeeting through this handler. Please do not use this parameter together with setDelegate.

    login

    This API is used to log in.

    public abstract void login(int sdkAppId,
     String userId, String userSig,
     TRTCMeetingCallback.ActionCallback callback);
    

    The parameters are as detailed below:

    Parameter Type Description
    sdkAppId int You can view the SDKAppID in the TRTC console > Application Management > "Application Info".
    userId String 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 protection signature. For more information on how to get it, please see How to Calculate UserSig.
    callback ActionCallback Callback for login. The code will be 0 if login succeeds.

    logout

    This API is used to log out.

    public abstract void logout(TRTCMeetingCallback.ActionCallback callback);
    

    The parameters are as detailed below:

    Parameter Type Description
    callback ActionCallback Callback for logout. The code is 0 if logout succeeds.

    setSelfProfile

    This API is used to set profile.

    public abstract void setSelfProfile(String userName, String avatarURL, TRTCMeetingCallback.ActionCallback callback);
    

    The parameters are as detailed below:

    Parameter Type Description
    userName String Nickname
    avatarURL String Profile photo address
    callback ActionCallback Callback for personal information setting. The code will be 0 if the operation succeeds.

    Meeting Room APIs

    createMeeting

    This API is used to create a meeting (called by the host).

    public abstract void createMeeting(int roomId, TRTCMeetingCallback.ActionCallback callback);
    

    The parameters are as detailed below:

    Parameter Type Description
    roomId int Meeting room ID. You need to assign and manage the IDs in a centralized manner.
    callback ActionCallback Callback for room creation result. The code will be 0 if the operation succeeds.

    Generally, the host calls the APIs in the following steps:

    1. The host calls createMeeting() to create a meeting. No matter whether the room is successfully created, the result will be notified to the host through ActionCallback.
    2. The host calls startCameraPreview() to enable camera preview. At this time, the beauty filter parameters can be adjusted.
    3. The host calls startMicrophone() to enable mic capturing.

    destroyMeeting

    This API is used to terminate a meeting room (called by the host). After creating a meeting, the host can call this API to terminate it.

    public abstract void destroyMeeting(int roomId, TRTCMeetingCallback.ActionCallback callback);
    

    The parameters are as detailed below:

    Parameter Type Description
    roomId int Meeting room ID. You need to assign and manage the IDs in a centralized manner.
    callback ActionCallback Callback for room termination result. The code is 0 if the operation succeeds.

    enterMeeting

    This API is used to enter a meeting (called by the attendee).

    public abstract void enterMeeting(int roomId, TRTCMeetingCallback.ActionCallback callback);
    

    The parameters are as detailed below:

    Parameter Type Description
    roomId int Meeting room ID.
    callback ActionCallback Callback for room entry result. The code is 0 if the operation succeeds.

    Generally, the attendee joins a meeting in the following steps:

    1. The attendee calls enterMeeting and passes in roomId to enter the meeting room.
    2. The attendee calls startCameraPreview() to enable camera preview and calls startMicrophone() to enable mic capturing.
    3. The attendee receives the onUserVideoAvailable event and calls startRemoteView(userId) and passes in the userId of the target member to start playback.

    leaveMeeting

    This API is used to leave a meeting (called by the attendee).

    public abstract void leaveMeeting(TRTCMeetingCallback.ActionCallback callback);
    

    The parameters are as detailed below:

    Parameter Type Description
    callback ActionCallback Callback for room exit result. The code is 0 if the operation succeeds.

    Remote User APIs

    getUserInfoList

    This API is used to get the list of all users in the room. It will take effect only if it is called after enterMeeting() succeeds.

    public abstract void getUserInfoList(TRTCMeetingCallback.UserListCallback userListCallback);
    

    The parameters are as detailed below:

    Parameter Type Description
    userListCallback UserListCallback Callback for user details.

    getUserInfo

    This API is used to get the details of a specified user in the room. It will take effect only if it is called after enterMeeting() succeeds.

    public abstract void getUserInfo(String userId, TRTCMeetingCallback.UserListCallback userListCallback);
    

    The parameters are as detailed below:

    Parameter Type Description
    userId String User ID
    userListCallback UserListCallback Callback for user details.

    startRemoteView

    This API is used to play back the remote video image of a specified member. It can be called when the callback of onUserVideoAvailable() is true.

    public abstract void startRemoteView(String userId, TXCloudVideoView view, final TRTCMeetingCallback.ActionCallback callback);
    

    The parameters are as detailed below:

    Parameter Type Description
    userId String ID of the user whose video image is to be played back.
    view TXCloudVideoView view control that carries the video image.
    callback ActionCallback Callback for operation.

    stopRemoteView

    This API is used to stop playing back the remote video image. It can be called when the callback of onUserVideoAvailable() is false.

    public abstract void stopRemoteView(String userId, final TRTCMeetingCallback.ActionCallback callback);
    

    The parameters are as detailed below:

    Parameter Type Description
    userId String ID of the user whose video image is to be stopped.
    callback ActionCallback Callback for operation.

    setRemoteViewFillMode

    This API is used to set the rendering mode of the remote video image based on user ID.

    public abstract void setRemoteViewFillMode(String userId, int fillMode);
    

    The parameters are as detailed below:

    Parameter Type Description
    userId String User ID
    fillMode int Fill or fit mode. Default value: fill (FILL). For more information, please see TRTC SDK.

    setRemoteViewRotation

    This API is used to set the clockwise rotation angle of the remote image.

    public abstract void setRemoteViewRotation(String userId, int rotation);
    

    The parameters are as detailed below:

    Parameter Type Description
    userId String User ID.
    rotation int Clockwise rotation angle. For more information, please see TRTC SDK.

    muteRemoteAudio

    This API is used to mute or unmute a remote user.

    public abstract void muteRemoteAudio(String userId, boolean mute);
    

    The parameters are as detailed below:

    Parameter Type Description
    userId String User ID.
    mute boolean true: mutes; false: unmutes.

    muteRemoteVideoStream

    This API is used to block the remote video stream of a specified member.

    public abstract void muteRemoteVideoStream(String userId, boolean mute);
    

    The parameters are as detailed below:

    Parameter Type Description
    userId String User ID.
    mute boolean true: blocks; false: unblocks.

    Local Video Operation APIs

    startCameraPreview

    This API is used to enable local video preview.

    public abstract void startCameraPreview(boolean isFront, TXCloudVideoView view);
    

    The parameters are as detailed below:

    Parameter Type Description
    isFront boolean true: front camera; false: rear camera.
    view TXCloudVideoView Control that carries the video image.

    stopCameraPreview

    This API is used to stop local video capturing and preview.

    public abstract void stopCameraPreview();
    

    switchCamera

    This API is used to switch between front and rear cameras.

    public abstract void switchCamera(boolean isFront);
    

    The parameters are as detailed below:

    Parameter Type Description
    isFront boolean Switches between front and rear cameras. true: front camera; false: rear camera.

    setVideoResolution

    Set the resolution

    public abstract void setVideoResolution(int resolution);
    

    The parameters are as detailed below:

    Parameter Type Description
    resolution int Video resolution. For more information, please see TRTC SDK.

    setVideoFps

    This API is used to set the frame rate.

    public abstract void setVideoFps(int fps);
    

    The parameters are as detailed below:

    Parameter Type Description
    fps int Video capturing frame rate.
    Note:

    Recommended value: 15 or 20 fps. If the frame rate is lower than 5 fps, there will be obvious lagging; if lower than 10 fps but higher than 5 fps, there will be slight lagging; if higher than 20 fps, too many resources will be wasted (the frame rate of movies is generally 24 fps).

    setVideoBitrate

    This API is used to set the bitrate.

    public abstract void setVideoBitrate(int bitrate);
    

    The parameters are as detailed below:

    Parameter Type Description
    bitrate int Bitrate. The SDK encodes streams at the target video bitrate and will actively reduce the bitrate only if the network conditions are poor. For more information, please see TRTC SDK.
    Note:

    Recommended value: please see the optimal bitrate for each tier in TRTCVideoResolution. You can also slightly increase the optimal bitrate. For example, TRTC_VIDEO_RESOLUTION_1280_720 corresponds to the target bitrate of 1,200 Kbps, and you can also set the bitrate to 1,500 Kbps for higher definition.

    setLocalViewMirror

    This API is used to set the mirroring preview mode of local video image.

    public abstract void setLocalViewMirror(int type);
    

    The parameters are as detailed below:

    Parameter Type Description
    type int Mirroring mode. For more information, please see TRTC SDK.

    Local Audio APIs

    startMicrophone

    This API is used to enable mic capturing.

    public abstract void startMicrophone();
    

    stopMicrophone

    This API is used to stop mic capturing.

    public abstract void stopMicrophone();
    

    setAudioQuality

    This API is used to set audio quality.

    public abstract void setAudioQuality(int quality);
    

    The parameters are as detailed below:

    Parameter Type Description
    quality int Audio quality. For more information, please see TRTC SDK.

    muteLocalAudio

    This API is used to mute/unmute local audio.

    public abstract void muteLocalAudio(boolean mute);
    

    The parameters are as detailed below:

    Parameter Type Description
    mute boolean Mutes/Unmutes. For more information, please see TRTC SDK.

    setSpeaker

    This API is used to enable the speaker.

    public abstract void setSpeaker(boolean useSpeaker);
    

    The parameters are as detailed below:

    Parameter Type Description
    useSpeaker boolean true: speaker; false: receiver.

    setAudioCaptureVolume

    This API is used to set the mic capturing volume.

    public abstract void setAudioCaptureVolume(int volume);
    

    The parameters are as detailed below:

    Parameter Type Description
    volume int Capture volume. Value range: 0–100. Default value: 100.

    setAudioPlayoutVolume

    This API is used to set the playback volume.

    public abstract void setAudioPlayoutVolume(int volume);
    

    The parameters are as detailed below:

    Parameter Type Description
    volume int Playback volume. Value range: 0–100. Default value: 100.

    startFileDumping

    This API is used to start audio recording.

    public abstract void startFileDumping(TRTCCloudDef.TRTCAudioRecordingParams trtcAudioRecordingParams);
    

    The parameters are as detailed below:

    Parameter Type Description
    trtcAudioRecordingParams TRTCCloudDef.TRTCAudioRecordingParams Audio recording parameters. For more information, please see TRTC SDK.
    Note:

    After this API is called, the SDK will record all audios (such as local audio, remote audio, and background music) in the current call to a file. No matter whether room entry is performed, this API will take effect once called. If audio recording is still ongoing when exitMeeting is called, it will stop automatically.

    stopFileDumping

    This API is used to stop audio recording.

    public abstract void stopFileDumping();
    

    enableAudioEvaluation

    This API is used to enable the volume reminder.

    public abstract void enableAudioEvaluation(boolean enable);
    

    The parameters are as detailed below:

    Parameter Type Description
    enable boolean true: enables; false: disables.
    Note:

    After this feature is enabled, the result of volume evaluation by the SDK will be obtained in onUserVolumeUpdate.

    Screen Sharing APIs

    startScreenCapture

    This API is used to start screen sharing.

    public abstract void startScreenCapture(TRTCCloudDef.TRTCVideoEncParam encParams, TRTCCloudDef.TRTCScreenShareParams screenShareParams);
    

    The parameters are as detailed below:

    Parameter Type Description
    encParams TRTCCloudDef.TRTCVideoEncParam Screen sharing encoding parameters. We recommend you use the above configuration. If you set encParams to null, the encoding parameter settings before startScreenCapture is called will be used.
    screenShareParams TRTCCloudDef.TRTCScreenShareParams Special screen sharing configuration. We recommend you set floatingView which can prevent the application from being killed by the system and help protect user privacy.
    Note:

    For more information, please see TRTC SDK.

    stopScreenCapture

    This API is used to stop screen capture.

    public abstract void stopScreenCapture();
    

    pauseScreenCapture

    This API is used to pause screen sharing.

    public abstract void pauseScreenCapture();
    

    resumeScreenCapture

    This API is used to resume screen sharing.

    public abstract void resumeScreenCapture();
    

    Sharing APIs

    getLiveBroadcastingURL

    This API is used to get the CDN sharing link.

    public abstract String getLiveBroadcastingURL();
    

    The returned values are as detailed below:

    Returned Value Type Description
    url String CDN sharing link.

    Beauty Filter APIs

    getBeautyManager

    This API is used to get the beauty filter management object TXBeautyManager.

    public abstract TXBeautyManager getBeautyManager();
    

    You can do the following using TXBeautyManager:

    • Set the beauty filter style and apply effects including skin brightening, rosy skin, eye enlarging, face slimming, chin slimming, chin lengthening/shortening, face shortening, nose narrowing, eye brightening, teeth whitening, eye bag removal, wrinkle removal, and smile line removal.
    • Adjust the hairline, eye spacing, eye corners, lip shape, nose wings, nose position, lip thickness, and face shape.
    • Apply animated effects such as face widgets (materials).
    • Add makeup effects.
    • Recognize gestures.

    Message Sending APIs

    sendRoomTextMsg

    This API is used to broadcast a text message in the room.

    public abstract void sendRoomTextMsg(String message, TRTCMeetingCallback.ActionCallback callback);
    

    The parameters are as detailed below:

    Parameter Type Description
    message String Text message.
    callback ActionCallback Callback for operation

    sendRoomCustomMsg

    This API is used to send a custom text message.

    public abstract void sendRoomCustomMsg(String cmd, String message, TRTCMeetingCallback.ActionCallback callback);
    

    The parameters are as detailed below:

    Parameter Type Description
    cmd String Custom command word used to distinguish between different message types
    message String Text message
    callback ActionCallback Callback for operation

    TRTCMeetingDelegate Event Callback APIs

    Common Event Callback APIs

    onError

    Callback for error.
    This callback indicates that the SDK encountered an unrecoverable error. Such errors must be listened for, and UI reminders should be sent to users if necessary.

    void onError(int code, String message);
    

    The parameters are as detailed below:

    Parameter Type Description
    code int Error code
    message String Error message

    Room Event Callback APIs

    onRoomDestroy

    Callback for room termination. When the host leaves the room, all users in the room will receive this callback.

    void onRoomDestroy(String roomId);
    

    The parameters are as detailed below:

    Parameter Type Description
    roomId String Room ID

    onNetworkQuality

    Callback for network status.

    void onNetworkQuality(TRTCCloudDef.TRTCQuality localQuality, List<TRTCCloudDef.TRTCQuality> remoteQuality);
    

    The parameters are as detailed below:

    Parameter Type Description
    localQuality TRTCCloudDef.TRTCQuality Upstream network quality.
    remoteQuality List&dxlt;TRTCCloudDef.TRTCQuality&dxgt; Downstream network quality.
    Note:

    For more information, please see TRTC SDK.

    onUserVolumeUpdate

    Notification to all members of the volume after the volume reminder is enabled.

    void onUserVolumeUpdate(String userId, int volume);
    

    The parameters are as detailed below:

    Parameter Type Description
    userId String User ID
    volume int Volume. Value range: 0–100

    Member Entry/Exit Event Callbacks

    onUserEnterRoom

    Notification of new member's room entry.

    void onUserEnterRoom(String userId);
    

    The parameters are as detailed below:

    Parameter Type Description
    userId String User ID of the new member who enters the room

    onUserLeaveRoom

    Notification of member's room exit.

    void onUserLeaveRoom(String userId);
    

    The parameters are as detailed below:

    Parameter Type Description
    userId String User ID of the member who leaves the room

    Member Audio/Video Event Callbacks

    onUserVideoAvailable

    Notification of member enabling/disabling camera.

    void onUserVideoAvailable(String userId, boolean available);
    

    The parameters are as detailed below:

    Parameter Type Description
    userId String User ID.
    available boolean true: the camera is enabled; false: the camera is disabled.

    onUserAudioAvailable

    Notification of member enabling/disabling mic.

    void onUserAudioAvailable(String userId, boolean available);
    

    The parameters are as detailed below:

    Parameter Type Description
    userId String User ID
    available boolean true: the mic is enabled; false: the mic is disabled;

    Message Event Callback APIs

    onRecvRoomTextMsg

    A text message was received.

    void onRecvRoomTextMsg(String message, TRTCMeetingDef.UserInfo userInfo);
    

    The parameters are as detailed below:

    Parameter Type Description
    message String Text message
    userInfo TRTCMeetingDef.UserInfo Information of sender

    onRecvRoomCustomMsg

    A custom message was received.

    void onRecvRoomCustomMsg(String cmd, String message, TRTCMeetingDef.UserInfo userInfo);
    

    The parameters are as detailed below:

    Parameter Type Description
    cmd String Custom command word used to distinguish between different message types
    message String Text message
    userInfo TRTCMeetingDef.UserInfo Information of sender

    Screen Sharing Event Callbacks

    onScreenCaptureStarted

    Screen sharing start notification.

    void onScreenCaptureStarted();
    

    onScreenCapturePaused

    Screen sharing pause notification.

    void onScreenCapturePaused();
    

    onScreenCaptureResumed

    Screen sharing resumption notification.

    void onScreenCaptureResumed();
    

    onScreenCaptureStoped

    Screen sharing stop notification.

    void onScreenCaptureStopped(int reason);
    

    The parameters are as detailed below:

    Parameter Type Description
    reason int Reason for stop. 0: the user stopped proactively; 1: stopped due to preemption by another application.