build.gradle.kts (or build.gradle)
file under the app directory and add the following code to include the dependency for SeatGridView component:api("io.trtc.uikit:voice-room-core:latest.release")
api 'io.trtc.uikit:voice-room-core:latest.release'
proguard-rules.pro
file:-keep class com.tencent.** { *; }-keep class com.trtc.uikit.livekit.voiceroomcore.** { *; }
AndroidManifest.xml
file under the app directory and add tools:replace="android:allowBackup" and android:allowBackup="false" in the application node to override the settings within the component with your own settings.// app/src/main/AndroidManifest.xml<application...// Add the following configuration to override the configuration in the dependency SDKandroid:allowBackup="false"tools:replace="android:allowBackup">
// Log inTUILogin.login(applicationContext,1400000001, // Please replace with the SDKAppID obtained in Step 1"denny", // Please replace with your UserID"xxxxxxxxxxx", // You can calculate a UserSig in the Console and fill it in hereobject : TUICallback() {override fun onSuccess() {Log.i(TAG, "login success")}override fun onError(errorCode: Int, errorMessage: String) {Log.e(TAG, "login failed, errorCode: $errorCode msg:$errorMessage")}})
// Log inTUILogin.login(context,1400000001, // Please replace with the SDKAppID obtained in Step 1"denny", // Please replace with your UserID"xxxxxxxxxxx", // You can calculate a UserSig in the Console and fill it in herenew TUICallback() {@Overridepublic void onSuccess() {Log.i(TAG, "login success");}@Overridepublic void onError(int errorCode, String errorMessage) {Log.e(TAG, "login failed, errorCode: " + errorCode + " msg:" + errorMessage);}});
Parameter | Type | Description |
SDKAppID | int | You have already obtained it in the last step of Step 1, so it will not be elaborated here. |
UserID | String | The ID of the current user, in string format, only allows letters (a-z and A-Z), digits (0-9), hyphens, and underscores. |
userSig | String | Use the SecretKey obtained in Step One, Step 3 to encrypt information such as SDKAppID and UserID to obtain UserSig, which is a token for authentication used by Tencent Cloud to identify whether the current user can use TRTC services. You can generate a temporarily usable UserSig through the Auxiliary Tools in the console. For more information, see UserSig. |
GenerateTestUserSig.genTestSig
function to generate UserSig. In this method, the SDKSecretKey is vulnerable to decompilation and reverse engineering. If your key is leaked, attackers can steal your Tencent Cloud traffic.val seatGridView = SeatGridView(this)
SeatGridView seatGridView = new SeatGridView(this);
val roomInfo = TUIRoomDefine.RoomInfo()roomInfo.roomId = "roomId_123456"seatGridView.startVoiceRoom(roomInfo, null)seatGridView.startMicrophone(null)
TUIRoomDefine.RoomInfo roomInfo = new TUIRoomDefine.RoomInfo();roomInfo.roomId = "roomId_123456";seatGridView.startVoiceRoom(roomInfo, null);seatGridView.startMicrophone(null);
seatGridView.joinVoiceRoom("roomId_123456", null)
seatGridView.joinVoiceRoom("roomId_123456", null);
Anchor starts the live streaming room and begins the live stream | Audience joins the live streaming room to watch the live stream |
|
|
// Set grid layoutseatGirdView.setLayoutMode(VoiceRoomDefine.LayoutMode.GRID, null)// Set element layoutseatGirdView.setLayoutMode(VoiceRoomDefine.LayoutMode.FOCUS, null)// Set vertical layoutseatGirdView.setLayoutMode(VoiceRoomDefine.LayoutMode.VERTICAL, null)// Set custom layoutval layoutConfig = VoiceRoomDefine.SeatViewLayoutConfig().apply {rowConfigs = ArrayList()rowSpacing = dp2px(10); //Spacing between each row}// First row configurationval rowConfig1 = VoiceRoomDefine.SeatViewLayoutRowConfig().apply {count = 3 //Number of seats displayed in the first rowseatSize = VoiceRoomDefine.Size(dp2px(50), dp2px(50)) //Size of each seat view in the first rowseatSpacing = dp2px(10) //Horizontal spacing of each seat in the first rowalignment = VoiceRoomDefine.SeatViewLayoutRowAlignment.CENTER //Alignment of seats in the first row}layoutConfig.rowConfigs.add(rowConfig1)// Second row configurationval rowConfig2 = VoiceRoomDefine.SeatViewLayoutRowConfig().apply {count = 3 //Number of seats displayed in the second rowseatSize = VoiceRoomDefine.Size(dp2px(50), dp2px(50)) //Size of each seat view in the second rowseatSpacing = dp2px(10) //Horizontal spacing of each seat in the second rowalignment = VoiceRoomDefine.SeatViewLayoutRowAlignment.SPACE_AROUND //Alignment of seats in the second row}layoutConfig.rowConfigs.add(rowConfig2)seatGirdView.setLayoutMode(VoiceRoomDefine.LayoutMode.FREE, layoutConfig)
// Set grid layoutseatGirdView.setLayoutMode(VoiceRoomDefine.LayoutMode.GRID, null)// Set element layoutseatGirdView.setLayoutMode(VoiceRoomDefine.LayoutMode.FOCUS, null)// Set vertical layoutseatGirdView.setLayoutMode(VoiceRoomDefine.LayoutMode.VERTICAL, null)// Set free layoutVoiceRoomDefine.SeatViewLayoutConfig layoutConfig = new VoiceRoomDefine.SeatViewLayoutConfig();layoutConfig.rowConfigs = new ArrayList<>();layoutConfig.rowSpacing = dp2px(10); //Spacing between each row// First row configurationVoiceRoomDefine.SeatViewLayoutRowConfig rowConfig1 = new VoiceRoomDefine.SeatViewLayoutRowConfig();rowConfig1.count = 3; //Number of seats displayed in the first rowrowConfig1.seatSize = new VoiceRoomDefine.Size(dp2px(50),dp2px(50)); //Size of each seat view in the first rowrowConfig1.seatSpacing = dp2px(10); //Horizontal spacing of each seat in the first rowrowConfig1.alignment = VoiceRoomDefine.SeatViewLayoutRowAlignment.CENTER; //Alignment of seats in the first rowlayoutConfig.rowConfigs.add(rowConfig1);// Second row configurationVoiceRoomDefine.SeatViewLayoutRowConfig rowConfig2 = new VoiceRoomDefine.SeatViewLayoutRowConfig();rowConfig2.count = 3; //Number of seats displayed in the second rowrowConfig2.seatSize = new VoiceRoomDefine.Size(dp2px(50),dp2px(50)); //Size of each seat view in the second rowrowConfig1.seatSpacing = dp2px(10); //Horizontal spacing of each seat in the second rowrowConfig2.alignment = VoiceRoomDefine.SeatViewLayoutRowAlignment.SPACE_AROUND; //Alignment of seats in the second rowlayoutConfig.rowConfigs.add(rowConfig2);seatGirdView.setLayoutMode(VoiceRoomDefine.LayoutMode.FREE, layoutConfig);
Grid Layout | Element Layout | Vertical Layout | Custom Layout |
| |
|
|
val adapter = object : VoiceRoomDefine.SeatViewAdapter {override fun createSeatView(seatGridView: SeatGridView, seatInfo: TUIRoomDefine.SeatInfo): View {return TestSeatInfoView(context, seatGridView, seatInfo)}override fun updateSeatView(seatGridView: SeatGridView,seatInfo: TUIRoomDefine.SeatInfo, seatView: View) {(seatView as TestSeatInfoView).updateSeatView(seatGridView, seatInfo)}override fun updateUserVolume(seatGridView: SeatGridView, volume: Int, customSeatView: View) {(customSeatView as TestSeatInfoView).updateUserVolume(seatGridView, volume)}}seatGirdView.setSeatViewAdapter(adapter)class TestSeatInfoView constructor(context: Context, seatGirdView: SeatGridView, seatInfo: TUIRoomDefine.SeatInfo) : FrameLayout(context) {init {initView() //Initialize view}fun updateSeatView(seatGirdView: SeatGridView, seatInfo: TUIRoomDefine.SeatInfo) {updateView(seatInfo) //Update custom seat view UI}fun updateUserVolume(seatGirdView: SeatGridView, volume: Int) {updateUserVolume(volume) //Update volume change UI}}
VoiceRoomDefine.SeatViewAdapter adapter = new VoiceRoomDefine.SeatViewAdapter() {@Overridepublic View createSeatView(SeatGridView seatGridView, TUIRoomDefine.SeatInfo seatInfo) {return new TestSeatInfoView(getApplicationContext(), seatGridView, seatInfo);}@Overridepublic void updateSeatView(SeatGridView seatGridView, TUIRoomDefine.SeatInfo seatInfo,View customSeatView) {((TestSeatInfoView) customSeatView).updateSeatView(seatGridView, seatInfo);}@Overridepublic void updateUserVolume(SeatGridView seatGridView, int volume, View customSeatView) {((TestSeatInfoView) customSeatView).updateUserVolume(seatGridView, volume);}};seatGirdView.setSeatViewAdapter(adapter);public class TestSeatInfoView extends FrameLayout {public TestSeatInfoView(@NonNull Context context, SeatGridView seatGirdView, TUIRoomDefine.SeatInfo seatInfo) {super(context);initView();}public void updateSeatView(SeatGridView seatGirdView, TUIRoomDefine.SeatInfo seatInfo) {updateView(seatInfo);}public void updateUserVolume(SeatGridView seatGirdView, int volume) {updateUserVolume(volume);}}
Default Mic View | Custom Mic View Example |
|
|
Was this page helpful?