Kebijakan Privasi
Perjanjian Pemrosesan dan Keamanan Data
Concept | Tencent RTC Engine | Twilio Video | Description |
Room | Room | Room | Session space connecting RTC participants. Tencent RTC uses roomId (numeric) or strRoomId (string); Twilio uses roomName (string). |
User | User | Participant | User participating in audio/video calls. |
Anchor | Anchor | — | User type with streaming permissions; can send and receive audio/video streams to/from the server. |
Audience | Audience | — | User type that only receives audio/video streams. |
Application Identifier | SDKAppID | Account SID | Unique application identifier. |
Authentication Credential | UserSig | Access Token | Client authentication credential. |
User Identifier | userId | Identity | Unique user identifier. |
Core Entry Class | TRTCCloud | Video (class) | SDK core entry class. |
LocalAudioTrack and LocalVideoTrack.ConnectOptions.Builder / the connect options).RemoteParticipant.Listener callbacks.VideoSink or VideoView.startLocalPreview() and startLocalAudio() to capture and publish.TRTCCloudListener callbacks and play it with startRemoteView().TXCloudVideoView.

dependencies {implementation 'com.twilio:video-android:7.10.2'}
dependencies section of app/build.gradle.dependencies {implementation 'com.tencent.liteav:LiteAVSDK_TRTC:latest.release'}
defaultConfig section of app/build.gradle for devices using armeabi-v7a/arm64-v8a.android {defaultConfig {ndk {abiFilters 'armeabi-v7a', 'arm64-v8a'}}}
AndroidManifest.xml.<uses-permission android:name="android.permission.INTERNET" /><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /><uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /><uses-permission android:name="android.permission.CAMERA" /><uses-permission android:name="android.permission.RECORD_AUDIO" /><uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /><uses-permission android:name="android.permission.BLUETOOTH" /><uses-feature android:name="android.hardware.camera.autofocus" />
android:hardwareAccelerated="false". Disabling hardware acceleration will prevent video streams from rendering.proguard-rules.pro.-keep class com.tencent.** { *; }
// Twilio Video does not require explicit SDK instance initialization.// Connect to a room directly using Video.connect() static method.// Optional: Set log levelVideo.setLogLevel(LogLevel.DEBUG);
// Create TRTCCloud singleton instanceTRTCCloud mCloud = TRTCCloud.sharedInstance(getApplicationContext());
// Create TRTCCloud singleton instanceval mCloud = TRTCCloud.sharedInstance(applicationContext)
Room.Listener roomListener = new Room.Listener() {@Overridepublic void onConnected(Room room) {Log.i("Twilio", "Connected to " + room.getName());}@Overridepublic void onConnectFailure(Room room, TwilioException twilioException) {Log.e("Twilio", "Connect failure: " + twilioException.getMessage());}@Overridepublic void onDisconnected(Room room, TwilioException twilioException) {Log.i("Twilio", "Disconnected from " + room.getName());}@Overridepublic void onParticipantConnected(Room room, RemoteParticipant remoteParticipant) {Log.i("Twilio", "Participant connected: " + remoteParticipant.getIdentity());}@Overridepublic void onParticipantDisconnected(Room room, RemoteParticipant remoteParticipant) {Log.i("Twilio", "Participant disconnected: " + remoteParticipant.getIdentity());}@Overridepublic void onReconnecting(Room room, TwilioException twilioException) {Log.i("Twilio", "Reconnecting...");}@Overridepublic void onReconnected(Room room) {Log.i("Twilio", "Reconnected");}};
TRTCCloudListener trtcListener = new TRTCCloudListener() {@Overridepublic void onEnterRoom(long result) {if (result > 0) {Log.i("TRTC", "Room entry successful, took " + result + "ms");} else {Log.e("TRTC", "Room entry failed, error code " + result);}}@Overridepublic void onExitRoom(int reason) {// reason: 0-user voluntarily left 1-kicked out 2-room dissolvedLog.i("TRTC", "Exited room, reason: " + reason);}@Overridepublic void onRemoteUserEnterRoom(String userId) {Log.i("TRTC", "Remote user entered room: " + userId);}@Overridepublic void onRemoteUserLeaveRoom(String userId, int reason) {Log.i("TRTC", "Remote user left room: " + userId);}@Overridepublic void onError(int errCode, String errMsg, Bundle extraInfo) {Log.e("TRTC", "Error: " + errCode + " - " + errMsg);}@Overridepublic void onConnectionLost() {Log.w("TRTC", "Disconnected from server");}@Overridepublic void onTryToReconnect() {Log.i("TRTC", "Attempting to reconnect...");}@Overridepublic void onConnectionRecovery() {Log.i("TRTC", "Connection recovered");}};mCloud.addListener(trtcListener);
val trtcListener = object : TRTCCloudListener() {override fun onEnterRoom(result: Long) {if (result > 0) {Log.i("TRTC", "Room entry successful, took ${result}ms")} else {Log.e("TRTC", "Room entry failed, error code $result")}}override fun onExitRoom(reason: Int) {// reason: 0-user voluntarily left 1-kicked out 2-room dissolvedLog.i("TRTC", "Exited room, reason: $reason")}override fun onRemoteUserEnterRoom(userId: String?) {Log.i("TRTC", "Remote user entered room: $userId")}override fun onRemoteUserLeaveRoom(userId: String?, reason: Int) {Log.i("TRTC", "Remote user left room: $userId")}override fun onError(errCode: Int, errMsg: String?, extraInfo: Bundle?) {Log.e("TRTC", "Error: $errCode - $errMsg")}override fun onConnectionLost() {Log.w("TRTC", "Disconnected from server")}override fun onTryToReconnect() {Log.i("TRTC", "Attempting to reconnect...")}override fun onConnectionRecovery() {Log.i("TRTC", "Connection recovered")}}mCloud.addListener(trtcListener)
Twilio Video Callback | Tencent RTC Engine Callback | Description |
onConnected | onEnterRoom (result > 0) | Successfully connected to/entered room. |
onConnectFailure | onEnterRoom (result < 0) or onError | Connection failed. |
onDisconnected | onExitRoom | Disconnected/left the room. |
onParticipantConnected | onRemoteUserEnterRoom | Remote user entered. |
onParticipantDisconnected | onRemoteUserLeaveRoom | Remote user left. |
onReconnecting | onConnectionLost + onTryToReconnect | Reconnecting. |
onReconnected | onConnectionRecovery | Reconnection successful. |
// Build connection options (exclude local tracks; publish tracks dynamically after connecting)ConnectOptions connectOptions = new ConnectOptions.Builder(accessToken).roomName("my-room").build();// Connect to the room using the predefined roomListenerRoom room = Video.connect(context, connectOptions, roomListener);
// Set up room entry parametersTRTCCloudDef.TRTCParams trtcParams = new TRTCCloudDef.TRTCParams();trtcParams.sdkAppId = 2000000000; // Your SDKAppIDtrtcParams.userId = "user_id"; // User IDtrtcParams.userSig = "user_sig"; // User signaturetrtcParams.role = TRTCCloudDef.TRTCRoleAudience; // User role when entering the roomtrtcParams.strRoomId = "my-room"; // Room ID (string type)// If using a numeric room ID:// trtcParams.roomId = 123456;// Enter the room// TRTC_APP_SCENE_VIDEOCALL: Video call scenario (equivalent to Twilio Peer-to-Peer Room)// TRTC_APP_SCENE_LIVE: Interactive Live Streaming scenario (equivalent to Twilio Group Room)mCloud.enterRoom(trtcParams, TRTCCloudDef.TRTC_APP_SCENE_LIVE);
// Set up room entry parametersval trtcParams = TRTCCloudDef.TRTCParams().apply {sdkAppId = 2000000000 // Your SDKAppIDuserId = "user_id" // User IDuserSig = "user_sig" // User signaturerole = TRTCCloudDef.TRTCRoleAudience // User role when entering the roomstrRoomId = "my-room" // Room ID (string type)// If using a numeric room ID:// roomId = 123456}// Enter the room// TRTC_APP_SCENE_VIDEOCALL: Video call scenario (equivalent to Twilio Peer-to-Peer Room)// TRTC_APP_SCENE_LIVE: Interactive Live Streaming scenario (equivalent to Twilio Group Room)mCloud.enterRoom(trtcParams, TRTCCloudDef.TRTC_APP_SCENE_LIVE)
// --- Local Video ---// Create camera capturerCameraCapturer cameraCapturer = new CameraCapturer(context,CameraCapturer.CameraSource.FRONT_CAMERA);// Create local video trackLocalVideoTrack localVideoTrack = LocalVideoTrack.create(context, true, cameraCapturer);// Render to viewVideoView localVideoView = findViewById(R.id.local_video_view);localVideoTrack.addSink(localVideoView);// --- Local Audio ---LocalAudioTrack localAudioTrack = LocalAudioTrack.create(context, true);// --- Publish tracks (Method 1: publish on connect) ---ConnectOptions connectOptions = new ConnectOptions.Builder(accessToken).roomName("my-room").audioTracks(Collections.singletonList(localAudioTrack)).videoTracks(Collections.singletonList(localVideoTrack)).build();Room room = Video.connect(context, connectOptions, roomListener);// --- Publish tracks (Method 2: publish dynamically after connect) ---room.getLocalParticipant().publishTrack(localVideoTrack);room.getLocalParticipant().publishTrack(localAudioTrack);
// --- Local Video ---// Use TXCloudVideoView in XML layout// <com.tencent.rtmp.ui.TXCloudVideoView// android:id="@+id/local_video_view"// android:layout_width="match_parent"// android:layout_height="match_parent" />TXCloudVideoView localVideoView = findViewById(R.id.local_video_view);// Set local render parametersTRTCCloudDef.TRTCRenderParams renderParams = new TRTCCloudDef.TRTCRenderParams();renderParams.fillMode = TRTCCloudDef.TRTC_VIDEO_RENDER_MODE_FILL;renderParams.mirrorType = TRTCCloudDef.TRTC_VIDEO_MIRROR_TYPE_AUTO;mCloud.setLocalRenderParams(renderParams);// Start local camera preview (true = front camera)mCloud.startLocalPreview(true, localVideoView);// --- Local Audio ---// Start local audio capture and publish// TRTC_AUDIO_QUALITY_SPEECH: Speech mode// TRTC_AUDIO_QUALITY_DEFAULT: Default mode// TRTC_AUDIO_QUALITY_MUSIC: Music modemCloud.startLocalAudio(TRTCCloudDef.TRTC_AUDIO_QUALITY_DEFAULT);
// --- Local Video ---val localVideoView: TXCloudVideoView = findViewById(R.id.local_video_view)// Set local render parametersval renderParams = TRTCCloudDef.TRTCRenderParams().apply {fillMode = TRTCCloudDef.TRTC_VIDEO_RENDER_MODE_FILLmirrorType = TRTCCloudDef.TRTC_VIDEO_MIRROR_TYPE_AUTO}mCloud.setLocalRenderParams(renderParams)// Start local camera preview (true = front camera)mCloud.startLocalPreview(true, localVideoView)// --- Local Audio ---// Start local audio capture and publishmCloud.startLocalAudio(TRTCCloudDef.TRTC_AUDIO_QUALITY_DEFAULT)
startLocalPreview and startLocalAudio. On Android, request CAMERA and RECORD_AUDIO permissions at runtime before calling these APIs.// Set listener for remote participantremoteParticipant.setListener(new RemoteParticipant.Listener() {@Overridepublic void onVideoTrackSubscribed(RemoteParticipant remoteParticipant,RemoteVideoTrackPublication remoteVideoTrackPublication,RemoteVideoTrack remoteVideoTrack) {// Remote video track subscribed, add rendererVideoView remoteVideoView = findViewById(R.id.remote_video_view);remoteVideoTrack.addSink(remoteVideoView);}@Overridepublic void onVideoTrackUnsubscribed(RemoteParticipant remoteParticipant,RemoteVideoTrackPublication remoteVideoTrackPublication,RemoteVideoTrack remoteVideoTrack) {// Remote video track unsubscribed, remove rendererremoteVideoTrack.removeSink(remoteVideoView);}@Overridepublic void onAudioTrackSubscribed(RemoteParticipant remoteParticipant,RemoteAudioTrackPublication remoteAudioTrackPublication,RemoteAudioTrack remoteAudioTrack) {// Remote audio track subscribed (auto-play)}// ... other callback methods});
@Overridepublic void onUserVideoAvailable(String userId, boolean available) {if (available) {// Remote user started publishing video, start renderingTXCloudVideoView remoteVideoView = findViewById(R.id.remote_video_view);mCloud.startRemoteView(userId, TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_BIG,remoteVideoView);} else {// Remote user stopped publishing video, stop renderingmCloud.stopRemoteView(userId, TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_BIG);}}@Overridepublic void onUserAudioAvailable(String userId, boolean available) {// Remote audio auto-plays by default, no manual handling needed// To mute a specific remote user:// mCloud.muteRemoteAudio(userId, true);}
override fun onUserVideoAvailable(userId: String?, available: Boolean) {if (available) {// Remote user started publishing video, start renderingval remoteVideoView: TXCloudVideoView = findViewById(R.id.remote_video_view)mCloud.startRemoteView(userId, TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_BIG,remoteVideoView)} else {// Remote user stopped publishing video, stop renderingmCloud.stopRemoteView(userId, TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_BIG)}}override fun onUserAudioAvailable(userId: String?, available: Boolean) {// Remote audio auto-plays by default, no manual handling needed// To mute a specific remote user:// mCloud.muteRemoteAudio(userId, true)}
// Mute/unmute local audiolocalAudioTrack.enable(false); // MutelocalAudioTrack.enable(true); // Unmute// Pause/resume local videolocalVideoTrack.enable(false); // Pause videolocalVideoTrack.enable(true); // Resume video
// Mute/unmute local audiomCloud.muteLocalAudio(true); // MutemCloud.muteLocalAudio(false); // Unmute// Pause/resume local videomCloud.muteLocalVideo(TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_BIG, true); // PausemCloud.muteLocalVideo(TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_BIG, false); // Resume// Completely stop/restart camera via stopLocalPreview/startLocalPreviewmCloud.stopLocalPreview(); // Completely stop camera
// Mute/unmute local audiomCloud.muteLocalAudio(true) // MutemCloud.muteLocalAudio(false) // Unmute// Pause/resume local videomCloud.muteLocalVideo(TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_BIG, true) // PausemCloud.muteLocalVideo(TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_BIG, false) // Resume// Completely stop/restart camera via stopLocalPreview/startLocalPreviewmCloud.stopLocalPreview() // Completely stop camera
// Twilio does not provide direct API to mute remote users.// Achieved by unsubscribing remote tracks.// Unsubscribe remote audioremoteAudioTrackPublication.getRemoteAudioTrack().setPlaybackEnabled(false);// Unsubscribe remote videoremoteVideoTrack.removeSink(remoteVideoView);
// Mute/unmute specified remote user's audiomCloud.muteRemoteAudio("remote_user_id", true); // Mute remote usermCloud.muteRemoteAudio("remote_user_id", false); // Unmute remote user// Mute/unmute all remote users' audiomCloud.muteAllRemoteAudio(true); // Mute all remote usersmCloud.muteAllRemoteAudio(false); // Unmute all remote users// Pause/resume specified remote user's videomCloud.muteRemoteVideoStream("remote_user_id",TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_BIG, true); // Pause remote videomCloud.muteRemoteVideoStream("remote_user_id",TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_BIG, false); // Resume remote video// Pause/resume all remote users' videomCloud.muteAllRemoteVideoStreams(true); // Pause all remote videomCloud.muteAllRemoteVideoStreams(false); // Resume all remote video
// Mute/unmute specified remote user's audiomCloud.muteRemoteAudio("remote_user_id", true) // Mute remote usermCloud.muteRemoteAudio("remote_user_id", false) // Unmute remote user// Mute/unmute all remote users' audiomCloud.muteAllRemoteAudio(true) // Mute all remote usersmCloud.muteAllRemoteAudio(false) // Unmute all remote users// Pause/resume specified remote user's videomCloud.muteRemoteVideoStream("remote_user_id",TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_BIG, true) // Pause remote videomCloud.muteRemoteVideoStream("remote_user_id",TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_BIG, false) // Resume remote video// Pause/resume all remote users' videomCloud.muteAllRemoteVideoStreams(true) // Pause all remote videomCloud.muteAllRemoteVideoStreams(false) // Resume all remote video
// Disconnect from roomroom.disconnect();// Release local track resourcesif (localAudioTrack != null) {localAudioTrack.release();localAudioTrack = null;}if (localVideoTrack != null) {localVideoTrack.release();localVideoTrack = null;}
// Stop local audio/video capturemCloud.stopLocalAudio();mCloud.stopLocalPreview();// Exit roommCloud.exitRoom();// If you no longer need the SDK, destroy the instanceTRTCCloud.destroySharedInstance();
// Stop local audio/video capturemCloud.stopLocalAudio()mCloud.stopLocalPreview()// Exit roommCloud.exitRoom()// If you no longer need the SDK, destroy the instanceTRTCCloud.destroySharedInstance()
// Create screen capturer (requires MediaProjection permission)ScreenCapturer screenCapturer = new ScreenCapturer(context, resultCode, data,new ScreenCapturer.Listener() {@Overridepublic void onScreenCaptureError(String errorDescription) {Log.e("Twilio", "Screen capture error: " + errorDescription);}@Overridepublic void onFirstFrameAvailable() {Log.i("Twilio", "First frame available");}});// Create local video track for screen sharingLocalVideoTrack screenTrack = LocalVideoTrack.create(context, true, screenCapturer);// Publish screen sharing trackroom.getLocalParticipant().publishTrack(screenTrack);
// Set screen sharing encoding parametersTRTCCloudDef.TRTCVideoEncParam encParam = new TRTCCloudDef.TRTCVideoEncParam();encParam.videoResolution = TRTCCloudDef.TRTC_VIDEO_RESOLUTION_1280_720;encParam.videoResolutionMode = TRTCCloudDef.TRTC_VIDEO_RESOLUTION_MODE_PORTRAIT;encParam.videoFps = 10;encParam.videoBitrate = 1200;encParam.enableAdjustRes = false;// Start screen sharing (requires floating window and MediaProjection permissions)TRTCCloudDef.TRTCScreenShareParams screenShareParams =new TRTCCloudDef.TRTCScreenShareParams();// Use sub stream to send screen sharing, does not occupy camera main streammCloud.startScreenCapture(TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_SUB, encParam,screenShareParams);// Stop screen sharingmCloud.stopScreenCapture();
// Set screen sharing encoding parametersval encParam = TRTCCloudDef.TRTCVideoEncParam().apply {videoResolution = TRTCCloudDef.TRTC_VIDEO_RESOLUTION_1280_720videoResolutionMode = TRTCCloudDef.TRTC_VIDEO_RESOLUTION_MODE_PORTRAITvideoFps = 10videoBitrate = 1200enableAdjustRes = false}// Start screen sharing (requires floating window and MediaProjection permissions)val screenShareParams = TRTCCloudDef.TRTCScreenShareParams()// Use sub stream to send screen sharing, does not occupy camera main streammCloud.startScreenCapture(TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_SUB, encParam,screenShareParams)// Stop screen sharingmCloud.stopScreenCapture()
// Set encoding parametersEncodingParameters encodingParameters = new EncodingParameters(16, // Max audio bitrate (kbps)800 // Max video bitrate (kbps));ConnectOptions connectOptions = new ConnectOptions.Builder(accessToken).roomName("my-room").encodingParameters(encodingParameters).preferVideoCodecs(Collections.singletonList(new H264Codec())).preferAudioCodecs(Collections.singletonList(new OpusCodec())).build();
// Set video encoding parametersTRTCCloudDef.TRTCVideoEncParam videoEncParam = new TRTCCloudDef.TRTCVideoEncParam();videoEncParam.videoResolution = TRTCCloudDef.TRTC_VIDEO_RESOLUTION_640_360;videoEncParam.videoResolutionMode = TRTCCloudDef.TRTC_VIDEO_RESOLUTION_MODE_PORTRAIT;videoEncParam.videoFps = 15;videoEncParam.videoBitrate = 800;videoEncParam.minVideoBitrate = 200;mCloud.setVideoEncoderParam(videoEncParam);// Set network quality control parametersTRTCCloudDef.TRTCNetworkQosParam qosParam = new TRTCCloudDef.TRTCNetworkQosParam();qosParam.preference = TRTCCloudDef.TRTC_VIDEO_QOS_PREFERENCE_SMOOTH; // Smooth priority// Or TRTCCloudDef.TRTC_VIDEO_QOS_PREFERENCE_CLEAR for clarity prioritymCloud.setNetworkQosParam(qosParam);
// Set video encoding parametersval videoEncParam = TRTCCloudDef.TRTCVideoEncParam().apply {videoResolution = TRTCCloudDef.TRTC_VIDEO_RESOLUTION_640_360videoResolutionMode = TRTCCloudDef.TRTC_VIDEO_RESOLUTION_MODE_PORTRAITvideoFps = 15videoBitrate = 800minVideoBitrate = 200}mCloud.setVideoEncoderParam(videoEncParam)// Set network quality control parametersval qosParam = TRTCCloudDef.TRTCNetworkQosParam().apply {preference = TRTCCloudDef.TRTC_VIDEO_QOS_PREFERENCE_SMOOTH // Smooth priority// Or TRTCCloudDef.TRTC_VIDEO_QOS_PREFERENCE_CLEAR for clarity priority}mCloud.setNetworkQosParam(qosParam)
// Switch front/rear cameraCameraCapturer cameraCapturer = (CameraCapturer) localVideoTrack.getVideoCapturer();cameraCapturer.switchCamera();
// Get device managerTXDeviceManager deviceManager = mCloud.getDeviceManager();// Switch front/rear cameradeviceManager.switchCamera(true);// Check if currently using front cameraboolean isFront = deviceManager.isFrontCamera();// Set camera zoomdeviceManager.setCameraZoomRatio(2.0f);// Turn on/off flashlightdeviceManager.enableCameraTorch(true);// Enable auto focusdeviceManager.enableCameraAutoFocus(true);// Set audio route (earpiece/speaker)deviceManager.setAudioRoute(TXDeviceManager.TXAudioRoute.TXAudioRouteSpeakerphone); // SpeakerdeviceManager.setAudioRoute(TXDeviceManager.TXAudioRoute.TXAudioRouteEarpiece); // Earpiece
// Get device managerval deviceManager = mCloud.deviceManager// Switch front/rear cameradeviceManager.switchCamera(true)// Check if currently using front cameraval isFront = deviceManager.isFrontCamera// Set camera zoomdeviceManager.setCameraZoomRatio(2.0f)// Turn on/off flashlightdeviceManager.enableCameraTorch(true)// Enable auto focusdeviceManager.enableCameraAutoFocus(true)// Set audio routedeviceManager.setAudioRoute(TXDeviceManager.TXAudioRoute.TXAudioRouteSpeakerphone) // SpeakerdeviceManager.setAudioRoute(TXDeviceManager.TXAudioRoute.TXAudioRouteEarpiece) // Earpiece
// Enable network quality API via ConnectOptionsConnectOptions connectOptions = new ConnectOptions.Builder(accessToken).roomName("my-room").enableNetworkQuality(true).build();// Get network quality levelNetworkQualityLevel level = localParticipant.getNetworkQualityLevel();
// Network quality callback@Overridepublic void onNetworkQuality(TRTCCloudDef.TRTCQuality localQuality,ArrayList<TRTCCloudDef.TRTCQuality> remoteQuality) {// localQuality.quality values:// 0-unknown 1-excellent 2-good 3-fair 4-poor 5-bad 6-disconnectedLog.i("TRTC", "Local network quality: " + localQuality.quality);for (TRTCCloudDef.TRTCQuality quality : remoteQuality) {Log.i("TRTC", "User " + quality.userId + " network quality: " + quality.quality);}}// Audio/video statistics callback@Overridepublic void onStatistics(TRTCStatistics statistics) {// Includes upstream/downstream bitrate, frame rate, latency, etc.Log.i("TRTC", "Upstream packet loss: " + statistics.upLoss + "%");Log.i("TRTC", "Downstream packet loss: " + statistics.downLoss + "%");Log.i("TRTC", "RTT: " + statistics.rtt + "ms");}
// Network quality callbackoverride fun onNetworkQuality(localQuality: TRTCCloudDef.TRTCQuality?,remoteQuality: ArrayList<TRTCCloudDef.TRTCQuality>?) {// localQuality.quality values:// 0-unknown 1-excellent 2-good 3-fair 4-poor 5-bad 6-disconnectedLog.i("TRTC", "Local network quality: ${localQuality?.quality}")remoteQuality?.forEach { quality ->Log.i("TRTC", "User ${quality.userId} network quality: ${quality.quality}")}}// Audio/video statistics callbackoverride fun onStatistics(statistics: TRTCStatistics?) {// Includes upstream/downstream bitrate, frame rate, latency, etc.Log.i("TRTC", "Upstream packet loss: ${statistics?.upLoss}%")Log.i("TRTC", "Downstream packet loss: ${statistics?.downLoss}%")Log.i("TRTC", "RTT: ${statistics?.rtt}ms")}
// Implement VideoCapturer interfacepublic class CustomCapturer implements VideoCapturer {@Overridepublic void initialize(SurfaceTextureHelper surfaceTextureHelper,Context context, CapturerObserver observer) {// Initialization}@Overridepublic void startCapture(int width, int height, int framerate) {// Start capture}@Overridepublic void stopCapture() {// Stop capture}@Overridepublic boolean isScreencast() {return false;}}// Use custom capturerLocalVideoTrack customTrack = LocalVideoTrack.create(context, true, customCapturer);
// Enable custom video capturemCloud.enableCustomVideoCapture(TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_BIG, true);// Send custom captured video frames to SDK// Android supports Buffer and Texture; Texture is recommended!TRTCCloudDef.TRTCVideoFrame frame = new TRTCCloudDef.TRTCVideoFrame();frame.pixelFormat = TRTCCloudDef.TRTC_VIDEO_PIXEL_FORMAT_Texture_2D;frame.bufferType = TRTCCloudDef.TRTC_VIDEO_BUFFER_TYPE_TEXTURE;frame.texture = new TRTCCloudDef.TRTCTexture();frame.texture.textureId = textureId;frame.texture.eglContext14 = eglContext;frame.width = width;frame.height = height;frame.timestamp = timestamp;mCloud.sendCustomVideoData(TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_BIG, frame);
// Enable custom video capturemCloud.enableCustomVideoCapture(TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_BIG, true)// Send custom captured video frames to SDK// Android supports Buffer and Texture; Texture is recommended!val frame = TRTCCloudDef.TRTCVideoFrame().apply {pixelFormat = TRTCCloudDef.TRTC_VIDEO_PIXEL_FORMAT_Texture_2DbufferType = TRTCCloudDef.TRTC_VIDEO_BUFFER_TYPE_TEXTUREtexture = TRTCCloudDef.TRTCTexture().apply {textureId = textureIdeglContext14 = eglContext}width = widthheight = heighttimestamp = timestamp}mCloud.sendCustomVideoData(TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_BIG, frame)
// Create data trackLocalDataTrack localDataTrack = LocalDataTrack.create(context);// Publish data trackroom.getLocalParticipant().publishTrack(localDataTrack);// Send messagelocalDataTrack.send("Hello, World!");localDataTrack.send(ByteBuffer.wrap(new byte[]{0x01, 0x02}));// Receive message (via RemoteDataTrack.Listener)remoteDataTrack.setListener(new RemoteDataTrack.Listener() {@Overridepublic void onMessage(RemoteDataTrack remoteDataTrack, String message) {Log.i("Twilio", "Received: " + message);}@Overridepublic void onMessage(RemoteDataTrack remoteDataTrack, ByteBuffer message) {Log.i("Twilio", "Received binary data");}});
// Method 1: Send custom command message via UDP channel// cmdID: custom command ID between 1-10// data: message content (max 1KB)// reliable: send reliably// ordered: send in orderboolean success = mCloud.sendCustomCmdMsg(1, "Hello, World!".getBytes(), true, true);// Method 2: Send message via SEI channel (embedded in video frame)// Parameter 2: repeatCount - number of times to send data, recommended as 1mCloud.sendSEIMsg("Hello via SEI".getBytes(), 1);// Receive custom message@Overridepublic void onRecvCustomCmdMsg(String userId, int cmdID, int seq, byte[] message) {String msg = new String(message);Log.i("TRTC", "Received message from " + userId + ": " + msg);}@Overridepublic void onRecvSEIMsg(String userId, byte[] data) {String msg = new String(data);Log.i("TRTC", "Received SEI message from " + userId + ": " + msg);}
// Method 1: Send custom command message via UDP channel// cmdID: custom command ID between 1-10// data: message content (max 1KB)// reliable: send reliably// ordered: send in orderval success = mCloud.sendCustomCmdMsg(1, "Hello, World!".toByteArray(), true, true)// Method 2: Send message via SEI channel (embedded in video frame)// Parameter 2: repeatCount - number of times to send data, recommended as 1mCloud.sendSEIMsg("Hello via SEI".toByteArray(), 1)// Receive custom messageoverride fun onRecvCustomCmdMsg(userId: String?, cmdID: Int, seq: Int, message: ByteArray?) {val msg = message?.let { String(it) }Log.i("TRTC", "Received message from $userId: $msg")}override fun onRecvSEIMsg(userId: String?, data: ByteArray?) {val msg = data?.let { String(it) }Log.i("TRTC", "Received SEI message from $userId: $msg")}
roomId): Integer range 1 ~ 4294967294 (recommended).strRoomId): Up to 64 bytes, supports letters, numbers, and select special characters.strRoomId.roomId and strRoomId within the same TRTC application; they are not interoperable.RemoteParticipant.Listener.onAudioTrackSubscribed. In TRTC, remote audio is automatically played when a user enters the room. To control remote audio playback for a specific user, use muteRemoteAudio(userId, true/false).Twilio Room Type | TRTC Scenario | Applicable Use Case |
Peer-to-Peer Room | TRTC_APP_SCENE_VIDEOCALL | 1v1 Video Call |
Peer-to-Peer Room (audio only) | TRTC_APP_SCENE_AUDIOCALL | 1v1 Audio Call |
Group Room | TRTC_APP_SCENE_LIVE | Interactive live streaming, video conference |
Group Room (audio only) | TRTC_APP_SCENE_VOICE_CHATROOM | Voice chatroom |
onConnectionLost(): Disconnected from serveronTryToReconnect(): Attempting to reconnectonConnectionRecovery(): Connection recoveredonReconnecting and onReconnected.Apakah halaman ini membantu?
Anda juga dapat Menghubungi Penjualan atau Mengirimkan Tiket untuk meminta bantuan.
masukan