Android/debug
,Android/tuiaudioeffect
, Android/tuibarrage
, Android/tuibeauty
, Android/tuigift
和 Android/tuiliveroom
目录到您的工程中,并完成如下导入动作:setting.gradle
中完成导入,参考如下:include ':debug'include ':tuibeauty'include ':tuibarrage'include ':tuiaudioeffect'include ':tuigift'include ':tuiliveroom'
app
的 build.gradle
文件中添加对 tuiliveroom
的依赖:api project(":tuiliveroom")
build.gradle
文件中添加 TRTC SDK
和 IM SDK
的依赖:ext {liteavSdk = "com.tencent.liteav:LiteAVSDK_TRTC:latest.release"imSdk = "com.tencent.imsdk:imsdk-plus:latest.release"}
<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.WRITE_EXTERNAL_STORAGE" /><uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /><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-permission android:name="android.permission.CAMERA" /><uses-permission android:name="android.permission.READ_PHONE_STATE" /><uses-feature android:name="android.hardware.camera"/><uses-feature android:name="android.hardware.camera.autofocus" />
-keep class com.tencent.** { *; }
// 1.添加事件监听及登录TUILogin.addLoginListener(new TUILoginListener() {@Overridepublic void onConnecting() { // 正在连接中super.onConnecting();}@Overridepublic void onConnectSuccess() { // 连接成功通知super.onConnectSuccess();}@Overridepublic void onConnectFailed(int errorCode, String errorMsg) { // 连接失败通知super.onConnectFailed(errorCode, errorMsg);}@Overridepublic void onKickedOffline() { // 登录被踢下线通知(示例:账号在其他设备登录)super.onKickedOffline();}@Overridepublic void onUserSigExpired() { // userSig过期通知super.onUserSigExpired();}});TUILogin.login(mContext, "Your SDKAppID", "Your userId", "Your userSig", new TUICallback() {@Overridepublic void onSuccess() {}@Overridepublic void onError(int errorCode, String errorMsg) {Log.d(TAG, "errorCode: " + errorCode + " errorMsg:" + errorMsg);}});// 2.初始化TUILiveRoom组件TUILiveRoom mLiveRoom = TUILiveRoom.sharedInstance(mContext);
mLiveRoom.createRoom(int roomId, String roomName, String coverUrl);
mLiveRoom.enterRoom(roomId);
// 1.观众端发起连麦请求// LINK_MIC_TIMEOUT为超时时间TRTCLiveRoom mTRTCLiveRoom=TRTCLiveRoom.sharedInstance(mContext);mTRTCLiveRoom.requestJoinAnchor(mSelfUserId + "请求和您连麦", LINK_MIC_TIMEOUTnew TRTCLiveRoomCallback.ActionCallback() {@Overridepublic void onCallback(int code, String msg) {if (code == 0) {// 主播接受了观众的请求TXCloudVideoView view = new TXCloudVideoView(context);parentView.add(view);// 观众启动预览,开启推流mTRTCLiveRoom.startCameraPreview(true, view, null);mTRTCLiveRoom.startPublish(mSelfUserId + "_stream", null);}}});// 2.主播端收到连麦请求mTRTCLiveRoom.setDelegate(new TRTCLiveRoomDelegate() {@Overridepublic void onRequestJoinAnchor(final TRTCLiveRoomDef.TRTCLiveUserInfo userInfo,String reason, final int timeout) {// 同意对方的连麦请求mTRTCLiveRoom.responseJoinAnchor(userInfo.userId, true, "同意连麦");}@Overridepublic void onAnchorEnter(final String userId) {// 主播收到连麦观众的上麦通知TXCloudVideoView view = new TXCloudVideoView(context);parentView.add(view);// 主播播放观众画面mTRTCLiveRoom.startPlay(userId, view, null);}});
// 主播 A 创建12345的房间mLiveRoom.createRoom(12345, "roomA", "Your coverUrl");// 主播 B 创建54321的房间mLiveRoom.createRoom(54321, "roomB", "Your coverUrl");// 主播 A:TRTCLiveRoom mTRTCLiveRoom=TRTCLiveRoom.sharedInstance(mContext);// 1.主播 A 向主播 B 发起 PK 请求mTRTCLiveRoom.requestRoomPK(54321, "B",new TRTCLiveRoomCallback.ActionCallback() {@Overridepublic void onCallback(int code, String msg) {// 5.收到是否同意的回调if (code == 0) {// 用户接受} else {// 用户拒绝}}});mTRTCLiveRoom.setDelegate(new TRTCLiveRoomDelegate() {@Overridepublic void onAnchorEnter(final String userId) {// 6.收到 B 进房的通知mTRTCLiveRoom.startPlay(userId, mTXCloudVideoView, null);}});// 主播 B:// 2.主播 B 收到主播 A 的消息mTRTCLiveRoom.setDelegate(new TRTCLiveRoomDelegate() {@Overridepublic void onRequestRoomPK(final TRTCLiveRoomDef.TRTCLiveUserInfo userInfo, final int timeout) {// 3.主播 B 回复主播 A 接受请求mTRTCLiveRoom.responseRoomPK(userInfo.userId, true, "");}@Overridepublic void onAnchorEnter(final String userId) {// 4.主播 B 收到主播 A 进房的通知,播放主播 A 的画面mTRTCLiveRoom.startPlay(userId, mTXCloudVideoView, null);}});
TUIBeautyView.getBeautyService().setLicense(context, “XMagicLicenseURL”, “XMagicLicenseKey”);
本页内容是否解决了您的问题?