Create a proguard-rules.pro file in the android/app directory of your project and add the following code to the proguard-rules.pro file:
-keep class com.tencent.**{*;}
1. After opening the .xcworkspace project file, click on the left Project Navigator in the Xcode Navbar, select Runner, and ensure the correct TARGETS is selected in the editing area.
2. Add ScreenCaptureKit.framework in the Frameworks, Libraries, and Embedded Content section of the General tab.
Note:
If you encounter any problems during the access process, please refer to FAQs.
print('You need toobtain audio and video permission toenter');
return;
}
Note:
The permission request here uses the third-party library permission_handler.
2. In the Tencent RTC Console, click Create Application to obtain the SDKAppID from Application Overview.
3. In UserSig Tools, select SDKAppID from the dropdown, enter your own username (UserID), and click Generate to get your own UserSig.
4. After setting the room parameters TRTCParams, call the enterRoom interface function to enter the room.
Anchor Role
trtcCloud.enterRoom(
TRTCParams(
sdkAppId: sdkAppId,// Replace with your SDKAppID
userId:"userId",// Replace with your userid
userSig: '',// Replace with your userSig
role:TRTCRoleType.anchor,
roomId:123123,// Replace with your roomId
),
TRTCAppScene.live
);
Audience Role
trtcCloud.enterRoom(
TRTCParams(
sdkAppId: sdkAppId,// Replace with your SDKAppID
userId:"userId",// Replace with your userid
userSig: '',// Replace with your userSig
role:TRTCRoleType.audience,
roomId:123123,// Replace with your roomId
),
TRTCAppScene.live
);
Note:
If you enter the room as an Audience Role, sdkAppId and roomId need to be the same as those at the anchor end, while userId and userSig need to be replaced with your own values.
Step 5. Enable the camera
1. Add TRTCCloudVideoView in the corresponding position of the build method on the page:
viewId is the unique identifier of the video rendering control TRTCCloudVideoView. You can store this identifier in any way you like. Here, localViewId is used to store it for rendering local video streams later.
2. Before invoking the interface startLocalPreview to enable camera preview, you can set the local preview rendering parameters by calling the interface setLocalRenderParams.
// Set local preview rendering parameters
trtcCloud.setLocalRenderParams(
TRTCRenderParams(
fillMode:TRTCVideoFillMode.fill,
mirrorType:TRTCVideoMirrorType.auto,
rotation:TRTCVideoRotation.rotation0,
),
);
// Local preview of front camera content
trtcCloud.startLocalPreview(true, localViewId);
// Local preview of rear camera content
trtcCloud.startLocalPreview(false, localViewId);
Call stopLocalPreview to turn off the camera preview and stop pushing local video information.
trtcCloud.stopLocalPreview();
3. You can call the TXDeviceManager interface to complete the use of equipment extension features such as "Toggle front/back camera","Set Focus Mode","Flashlight".
// Turn on the flash when switching to the rear-facing camera
manager.enableCameraTorch(true);
// Turn the flash off
manager.enableCameraTorch(false);
Step 6. Enable the microphone
You can call startLocalAudio to enable microphone capture. This interface requires you to determine the capture mode through the quality parameter. It is recommended to select one of the following modes that suits your project.
// Enable mic capture and set the current scene to: Speech mode
// Strong noise suppression capability, adapts well to strong and weak network conditions
Call stopLocalAudio to turn off the mic capture and stop pushing local audio information.
trtcCloud.stopLocalAudio();
Step 7. Play/Stop Video Streams
1. Listen to onUserVideoAvailable before entering the room. When you receive the onUserVideoAvailable(userId, true) notification, it means that the video frame from this stream has arrived and is ready for playback.
Note:
Here it is assumed that the user who can play the video is denny, and the video stream of the user denny is expected to be rendered to the TRTCCloudVideoView control with the unique identifier remoteViewId.
2. You can play the remote user's video by calling the startRemoteView interface.
// Play the primary video stream of the remote user denny
Then, you can stop a remote user's video by calling the stopRemoteView interface, or stop all remote users' videos by calling the stopAllRemoteView interface.
// Stop playing the primary video stream of the remote user denny