From 03b05d0de06d2220d71ff7f0c6d0c170e10e833b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=81=E7=9A=AE?= <14840170+lao-pi123@user.noreply.gitee.com> Date: Mon, 23 Sep 2024 15:59:41 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E5=88=A0=E9=99=A4=E8=9E=8D=E4=BA=91R?= =?UTF-8?q?TC=E5=8A=9F=E8=83=BD=EF=BC=8Capp=E8=83=BD=E8=B7=91=E8=B5=B7?= =?UTF-8?q?=E6=9D=A5=E4=BA=86=E3=80=82=E4=BD=86=E6=98=AF=E6=B8=B8=E6=88=8F?= =?UTF-8?q?IM=E5=87=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yunbao/faceunity/FaceManager.java | 47 - .../java/com/shayu/phonelive/AppContext.java | 8 +- common/build.gradle | 2 +- .../common/fragment/ProcessFragment.java | 6 - .../yunbao/common/manager/IMRTCManager.java | 270 -- .../manager/imrongcloud/GameRyMicManager.java | 559 ---- .../manager/imrongcloud/GameSwMicManager.java | 449 --- .../yunbao/common/utils/MicStatusManager.java | 69 - .../yunbao/live/activity/LiveActivity.java | 40 +- .../live/activity/LiveAnchorActivity.java | 6 - .../live/activity/LiveRyAnchorActivity.java | 1974 ------------ .../live/activity/LiveSwAnchorActivity.java | 33 +- .../live/activity/SudRyGameActivity.java | 765 ----- .../live/activity/SudSwGameActivity.java | 234 +- .../live/adapter/FreePkRecyclerAdapter.java | 7 - .../dialog/LiveLinkMicListDialogFragment.java | 8 - .../dialog/LiveNewFunctionDialogFragment.java | 5 - .../dialog/LiveOldUserDialogFragment.java | 3 - .../dialog/LiveWishListDialogFragment.java | 4 - .../live/dialog/RandomPkDialogFragment.java | 3 +- .../presenter/LiveRyLinkMicPkPresenter.java | 2778 ----------------- .../presenter/LiveSwLinkMicPkPresenter.java | 111 +- .../yunbao/live/socket/SocketRyChatUtil.java | 52 +- .../yunbao/live/socket/SocketRyClient.java | 1557 --------- .../live/socket/SocketRyLinkMicPkUtil.java | 211 -- .../yunbao/live/views/LiveEndViewHolder.java | 13 +- .../live/views/LiveNewReadyRyViewHolder.java | 981 ------ .../live/views/LivePlayRyViewHolder.java | 1418 --------- .../live/views/LivePlaySwViewHolder.java | 3 - .../live/views/LivePushRyViewHolder.java | 1108 ------- .../live/views/LivePushSwViewHolder.java | 41 +- .../live/views/LiveReadyRyViewHolder.java | 528 ---- .../yunbao/live/views/LiveRoomViewHolder.java | 68 +- .../live/views/LiveRyAnchorViewHolder.java | 9 - .../live/views/PortraitLiveManager.java | 97 +- .../yunbao/main/activity/MainActivity.java | 6 - .../yunbao/main/activity/SettingActivity.java | 2 - .../main/dialog/MainStartDialogFragment.java | 3 - 38 files changed, 149 insertions(+), 13329 deletions(-) delete mode 100644 common/src/main/java/com/yunbao/common/manager/IMRTCManager.java delete mode 100644 common/src/main/java/com/yunbao/common/manager/imrongcloud/GameRyMicManager.java delete mode 100644 live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java delete mode 100644 live/src/main/java/com/yunbao/live/activity/SudRyGameActivity.java delete mode 100644 live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java delete mode 100644 live/src/main/java/com/yunbao/live/socket/SocketRyClient.java delete mode 100644 live/src/main/java/com/yunbao/live/socket/SocketRyLinkMicPkUtil.java delete mode 100644 live/src/main/java/com/yunbao/live/views/LiveNewReadyRyViewHolder.java delete mode 100644 live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java delete mode 100644 live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java delete mode 100644 live/src/main/java/com/yunbao/live/views/LiveReadyRyViewHolder.java diff --git a/FaceUnity/src/main/java/com/yunbao/faceunity/FaceManager.java b/FaceUnity/src/main/java/com/yunbao/faceunity/FaceManager.java index 0c3c09d6e..672746653 100644 --- a/FaceUnity/src/main/java/com/yunbao/faceunity/FaceManager.java +++ b/FaceUnity/src/main/java/com/yunbao/faceunity/FaceManager.java @@ -38,9 +38,6 @@ import java.util.Locale; import java.util.Map; import java.util.Objects; -import cn.rongcloud.rtc.api.RCRTCEngine; -import cn.rongcloud.rtc.api.callback.IRCRTCVideoOutputFrameListener; -import cn.rongcloud.rtc.base.RCRTCVideoFrame; /** * 美颜模块管理类 @@ -178,44 +175,6 @@ public class FaceManager implements SensorEventListener { private static final int CAMERA_SWITCH_SKIP_FRAME = 0; private volatile boolean mSkip; - /** - * 渲染融云视频帧 - */ - public void drawRongFrame(Context context) { - RCRTCEngine.getInstance().getDefaultVideoStream().setVideoFrameListener(new IRCRTCVideoOutputFrameListener() { - @Override - public RCRTCVideoFrame processVideoFrame(RCRTCVideoFrame callVideoFrame) { - //Log.i(TAG, "processVideoFrame: egl context " + EGL14.eglGetCurrentContext()); - if (pauseFace) { - return callVideoFrame; - } - int width = callVideoFrame.getWidth(); - int height = callVideoFrame.getHeight(); - - if (mIsFirstFrame) { - mIsFirstFrame = false; - //initCsvUtil(context); - mFURenderer.prepareRenderer(mFURendererListener); - } - //long start = System.nanoTime(); - mFURenderer.setInputOrientation(callVideoFrame.getRotation()); - FURenderOutputData data = mFURenderer.onDrawFrameInputWithReturn(callVideoFrame.getData(), width, height); - /* long time = System.nanoTime() - start; - if (mCSVUtils != null) { - mCSVUtils.writeCsv(null, time); - }*/ - if (mSkippedFrames > 0 || mSkip) { - --mSkippedFrames; - return callVideoFrame; - } - if (data != null && data.getImage() != null && data.getImage().getBuffer() != null) { - callVideoFrame.setData(data.getImage().getBuffer()); - } - return callVideoFrame; - } - }); - - } /** * 记录渲染工具,调试用,在processVideoFrame里使用 @@ -278,12 +237,6 @@ public class FaceManager implements SensorEventListener { } - /** - * 离开渲染界面时注销融云监听器,不然会绿屏 - */ - public void onClose() { - RCRTCEngine.getInstance().getDefaultVideoStream().setVideoFrameListener(null); - } /** * 释放资源 diff --git a/app/src/main/java/com/shayu/phonelive/AppContext.java b/app/src/main/java/com/shayu/phonelive/AppContext.java index 9069a94f4..f09b48ffd 100644 --- a/app/src/main/java/com/shayu/phonelive/AppContext.java +++ b/app/src/main/java/com/shayu/phonelive/AppContext.java @@ -5,8 +5,6 @@ import static com.yunbao.live.socket.SocketClient.mSocketHandler; import android.app.Activity; import android.app.ActivityManager; import android.content.Context; -import android.content.res.Configuration; -import android.content.res.Resources; import android.net.http.HttpResponseCache; import android.os.Build; import android.os.Bundle; @@ -27,7 +25,6 @@ import com.blankj.utilcode.util.Utils; import com.facebook.appevents.AppEventsLogger; import com.fm.openinstall.OpenInstall; import com.google.gson.Gson; -import com.yunbao.common.manager.IMLoginManager; import com.yunbao.common.utils.DebugUtils; import com.yunbao.common.utils.LogUtils; import com.tencent.imsdk.v2.V2TIMGroupMemberInfo; @@ -54,7 +51,6 @@ import com.yunbao.common.utils.GoogleUtils; import com.yunbao.common.utils.L; import com.yunbao.common.utils.SpUtil; import com.yunbao.live.socket.SocketReceiveBean; -import com.yunbao.live.socket.SocketRyClient; import com.yunbao.live.socket.SocketSwClient; import com.yunbao.live.utils.LiveImDeletUtil; import com.yunbao.live.views.PortraitLiveManager; @@ -246,7 +242,7 @@ public class AppContext extends CommonAppContext { } //融云 - if (SocketRyClient.mSocketHandler != null && (TextUtils.equals("__system__", message.getTargetId()) || ("g" + PortraitLiveManager.liveID).contains(message.getTargetId()))) { + /* if (SocketRyClient.mSocketHandler != null && (TextUtils.equals("__system__", message.getTargetId()) || ("g" + PortraitLiveManager.liveID).contains(message.getTargetId()))) { SocketRyClient.mSocketHandler.sendMessage(msg); } else if (content.getContent().contains("LivePK_anchorStartLiveNotify")) {//开播通知 SocketReceiveBean received = JSON.parseObject(content.getContent(), SocketReceiveBean.class); @@ -265,7 +261,7 @@ public class AppContext extends CommonAppContext { //主播页面 if (TextUtils.isEmpty(PortraitLiveManager.liveID) && SocketRyClient.mSocketHandler != null) { SocketRyClient.mSocketHandler.sendMessage(msg); - } + }*/ } else if (message.getConversationType() == Conversation.ConversationType.PRIVATE) {//私聊信息 EventBus.getDefault().post(message); } diff --git a/common/build.gradle b/common/build.gradle index 27b4ed16b..1ef0a388f 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -178,7 +178,7 @@ dependencies { //腾讯im api 'com.tencent.imsdk:imsdk-plus:5.4.666' api 'com.google.code.gson:gson:2.8.8' - api 'cn.rongcloud.sdk:rtc_lib:5.7.0' // 音视频通话基础能力库 + //此处以集成 5.1.2 版本为例 api 'cn.rongcloud.sdk:im_lib:5.7.0' diff --git a/common/src/main/java/com/yunbao/common/fragment/ProcessFragment.java b/common/src/main/java/com/yunbao/common/fragment/ProcessFragment.java index 49793cd89..5a52276be 100644 --- a/common/src/main/java/com/yunbao/common/fragment/ProcessFragment.java +++ b/common/src/main/java/com/yunbao/common/fragment/ProcessFragment.java @@ -15,7 +15,6 @@ import com.yunbao.common.R; import com.yunbao.common.interfaces.ActivityResultCallback; import com.yunbao.common.utils.ToastUtil; -import cn.rongcloud.rtc.api.RCRTCEngine; /** * Created by cxf on 2018/9/29. @@ -117,11 +116,6 @@ public class ProcessFragment extends Fragment { @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { - try { - RCRTCEngine.getInstance().getDefaultVideoStream().startCamera(null); - }catch (Exception e){ - - } if (mActivityResultCallback != null) { if (resultCode == -1) {//RESULT_OK mActivityResultCallback.onSuccess(data); diff --git a/common/src/main/java/com/yunbao/common/manager/IMRTCManager.java b/common/src/main/java/com/yunbao/common/manager/IMRTCManager.java deleted file mode 100644 index c1b85d3ab..000000000 --- a/common/src/main/java/com/yunbao/common/manager/IMRTCManager.java +++ /dev/null @@ -1,270 +0,0 @@ -package com.yunbao.common.manager; - -import static cn.rongcloud.rtc.base.RTCErrorCode.JOIN_CHAT_ROOM_TIMEOUT; - -import android.os.Handler; -import android.os.Looper; - -import com.yunbao.common.utils.ToastUtil; -import com.yunbao.common.utils.WordUtil; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Timer; -import java.util.TimerTask; - -import cn.rongcloud.rtc.api.RCRTCEngine; -import cn.rongcloud.rtc.api.RCRTCRemoteUser; -import cn.rongcloud.rtc.api.RCRTCRoom; -import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback; -import cn.rongcloud.rtc.api.callback.IRCRTCRoomEventsListener; -import cn.rongcloud.rtc.api.stream.RCRTCInputStream; -import cn.rongcloud.rtc.base.RTCErrorCode; - -/** - * RTC管理类,负责管理申请、同意、拒绝PK - */ -public class IMRTCManager { - private static IMRTCManager manager; - private RCRTCRoom rtcRoom; - private List requestUid; - - private IMRTCManager() { - requestUid = new ArrayList<>(); - } - - public static IMRTCManager getInstance() { - if (manager == null) { - manager = new IMRTCManager(); - } - return manager; - } - - public void setRtcRoom(RCRTCRoom rtcRoom) { - this.rtcRoom = rtcRoom; - } - - /** - * 响应PK请求 - * - * @param liveUid 对方房间号 - * @param agree 是否同意 - * @param extra 扩展参数 - * @param callback 回调 - */ - public void responseJoinOtherRoom(String liveUid, boolean agree, String extra, IRCRTCResultCallback callback) { - if (rtcRoom != null) { - /* - inviterRoomId - 邀请者所在房间 id, - inviterUserId - 邀请者用户 id - agree - 被邀请者是否同意连麦邀请 - inviteeAutoMix - 是否将被邀请者音视频资源发送到邀请人房间中合流 - 1:inviteeAutoMix 为true时: - 1.1:如果邀请方在发送连麦请求之前发布了资源,当被邀请方加入邀请者房间成功后,服务器会把邀请方流资源合并到被邀请方视图(默认仅悬浮布局合流)上。 - 1.2:如果邀请方在发送连麦请求之前没有发布资源,将会在邀请方发布资源成功后,服务器才会把邀请方的资源合并到被邀请方视图(默认仅悬浮布局合流)上。 - 2: 无论为true或false,双方都可以使用RCRTCLiveInfo.setMixConfig(RCRTCMixConfig, IRCRTCResultCallback) 方法主动设置合流布局。一旦主动设置过合流布局,后续音视频直播过程中设置的自动合流参数将失效。 - extra - 扩展字段,默认为空 - */ - rtcRoom.getLocalUser().responseJoinOtherRoom(liveUid, liveUid, agree, agree, extra, callback); - } else { - callback.onFailed(RTCErrorCode.RongRTCCodeIMError); - } - } - - /** - * 申请PK - * - * @param liveUid 对方房间号 - * @param inviterAutoMix 是否将邀请者音视频资源发送到被邀请人房间中合流 - * @param extra 扩展参数 - * @param callback 回调 - */ - public void requestJoinOtherRoom(String liveUid, boolean inviterAutoMix, String extra, IRCRTCResultCallback callback) { - if (requestUid.contains(liveUid)) { - callback.onFailed(RTCErrorCode.RongRTCCodeJoinRepeatedRoom); - return; - } - if (rtcRoom != null && rtcRoom.getLocalUser() != null) { - /* - inviteeRoomId - 被邀请者所在房间 id - inviteeUserId - 被邀请用户 id - inviterAutoMix - 是否将邀请者音视频资源发送到被邀请人房间中合流 - 1: inviterAutoMix为true时: - 1.1:如果被邀请方在加入邀请方房间之前发布了资源,当被邀请方加入邀请者房间成功后,服务器会把被邀请方流资源合并到邀请方视图 ·(默认仅悬浮布局合流)上。 - 1.2:如果被邀请方在加入邀请方房间之前没有发布过资源,将会在被邀请方发布资源成功后,服务器会把被邀请方流资源合并到邀请方视图(默认仅悬浮布局合流)上。 - 2:无论为true或false,双方都可以使用RCRTCLiveInfo.setMixConfig(RCRTCMixConfig, IRCRTCResultCallback) 方法主动设置合流布局。一旦主动设置过合流布局,后续音视频直播过程中设置的自动合流参数将失效。 - extra - 扩展字段,默认为空 - */ - rtcRoom.getLocalUser().requestJoinOtherRoom(liveUid, liveUid, inviterAutoMix, extra, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - callback.onSuccess(); - if (!RandomPkManager.getInstance().isRandomModel()) { - if(WordUtil.isNewZh()) { - ToastUtil.show("发起邀请成功"); - }else{ - ToastUtil.show("successful"); - } - } - requestUid.add(liveUid); - startRequestTimeoutTask(liveUid); - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - if (!RandomPkManager.getInstance().isRandomModel()) { - if(WordUtil.isNewZh()) { - ToastUtil.show("邀请失败 " + errorCode.getValue()); - }else{ - ToastUtil.show("invite failed:" +errorCode.getValue()); - } - } - if (RandomPkManager.getInstance().isRequestPk()) { - RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_REFUSE); - } - requestUid.remove(liveUid); - callback.onFailed(errorCode); - } - }); - } else { - callback.onFailed(RTCErrorCode.RongRTCCodeIMError); - } - } - - /** - * 注册监听对方通知类,还没搞清楚具体用法,先搁置 - * - * @param listener - */ - public void registerRoomListener(IRCRTCRoomEventsListener listener) { - if (rtcRoom != null && rtcRoom.getLocalUser() != null) { - rtcRoom.registerRoomListener(new IRCRTCRoomEventsListener() { - @Override - public void onRemoteUserPublishResource(RCRTCRemoteUser remoteUser, List streams) { - listener.onRemoteUserPublishResource(remoteUser, streams); - } - - @Override - public void onRemoteUserMuteAudio(RCRTCRemoteUser remoteUser, RCRTCInputStream stream, boolean mute) { - listener.onRemoteUserMuteAudio(remoteUser, stream, mute); - } - - @Override - public void onRemoteUserMuteVideo(RCRTCRemoteUser remoteUser, RCRTCInputStream stream, boolean mute) { - listener.onRemoteUserMuteVideo(remoteUser, stream, mute); - } - - @Override - public void onRemoteUserUnpublishResource(RCRTCRemoteUser remoteUser, List streams) { - listener.onRemoteUserUnpublishResource(remoteUser, streams); - } - - @Override - public void onUserJoined(RCRTCRemoteUser remoteUser) { - listener.onUserJoined(remoteUser); - } - - @Override - public void onUserLeft(RCRTCRemoteUser remoteUser) { - listener.onUserLeft(remoteUser); - } - - @Override - public void onUserOffline(RCRTCRemoteUser remoteUser) { - listener.onUserOffline(remoteUser); - } - - @Override - public void onPublishLiveStreams(List streams) { - listener.onPublishLiveStreams(streams); - } - - @Override - public void onUnpublishLiveStreams(List streams) { - listener.onUnpublishLiveStreams(streams); - } - }); - } - } - - /** - * 取消邀请 - * - * @param liveUid 房间号 - * @param extra 扩展参数 - * @param callback 回调 - */ - public void cancelRequestJoinOtherRoom(String liveUid, String extra, IRCRTCResultCallback callback) { - if (rtcRoom != null && rtcRoom.getLocalUser() != null) { - rtcRoom.getLocalUser().cancelRequestJoinOtherRoom(liveUid, liveUid, extra, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - callback.onSuccess(); - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - callback.onFailed(errorCode); - } - }); - } else { - callback.onFailed(RTCErrorCode.RongRTCCodeIMError); - } - } - - public void callPkSuccess(String liveUid) { - requestUid.remove(liveUid); - } - - private void startRequestTimeoutTask(String liveUid) { - new Timer().schedule(new TimerTask() { - int waitTime = 15; - - @Override - public void run() { - if (!requestUid.contains(liveUid)) { - cancel(); - return; - } - if (waitTime-- == 0) { - //callback.onFailed(JOIN_CHAT_ROOM_TIMEOUT); - cancelRequestJoinOtherRoom(liveUid, "extra", new IRCRTCResultCallback() { - @Override - public void onSuccess() { - requestUid.remove(liveUid); - if (RandomPkManager.getInstance().isRandomModel()) { - RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_REFUSE); - } - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - requestUid.remove(liveUid); - if (RandomPkManager.getInstance().isRandomModel()) { - RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_REFUSE); - } - } - }); - cancel(); - } - } - }, 1000, 1000); - } - - public void leaveOtherRoom(String roomId, - boolean notifyFinished, - IRCRTCResultCallback callBack) { - RCRTCEngine.getInstance().leaveOtherRoom(roomId, notifyFinished, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - callBack.onSuccess(); - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - callBack.onFailed(rtcErrorCode); - } - }); - } -} diff --git a/common/src/main/java/com/yunbao/common/manager/imrongcloud/GameRyMicManager.java b/common/src/main/java/com/yunbao/common/manager/imrongcloud/GameRyMicManager.java deleted file mode 100644 index d696513dd..000000000 --- a/common/src/main/java/com/yunbao/common/manager/imrongcloud/GameRyMicManager.java +++ /dev/null @@ -1,559 +0,0 @@ -package com.yunbao.common.manager.imrongcloud; - -import android.content.Context; -import android.text.TextUtils; -import android.util.Log; - -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; -import com.yunbao.common.CommonAppContext; -import com.yunbao.common.bean.IMLoginModel; -import com.yunbao.common.bean.SudGameChatImModel; -import com.yunbao.common.bean.SudGameUserModel; -import com.yunbao.common.event.SudGameSocketImEvent; -import com.yunbao.common.manager.IMLoginManager; -import com.yunbao.common.utils.ToastUtil; -import com.yunbao.common.utils.WordUtil; - -import java.util.ArrayList; -import java.util.List; - -import cn.rongcloud.rtc.api.RCRTCEngine; -import cn.rongcloud.rtc.api.RCRTCRemoteUser; -import cn.rongcloud.rtc.api.RCRTCRoom; -import cn.rongcloud.rtc.api.RCRTCRoomConfig; -import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback; -import cn.rongcloud.rtc.api.callback.IRCRTCResultDataCallback; -import cn.rongcloud.rtc.api.callback.IRCRTCRoomEventsListener; -import cn.rongcloud.rtc.api.stream.RCRTCInputStream; -import cn.rongcloud.rtc.base.RCRTCParamsType; -import cn.rongcloud.rtc.base.RCRTCRoomType; -import cn.rongcloud.rtc.base.RTCErrorCode; -import io.rong.imlib.IRongCallback; -import io.rong.imlib.IRongCoreCallback; -import io.rong.imlib.IRongCoreEnum; -import io.rong.imlib.RongIMClient; -import io.rong.imlib.chatroom.base.RongChatRoomClient; -import io.rong.imlib.model.Conversation; -import io.rong.imlib.model.Message; -import io.rong.message.TextMessage; - -public class GameRyMicManager { - MeetingCallback mMeetingCallback = null; - private RCRTCRoom mRtcRoom = null; - private String mRoomID = ""; - - - private final IRCRTCRoomEventsListener roomEventsListener = new IRCRTCRoomEventsListener() { - /** - * 房间内用户发布资源 - * - * @param rcrtcRemoteUser 远端用户 - * @param list 发布的资源 - */ - @Override - public void onRemoteUserPublishResource(RCRTCRemoteUser rcrtcRemoteUser, final List list) { -// subscribeAVStream(); - } - - @Override - public void onRemoteUserMuteAudio(RCRTCRemoteUser rcrtcRemoteUser, RCRTCInputStream rcrtcInputStream, boolean b) { - - } - - @Override - public void onRemoteUserMuteVideo(RCRTCRemoteUser rcrtcRemoteUser, RCRTCInputStream rcrtcInputStream, boolean b) { - } - - - @Override - public void onRemoteUserUnpublishResource(RCRTCRemoteUser rcrtcRemoteUser, List list) { - } - - /** - * 用户加入房间 - * - * @param rcrtcRemoteUser 远端用户 - */ - @Override - public void onUserJoined(final RCRTCRemoteUser rcrtcRemoteUser) { - try { - getView().onUserJoined(rcrtcRemoteUser); - } catch (IllegalStateException e) { - e.printStackTrace(); - } - } - - /** - * 用户离开房间 - * - * @param rcrtcRemoteUser 远端用户 - */ - @Override - public void onUserLeft(RCRTCRemoteUser rcrtcRemoteUser) { - try { - getView().onUserLeft(rcrtcRemoteUser); - } catch (IllegalStateException e) { - e.printStackTrace(); - } - } - - @Override - public void onUserOffline(RCRTCRemoteUser rcrtcRemoteUser) { - } - - @Override - public void onPublishLiveStreams(List list) { - } - - @Override - public void onUnpublishLiveStreams(List list) { - } - - /** - * 自己退出房间。 例如断网退出等 - * @param i 状态码 - */ - @Override - public void onLeaveRoom(int i) { - } - }; - - protected MeetingCallback getView() { - if (mMeetingCallback == null) { - throw new IllegalStateException("view is not attached"); - } else { - return mMeetingCallback; - } - } - - public void attachView(MeetingCallback callback) { - mMeetingCallback = callback; - } - - public void detachView() { - mMeetingCallback = null; - } - - /** - * 主动订阅远端用户发布的流 - * 视频流需要用户设置用于显示载体的videoview - */ - public void subscribeAVStream() { - if (mRtcRoom == null || mRtcRoom.getRemoteUsers() == null) { - return; - } - final List inputStreams = new ArrayList<>(); - for (final RCRTCRemoteUser remoteUser : mRtcRoom.getRemoteUsers()) { - if (remoteUser.getStreams().size() == 0) { - continue; - } - - inputStreams.addAll(remoteUser.getStreams()); - - } - - if (inputStreams.size() == 0) { - return; - } - mRtcRoom.getLocalUser().subscribeStreams(inputStreams, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - - - try { - getView().onSubscribeSuccess(inputStreams); - } catch (IllegalStateException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - try { - getView().onSubscribeFailed(); - } catch (IllegalStateException e) { - e.printStackTrace(); - } - } - }); - } - - - public void refreshStreams(List personList) { - - final List inputStreams = new ArrayList<>(); - - for (SudGameUserModel sudGameUserModel : personList) { - List rcrtcRemoteUsers = mRtcRoom.getRemoteUsers(); - - for (RCRTCRemoteUser rcrtcRemoteUser : rcrtcRemoteUsers) { - if (TextUtils.equals(rcrtcRemoteUser.getUserId(), String.valueOf(sudGameUserModel.getId()))) { - for (RCRTCInputStream rcrtcInputStream : rcrtcRemoteUser.getStreams()) { - rcrtcInputStream.mute(sudGameUserModel.getMicStatus() == 3); - } - inputStreams.addAll(rcrtcRemoteUser.getStreams()); - } - } - } - if (inputStreams.size() == 0) { - return; - } - mRtcRoom.getLocalUser().subscribeStreams(inputStreams, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - - - try { - getView().onSubscribeSuccess(inputStreams); - } catch (IllegalStateException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - try { - getView().onSubscribeFailed(); - } catch (IllegalStateException e) { - e.printStackTrace(); - } - } - }); - } - - public void refreshStreams(String userID, boolean mute, int position) { - - final List inputStreams = new ArrayList<>(); - - List rcrtcRemoteUsers = mRtcRoom.getRemoteUsers(); - - for (RCRTCRemoteUser rcrtcRemoteUser : rcrtcRemoteUsers) { - if (TextUtils.equals(rcrtcRemoteUser.getUserId(), String.valueOf(userID))) { - for (RCRTCInputStream rcrtcInputStream : rcrtcRemoteUser.getStreams()) { - rcrtcInputStream.mute(mute); - } - inputStreams.addAll(rcrtcRemoteUser.getStreams()); - } - } - if (inputStreams.size() == 0) { - return; - } - mRtcRoom.getLocalUser().subscribeStreams(inputStreams, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - - - try { - getView().onSubscribeSuccess(userID, mute, position); - } catch (IllegalStateException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - try { - getView().onSubscribeFailed(userID); - } catch (IllegalStateException e) { - e.printStackTrace(); - } - } - }); - } - - public void unPublishStreams() { - if (mRtcRoom == null) { - return; - } - mRtcRoom.getLocalUser().unpublishStream(RCRTCEngine.getInstance().getDefaultAudioStream(), new IRCRTCResultCallback() { - @Override - public void onSuccess() { - try { - getView().onUnPublishStreamsSuccess(); - } catch (IllegalStateException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - try { - getView().onUnPublishStreamsFailed(); - } catch (IllegalStateException e) { - e.printStackTrace(); - } - } - }); - } - - /** - * 发布默认流 - */ - public void publishDefaultAVStream() { - if (mRtcRoom == null) { - return; - } - mRtcRoom.getLocalUser().publishStream(RCRTCEngine.getInstance().getDefaultAudioStream(), new IRCRTCResultCallback() { - @Override - public void onSuccess() { - try { - getView().onPublishSuccess(); - } catch (IllegalStateException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - try { - getView().onPublishFailed(); - } catch (IllegalStateException e) { - e.printStackTrace(); - } - } - }); - } - - - /** - * 配置rtc sdk - */ - public void config(Context context) { - -// RCRTCConfig.Builder configBuilder = RCRTCConfig.Builder.create(); -// // 是否硬解码 -// configBuilder.enableHardwareDecoder(true); -// // 是否硬编码 -// configBuilder.enableHardwareEncoder(true); -// -// // init 需结合 uninit 使用,否则有些配置无法重新初始化 -// RCRTCEngine.getInstance().unInit(); -// RCRTCEngine.getInstance().init(context, configBuilder.build()); - -// RCRTCVideoStreamConfig.Builder videoConfigBuilder = RCRTCVideoStreamConfig.Builder.create(); -// // 设置分辨率 -// videoConfigBuilder.setVideoResolution(RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_720_1280); -// // 设置帧率 -// videoConfigBuilder.setVideoFps(RCRTCParamsType.RCRTCVideoFps.Fps_30); -// /** -// * 设置最小码率,可根据分辨率RCRTCVideoResolution设置 -// * {@link RCRTCParamsType.RCRTCVideoResolution)} -// */ -// videoConfigBuilder.setMinRate(250); -// /** -// * 设置最大码率,可根据分辨率RCRTCVideoResolution设置 -// * {@link RCRTCParamsType.RCRTCVideoResolution)} -// */ -// videoConfigBuilder.setMaxRate(2200); -// RCRTCEngine.getInstance().getDefaultVideoStream().setVideoConfig(videoConfigBuilder.build()); - //打开扬声器。 - RCRTCEngine.getInstance().enableSpeaker(true); - // 启用耳返功能 - RCRTCEngine.getInstance().getDefaultAudioStream().enableEarMonitoring(true); - RCRTCEngine.getInstance().getDefaultAudioStream().setMicrophoneDisable(false); - RCRTCEngine.getInstance().getDefaultAudioStream().setAudioQuality(RCRTCParamsType.AudioQuality.MUSIC_HIGH, RCRTCParamsType.AudioScenario.MUSIC_CHATROOM); - } - - public void joinRoom(String roomId, boolean imOff) { - mRoomID = roomId; - if (imOff) { - - RCRTCRoomConfig roomConfig = RCRTCRoomConfig.Builder.create() - // 根据实际场景,选择音视频直播:LIVE_AUDIO_VIDEO 或音频直播:LIVE_AUDIO - .setRoomType(RCRTCRoomType.MEETING) - - .build(); - RCRTCEngine.getInstance().joinRoom("v" + roomId, roomConfig, new IRCRTCResultDataCallback() { - @Override - public void onSuccess(final RCRTCRoom rcrtcRoom) { - GameRyMicManager.this.mRtcRoom = rcrtcRoom; - // 注册房间回调 - rcrtcRoom.registerRoomListener(roomEventsListener); - try { - getView().onJoinRoomSuccess(rcrtcRoom); - } catch (IllegalStateException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - try { - getView().onJoinRoomFailed(rtcErrorCode); - } catch (IllegalStateException e) { - e.printStackTrace(); - } - } - }); - } - - RongChatRoomClient.getInstance().joinChatRoom("v" + roomId, -1, new IRongCoreCallback.OperationCallback() { - @Override - public void onSuccess() { - Log.i("tx", "加入成功"); - enterRoom(); - - } - - @Override - public void onError(IRongCoreEnum.CoreErrorCode coreErrorCode) { - Log.i("tx", "加入" + "失败" + coreErrorCode); - if (WordUtil.isNewZh()) { - ToastUtil.show("網絡不佳無法連接,請重新進入"); - } else { - ToastUtil.show("The network is not connected, please re-enter"); - } - } - }); - } - - public void leaveRoom() { - RCRTCEngine.getInstance().leaveRoom(new IRCRTCResultCallback() { - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - } - - @Override - public void onSuccess() { - } - }); - RongChatRoomClient.getInstance().quitChatRoom("v" + mRoomID, new IRongCoreCallback.OperationCallback() { - @Override - public void onSuccess() { - Log.i("tx", "退出成功"); - } - - @Override - public void onError(IRongCoreEnum.CoreErrorCode coreErrorCode) { - Log.i("tx", "退出" + "" + coreErrorCode); - } - }); - } - - /** - * 处理游戏房Im消息 - */ - public void processingMessage(SudGameSocketImEvent socketImModel) { - - List msgDTOS = socketImModel.getMsg(); - if (msgDTOS.isEmpty()) return; - SudGameSocketImEvent.MsgDTO msgDTO = msgDTOS.get(0); - //正常文字消息 - if (TextUtils.equals(msgDTO.getMethod(), "SendMsg")) { - getView().insertItem(new SudGameChatImModel().setWelcomMessage(false).setNickname(msgDTO.getUname()).setTextMessage(msgDTO.getCt())); - } else if (TextUtils.equals(msgDTO.getMethod(), "welcomMessage")) { - // 欢迎(用户名)进入房间 Welcome (username) to the room - - StringBuffer stringBuffer = new StringBuffer(); - if (WordUtil.isNewZh()) { - stringBuffer.append("歡迎 ").append(msgDTO.getCt()).append(" 進入房間"); - } else { - stringBuffer.append("Welcome ").append(msgDTO.getCt()).append(" to enter the room"); - } - - getView().insertItem(new SudGameChatImModel().setWelcomMessage(true).setNickname(msgDTO.getCt()).setTextMessage(stringBuffer.toString())); - } else if (TextUtils.equals(msgDTO.getMethod(), "sudGameRoomVoiceList")) { - List personList = new Gson().fromJson(msgDTO.getCt(), new TypeToken>() { - }.getType()); - getView().refreshSudGameUserList(personList); - - refreshStreams(personList); - - } - } - - private void sendChatMessage(String textMessage, String method) { - IMLoginModel loginModel = IMLoginManager.get(CommonAppContext.sInstance.getApplicationContext()).getUserInfo(); - SudGameSocketImEvent sudGameSocketImEvent = new SudGameSocketImEvent(); - sudGameSocketImEvent.setRetcode("000000"); - sudGameSocketImEvent.setRetmsg("ok"); - - SudGameSocketImEvent.MsgDTO msgDTO = new SudGameSocketImEvent.MsgDTO(); - msgDTO.setAction("0") - .setCt(textMessage) - .setEquipment("app") - .setUid(String.valueOf(loginModel.getId())) - .setMethod(method) - .setUname(loginModel.getUserNicename()) - .setRoomnum(mRoomID); - - List msgDTOS = new ArrayList<>(); - msgDTOS.add(msgDTO); - sudGameSocketImEvent.setMsg(msgDTOS); - Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; - TextMessage messageContent = TextMessage.obtain(new Gson().toJson(sudGameSocketImEvent)); - Message message = Message.obtain("v" + mRoomID, conversationType, messageContent); - RongcloudIMManager.sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { - @Override - public void onAttached(Message message) { - - } - - @Override - public void onSuccess(Message message) { - Log.i("tx", "发送成功"); - String contentJson = ((TextMessage) message.getContent()).getContent(); - Log.e("wewe", contentJson); - SudGameSocketImEvent sudGameSocketImEvent = new Gson().fromJson(contentJson, SudGameSocketImEvent.class); - processingMessage(sudGameSocketImEvent); - } - - @Override - public void onError(Message message, RongIMClient.ErrorCode errorCode) { - Log.i("tx", "发送成功" + errorCode.toString()); - } - }); - } - - /** - * 发送聊天信息 - * - * @param textMessage - */ - public void sendMessage(String textMessage) { - sendChatMessage(textMessage, "SendMsg"); - } - - /** - * 进房间 - */ - public void enterRoom() { - IMLoginModel loginModel = IMLoginManager.get(CommonAppContext.sInstance.getApplicationContext()).getUserInfo(); - sendChatMessage(loginModel.getUserNicename(), "welcomMessage"); - } - - /** - * activity相关回调 - */ - public interface MeetingCallback { - void onJoinRoomSuccess(RCRTCRoom rcrtcRoom); - - void onJoinRoomFailed(RTCErrorCode rtcErrorCode); - - void onPublishSuccess(); - - - void onPublishFailed(); - - void onUnPublishStreamsSuccess(); - - void onUnPublishStreamsFailed(); - - void onSubscribeSuccess(List inputStreamList); - - void onSubscribeFailed(); - - void onSubscribeSuccess(String userID, boolean mute, int position); - - void onSubscribeFailed(String userID); - - void onUserJoined(RCRTCRemoteUser rcrtcRemoteUser); - - void onUserLeft(RCRTCRemoteUser rcrtcRemoteUser); - - void insertItem(SudGameChatImModel sudGameChatImModel); - - void refreshSudGameUserList(List personList); - } -} diff --git a/common/src/main/java/com/yunbao/common/manager/imrongcloud/GameSwMicManager.java b/common/src/main/java/com/yunbao/common/manager/imrongcloud/GameSwMicManager.java index 467dbecd3..73c90d4a7 100644 --- a/common/src/main/java/com/yunbao/common/manager/imrongcloud/GameSwMicManager.java +++ b/common/src/main/java/com/yunbao/common/manager/imrongcloud/GameSwMicManager.java @@ -1,127 +1,30 @@ package com.yunbao.common.manager.imrongcloud; -import android.content.Context; -import android.text.TextUtils; import android.util.Log; import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; import com.yunbao.common.CommonAppContext; import com.yunbao.common.bean.IMLoginModel; -import com.yunbao.common.bean.SudGameChatImModel; -import com.yunbao.common.bean.SudGameUserModel; import com.yunbao.common.event.SudGameSocketImEvent; import com.yunbao.common.manager.IMLoginManager; -import com.yunbao.common.utils.ToastUtil; -import com.yunbao.common.utils.WordUtil; import java.util.ArrayList; import java.util.List; -import cn.rongcloud.rtc.api.RCRTCEngine; -import cn.rongcloud.rtc.api.RCRTCRemoteUser; -import cn.rongcloud.rtc.api.RCRTCRoom; -import cn.rongcloud.rtc.api.RCRTCRoomConfig; -import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback; -import cn.rongcloud.rtc.api.callback.IRCRTCResultDataCallback; -import cn.rongcloud.rtc.api.callback.IRCRTCRoomEventsListener; -import cn.rongcloud.rtc.api.stream.RCRTCInputStream; -import cn.rongcloud.rtc.base.RCRTCParamsType; -import cn.rongcloud.rtc.base.RCRTCRoomType; -import cn.rongcloud.rtc.base.RTCErrorCode; import io.rong.imlib.IRongCallback; -import io.rong.imlib.IRongCoreCallback; -import io.rong.imlib.IRongCoreEnum; import io.rong.imlib.RongIMClient; -import io.rong.imlib.chatroom.base.RongChatRoomClient; import io.rong.imlib.model.Conversation; import io.rong.imlib.model.Message; import io.rong.message.TextMessage; public class GameSwMicManager { MeetingCallback mMeetingCallback = null; - private RCRTCRoom mRtcRoom = null; private String mRoomID = ""; public void setmRoomID(String mRoomID) { this.mRoomID = mRoomID; } - private final IRCRTCRoomEventsListener roomEventsListener = new IRCRTCRoomEventsListener() { - /** - * 房间内用户发布资源 - * - * @param rcrtcRemoteUser 远端用户 - * @param list 发布的资源 - */ - @Override - public void onRemoteUserPublishResource(RCRTCRemoteUser rcrtcRemoteUser, final List list) { -// subscribeAVStream(); - } - - @Override - public void onRemoteUserMuteAudio(RCRTCRemoteUser rcrtcRemoteUser, RCRTCInputStream rcrtcInputStream, boolean b) { - - } - - @Override - public void onRemoteUserMuteVideo(RCRTCRemoteUser rcrtcRemoteUser, RCRTCInputStream rcrtcInputStream, boolean b) { - } - - - @Override - public void onRemoteUserUnpublishResource(RCRTCRemoteUser rcrtcRemoteUser, List list) { - } - - /** - * 用户加入房间 - * - * @param rcrtcRemoteUser 远端用户 - */ - @Override - public void onUserJoined(final RCRTCRemoteUser rcrtcRemoteUser) { - try { - getView().onUserJoined(rcrtcRemoteUser); - } catch (IllegalStateException e) { - e.printStackTrace(); - } - } - - /** - * 用户离开房间 - * - * @param rcrtcRemoteUser 远端用户 - */ - @Override - public void onUserLeft(RCRTCRemoteUser rcrtcRemoteUser) { - try { - getView().onUserLeft(rcrtcRemoteUser); - } catch (IllegalStateException e) { - e.printStackTrace(); - } - } - - @Override - public void onUserOffline(RCRTCRemoteUser rcrtcRemoteUser) { - } - - @Override - public void onPublishLiveStreams(List list) { - } - - @Override - public void onUnpublishLiveStreams(List list) { - } - - /** - * 自己退出房间。 例如断网退出等 - * @param i 状态码 - */ - @Override - public void onLeaveRoom(int i) { - } - }; - protected MeetingCallback getView() { if (mMeetingCallback == null) { throw new IllegalStateException("view is not attached"); @@ -138,336 +41,6 @@ public class GameSwMicManager { mMeetingCallback = null; } - /** - * 主动订阅远端用户发布的流 - * 视频流需要用户设置用于显示载体的videoview - */ - public void subscribeAVStream() { - if (mRtcRoom == null || mRtcRoom.getRemoteUsers() == null) { - return; - } - final List inputStreams = new ArrayList<>(); - for (final RCRTCRemoteUser remoteUser : mRtcRoom.getRemoteUsers()) { - if (remoteUser.getStreams().size() == 0) { - continue; - } - - inputStreams.addAll(remoteUser.getStreams()); - - } - - if (inputStreams.size() == 0) { - return; - } - mRtcRoom.getLocalUser().subscribeStreams(inputStreams, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - - - try { - getView().onSubscribeSuccess(inputStreams); - } catch (IllegalStateException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - try { - getView().onSubscribeFailed(); - } catch (IllegalStateException e) { - e.printStackTrace(); - } - } - }); - } - - - public void refreshStreams(List personList) { - - final List inputStreams = new ArrayList<>(); - if(mRtcRoom!=null){ - for (SudGameUserModel sudGameUserModel : personList) { - List rcrtcRemoteUsers = mRtcRoom.getRemoteUsers(); - - for (RCRTCRemoteUser rcrtcRemoteUser : rcrtcRemoteUsers) { - if (TextUtils.equals(rcrtcRemoteUser.getUserId(), String.valueOf(sudGameUserModel.getId()))) { - for (RCRTCInputStream rcrtcInputStream : rcrtcRemoteUser.getStreams()) { - rcrtcInputStream.mute(sudGameUserModel.getMicStatus() == 3); - } - inputStreams.addAll(rcrtcRemoteUser.getStreams()); - } - } - } - if (inputStreams.size() == 0) { - return; - } - mRtcRoom.getLocalUser().subscribeStreams(inputStreams, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - - - try { - getView().onSubscribeSuccess(inputStreams); - } catch (IllegalStateException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - try { - getView().onSubscribeFailed(); - } catch (IllegalStateException e) { - e.printStackTrace(); - } - } - }); - } - } - - public void refreshStreams(String userID, boolean mute, int position) { - - final List inputStreams = new ArrayList<>(); - - List rcrtcRemoteUsers = mRtcRoom.getRemoteUsers(); - - for (RCRTCRemoteUser rcrtcRemoteUser : rcrtcRemoteUsers) { - if (TextUtils.equals(rcrtcRemoteUser.getUserId(), String.valueOf(userID))) { - for (RCRTCInputStream rcrtcInputStream : rcrtcRemoteUser.getStreams()) { - rcrtcInputStream.mute(mute); - } - inputStreams.addAll(rcrtcRemoteUser.getStreams()); - } - } - if (inputStreams.size() == 0) { - return; - } - mRtcRoom.getLocalUser().subscribeStreams(inputStreams, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - try { - getView().onSubscribeSuccess(userID, mute, position); - } catch (IllegalStateException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - try { - getView().onSubscribeFailed(userID); - } catch (IllegalStateException e) { - e.printStackTrace(); - } - } - }); - } - - public void unPublishStreams() { - if (mRtcRoom == null) { - return; - } - mRtcRoom.getLocalUser().unpublishStream(RCRTCEngine.getInstance().getDefaultAudioStream(), new IRCRTCResultCallback() { - @Override - public void onSuccess() { - try { - getView().onUnPublishStreamsSuccess(); - } catch (IllegalStateException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - try { - getView().onUnPublishStreamsFailed(); - } catch (IllegalStateException e) { - e.printStackTrace(); - } - } - }); - } - - /** - * 发布默认流 - */ - public void publishDefaultAVStream() { - if (mRtcRoom == null) { - return; - } - mRtcRoom.getLocalUser().publishStream(RCRTCEngine.getInstance().getDefaultAudioStream(), new IRCRTCResultCallback() { - @Override - public void onSuccess() { - try { - getView().onPublishSuccess(); - } catch (IllegalStateException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - try { - getView().onPublishFailed(); - } catch (IllegalStateException e) { - e.printStackTrace(); - } - } - }); - } - - - /** - * 配置rtc sdk - */ - public void config(Context context) { - -// RCRTCConfig.Builder configBuilder = RCRTCConfig.Builder.create(); -// // 是否硬解码 -// configBuilder.enableHardwareDecoder(true); -// // 是否硬编码 -// configBuilder.enableHardwareEncoder(true); -// -// // init 需结合 uninit 使用,否则有些配置无法重新初始化 -// RCRTCEngine.getInstance().unInit(); -// RCRTCEngine.getInstance().init(context, configBuilder.build()); - -// RCRTCVideoStreamConfig.Builder videoConfigBuilder = RCRTCVideoStreamConfig.Builder.create(); -// // 设置分辨率 -// videoConfigBuilder.setVideoResolution(RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_720_1280); -// // 设置帧率 -// videoConfigBuilder.setVideoFps(RCRTCParamsType.RCRTCVideoFps.Fps_30); -// /** -// * 设置最小码率,可根据分辨率RCRTCVideoResolution设置 -// * {@link RCRTCParamsType.RCRTCVideoResolution)} -// */ -// videoConfigBuilder.setMinRate(250); -// /** -// * 设置最大码率,可根据分辨率RCRTCVideoResolution设置 -// * {@link RCRTCParamsType.RCRTCVideoResolution)} -// */ -// videoConfigBuilder.setMaxRate(2200); -// RCRTCEngine.getInstance().getDefaultVideoStream().setVideoConfig(videoConfigBuilder.build()); - //打开扬声器。 - RCRTCEngine.getInstance().enableSpeaker(true); - // 启用耳返功能 - RCRTCEngine.getInstance().getDefaultAudioStream().enableEarMonitoring(true); - RCRTCEngine.getInstance().getDefaultAudioStream().setMicrophoneDisable(false); - RCRTCEngine.getInstance().getDefaultAudioStream().setAudioQuality(RCRTCParamsType.AudioQuality.MUSIC_HIGH, RCRTCParamsType.AudioScenario.MUSIC_CHATROOM); - } - - public void joinRoom(String roomId, boolean imOff) { - mRoomID = roomId; - if (imOff) { - - RCRTCRoomConfig roomConfig = RCRTCRoomConfig.Builder.create() - // 根据实际场景,选择音视频直播:LIVE_AUDIO_VIDEO 或音频直播:LIVE_AUDIO - .setRoomType(RCRTCRoomType.MEETING) - - .build(); - RCRTCEngine.getInstance().joinRoom("v" + roomId, roomConfig, new IRCRTCResultDataCallback() { - @Override - public void onSuccess(final RCRTCRoom rcrtcRoom) { - GameSwMicManager.this.mRtcRoom = rcrtcRoom; - // 注册房间回调 - rcrtcRoom.registerRoomListener(roomEventsListener); - try { - getView().onJoinRoomSuccess(rcrtcRoom); - } catch (IllegalStateException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - try { - getView().onJoinRoomFailed(rtcErrorCode); - } catch (IllegalStateException e) { - e.printStackTrace(); - } - } - }); - } - - RongChatRoomClient.getInstance().joinChatRoom("v" + roomId, -1, new IRongCoreCallback.OperationCallback() { - @Override - public void onSuccess() { - Log.i("tx", "加入成功"); - enterRoom(); - - } - - @Override - public void onError(IRongCoreEnum.CoreErrorCode coreErrorCode) { - Log.i("tx", "加入" + "失败" + coreErrorCode); - if (WordUtil.isNewZh()) { - ToastUtil.show("網絡不佳無法連接,請重新進入"); - } else { - ToastUtil.show("The network is not connected, please re-enter"); - } - } - }); - } - - public void leaveRoom() { - RCRTCEngine.getInstance().leaveRoom(new IRCRTCResultCallback() { - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - } - - @Override - public void onSuccess() { - } - }); - RongChatRoomClient.getInstance().quitChatRoom("v" + mRoomID, new IRongCoreCallback.OperationCallback() { - @Override - public void onSuccess() { - Log.i("tx", "退出成功"); - } - - @Override - public void onError(IRongCoreEnum.CoreErrorCode coreErrorCode) { - Log.i("tx", "退出" + "" + coreErrorCode); - } - }); - } - - - /** - * 处理游戏房Im消息 - */ - public void processingMessage(SudGameSocketImEvent socketImModel) { - - List msgDTOS = socketImModel.getMsg(); - if (msgDTOS.isEmpty()) return; - SudGameSocketImEvent.MsgDTO msgDTO = msgDTOS.get(0); - - - //正常文字消息 - if (TextUtils.equals(msgDTO.getMethod(), "SendMsg")) { - getView().insertItem(new SudGameChatImModel().setWelcomMessage(false).setNickname(msgDTO.getUname()).setTextMessage(msgDTO.getCt())); - } else if (TextUtils.equals(msgDTO.getMethod(), "welcomMessage")) { - // 欢迎(用户名)进入房间 Welcome (username) to the room - - StringBuffer stringBuffer = new StringBuffer(); - if (WordUtil.isNewZh()) { - stringBuffer.append("歡迎 ").append(msgDTO.getCt()).append(" 進入房間"); - } else { - stringBuffer.append("Welcome ").append(msgDTO.getCt()).append(" to enter the room"); - } - - getView().insertItem(new SudGameChatImModel().setWelcomMessage(true).setNickname(msgDTO.getCt()).setTextMessage(stringBuffer.toString())); - } else if (TextUtils.equals(msgDTO.getMethod(), "sudGameRoomVoiceList")) { - List personList = new Gson().fromJson(msgDTO.getCt(), new TypeToken>() { - }.getType()); - getView().refreshSudGameUserList(personList); - - refreshStreams(personList); - - } - } - private void sendChatMessage(String textMessage, String method) { IMLoginModel loginModel = IMLoginManager.get(CommonAppContext.sInstance.getApplicationContext()).getUserInfo(); SudGameSocketImEvent sudGameSocketImEvent = new SudGameSocketImEvent(); @@ -502,7 +75,6 @@ public class GameSwMicManager { Log.e("wewe", contentJson); SudGameSocketImEvent sudGameSocketImEvent = new Gson().fromJson(contentJson, SudGameSocketImEvent.class); sudGameSocketImEvent.getMsg().get(0).setTime("11"); - processingMessage(sudGameSocketImEvent); } @Override @@ -533,33 +105,12 @@ public class GameSwMicManager { * activity相关回调 */ public interface MeetingCallback { - void onJoinRoomSuccess(RCRTCRoom rcrtcRoom); - - void onJoinRoomFailed(RTCErrorCode rtcErrorCode); void onPublishSuccess(); - - void onPublishFailed(); - void onUnPublishStreamsSuccess(); - void onUnPublishStreamsFailed(); - - void onSubscribeSuccess(List inputStreamList); - - void onSubscribeFailed(); - void onSubscribeSuccess(String userID, boolean mute, int position); - void onSubscribeFailed(String userID); - - void onUserJoined(RCRTCRemoteUser rcrtcRemoteUser); - - void onUserLeft(RCRTCRemoteUser rcrtcRemoteUser); - - void insertItem(SudGameChatImModel sudGameChatImModel); - - void refreshSudGameUserList(List personList); } } diff --git a/common/src/main/java/com/yunbao/common/utils/MicStatusManager.java b/common/src/main/java/com/yunbao/common/utils/MicStatusManager.java index 66c3043ed..7bc085e78 100644 --- a/common/src/main/java/com/yunbao/common/utils/MicStatusManager.java +++ b/common/src/main/java/com/yunbao/common/utils/MicStatusManager.java @@ -16,10 +16,6 @@ import com.yunbao.common.http.ResponseModel; import java.util.ArrayList; import java.util.List; -import cn.rongcloud.rtc.api.RCRTCEngine; -import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback; -import cn.rongcloud.rtc.api.callback.IRCRTCSwitchRoleCallback; -import cn.rongcloud.rtc.base.RTCErrorCode; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.functions.Consumer; import io.reactivex.schedulers.Schedulers; @@ -100,71 +96,6 @@ public class MicStatusManager { '}'; } - /** - * 断开连麦 - */ - public void downMic() { - HttpClient.getInstance().get("live.leaveDrLm", "live.leaveDrLm") - .params("roomid", micLiveId) - .params("uid", CommonAppConfig.getInstance().getUid()) - .execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - Log.e("ry", code + "退出多人"); - RCRTCEngine.getInstance().getRoom().getLocalUser().switchToAudience(new IRCRTCSwitchRoleCallback() { - - /** - * 当切换失败且SDK处于无法回退状态时回调,该角色已经无法使用当前角色继续进行音视频。 - * SDK内部会退出房间并清理所有资源,该用户只能重新加入房间才能继续音视频。 - */ - @Override - public void onKicked() { - - } - - @Override - public void onSuccess() { - Log.e("ry", "下麦成功"); - // 该用户切换为观众成功,可以以观众身份进行音视频 - //退出rtc播放 - RCRTCEngine.getInstance().leaveRoom(new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.e("ry", "退出多人房间成功"); - new Handler(Looper.getMainLooper()).post(new Runnable() { - public void run() { - MicStatusManager.getInstance().clear(); - if(WordUtil.isNewZh()) { - ToastUtil.show("已成功退出語音連麥"); - }else{ - ToastUtil.show("You have successfully exited the voice connection"); - } - } - }); - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.e("ry", errorCode + "退出多人房间成功"); - - } - }); - - } - - /** - * 当切换失败且不影响当前角色继续音视频时回调 - * @param errorCode 失败错误码 - */ - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.e("ry", "下麦失败" + errorCode); - - } - }); - } - }); - } /** * 主播关闭连麦权限 diff --git a/live/src/main/java/com/yunbao/live/activity/LiveActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveActivity.java index c373be3c6..fe4b6f1ed 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveActivity.java @@ -82,12 +82,10 @@ import com.yunbao.live.dialog.LiveUserMoreDialogFragment; import com.yunbao.live.presenter.LiveLinkMicAnchorPresenter; import com.yunbao.live.presenter.LiveLinkMicPkPresenter; import com.yunbao.live.presenter.LiveLinkMicPresenter; -import com.yunbao.live.presenter.LiveRyLinkMicPkPresenter; import com.yunbao.live.presenter.LiveSwLinkMicPkPresenter; import com.yunbao.live.socket.SocketClient; import com.yunbao.live.socket.SocketMessageListener; import com.yunbao.live.socket.SocketRyChatUtil; -import com.yunbao.live.socket.SocketRyClient; import com.yunbao.live.socket.SocketSwChatUtil; import com.yunbao.live.socket.SocketSwClient; import com.yunbao.live.utils.LoadDian9TuUtil; @@ -129,13 +127,13 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL protected LiveLinkMicPresenter mLiveLinkMicPresenter;//观众与主播连麦逻辑 protected LiveLinkMicAnchorPresenter mLiveLinkMicAnchorPresenter;//主播与主播连麦逻辑 protected LiveLinkMicPkPresenter mLiveLinkMicPkPresenter;//主播与主播PK逻辑 腾讯 - public static LiveRyLinkMicPkPresenter mLiveRyLinkMicPkPresenter;//主播与主播PK逻辑 融云 +// public static LiveRyLinkMicPkPresenter mLiveRyLinkMicPkPresenter;//主播与主播PK逻辑 融云 public static LiveSwLinkMicPkPresenter mLiveSwLinkMicPkPresenter;//主播与主播PK逻辑 声网 public SocketClient mSocketClient; public SocketSwClient mSocketSwClient; - public SocketRyClient mSocketRyClient; +// public SocketRyClient mSocketRyClient; protected LiveBean mLiveBean; protected int mLiveSDK;//sdk类型 0金山 1腾讯 @@ -412,9 +410,6 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL @Override public void onSendGiftPk(long leftGift, long rightGift, LivePKUserListBean bean) { - if (mLiveRyLinkMicPkPresenter != null) { - mLiveRyLinkMicPkPresenter.onPkProgressChanged(leftGift, rightGift, bean); - } if (mLiveSwLinkMicPkPresenter != null) { mLiveSwLinkMicPkPresenter.onPkProgressChanged(leftGift, rightGift, bean); } @@ -422,14 +417,6 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL @Override public void onEndPk(long leftUid, long rightUid, long left, long right, LivePKUserListBean bean) { - if (mLiveRyLinkMicPkPresenter != null) { - L.eSw("onEndPk 结束PK mLiveRyLinkMicPkPresenter"); - if (mLiveUid.equals(leftUid + "")) { - mLiveRyLinkMicPkPresenter.onPkProgressEnd(left, right, bean); - } else { - mLiveRyLinkMicPkPresenter.onPkProgressEnd(right, left, bean); - } - } if (mLiveSwLinkMicPkPresenter != null) { L.eSw("onEndPk 结束PK mLiveSwLinkMicPkPresenter"); if (mLiveUid.equals(leftUid + "")) { @@ -699,9 +686,6 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL if (mLiveLinkMicAnchorPresenter != null) { mLiveLinkMicAnchorPresenter.onLinkMicAnchorClose(); } - if (mLiveRyLinkMicPkPresenter != null) { - mLiveRyLinkMicPkPresenter.onLinkMicPkClose(1); - } if (mLiveSwLinkMicPkPresenter != null) { mLiveSwLinkMicPkPresenter.onLinkMicPkClose(1); @@ -774,13 +758,6 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL mLiveRoomViewHolder.initAnchorSay(); mLiveRoomViewHolder.closePrankView(); } - } else { - if (mLiveRyLinkMicPkPresenter != null && mLiveRoomViewHolder != null) { - mLiveRyLinkMicPkPresenter.onLinkMicPkStart(pkUid, 1); - pr = new pkRunnable(pkUid, pkhead, pkname, isLadders); - mHandler.postDelayed(pr, 4000);//3秒后执行Runnable中的run方法 - mLiveRoomViewHolder.closePrankView(); - } } } @@ -817,9 +794,7 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL */ @Override public void onLinkMicPkClose(int i) { - if (mLiveRyLinkMicPkPresenter != null) { - mLiveRyLinkMicPkPresenter.onLinkMicPkClose(i); - } else if (mLiveLinkMicPkPresenter != null) { + if (mLiveLinkMicPkPresenter != null) { mLiveLinkMicPkPresenter.onLinkMicPkClose(i); } else if (mLiveSwLinkMicPkPresenter != null) { mLiveSwLinkMicPkPresenter.onLinkMicPkClose(i); @@ -855,10 +830,7 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL */ @Override public void onLinkMicPkEnd(String winUid) { - if (mLiveRyLinkMicPkPresenter != null) { - mLiveRyLinkMicPkPresenter.onLinkMicPkEnd(winUid); - mLiveRoomViewHolder.setDelOtherInfo(); - } else if (mLiveLinkMicPkPresenter != null) { + if (mLiveLinkMicPkPresenter != null) { mLiveLinkMicPkPresenter.onLinkMicPkEnd(winUid); mLiveRoomViewHolder.setDelOtherInfo(); } else if (mLiveSwLinkMicPkPresenter != null) { @@ -1060,8 +1032,6 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL int guardType = mLiveGuardInfo != null ? mLiveGuardInfo.getMyGuardType() : Constants.GUARD_TYPE_NONE; if(isSw){ SocketSwChatUtil.sendChatMessage(mLiveUid, content, IMLoginManager.get(mContext).getUserInfo().anchorUserType(), mSocketUserType, guardType, atUserID, atUserName); - }else{ - SocketRyChatUtil.sendChatMessage(mLiveUid, content, IMLoginManager.get(mContext).getUserInfo().anchorUserType(), mSocketUserType, guardType, atUserID, atUserName); } } @@ -1812,8 +1782,6 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL fragment.setAudienceList(mAudienceList); if(isSw){ fragment.show(((LiveSwAnchorActivity) mContext).getSupportFragmentManager(), "LiveMicAnchorDialogFragment"); - }else{ - fragment.show(((LiveRyAnchorActivity) mContext).getSupportFragmentManager(), "LiveMicAnchorDialogFragment"); } } diff --git a/live/src/main/java/com/yunbao/live/activity/LiveAnchorActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveAnchorActivity.java index 9085ab432..3484ca28f 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveAnchorActivity.java @@ -517,9 +517,6 @@ public class LiveAnchorActivity extends LiveActivity implements LiveFunctionClic mLiveLinkMicPkPresenter.setLiveUid(mLiveUid, mUrl); mLiveLinkMicPkPresenter.setSelfStream(mStream); } - if (mLiveRyLinkMicPkPresenter != null) { - mLiveRyLinkMicPkPresenter.setLiveUid(mLiveUid, ""); - } //开始推流 @@ -635,9 +632,6 @@ public class LiveAnchorActivity extends LiveActivity implements LiveFunctionClic if (mSocketSwClient != null) { mSocketSwClient.disConnect(); } - if (mSocketRyClient != null) { - mSocketRyClient.disConnect(); - } } if (mLiveEndViewHolder == null) { mLiveEndViewHolder = new LiveEndViewHolder(mContext, mRoot, mLiveBean.getUid()); diff --git a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java deleted file mode 100644 index 1160fc7da..000000000 --- a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java +++ /dev/null @@ -1,1974 +0,0 @@ -package com.yunbao.live.activity; - -import static com.blankj.utilcode.util.SnackbarUtils.dismiss; -import static com.tencent.trtc.TRTCCloudDef.TRTC_VIDEO_MIRROR_TYPE_DISABLE; -import static com.tencent.trtc.TRTCCloudDef.TRTC_VIDEO_MIRROR_TYPE_ENABLE; -import static com.yunbao.common.Constants.SOCKET_LIVE_DRPK; -import static com.yunbao.common.Constants.SOCKET_LIVE_DRPK_RANDOM; -import static com.yunbao.live.views.LiveRyAnchorViewHolder.btn_dr_pk_nub; -import static com.yunbao.live.views.LiveRyAnchorViewHolder.btn_start_dr_pk; -import static com.yunbao.live.views.LiveRyAnchorViewHolder.btn_start_dr_pk_view; - -import android.app.Dialog; -import android.content.Context; -import android.content.Intent; -import android.graphics.Bitmap; -import android.graphics.drawable.Drawable; -import android.os.Bundle; -import android.os.Handler; -import android.text.TextUtils; -import android.util.Log; -import android.view.KeyEvent; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ImageView; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.fragment.app.DialogFragment; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; -import com.blankj.utilcode.util.GsonUtils; -import com.bumptech.glide.Glide; -import com.bumptech.glide.request.target.CustomTarget; -import com.bumptech.glide.request.transition.Transition; -import com.lxj.xpopup.XPopup; -import com.lxj.xpopup.core.BasePopupView; -import com.lxj.xpopup.interfaces.XPopupCallback; -import com.opensource.svgaplayer.SVGAImageView; -import com.tencent.trtc.TRTCCloudDef; -import com.yunbao.common.CommonAppConfig; -import com.yunbao.common.CommonAppContext; -import com.yunbao.common.Constants; -import com.yunbao.common.bean.AiAutomaticSpeechModel; -import com.yunbao.common.bean.IMLoginModel; -import com.yunbao.common.bean.LinkMicUserBean; -import com.yunbao.common.bean.LiveAiRobotBean; -import com.yunbao.common.bean.LiveBean; -import com.yunbao.common.bean.LiveUserGiftBean; -import com.yunbao.common.bean.MicUserBean; -import com.yunbao.common.bean.SendMoneyLongModel; -import com.yunbao.common.bean.UserBean; -import com.yunbao.common.dialog.NotCancelableDialog; -import com.yunbao.common.event.AllServerNotifyFFGGGDJANEvent; -import com.yunbao.common.event.GiftWallIlluminateEvent; -import com.yunbao.common.event.LiveSudGamePopupShowOrHideEvent; -import com.yunbao.common.event.LoginInvalidEvent; -import com.yunbao.common.event.SendBlindGiftEvent; -import com.yunbao.common.event.SendMoneyLongEndEvent; -import com.yunbao.common.event.ShowHideEvent; -import com.yunbao.common.http.CommonHttpConsts; -import com.yunbao.common.http.CommonHttpUtil; -import com.yunbao.common.http.HttpCallback; -import com.yunbao.common.http.HttpClient; -import com.yunbao.common.http.LiveHttpConsts; -import com.yunbao.common.http.LiveHttpUtil; -import com.yunbao.common.http.live.LiveNetManager; -import com.yunbao.common.manager.IMLoginManager; -import com.yunbao.common.manager.IMRTCManager; -import com.yunbao.common.manager.MicUserManager; -import com.yunbao.common.manager.MicedUserManager; -import com.yunbao.common.manager.RandomPkManager; -import com.yunbao.common.manager.imrongcloud.RongcloudIMManager; -import com.yunbao.common.utils.BitmapUtil; -import com.yunbao.common.utils.Bus; -import com.yunbao.common.utils.DateFormatUtil; -import com.yunbao.common.utils.DialogUitl; -import com.yunbao.common.utils.L; -import com.yunbao.common.utils.LogUtil; -import com.yunbao.common.utils.MicStatusManager; -import com.yunbao.common.utils.StringUtil; -import com.yunbao.common.utils.ToastUtil; -import com.yunbao.common.utils.WordUtil; -import com.yunbao.common.views.LiveNewWishListPopup; -import com.yunbao.common.views.LiveRobotSettingCustomPopup; -import com.yunbao.common.views.LiveSudGamePopup; -import com.yunbao.faceunity.FaceManager; -import com.yunbao.live.R; -import com.yunbao.live.bean.LiveChatBean; -import com.yunbao.live.bean.LiveGuardInfo; -import com.yunbao.live.bean.LiveKsyConfigBean; -import com.yunbao.live.bean.LiveReceiveGiftBean; -import com.yunbao.live.dialog.FreePkDialogFragment; -import com.yunbao.live.dialog.LiveInputDialogFragment; -import com.yunbao.live.dialog.LiveNewFunctionDialogFragment; -import com.yunbao.live.dialog.LivePrankDialogFragment; -import com.yunbao.live.dialog.LiveWishListDialogFragment4Audience; -import com.yunbao.live.dialog.RandomPkDialogFragment; -import com.yunbao.live.event.LinkMicTxMixStreamEvent; -import com.yunbao.live.event.LiveAudienceEvent; -import com.yunbao.live.interfaces.LiveFunctionClickListener; -import com.yunbao.live.interfaces.LivePushListener; -import com.yunbao.live.music.LiveMusicDialogFragment; -import com.yunbao.live.presenter.LiveLinkMicAnchorPresenter; -import com.yunbao.live.presenter.LiveLinkMicPresenter; -import com.yunbao.live.presenter.LiveRyLinkMicPkPresenter; -import com.yunbao.live.socket.SocketRyChatUtil; -import com.yunbao.live.socket.SocketRyClient; -import com.yunbao.live.socket.SocketSendBean; -import com.yunbao.live.views.LiveEndViewHolder; -import com.yunbao.live.views.LiveMusicViewHolder; -import com.yunbao.live.views.LiveNewReadyRyViewHolder; -import com.yunbao.live.views.LivePushRyViewHolder; -import com.yunbao.live.views.LiveRoomViewHolder; -import com.yunbao.live.views.LiveRyAnchorViewHolder; - -import org.greenrobot.eventbus.EventBus; -import org.greenrobot.eventbus.Subscribe; -import org.greenrobot.eventbus.ThreadMode; - -import java.io.File; -import java.util.List; -import java.util.Map; -import java.util.Random; - -import cn.rongcloud.rtc.api.RCRTCEngine; -import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback; -import cn.rongcloud.rtc.api.callback.IRCRTCStatusReportListener; -import cn.rongcloud.rtc.api.report.StatusBean; -import cn.rongcloud.rtc.api.report.StatusReport; -import cn.rongcloud.rtc.base.RCRTCRect; -import cn.rongcloud.rtc.base.RTCErrorCode; -import io.rong.imlib.IRongCallback; -import io.rong.imlib.RongIMClient; -import io.rong.imlib.model.Conversation; -import io.rong.imlib.model.Message; -import io.rong.message.TextMessage; -import pl.droidsonroids.gif.GifImageView; - - -/** - * Created by cxf on 2018/10/7. - * 主播直播间 - */ - -public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionClickListener { - - private static final String TAG = "LiveAnchorActivity"; - - public static void forward(Context context, int liveSdk, LiveKsyConfigBean bean) { - Intent intent = new Intent(context, LiveRyAnchorActivity.class); - intent.putExtra(Constants.LIVE_SDK, liveSdk); - intent.putExtra(Constants.LIVE_KSY_CONFIG, bean); - context.startActivity(intent); - } - - private ViewGroup mRoot; - private ViewGroup mContainerWrap; - public LivePushRyViewHolder mLivePushViewHolder; - public LiveNewReadyRyViewHolder mLiveReadyViewHolder; - public static LiveRyAnchorViewHolder mLiveAnchorViewHolder; - private LiveMusicViewHolder mLiveMusicViewHolder; - private boolean mStartPreview;//是否开始预览 - private boolean mStartLive;//是否开始了直播 - private List mGameList;//游戏开关 - private boolean mBgmPlaying;//是否在播放背景音乐 - private LiveKsyConfigBean mLiveKsyConfigBean; - private HttpCallback mCheckLiveCallback; - private File mLogFile; - private int mReqCount; - private boolean mPaused; - String mBeautySdkType; - public static int pk_nub; - public static int backIndex = 0;//0=未判断,1=已判断 - private FaceManager manager; - private ImageView leave_img; - - private final RandomPkManager.OnRandomPkTimer onRandomPkTimer = new RandomPkManager.OnRandomPkTimer() { - @Override - public void onTimer(String time) { - if (mLiveRoomViewHolder != null) { - mLiveRoomViewHolder.setRandomPkTimer(String.format(mContext.getString(R.string.random_pk_info_btn_ing), time)); - } - } - - @Override - public void onStartPK(String pkUid) { - JSONObject msg1 = buildLinkMicJSON(); - msg1.put("random_pk", "1"); - if (RandomPkManager.getInstance().isRankModel()) { - msg1.put("is_ladders", "https://downs.yaoulive.com/rank_top_box.png"); - } - linkMicAnchorApply(pkUid, pkUid, msg1.toString()); - } - - @Override - public void onPking() { - if (mLiveRoomViewHolder != null) { - mLiveRoomViewHolder.setRandomPkTimer(null); - } - } - - @Override - public void onPkEnd() { - if (mLiveRoomViewHolder != null) { - mLiveRoomViewHolder.setRandomPkTimer(null); - } - } - }; - - @Override - protected int getLayoutId() { - return R.layout.activity_live_anchor; - } - - @Override - protected void main() { - super.main(); - Bus.getOn(this); - Intent intent = getIntent(); - initFaceManager(); - RCRTCEngine.getInstance().registerStatusReportListener(new IRCRTCStatusReportListener() { - - @Override - public void onConnectionStats(StatusReport statusReport) { - //视频发送信息 - for (Map.Entry entry : statusReport.statusVideoSends.entrySet()) { - StatusBean statusBean = entry.getValue(); - //获取userID - String userId = statusBean.uid; - //获取视频 宽x高@帧率 - String resolution = statusBean.frameWidth + "x" + statusBean.frameHeight + "@" + statusBean.frameRate; - //获取码率 - long bitRate = statusBean.bitRate; - //丢包率 - long lossRate = statusBean.packetLostRate; - //带宽 -// String googAvailableSendBandwidth = statusReport.googAvailableSendBandwidth; -// Log.e("网速和内存", "获取视频:" + resolution + " 丢包率:" + lossRate + " 带宽:" + googAvailableSendBandwidth); - } - } - }); - leave_img = findViewById(R.id.leave_img); - mLiveSDK = intent.getIntExtra(Constants.LIVE_SDK, Constants.LIVE_SDK_KSY); - mLiveKsyConfigBean = intent.getParcelableExtra(Constants.LIVE_KSY_CONFIG); - L.e(TAG, "直播sdk----->" + (mLiveSDK == Constants.LIVE_SDK_KSY ? "金山云" : "腾讯云")); - mRoot = (ViewGroup) findViewById(R.id.root); - mSocketUserType = Constants.SOCKET_USER_TYPE_ANCHOR; - UserBean u = CommonAppConfig.getInstance().getUserBean(); - mLiveUid = u.getId(); - mLiveBean = new LiveBean(); - mLiveBean.setUid(mLiveUid); - mLiveBean.setUserNiceName(u.getUserNiceName()); - mLiveBean.setAvatar(u.getAvatar()); - mLiveBean.setAvatarThumb(u.getAvatarThumb()); - mLiveBean.setLevelAnchor(u.getLevelAnchor()); - mLiveBean.setGoodNum(u.getGoodName()); - mLiveBean.setCity(u.getCity()); - mBeautySdkType = CommonAppConfig.getInstance().getBeautySdkType(); - - mLivePushViewHolder = new LivePushRyViewHolder(mContext, (ViewGroup) findViewById(R.id.preview_container)); - mLivePushViewHolder.setLiveActivityContainer(mContainer); - - mLivePushViewHolder.addToParent(); - mLivePushViewHolder.subscribeActivityLifeCycle(); - mContainerWrap = (ViewGroup) findViewById(R.id.container_wrap); - mContainer = (ViewGroup) findViewById(R.id.container); - mLiveRyLinkMicPkPresenter = new LiveRyLinkMicPkPresenter(mContext, mLivePushViewHolder, true, mContainer); - RandomPkManager.getInstance().addOnRandomPkTimer(onRandomPkTimer); - - //添加开播前设置控件 - mLiveReadyViewHolder = new LiveNewReadyRyViewHolder(mContext, mContainer, mLiveSDK); - mLiveReadyViewHolder.setManager(manager); - mLiveReadyViewHolder.addToParent(); - mLiveReadyViewHolder.setLiveUid(mLiveUid); - mLiveReadyViewHolder.subscribeActivityLifeCycle(); - mLiveLinkMicPresenter = new LiveLinkMicPresenter(mContext, mLivePushViewHolder, true, mLiveSDK, mContainer); - mLiveLinkMicAnchorPresenter = new LiveLinkMicAnchorPresenter(mContext, mLivePushViewHolder, true, mLiveSDK, mContainer); - mLivePushViewHolder.setLivePushListener(new LivePushListener() { - @Override - public void onPreviewStart() { - //开始预览回调 - mStartPreview = true; - } - - @Override - public void onPushStart() { - //开始推流回调 - LiveHttpUtil.changeLive(mStream); - - - } - - @Override - public void onPushFailed() { - //推流失败回调 - ToastUtil.show(mContext.getString(R.string.live_push_failed)); - } - }); - } - - private void initFaceManager() { - manager = new FaceManager(); - manager.initFURender(mContext); - manager.drawRongFrame(mContext); - } - - public boolean isStartPreview() { - return mStartPreview; - } - - /** - * 主播直播间功能按钮点击事件 - * - * @param functionID - */ - int mrr = 0; - public int leave = 0; - - - @Override - public void onClick(int functionID) { - switch (functionID) { - case Constants.LIVE_ROBOT: - new XPopup.Builder(mContext) - .setPopupCallback(new XPopupCallback() { - @Override - public void onCreated(BasePopupView popupView) { - - } - - @Override - public void beforeShow(BasePopupView popupView) { - - } - - @Override - public void onShow(BasePopupView popupView) { - - } - - @Override - public void onDismiss(BasePopupView popupView) { - EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.UPDATA_ROBOT)); - } - - @Override - public void beforeDismiss(BasePopupView popupView) { - - } - - @Override - public boolean onBackPressed(BasePopupView popupView) { - return false; - } - - @Override - public void onKeyBoardStateChanged(BasePopupView popupView, int height) { - - } - - @Override - public void onDrag(BasePopupView popupView, int value, float percent, boolean upOrLeft) { - - } - - @Override - public void onClickOutside(BasePopupView popupView) { - - } - }) - .asCustom(new LiveRobotSettingCustomPopup(mContext)) - .show(); - break; - case Constants.LIVE_FUNC_ZG://zg - // ToastUtil.show("開發中,敬請期待"); - LivePrankDialogFragment fragment = new LivePrankDialogFragment(); - fragment.setOnPrankResultListener(new LivePrankDialogFragment.onPrankResultListener() { - @Override - public void OpenAndCloseListener() { - if(mLiveRoomViewHolder!=null){ - mLiveRoomViewHolder.initPrankProgress(1); - } - } - }); - fragment.setmLiveUid(mLiveUid); - fragment.show(getSupportFragmentManager(), "LivePrankDialogFragment"); - mLiveAnchorViewHolder.closeMenuRed(); - break; - case Constants.LIVE_FUNC_MIC://語音 - //ToastUtil.show("開發中,敬請期待"); - if (isDRPK != 1) { - openMicWindow(1); - } else { - ToastUtil.show(WordUtil.isNewZh() ? "您已在PK中" : "You are already in the PK"); - } - break; - case Constants.LIVE_FUNC_DR://多人PK -// if (LiveRyLinkMicPkPresenter.inputStreamList.size() == 4) { -// return; -// } - if (isDRPK != 1) { - HttpClient.getInstance().get("live.getdrnum", "live.getdrnum") - .execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - if (code == 0) { - JSONObject obj = JSONObject.parseObject(info[0]); - pk_nub = Integer.valueOf(obj.getString("pk_num_day")); - - btn_dr_pk_nub.setText(String.format(getString(R.string.number_of_remaining_times), String.valueOf(pk_nub))); - DialogUitl.showSimpleDialog(mContext, String.format(getString(R.string.confirmed_to_proceed), String.valueOf(pk_nub)), - false, - new DialogUitl.SimpleCallback2() { - @Override - public void onConfirmClick(Dialog dialog, String content) { - HttpClient.getInstance().get("live.createDRPKroom", "live.createDRPKroom") - .params("type", "1") - .params("sign", "1") - .execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - - if (code == 0) { - btn_start_dr_pk.setVisibility(View.VISIBLE); -// dr_pk_view.setVisibility(View.VISIBLE); - final SocketSendBean msg1 = new SocketSendBean() - .param("_method_", SOCKET_LIVE_DRPK) - .param("action", 9) - .param("msgtype", 1); - msg1.create(); - - Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; - TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); - Message message = Message.obtain("g" + mLiveUid, conversationType, messageContent); - - RongcloudIMManager.sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { - @Override - public void onAttached(Message message) { - - } - - @Override - public void onSuccess(Message message) { - isDRPK = 1; - btn_start_dr_pk_view.setVisibility(View.VISIBLE); - mLiveRyLinkMicPkPresenter.setDRInitiator(true); - } - - @Override - public void onError(Message message, RongIMClient.ErrorCode errorCode) { - Log.i("tx", "发送失败" + errorCode + message); - - } - }); - - } else { - ToastUtil.show(msg); - } - } - }); - - } - - @Override - public void onCancelClick() { - - } - }); - } else { - ToastUtil.show(msg); - } - } - }); - } else { - ToastUtil.show(WordUtil.isNewZh() ? "您已在PK中" : "You are already in the PK"); - } - break; - case Constants.LIVE_FUNC_BEAUTY://美颜 - beauty(); - break; - case Constants.LIVE_FUNC_CAMERA://切换镜头 - toggleCamera(); - break; - case Constants.LIVE_FUNC_FLASH://切换闪光灯 - toggleFlash(); - break; - case Constants.LIVE_FUNC_MUSIC://伴奏 - openMusicWindow(); - break; - case Constants.LIVE_FUNC_SHARE://分享 - openShareWindow(); - break; - case Constants.LIVE_FUNC_GAME://游戏 - openGameWindow(); - break; - case Constants.LIVE_FUNC_RED_PACK://红包 - openRedPackSendWindow(); - break; - case Constants.LIVE_FUNC_ZSLK://暫時離開 - leaveLive(); - break; - case Constants.LIVE_FUNC_WKS: - String url = CommonAppConfig.HOST + "/h5/activity/weekStar/index.html?&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&anchorUid=" + mLiveUid; - ZhuangBanActivity.forward(mContext, url, false, 0); - break; - case Constants.LIVE_FUNC_LINK_MIC://连麦 - if (isDRPK != 1) { - //openLinkMicAnchorWindow(false); - openFreePkWindow(); - } else { - ToastUtil.show(WordUtil.isNewZh() ? "您已在PK中" : "You are already in the PK"); - } - break; - case Constants.LIVE_FUNC_WISHLIST://心愿单 - openWishListWindow(); - break; - case Constants.LIVE_FUNC_MIRROR://鏡像 - - TRTCCloudDef.TRTCRenderParams t = new TRTCCloudDef.TRTCRenderParams(); - if (mrr == 0) { - mrr = 1; - t.mirrorType = TRTC_VIDEO_MIRROR_TYPE_ENABLE; - } else if (mrr == 1) { - mrr = 0; - t.mirrorType = TRTC_VIDEO_MIRROR_TYPE_DISABLE; - } - break; - case Constants.LIVE_FUNC_RANDOM_PK: - if (isDRPK != 1) { - openRandomPkWindow(); - } else { - ToastUtil.show(WordUtil.isNewZh() ? "您已在PK中" : "You are already in the PK"); - } - break; - default: - break; - } - - } - - - /** - * 主播展示离开直播间 - */ - private void leaveLive() { - if (PKing || isDRPK == 1) { - return; - } - RCRTCRect rect = new RCRTCRect(0f, 0f, 1.0f); - if (leave == 0) { - leave = 1; - leave_img.setVisibility(View.VISIBLE); - Glide.with(mContext).asBitmap().load(R.mipmap.zslk).into(new CustomTarget() { - @Override - public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition transition) { - - boolean ret = RCRTCEngine.getInstance().getDefaultVideoStream().setWatermark(BitmapUtil.getInstance().convertMirror(resource), rect); - sendSystemMessageRy(mContext.getString(R.string.live_anchor_leave)); - } - - @Override - public void onLoadCleared(@Nullable Drawable placeholder) { - - } - }); - } else if (leave == 1) { - leave = 0; - leave_img.setVisibility(View.GONE); - // 清除水印 - boolean ret = RCRTCEngine.getInstance().getDefaultVideoStream().setWatermark(null, rect); - sendSystemMessageRy(mContext.getString(R.string.live_anchor_come_back)); - } - - HttpClient.getInstance().get("Live.isLeave", "Live.isLeave") - .params("uid", CommonAppConfig.getInstance().getUid()) - .params("isleave", leave) - .params("token", CommonAppConfig.getInstance().getToken()) - .execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - - } - }); - } - - - /** - * 打开心愿单窗口 - */ - public void openWishListWindow() { -// LiveNewWishListDialogFragment fragment = new LiveNewWishListDialogFragment(); -// if (mContext instanceof LiveRyAnchorActivity) { -// fragment.show(((LiveRyAnchorActivity) mContext).getSupportFragmentManager(), "LiveWishListDialogFragment"); -// } - new XPopup.Builder(mContext) - .enableDrag(false) - .asCustom(new LiveNewWishListPopup(LiveRyAnchorActivity.this)) - - .show(); - } - - //打开相机前执行 - public void beforeCamera() { - if (mLivePushViewHolder != null) { - mLivePushViewHolder.setOpenCamera(true); - } - } - - - /** - * 切换镜头 - */ - public void toggleCamera() { - if (mLivePushViewHolder != null) { - mLivePushViewHolder.toggleCamera(); - } - } - - /** - * 切换闪光灯 - */ - public void toggleFlash() { - if (mLivePushViewHolder != null) { - mLivePushViewHolder.toggleFlash(); - } - } - - /** - * 设置美颜 - */ - public void beauty() { - if (mLiveReadyViewHolder != null) { - mLiveReadyViewHolder.hide(); - } - if (mLiveRoomViewHolder != null) { - mLiveRoomViewHolder.changeFaceUnityView(); - } - } - - /** - * 飘心 - */ - public void light() { - if (mLiveRoomViewHolder != null) { - } - } - - /** - * 打开音乐窗口 - */ - private void openMusicWindow() { - if (isLinkMicAnchor() || isLinkMicAnchor()) { - ToastUtil.show(mContext.getString(R.string.link_mic_not_bgm)); - return; - } - LiveMusicDialogFragment fragment = new LiveMusicDialogFragment(); - fragment.setActionListener(new LiveMusicDialogFragment.ActionListener() { - @Override - public void onChoose(String musicId) { - if (mLivePushViewHolder != null) { - if (mLiveMusicViewHolder == null) { - mLiveMusicViewHolder = new LiveMusicViewHolder(mContext, mContainer, mLivePushViewHolder); - mLiveMusicViewHolder.subscribeActivityLifeCycle(); - mLiveMusicViewHolder.addToParent(); - } - mLiveMusicViewHolder.play(musicId); - mBgmPlaying = true; - } - } - }); - fragment.show(getSupportFragmentManager(), "LiveMusicDialogFragment"); - } - - /** - * 关闭背景音乐 - */ - public void stopBgm() { - if (mLiveMusicViewHolder != null) { - mLiveMusicViewHolder.release(); - } - mLiveMusicViewHolder = null; - mBgmPlaying = false; - } - - public boolean isBgmPlaying() { - return mBgmPlaying; - } - - - /** - * 打开功能弹窗 - */ - public void showFunctionDialog() { - LiveNewFunctionDialogFragment fragment = new LiveNewFunctionDialogFragment(); - Bundle bundle = new Bundle(); - boolean hasGame = false; - if (CommonAppConfig.GAME_ENABLE && mGameList != null) { - hasGame = mGameList.size() > 0; - } - bundle.putBoolean(Constants.HAS_GAME, hasGame); - bundle.putInt("leave", leave); - bundle.putString("liveUid", mLiveUid); - bundle.putBoolean("isPk", isDRPK == 1 || PKing || mLivePushViewHolder.isPking()); - bundle.putLong("liveTime", mLiveAnchorViewHolder.getmAnchorLiveTime()); - bundle.putBoolean(Constants.OPEN_FLASH, mLivePushViewHolder != null && mLivePushViewHolder.isFlashOpen()); - bundle.putBoolean("isShowZgRed",mLiveAnchorViewHolder.isShowMenuRed()); - fragment.setArguments(bundle); - fragment.setFunctionClickListener(this); - fragment.show(getSupportFragmentManager(), "LiveFunctionDialogFragment"); - } - - /** - * 打开主播连麦窗口 - */ - public void openLinkMicAnchorWindow(boolean isDRPK) { - if (mLiveLinkMicAnchorPresenter != null && !mLiveLinkMicAnchorPresenter.canOpenLinkMicAnchor()) { - return; - } -/* LiveLinkMicListDialogFragment fragment = new LiveLinkMicListDialogFragment(); - Bundle bundle = new Bundle(); - bundle.putBoolean("isDRPK", isDRPK); - fragment.setArguments(bundle); - fragment.show(getSupportFragmentManager(), "LiveLinkMicListDialogFragment");*/ - FreePkDialogFragment fragment = new FreePkDialogFragment(); - fragment.setDrPkNum(pk_nub); - fragment.setLiveUid(mLiveUid); - fragment.show(getSupportFragmentManager(), "LiveLinkMicListDialogFragment"); - - } - - public void openFreePkWindow() { - FreePkDialogFragment fragment = new FreePkDialogFragment(); - Bundle bundle = new Bundle(); - fragment.setArguments(bundle); - fragment.show(getSupportFragmentManager(), "FreePkDialogFragment"); - } - - /** - * 随机PK - */ - public void openRandomPkWindow() { - RandomPkDialogFragment fragment = new RandomPkDialogFragment(); - Bundle bundle = new Bundle(); - bundle.putBoolean("isSw",false); - fragment.setArguments(bundle); - fragment.show(getSupportFragmentManager(), "RandomPkDialogFragment"); - } - - /** - * 打开选择游戏窗口 - */ - private void openGameWindow() { - if (isLinkMic() || isLinkMicAnchor()) { - ToastUtil.show(mContext.getString(R.string.live_link_mic_cannot_game)); - return; - } - } - - /** - * 关闭游戏 - */ - public void closeGame() { -// if (mGamePresenter != null) { -// mGamePresenter.closeGame(); -// } - } - - /** - * 开播成功 - * - * @param data createRoom返回的数据 - */ - public void startLiveSuccess(String data, int liveType, int liveTypeVal) { - Log.e("随机打招呼", "(((((((((((((((((((((((((((((((((((((((((((((((" + data); - mLiveType = liveType; - mLiveTypeVal = liveTypeVal; - //处理createRoom返回的数据 - JSONObject obj = JSON.parseObject(data); - mStream = obj.getString("stream"); - mDanmuPrice = obj.getString("barrage_fee"); - String playUrl = obj.getString("pull"); - L.e("createRoom----播放地址--->" + playUrl); - mLiveBean.setPull(playUrl); - mTxAppId = obj.getString("tx_appid"); - - //移除开播前的设置控件,添加直播间控件 - if (mLiveReadyViewHolder != null) { - mLiveReadyViewHolder.removeFromParent(); - mLiveReadyViewHolder.release(); - } - mLiveReadyViewHolder = null; - if (mLiveRoomViewHolder == null) { - mLiveRoomViewHolder = new LiveRoomViewHolder(true, 2, mContext, mContainer, (GifImageView) findViewById(R.id.gift_gif), (SVGAImageView) findViewById(R.id.gift_svga), mContainerWrap, getWindowManager(),isSw); - mLiveRoomViewHolder.setManager(manager); - mLiveRoomViewHolder.addToParent(); - mLiveRoomViewHolder.subscribeActivityLifeCycle(); - mLiveRoomViewHolder.setLiveInfo(mLiveUid, mStream, obj.getIntValue("userlist_time") * 1000); - mLiveRoomViewHolder.setVotes(obj.getString("votestotal")); - mLiveRoomViewHolder.setMedaRankNum(obj.getString("medalRankNum")); - mLiveRoomViewHolder.startFace(); - UserBean u = CommonAppConfig.getInstance().getUserBean(); - if (u != null) { - mLiveRoomViewHolder.setRoomNum(u.getLiangNameTip()); - mLiveRoomViewHolder.setName(u.getUserNiceName()); - mLiveRoomViewHolder.setAvatar(u.getAvatar()); - mLiveRoomViewHolder.setAnchorLevel(u.getLevelAnchor()); - mLiveRoomViewHolder.setAnchorGoodNumber(u.getGoodName()); - mLiveRoomViewHolder.initHourRankList(); - } - mLiveRoomViewHolder.startAnchorLight(); - //初始化女神说 - mLiveRoomViewHolder.initAnchorSay(); - mLiveRoomViewHolder.setGiftWall(obj.getString("gift_wall_lighten_number"), obj.getString("gift_wall_lighten_total")); - } - mLiveRyLinkMicPkPresenter.setmLiveRoomViewHolder(mLiveRoomViewHolder); - if (mLiveAnchorViewHolder == null) { - mLiveAnchorViewHolder = new LiveRyAnchorViewHolder(mContext, mContainer); - mLiveAnchorViewHolder.setLiveBean(mLiveBean); - mLiveAnchorViewHolder.addToParent(); - mLiveAnchorViewHolder.startAnchorLiveTime(); - } - mLiveBottomViewHolder = mLiveAnchorViewHolder; - mSocketRyClient = new SocketRyClient(mLiveUid, this, mContext); - mSocketRyClient.setLivePushRyViewHolder(mLivePushViewHolder); - CommonAppContext.Ingroup = 1; - - if (mLiveLinkMicPresenter != null) { - mLiveLinkMicPresenter.setSocketClient(mSocketClient); - } - if (mLiveLinkMicAnchorPresenter != null) { - mLiveLinkMicAnchorPresenter.setSocketClient(mSocketClient); - mLiveLinkMicAnchorPresenter.setPlayUrl(playUrl); - mLiveLinkMicAnchorPresenter.setSelfStream(mStream); - } - if (mLiveRyLinkMicPkPresenter != null) { - mLiveRyLinkMicPkPresenter.setSelfStream(mStream); - } - if (mLiveRyLinkMicPkPresenter != null) { - mLiveRyLinkMicPkPresenter.setLiveUid(mLiveUid, ""); - } - - //开始推流 - if (mLivePushViewHolder != null) { - mLivePushViewHolder.startPush(obj.getString("push")); - } - //开始显示直播时长 - if (mLiveRoomViewHolder != null) { - mLiveRoomViewHolder.startAnchorLiveTime(); - mLiveRoomViewHolder.startAnchorCheckLive(); - mLiveRoomViewHolder.setAnchorGoodNumber(obj.getString("goodnum")); - } - mStartLive = true; - mLiveRoomViewHolder.startRefreshUserList(); - mLiveRoomViewHolder.hideFloatMsg(); - mLiveRoomViewHolder.initPkRank(null); - - //守护相关 - mLiveGuardInfo = new LiveGuardInfo(); - int guardNum = obj.getIntValue("guard_nums"); - mLiveGuardInfo.setGuardNum(guardNum); - if (mLiveRoomViewHolder != null) { - mLiveRoomViewHolder.setGuardNum(guardNum); - - } - - //奖池等级 - int giftPrizePoolLevel = obj.getIntValue("jackpot_level"); - if (giftPrizePoolLevel >= 0) { - if (mLiveRoomViewHolder != null) { - mLiveRoomViewHolder.showPrizePoolLevel(String.valueOf(giftPrizePoolLevel)); - } - } - - //游戏相关 - if (CommonAppConfig.GAME_ENABLE) { - mGameList = JSON.parseArray(obj.getString("game_switch"), Integer.class); - } - getAiRobotStatus(); - MicedUserManager.get().removeAllMicUserList(); - MicUserManager.get().removeAllMicUserList(); - - if(mLiveRoomViewHolder!=null){ - //加载整蛊 - mLiveRoomViewHolder.initPrankProgress(2); - mLiveRoomViewHolder.sendMsgPrank(); - - //初始化天梯数据 - mLiveRoomViewHolder.initRankPKInfo(mLiveUid,""); - } - } - - /** - * 关闭直播 - */ - public void closeLive() { - DialogUitl.showSimpleDialog(mContext, mContext.getString(R.string.live_end_live), new DialogUitl.SimpleCallback() { - @Override - public void onConfirmClick(Dialog dialog, String content) { - MicStatusManager.getInstance().closeMic(mContext); - MicedUserManager.get().removeAllMicUserList(); - MicUserManager.get().removeAllMicUserList(); - PKing = false; - isDRPK = 0; - endLive(); - RandomPkManager.getInstance().release(); - } - }); - } - - public void endLives() { - - - RCRTCEngine.getInstance().getDefaultVideoStream().stopCamera(new IRCRTCResultCallback() { - @Override - public void onSuccess() { - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - - } - }); - RCRTCEngine.getInstance().leaveRoom(new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.i("ry", "退出成功"); - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.i("ry", "退出失败" + errorCode); - } - }); - - - if (mLivePushViewHolder != null) { - mLivePushViewHolder.release(); - } - if (mLiveLinkMicPresenter != null) { - mLiveLinkMicPresenter.release(); - } - mLivePushViewHolder = null; - mLiveLinkMicPresenter = null; - - superBackPressed(); - - - release(); - mStartLive = false; - } - - /** - * 结束直播 - */ - public void endLive() { - RCRTCEngine.getInstance().getDefaultVideoStream().stopCamera(new IRCRTCResultCallback() { - @Override - public void onSuccess() { - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - - } - }); - RCRTCEngine.getInstance().leaveRoom(new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.i("ry", "退出成功"); - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.i("ry", "退出失败" + errorCode); - } - }); - //请求关播的接口 - LiveHttpUtil.stopLive(mStream, new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - if (robotRunnable != null) { - robotHandler.removeCallbacks(robotRunnable); - robotRunnable = null; - } - if (code == 0) { - JSONObject obj = JSON.parseObject(info[0]); - JSONObject datas = obj.getJSONObject("data"); - try { - SocketRyChatUtil.closeLive(datas.getString("votes"), datas.getString("length"), datas.getString("nums"), mLiveUid); - } catch (Exception e) { - e.printStackTrace(); - } - - if (mLiveEndViewHolder == null) { - mLiveEndViewHolder = new LiveEndViewHolder(mContext, mRoot, mLiveBean.getUid()); - mLiveEndViewHolder.subscribeActivityLifeCycle(); - mLiveEndViewHolder.addToParent(); - mLiveEndViewHolder.showData(mLiveBean, mStream); - mLiveEndViewHolder.upData(datas.getString("votes"), datas.getString("length"), Long.parseLong(datas.getString("nums"))); - } - if (mLiveAnchorViewHolder != null) { - mLiveAnchorViewHolder.release(); - mLiveAnchorViewHolder = null; - } - - if (mLivePushViewHolder != null) { - mLivePushViewHolder.release(); - } - if (mLiveLinkMicPresenter != null) { - mLiveLinkMicPresenter.release(); - } - mLivePushViewHolder = null; - mLiveLinkMicPresenter = null; - release(); - mStartLive = false; - } else { - ToastUtil.show(msg); - } - } - - @Override - public boolean showLoadingDialog() { - return true; - } - - @Override - public Dialog createLoadingDialog() { - return DialogUitl.loadingDialog(mContext, mContext.getString(R.string.live_end_ing)); - } - }); - } - - - @Override - public void onBackPressed() { - - if (mStartLive) { - if (!canBackPressed()) { - return; - } - closeLive(); - } else { - endLives(); - } - - } - - public void superBackPressed() { - super.onBackPressed(); - } - - public void release() { - LiveHttpUtil.cancel(LiveHttpConsts.CHANGE_LIVE); - LiveHttpUtil.cancel(LiveHttpConsts.STOP_LIVE); - LiveHttpUtil.cancel(LiveHttpConsts.LIVE_PK_CHECK_LIVE); - LiveHttpUtil.cancel(LiveHttpConsts.SET_LINK_MIC_ENABLE); - CommonHttpUtil.cancel(CommonHttpConsts.CHECK_TOKEN_INVALID); - if (mLiveReadyViewHolder != null) { - mLiveReadyViewHolder.release(); - } - if (mLiveMusicViewHolder != null) { - mLiveMusicViewHolder.release(); - } - if (mLivePushViewHolder != null) { - mLivePushViewHolder.release(); - } - if (mLiveLinkMicPresenter != null) { - mLiveLinkMicPresenter.release(); - } - mLiveMusicViewHolder = null; - mLiveReadyViewHolder = null; - mLivePushViewHolder = null; - mLiveLinkMicPresenter = null; - //断开socket - if (mSocketRyClient != null) { - mSocketRyClient.disConnect(); - } - super.release(); - } - - private boolean isKeyBack = false; - - @Override - public boolean onKeyUp(int keyCode, KeyEvent event) { - if (keyCode == KeyEvent.KEYCODE_BACK) { - isKeyBack = true; - } - return super.onKeyUp(keyCode, event); - } - - @Override - protected void onDestroy() { - if (manager != null) { - manager.release(); - } - LiveHttpUtil.cancel(LiveHttpConsts.ANCHOR_CHECK_LIVE); - super.onDestroy(); - if (mLivePushViewHolder != null) { - mLivePushViewHolder.onDestroy(); - } - if (mLiveReadyViewHolder != null) { - mLiveReadyViewHolder.onDestroy(); - } - if (mLiveAnchorViewHolder != null) { - mLiveAnchorViewHolder.onDestroy(); - } - mLivePushViewHolder = null; - mLiveReadyViewHolder = null; - mLiveAnchorViewHolder = null; - if (MicStatusManager.getInstance().isAnchorOpenRoom()) { - MicStatusManager.getInstance().closeMic(mContext); - } - L.e("LiveAnchorActivity-------onDestroy------->"); - RandomPkManager.getInstance().unregisterOnRandomPkTimer(onRandomPkTimer); - Bus.getOff(this); - } - - - @Override - protected void onPause() { -// if (mLiveRoomViewHolder != null) { -// mLiveRoomViewHolder.anchorPause(); -// } - super.onPause(); -// if (isKeyBack) { -// sendSystemMessage(mContext.getString(R.string.live_anchor_leave)); -// } -// mPaused = true; - } - - @Override - protected void onResume() { - super.onResume(); -// if (mPaused) { -// if (mLiveRoomViewHolder != null) { -// mLiveRoomViewHolder.anchorResume(); -// } -// sendSystemMessage(mContext.getString(R.string.live_anchor_come_back)); -// CommonHttpUtil.checkTokenInvalid(); -// } -// mPaused = false; - } - - - /** - * 直播间 主播登录失效 - */ - @Override - public void onAnchorInvalid() { - super.onAnchorInvalid(); - endLive(); - } - - /** - * 超管关闭直播间 - */ - @Override - public void onSuperCloseLive() { - endLive(); - DialogUitl.showSimpleTipDialog(mContext, mContext.getString(R.string.live_illegal)); - } - - @Subscribe(threadMode = ThreadMode.MAIN) - public void onLoginInvalidEvent(LoginInvalidEvent e) { - release(); - } - - public void setBtnFunctionDark() { - if (mLiveAnchorViewHolder != null) { - mLiveAnchorViewHolder.setBtnFunctionDark(); - } - } - - /** - * 主播与主播连麦 主播收到其他主播发过来的连麦申请 - */ - @Override - public void onLinkMicAnchorApply(UserBean u, String stream) { - if (mLiveLinkMicAnchorPresenter != null) { - mLiveLinkMicAnchorPresenter.onLinkMicAnchorApply(u, stream); - } - } - - /** - * 主播与主播连麦 对方主播拒绝连麦的回调 - */ - @Override - public void onLinkMicAnchorRefuse() { - if (mLiveLinkMicAnchorPresenter != null) { - mLiveLinkMicAnchorPresenter.onLinkMicAnchorRefuse(); - } - } - - /** - * 主播与主播连麦 对方主播无响应的回调 - */ - @Override - public void onLinkMicAnchorNotResponse() { - if (mLiveLinkMicAnchorPresenter != null) { - mLiveLinkMicAnchorPresenter.onLinkMicNotResponse(); - } - } - - /** - * 主播与主播连麦 对方主播正在游戏 - */ - @Override - public void onlinkMicPlayGaming() { - if (mLiveLinkMicAnchorPresenter != null) { - mLiveLinkMicAnchorPresenter.onlinkMicPlayGaming(); - } - } - - - /** - * 主播与主播连麦 对方主播正在忙的回调 - */ - @Override - public void onLinkMicAnchorBusy() { - if (mLiveLinkMicAnchorPresenter != null) { - mLiveLinkMicAnchorPresenter.onLinkMicAnchorBusy(); - } - } - - /** - * 发起主播连麦PK申请 - * - * @param pkUid 对方主播的uid - * @param stream 对方主播的stream - */ - public void linkMicAnchorApply(String pkUid, String stream) { - JSONObject msg1 = buildLinkMicJSON(); - linkMicAnchorApply(pkUid, stream, msg1.toString()); - } - - public JSONObject buildLinkMicJSON() { - JSONObject msg1 = new JSONObject(); - msg1.put("uid", CommonAppConfig.getInstance().getUid()); - msg1.put("pkuid", CommonAppConfig.getInstance().getUid()); - msg1.put("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); - msg1.put("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()); - return msg1; - } - - public void linkMicAnchorApply(final String pkUid, String stream, String extra) { - - LiveHttpUtil.livePkCheckLive(pkUid, stream, mStream, new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - if (code == 0 && info.length > 0) { - JSONObject obj = JSON.parseObject(info[0]); - if (obj != null) { - if (obj.getString("ispk").equals("0")) { - IMRTCManager.getInstance().requestJoinOtherRoom(pkUid, true, extra, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - // ToastUtil.show("邀请 " + pkUid + " 发送成功"); - runOnUiThread(new Runnable() { - @Override - public void run() { - dismiss(); - } - }); - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - runOnUiThread(new Runnable() { - @Override - public void run() { - dismiss(); - } - }); - //todo 安卓端状态码说明文档:https://docs.rongcloud.cn/v4/views/rtc/call/code/android.html - Log.e("ry", rtcErrorCode + "aaaaaa" + CommonAppConfig.getInstance().getUid() + "VDSSSS" + pkUid); - if (WordUtil.isNewZh()) { - ToastUtil.show("邀请 " + pkUid + " 发送失败 :" + rtcErrorCode); - } else { - ToastUtil.show("invite " + pkUid + " failed:" + rtcErrorCode); - } - } - }); - - } else { - ToastUtil.show(mContext.getString(R.string.pking_over)); - if (RandomPkManager.getInstance().isRandomModel()) { - RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_REFUSE); - } - } - } - } - } - }); - - - } - - /** - * 发起多人主播连麦PK申请 - * - * @param pkUid 对方主播的uid - * @param stream 对方主播的stream (无需steam) - */ - public void linkDrMicAnchorApply(String pkUid, String stream) { - linkDrMicAnchorApply(pkUid, stream, SOCKET_LIVE_DRPK); - if (mLiveAnchorViewHolder != null) { - mLiveAnchorViewHolder.setYaoqing(pkUid); - } - - } - - /** - * 发起多人主播连麦PK申请 - * - * @param pkUid 对方主播的uid - * @param stream 对方主播的stream (无需steam) - * @param extra PK类型 - */ - public void linkDrMicAnchorApply(final String pkUid, String stream, String extra) { - - LiveHttpUtil.livePkCheckLive(pkUid, stream, mStream, new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - if (code == 0 && info.length > 0) { - JSONObject obj = JSON.parseObject(info[0]); - if (obj != null) { - if (obj.getString("ispk").equals("0")) { - - IMRTCManager.getInstance().requestJoinOtherRoom(pkUid, true, extra, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - if (!extra.equals(SOCKET_LIVE_DRPK_RANDOM)) { - if (WordUtil.isNewZh()) { - ToastUtil.show("邀请 " + pkUid + " 发送成功"); - } else { - ToastUtil.show("invite " + pkUid + " successful"); - } - } - runOnUiThread(new Runnable() { - @Override - public void run() { - dismiss(); - } - }); - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - runOnUiThread(new Runnable() { - @Override - public void run() { - dismiss(); - } - }); - //todo 安卓端状态码说明文档:https://docs.rongcloud.cn/v4/views/rtc/call/code/android.html - Log.e("ry", rtcErrorCode + "aaaaaa" + CommonAppConfig.getInstance().getUid() + "VDSSSS" + pkUid); - } - }); - } else { - ToastUtil.show(mContext.getString(R.string.pking_over)); - } - } - } - } - }); - - - } - - /** - * 设置连麦pk按钮是否可见 - */ - public void setPkBtnVisible(boolean visible) { - if (mLiveAnchorViewHolder != null) { - if (visible) { - if (mLiveLinkMicAnchorPresenter.isLinkMic()) { - mLiveAnchorViewHolder.setPkBtnVisible(true); - } - } else { - mLiveAnchorViewHolder.setPkBtnVisible(false); - } - } - } - - /** - * 发起主播连麦pk - */ - public void applyLinkMicPk() { - String pkUid = null; - if (mLiveLinkMicAnchorPresenter != null) { - pkUid = mLiveLinkMicAnchorPresenter.getPkUid(); - } - if (!TextUtils.isEmpty(pkUid) && mLiveRyLinkMicPkPresenter != null) { - mLiveRyLinkMicPkPresenter.applyLinkMicPk(pkUid, mStream); - } - } - - /** - * 主播与主播PK 主播收到对方主播发过来的PK申请的回调 - * - * @param u 对方主播的信息 - * @param stream 对方主播的stream - */ - @Override - public void onLinkMicPkApply(UserBean u, String stream, int forwhat) { - if (mLiveRyLinkMicPkPresenter != null) { - mLiveRyLinkMicPkPresenter.onLinkMicPkApply(u, stream, 0); - } - } - - //多人PK接受 - @Override - public void onLinkDRMicPkApply(UserBean u) { - if (mLiveRyLinkMicPkPresenter != null) { - mLiveRyLinkMicPkPresenter.onLinkDRMicPkApply(u); - } - } - - @Override - public void onLinkDRMicPKToUser(UserBean u) { - - } - - //多人PK接受 - @Override - public void onLinkDRMicPkApplyOk(UserBean u) { - if (mLiveRyLinkMicPkPresenter != null) { - mLiveRyLinkMicPkPresenter.onLinkDRMicPkApplyOk(u); - } - } - - /** - * 主播与主播PK 对方主播拒绝pk的回调 - */ - @Override - public void onLinkMicPkRefuse() { - if (mLiveRyLinkMicPkPresenter != null) { - mLiveRyLinkMicPkPresenter.onLinkMicPkRefuse(); - } - } - - /** - * 主播与主播PK 对方主播正在忙的回调 - */ - @Override - public void onLinkMicPkBusy() { - if (mLiveRyLinkMicPkPresenter != null) { - mLiveRyLinkMicPkPresenter.onLinkMicPkBusy(); - } - } - - /** - * 主播与主播PK 对方主播无响应的回调 - */ - @Override - public void onLinkMicPkNotResponse() { - if (mLiveRyLinkMicPkPresenter != null) { - mLiveRyLinkMicPkPresenter.onLinkMicPkNotResponse(); - } - } - - @Override - public void onLinkMicToPk(String uid, String pkhead, String pkname) { - - } - - @Override - public void prankTurntable(String msgtype, int time, JSONObject jsonObject) { - if (mLiveRoomViewHolder != null) { - mLiveRoomViewHolder.closeAndOpenTrickery(msgtype, time, jsonObject); - } - } - - @Override - public void onUpdatePrankProgress(String prankString) { - if (mLiveRoomViewHolder != null){ - mLiveRoomViewHolder.refreshPrank(prankString); - } - } - - - /** - * 腾讯sdk连麦时候主播混流 - */ - @Subscribe(threadMode = ThreadMode.MAIN) - public void onLinkMicTxMixStreamEvent(LinkMicTxMixStreamEvent e) { - - } - - /** - * 主播checkLive - */ - public void checkLive() { - if (mCheckLiveCallback == null) { - mCheckLiveCallback = new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - if (code == 0 && info.length > 0) { - int status = JSON.parseObject(info[0]).getIntValue("status"); - printLog(DateFormatUtil.getCurTimeString2() + " <=== " + mReqCount + "----status=" + status + "\n"); - if (status == 0) { - NotCancelableDialog dialog = new NotCancelableDialog(); - dialog.setContent(mContext.getString(R.string.live_anchor_error)); - dialog.setActionListener(new NotCancelableDialog.ActionListener() { - @Override - public void onConfirmClick(Context context, DialogFragment dialog) { - dialog.dismiss(); - release(); - superBackPressed(); - } - }); - dialog.show(getSupportFragmentManager(), "VersionUpdateDialog"); - } - } - } - }; - } - mReqCount++; - printLog(DateFormatUtil.getCurTimeString2() + " ===> " + mReqCount + "\n"); - LiveHttpUtil.anchorCheckLive(mLiveUid, mStream, mCheckLiveCallback); - } - - @Override - public void onSendGift(LiveReceiveGiftBean bean, SendBlindGiftEvent event) { - if (event != null) { - LiveChatBean liveChatBean = null; - if (!TextUtils.isEmpty(event.isBlindBoxStatus()) && TextUtils.equals(event.isBlindBoxStatus(), "true")) { - if (!TextUtils.isEmpty(event.getDressName()) && !TextUtils.isEmpty(event.getDressMsg())) { - liveChatBean = new LiveChatBean(); - liveChatBean.setUserNiceName(event.getUserNiceName()); - liveChatBean.setType(LiveChatBean.BLIND_BOX); - liveChatBean.setGiftName(event.getDressName()); - liveChatBean.setContent(event.getDressMsg()); - } - //插入盲盒礼物消息 - bean.getLiveChatBean().setType(LiveChatBean.BLIND_BOX); - bean.getLiveChatBean().setContent(WordUtil.isNewZh() ? event.getGiftMsg() : event.getGiftMsgen()); - bean.getLiveChatBean().setGiftName(WordUtil.isNewZh() ? event.getGiftname() : event.getGiftname_en()); - bean.getLiveChatBean().setUserNiceName(event.getUserNiceName()); - } - - - if (mLiveRoomViewHolder != null) { - if (bean.getmLiveUId().equals(bean.getRoomnum())) { - if (liveChatBean != null) { - mLiveRoomViewHolder.insertChat(liveChatBean, 1); - } - mLiveRoomViewHolder.insertChat(bean.getLiveChatBean(), 1); - } - mLiveRoomViewHolder.showGiftMessage(bean, false); - mLiveRoomViewHolder.updataWishList(bean.getGiftId(), bean.getGiftCount()); - } - } else { - //购买守护 - if (bean.ismTypeBuyGuard()) { - if (mLiveRoomViewHolder != null) { - mLiveRoomViewHolder.showGuardGifMessage(bean); - } - } else { - - if (mLiveRoomViewHolder != null) { - if (bean.getmLiveUId().equals(bean.getRoomnum())) { - mLiveRoomViewHolder.insertChat(bean.getLiveChatBean(), 1); - } - mLiveRoomViewHolder.showGiftMessage(bean, false); - mLiveRoomViewHolder.updataWishList(bean.getGiftId(), bean.getGiftCount()); - } - - } - } - - } - - private void printLog(String content) { - if (mLogFile == null) { - File dir = new File(CommonAppConfig.LOG_PATH); - if (!dir.exists()) { - dir.mkdirs(); - } - mLogFile = new File(dir, DateFormatUtil.getCurTimeString2() + "_" + mLiveUid + "_" + mStream + ".txt"); - } - L.e(TAG, content); - LogUtil.print(mLogFile, content); - } - - @Subscribe(threadMode = ThreadMode.MAIN) - public void onOpenDrawer(LiveAudienceEvent event) { - Bundle bundle = new Bundle(); - IMLoginModel userInfo = IMLoginManager.get(mContext).getUserInfo(); - switch (event.getType()) { - case LIVE_WKS: - String weeklyStarUrl = CommonAppConfig.HOST + "/h5/activity/weekStar/index.html?&uid=" - + userInfo.getId() + - "&token=" + userInfo.getToken() + "&anchorUid=" + mLiveUid; - ZhuangBanActivity.forward(mContext, weeklyStarUrl, false, 0); - break; - case WISH_LIST: - LiveWishListDialogFragment4Audience fragment4Audience = new LiveWishListDialogFragment4Audience(); - bundle.putString(Constants.LIVE_UID, mLiveUid); - fragment4Audience.setArguments(bundle); - if (mContext instanceof LiveRyAnchorActivity) { - fragment4Audience.show(((LiveRyAnchorActivity) mContext).getSupportFragmentManager(), "LiveWishListDialogFragment4Audience"); - } - break; - case UN_LEAVELIVE: - if (leave == 1) { - leaveLive(); - } - break; - case LINK_MIC: - if (!StringUtil.isEmpty(((LinkMicUserBean) event.getObject()).getId())) { - mMicQueueList.put(((LinkMicUserBean) event.getObject()).getId(), (LinkMicUserBean) event.getObject()); - } - if (micListener != null) { - micListener.updateMicList(mMicQueueList); - DialogUitl.showSimpleDialog(mContext, - String.format(mContext.getString(R.string.live_mic_user_apply), ((LinkMicUserBean) event.getObject()).getUserNicename()), - new DialogUitl.SimpleCallback() { - @Override - public void onConfirmClick(Dialog dialog, String content) { - openMicWindow(2); - dialog.dismiss(); - } - } - ); - } - break; - case LINK_MIC_CANCEL: - mMicQueueList.remove(((LinkMicUserBean) event.getObject()).getId()); - if (micListener != null) { - micListener.updateMicList(mMicQueueList); - } - break; - case LINK_MIC_UPDATE_MIC_LIST: - List list = (List) event.getObject(); - mMicQueueList.clear(); - for (LinkMicUserBean bean : list) { - if (!StringUtil.isEmpty(bean.getId())) { - mMicQueueList.put(bean.getId(), bean); - } - } - if (micListener != null) { - micListener.updateMicList(mMicQueueList); - } - if (mLiveRoomViewHolder != null) { - mLiveRoomViewHolder.updataMicList(list); - Log.i("多人连麦", "onOpenDrawer: " + list.size()); - for (LinkMicUserBean userBean : list) { - Log.i("多人连麦", "u list: " + userBean.toString()); - } - } - break; - case LINK_MIC_UPDATE_AUDIENCE_LIST: - mAudienceList = (List) event.getObject(); - if (micListener != null) { - micListener.updateAudienceList(mAudienceList); - } - break; - case LINK_MIC_CLOSE: - if (mLiveRoomViewHolder != null) { - mLiveRoomViewHolder.updataCleanMic(); - } - break; - case LEAVE_DR_ROOM: - if (mLiveRyLinkMicPkPresenter != null) { - mLiveRyLinkMicPkPresenter.leaveDRRoom(); - } - if (mLiveRoomViewHolder != null) { - mLiveRoomViewHolder.seisShowGif(true); - if(isDRPK==1){ - mLiveRoomViewHolder.endDRGif(); - } - - } -// if (mLiveRoomViewHolder != null) { -// mLiveRoomViewHolder.hotAddVisibility(false); -// } - break; - case LEAVE_PK_SCORE: - if (mLiveRyLinkMicPkPresenter != null) { - mLiveRyLinkMicPkPresenter.upDataPkScore(event.getPkScores(), event.getUid(), event.getTime()); - } - if (mLiveRoomViewHolder != null) { - mLiveRoomViewHolder.seisShowGif(true); - } -// if (mLiveRoomViewHolder != null) { -// mLiveRoomViewHolder.hotAddVisibility(true); -// } - break; - case PK_TIME_COUNT: - if (mLiveRoomViewHolder != null) { - mLiveRoomViewHolder.endDRGif(); - } - break; - case DISCONNEXT_PK_TIME: - if (mLivePushViewHolder != null) { - mLivePushViewHolder.changeToBig(); - mLiveRyLinkMicPkPresenter.leaveDRRoom(); - } - break; - case AI_AUTOMATIC_SPEECH: - if (mLiveRoomViewHolder != null) { - mLiveRoomViewHolder.aiAutomaticSpeech((event.getAiAutomaticSpeechModel())); - } - break; - case UPDATA_ROBOT: - getAiRobotStatus(); - break; - //主播强制下播 - case LIVE_END: - endLive(); - break; - case RED_PACKET: - if (manager != null) { - mLiveRoomViewHolder.redPacketManage(event.getRedPacketModel()); - } - break; - case BLIND_BOX: - if (mLiveRoomViewHolder != null) { - if (event.getAllServerNotifyEvent().isRedPacket()) - mLiveRoomViewHolder.blindBoxAllServerNotify(event.getAllServerNotifyEvent()); - } - break; - case GIFT_WALL: - if (mLiveRoomViewHolder != null) { - mLiveRoomViewHolder.showGiftWall(event.getUid(), event.isVoicePress(), event.getUname(), event.getAvatar()); - } - break; - case INPUT_DIALOG: - LiveInputDialogFragment liveInputDialogFragment = new LiveInputDialogFragment(); - Bundle liveInputBundle = new Bundle(); - liveInputBundle.putString(Constants.LIVE_DANMU_PRICE, mDanmuPrice); - liveInputBundle.putString(Constants.COIN_NAME, mCoinName); - liveInputBundle.putString(Constants.LIVE_UID, mLiveUid); - liveInputBundle.putString(Constants.LIVE_STREAM, mStream); - liveInputBundle.putString(Constants.LIVE_UID, mLiveUid); - if (event.getOlineUserlistModel() == null) { - liveInputBundle.putString("TagUser", ""); - } else { - liveInputBundle.putString("TagUser", GsonUtils.toJson(event.getOlineUserlistModel())); - } - liveInputDialogFragment.setArguments(liveInputBundle); - liveInputDialogFragment.show(getSupportFragmentManager(), "LiveInputDialogFragment"); - break; - case LIVE_DIALOG_ANCHOR_TIPS: - new DialogUitl.Builder(mContext) - .setContent(event.getObject().toString()) - .setConfirmString(WordUtil.isNewZh() ? "確定" : "confirm") - .setCancelable(true) - .setShowCancelButton(false) - .build() - .show(); - break; - - } - } - - @Subscribe(threadMode = ThreadMode.MAIN) - public void onSendMoneyLongModel(SendMoneyLongModel sendMoneyLongModel) { - if (mLiveRoomViewHolder != null) { - mLiveRoomViewHolder.onSendMoneyLongModel(sendMoneyLongModel); - } - } - - @Subscribe(threadMode = ThreadMode.MAIN) - public void onSendMoneyLongEndEvent(SendMoneyLongEndEvent sendMoneyLongModel) { - Log.e("DateRemindModel", sendMoneyLongModel.toString()); - if (mLiveRoomViewHolder != null) { - mLiveRoomViewHolder.onSendMoneyLongEndEvent(sendMoneyLongModel); - } - - - } - - @Subscribe(threadMode = ThreadMode.MAIN) - public void GiftWallIlluminateEvent(GiftWallIlluminateEvent event) { - if (mLiveRoomViewHolder != null) { - mLiveRoomViewHolder.setGiftWall(String.valueOf(event.getNewNumber()), String.valueOf(event.getMaxNumber())); - } - } - - @Subscribe(threadMode = ThreadMode.MAIN) - public void onShowHideEvent(ShowHideEvent event) { - if (mLiveRoomViewHolder != null) { - mLiveRoomViewHolder.onShowHideEvent(); - - } - } - - /** - * 检查指定直播间连麦人数 - * - * @param mLiveUid 直播间 - */ - public static void checkMicUserLength(String mLiveUid, LiveFunctionClickListener listener) { - LiveHttpUtil.getMicList(mLiveUid, 0, new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - if (code == 0) { - try { - JSONObject obj = JSON.parseObject(info[0]); - List list = JSON.parseArray(obj.getString("userlist"), MicUserBean.class); - listener.onClick(list.size()); - } catch (Exception e) { - e.printStackTrace(); - } - - } - } - }); - } - - /** - * 获取机器人配置;取得求关注时间间隔 - */ - private long robotTime = 0; - - private void getAiRobotStatus() { - Log.e("随机打招呼", "((((((((((((((((((((((((((((((((((((((((((((((("); - LiveNetManager.get(mContext) - .getAiRobotStatus(new com.yunbao.common.http.base.HttpCallback() { - @Override - public void onSuccess(LiveAiRobotBean data) { - Log.e("随机打招呼", "(((((((((((((((((((((((((((((((((((((((((((((((" + data.toString()); - if (data.getStatus() == 1) { - if (robotRunnable != null) { - robotHandler.removeCallbacks(robotRunnable); - robotRunnable = null; - } - robotRunnable = new Runnable() { - @Override - public void run() { - Log.e("随机打招呼", "(((((((((((((((((((((((((((((((((((((((((((((((data.getName())" + data.getName()); - String robotName = data.getName(); - //发送消息 - LiveNetManager.get(mContext) - .getAiRobotBody(LiveAiRobotBean.Message.TYPE_FOLLOW, - new com.yunbao.common.http.base.HttpCallback>() { - @Override - public void onSuccess(List messageList) { - Random random = new Random(); - int randNumber = random.nextInt(messageList.size()) - 1; - if (randNumber < 0) { - randNumber = 0; - } - Log.e("随机打招呼", "(((((((((((((((((((((((((((((((((((((((((((((((data.randNumber())" + randNumber); - Log.e("随机打招呼", "(((((((((((((((((((((((((((((((((((((((((((((((data)" + messageList.toString()); - sendRobotMessage(robotName, messageList.get(randNumber).getContent()); - } - - @Override - public void onError(String error) { - Log.e("随机打招呼", "(((((((((((((((((((((((((((((((((((((((((((((((data.error())" + error); - } - }); - - } - }; - robotTime = data.getTime() * 60 * 1000; - Log.e("随机打招呼", "(((((((((((((((((((((((((((((((((((((((((((((((robotTime)" + robotTime); - robotHandler.postDelayed(robotRunnable, robotTime); - } - } - - @Override - public void onError(String error) { - ToastUtil.show(WordUtil.isNewZh() ? "抱歉!出錯了!" : "i \\'m sorry! An error occurred"); - } - }); - } - - //机器人求关注轮询器 - private Handler robotHandler = new Handler(); - private Runnable robotRunnable = null; - - /** - * '{"msg": - * [{"_method_":"aiAutomaticSpeech", - * "ct":{"name_color":"#f19ec2","ai_name":"'+_this.robotInfo.ai_name+'", - * "content":"'+content+'","user_name":"", - * "icon":"https://downs.yaoulive.com/xzs_tab.png", - * "system_bubble":"https://downs.yaoulive.com/xzs_qipao.9.png"}, - * "msgtype":"10"}],"retcode":"000000","retmsg":"OK"}' - */ - private void sendRobotMessage(String name, String content) { - Log.e("随机打招呼", name + "==========00000000000000++++" + content); - AiAutomaticSpeechModel aiAutomaticSpeechModel = new AiAutomaticSpeechModel(); - aiAutomaticSpeechModel.setAiName(name) - .setIcon("https://downs.yaoulive.com/xzs_tab.png") - .setNameColor("#f19ec2") - .setSystemBubble("https://downs.yaoulive.com/xzs_qipao.9.png") - .setIconEn("https://downs.yaoulive.com/Robot_en.png") - .setUserName("") - .setContent(content); - SocketSendBean msg = - new SocketSendBean() - .param("_method_", "aiAutomaticSpeechNew") - .param("msgtype", "10") - .param("ct", GsonUtils.toJson(aiAutomaticSpeechModel, AiAutomaticSpeechModel.class)); - msg.create(); - String targetId = "g" + mLiveUid; - Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; - TextMessage messageContent = TextMessage.obtain(msg.mResult.toString()); - Message message = Message.obtain(targetId, conversationType, messageContent); - - RongcloudIMManager.sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { - @Override - public void onAttached(Message message) { - - } - - @Override - public void onSuccess(Message message) { - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); - } - } - - @Override - public void onError(Message message, RongIMClient.ErrorCode errorCode) { - Log.e("tx", "aaa" + errorCode.toString()); - ToastUtil.show(errorCode.code + ":" + errorCode.msg); - } - }); - robotHandler.postDelayed(robotRunnable, robotTime); - } - - private LiveSudGamePopup liveSudGamePopupXPopup = null; - - @Subscribe(threadMode = ThreadMode.MAIN) - public void onLiveSudGamePopupShowOrHideEvent(LiveSudGamePopupShowOrHideEvent event) { - switch (event.getType()) { - case 0: - if (liveSudGamePopupXPopup == null) { - liveSudGamePopupXPopup = new LiveSudGamePopup(mContext, event.getCreateSudRoomModel()); - new XPopup.Builder(mContext) - .enableDrag(false) - .dismissOnTouchOutside(false) - .dismissOnBackPressed(false) - .asCustom(liveSudGamePopupXPopup).show(); - } else { - if (liveSudGamePopupXPopup != null) { - liveSudGamePopupXPopup.dialog.show(); - } - } - - - break; - - case 1: - if (liveSudGamePopupXPopup != null) { - liveSudGamePopupXPopup.dialog.hide(); - } - - break; - case 2: - if (liveSudGamePopupXPopup != null) { - liveSudGamePopupXPopup.BusGetOff(); - liveSudGamePopupXPopup.dialog.dismiss(); - liveSudGamePopupXPopup = null; - } - break; - } - - - } - @Subscribe(threadMode = ThreadMode.MAIN) - public void onAllServerNotifyFFGGGDJANEvent(AllServerNotifyFFGGGDJANEvent event) { - if (mLiveRoomViewHolder != null) { - mLiveRoomViewHolder.showAllServerNotifyFFGGGD(event,false); - } - } -} diff --git a/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java index aed602546..1a323b749 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java @@ -124,10 +124,6 @@ import java.io.File; import java.util.List; import java.util.Random; -import cn.rongcloud.rtc.api.RCRTCEngine; -import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback; -import cn.rongcloud.rtc.base.RCRTCRect; -import cn.rongcloud.rtc.base.RTCErrorCode; import io.agora.beautyapi.faceunity.agora.SWManager; import io.agora.rtc2.RtcEngine; import io.rong.imlib.IRongCallback; @@ -559,7 +555,7 @@ public class LiveSwAnchorActivity extends LiveActivity implements LiveFunctionCl if (PKing || isDRPK == 1) { return; } - RCRTCRect rect = new RCRTCRect(0f, 0f, 1.0f); +// RCRTCRect rect = new RCRTCRect(0f, 0f, 1.0f); if (leave == 0) { leave = 1; leave_img.setVisibility(View.VISIBLE); @@ -567,7 +563,6 @@ public class LiveSwAnchorActivity extends LiveActivity implements LiveFunctionCl @Override public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition transition) { - boolean ret = RCRTCEngine.getInstance().getDefaultVideoStream().setWatermark(BitmapUtil.getInstance().convertMirror(resource), rect); sendSystemMessageSw(mContext.getString(R.string.live_anchor_leave)); } @@ -582,7 +577,6 @@ public class LiveSwAnchorActivity extends LiveActivity implements LiveFunctionCl leave = 0; leave_img.setVisibility(View.GONE); // 清除水印 - boolean ret = RCRTCEngine.getInstance().getDefaultVideoStream().setWatermark(null, rect); sendSystemMessageSw(mContext.getString(R.string.live_anchor_come_back)); SWManager.get().setLeaveFlag(false); mLiveAnchorViewHolder.setLeaveFlag(false); @@ -926,31 +920,6 @@ public class LiveSwAnchorActivity extends LiveActivity implements LiveFunctionCl } public void endLives() { - - - RCRTCEngine.getInstance().getDefaultVideoStream().stopCamera(new IRCRTCResultCallback() { - @Override - public void onSuccess() { - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - - } - }); - RCRTCEngine.getInstance().leaveRoom(new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.i("ry", "退出成功"); - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.i("ry", "退出失败" + errorCode); - } - }); - - if (mLivePushViewHolder != null) { mLivePushViewHolder.release(); } diff --git a/live/src/main/java/com/yunbao/live/activity/SudRyGameActivity.java b/live/src/main/java/com/yunbao/live/activity/SudRyGameActivity.java deleted file mode 100644 index a52fbae04..000000000 --- a/live/src/main/java/com/yunbao/live/activity/SudRyGameActivity.java +++ /dev/null @@ -1,765 +0,0 @@ -package com.yunbao.live.activity; - -import android.Manifest; -import android.app.Activity; -import android.os.Bundle; -import android.os.Handler; -import android.os.Looper; -import android.text.TextUtils; -import android.util.Log; -import android.view.View; -import android.widget.FrameLayout; -import android.widget.ImageView; -import android.widget.TextView; - -import androidx.lifecycle.Observer; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - -import com.alibaba.android.arouter.facade.annotation.Route; -import com.alibaba.fastjson.JSONObject; -import com.google.gson.Gson; -import com.lxj.xpopup.XPopup; -import com.lzf.easyfloat.EasyFloat; -import com.yunbao.common.CommonAppConfig; -import com.yunbao.common.Constants; -import com.yunbao.common.R; -import com.yunbao.common.activity.AbsActivity; -import com.yunbao.common.adapter.SudGameChatAdapter; -import com.yunbao.common.adapter.SudGameUserListAdapter; -import com.yunbao.common.bean.CheckRemainingBalance; -import com.yunbao.common.bean.CreateSudRoomModel; -import com.yunbao.common.bean.CustomSidebarChildModel; -import com.yunbao.common.bean.CustomSidebarInfoModel; -import com.yunbao.common.bean.HttpCallbackModel; -import com.yunbao.common.bean.RoomMicStatusModel; -import com.yunbao.common.bean.SudGameChatImModel; -import com.yunbao.common.bean.SudGameInfoBean; -import com.yunbao.common.bean.SudGameScoreBean; -import com.yunbao.common.bean.SudGameUserModel; -import com.yunbao.common.dialog.SudGameDoubleDialog; -import com.yunbao.common.dialog.SudGameMultipleDialog; -import com.yunbao.common.dialog.SudGameInputPopupWindow; -import com.yunbao.common.dialog.SudLoadDialog; -import com.yunbao.common.event.CheckRemainingBalanceEvent; -import com.yunbao.common.event.SubGameEvent; -import com.yunbao.common.event.SudGameSocketImEvent; -import com.yunbao.common.glide.ImgLoader; -import com.yunbao.common.http.base.HttpCallback; -import com.yunbao.common.http.live.LiveNetManager; -import com.yunbao.common.manager.IMLoginManager; -import com.yunbao.common.manager.imrongcloud.GameRyMicManager; -import com.yunbao.common.sud.QuickStartGameViewModel; -import com.yunbao.common.sud.model.GameConfigModel; -import com.yunbao.common.sud.model.GameViewInfoModel; -import com.yunbao.common.sud.state.SudMGPAPPState; -import com.yunbao.common.sud.state.SudMGPMGState; -import com.yunbao.common.utils.Bus; -import com.yunbao.common.utils.DpUtil; -import com.yunbao.common.utils.ProcessResultUtil; -import com.yunbao.common.utils.RouteUtil; -import com.yunbao.common.utils.ToastUtil; -import com.yunbao.common.utils.WordUtil; -import com.yunbao.common.views.LiveSudGameHistoryPopup; -import com.yunbao.common.views.TopGradual; -import com.yunbao.common.views.floatingview.APPEasyFloat; -import com.yunbao.common.views.weight.ViewClicksAntiShake; -import com.yunbao.live.dialog.LiveUserDialogFragment; - -import org.greenrobot.eventbus.Subscribe; -import org.greenrobot.eventbus.ThreadMode; - -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; - -import cn.rongcloud.rtc.api.RCRTCEngine; -import cn.rongcloud.rtc.api.RCRTCRemoteUser; -import cn.rongcloud.rtc.api.RCRTCRoom; -import cn.rongcloud.rtc.api.stream.RCRTCInputStream; -import cn.rongcloud.rtc.base.RTCErrorCode; - -@Route(path = RouteUtil.PATH_SudRyGameActivity) -public class SudRyGameActivity extends AbsActivity implements GameRyMicManager.MeetingCallback { - private FrameLayout gameContainer; - private long mInteractionID; - private String mLiveUid; - private final QuickStartGameViewModel gameViewModel = new QuickStartGameViewModel(); // 创建ViewModel - - private CreateSudRoomModel mCreateSudRoomModel; - private TextView roomName, roomNumber; - private GameRyMicManager gameMicManager; - private ImageView gameCloseWheat, gameSeat; - private boolean disable = true, publishDefault = false; - - private RecyclerView chatList, userList; - private SudGameChatAdapter mLiveChatAdapter; - private SudGameUserListAdapter sudGameUserListAdapter; - private ProcessResultUtil mProcessResultUtil; - private List muteUser = new ArrayList<>(); - private boolean imOff; - private SudGameDoubleDialog sudGameDoubleDialog;//双人游戏弹窗 - private SudGameMultipleDialog sudGameMultipleDialog;//多人游戏弹窗 - private SudLoadDialog sudLoadDialog;//加载弹窗 - - @Override - protected int getLayoutId() { - return R.layout.activity_sud_game; - } - - @Override - protected void main() { - Bus.getOn(this); - super.main(); - initView(); - //进游戏房就关掉小窗 - EasyFloat.dismiss("LiveFloatView", true); - APPEasyFloat.getInstance().dismiss(mContext); - initDate(); - } - - private List customSidebarChildModels = new ArrayList<>(); - - private void initDate() { - CommonAppConfig.getInstance().getConfig().isSw(); - LiveNetManager.get(mContext) - .getCustomSidebarInfo("1", new HttpCallback>() { - @Override - public void onSuccess(List data) { - for (CustomSidebarInfoModel datum : data) { - if (datum.getType().equals("6")) { - customSidebarChildModels = datum.getChild(); - return; - } - } - } - - @Override - public void onError(String error) { - - } - }); - - // 设置禁用麦克风采集 - RCRTCEngine.getInstance().getDefaultAudioStream().setMicrophoneDisable(disable); - ImgLoader.display(mContext, R.mipmap.icon_game_close_wheat, gameCloseWheat); - gameCloseWheat.setVisibility(View.INVISIBLE); - - - mProcessResultUtil = new ProcessResultUtil(this); - LiveNetManager.get(mContext) - .getRoomMicStatus(new HttpCallback() { - @Override - public void onSuccess(RoomMicStatusModel data) { - gameMicManager = new GameRyMicManager(); - gameMicManager.attachView(SudRyGameActivity.this); - gameMicManager.config(SudRyGameActivity.this); - //语音 - if (TextUtils.equals(data.getMicStatus(), "1")) { - imOff = true; - gameSeat.setVisibility(View.VISIBLE); - userList.setVisibility(View.VISIBLE); - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - if (!mProcessResultUtil.checkPermissions(new String[]{Manifest.permission.RECORD_AUDIO})) { - ToastUtil.show("拒绝权限将无法使用上麦功能"); - mProcessResultUtil.requestPermissions(new String[]{Manifest.permission.RECORD_AUDIO}, new Runnable() { - @Override - public void run() { - - } - }); - } - } - }, 1500); - } else { - imOff = false; - gameSeat.setVisibility(View.GONE); - userList.setVisibility(View.GONE); - } - if (TextUtils.equals(data.getImStatus(), "1")) { - findViewById(R.id.game_review_input).setVisibility(View.VISIBLE); - chatList.setVisibility(View.VISIBLE); - } else { - findViewById(R.id.game_review_input).setVisibility(View.GONE); - chatList.setVisibility(View.GONE); - } - gameMicManager.joinRoom(mLiveUid, imOff); - } - - @Override - public void onError(String error) { - imOff = false; - //文字 - findViewById(R.id.game_review_input).setVisibility(View.GONE); - chatList.setVisibility(View.GONE); - //语音 - gameCloseWheat.setVisibility(View.GONE); - gameSeat.setVisibility(View.GONE); - userList.setVisibility(View.GONE); - } - }); - - - } - - @Override - protected void onDestroy() { - - LiveNetManager.get(mContext) - .leaveMic(mLiveUid, new HttpCallback() { - @Override - public void onSuccess(HttpCallbackModel data) { - - } - - @Override - public void onError(String error) { - - } - }); - - if (gameMicManager != null) { - gameMicManager.leaveRoom(); - gameMicManager.detachView(); - } - Bus.getOff(this); - - super.onDestroy(); - } - - private void initView() { - - String createSudRoomJson = getIntent().getStringExtra("CreateSudRoom"); - mCreateSudRoomModel = new Gson().fromJson(createSudRoomJson, CreateSudRoomModel.class); - mInteractionID = mCreateSudRoomModel.getLongSudGameId(); - mLiveUid = mCreateSudRoomModel.getSudGameRoomId(); - //第二次进入时,viewmodel数据丢失,所以初始化时直接获取 - gameViewModel.getScore(mCreateSudRoomModel.getSudGameRoomId(),mContext); - gameContainer = findViewById(R.id.game_container); - roomName = findViewById(R.id.room_name); - roomNumber = findViewById(R.id.room_number); - gameCloseWheat = findViewById(R.id.game_close_wheat); - gameSeat = findViewById(R.id.game_seat); - chatList = findViewById(R.id.chat_list); - userList = findViewById(R.id.user_list); - //聊天栏 - FrameLayout.LayoutParams params1 = (FrameLayout.LayoutParams) - chatList.getLayoutParams(); - params1.topMargin = DpUtil.dp2px(65); - chatList.setLayoutParams(params1); - - chatList.setHasFixedSize(true); - LinearLayoutManager layoutManager = new LinearLayoutManager(mContext); - layoutManager.setOrientation(RecyclerView.VERTICAL); - layoutManager.setStackFromEnd(true); - chatList.setLayoutManager(layoutManager); - chatList.addItemDecoration(new TopGradual()); - chatList.setItemViewCacheSize(10); - mLiveChatAdapter = new SudGameChatAdapter(mContext); - chatList.setAdapter(mLiveChatAdapter); - sudGameUserListAdapter = new SudGameUserListAdapter(new ArrayList<>()); - ImgLoader.display(mContext, WordUtil.isNewZh() ? R.mipmap.icon_game_seat : R.mipmap.icon_game_seat_en, gameSeat); - sudGameUserListAdapter.setSudGameSmallCallBack(new SudGameUserListAdapter.SudGameSmallCallBack() { - @Override - public void unMute(String userID, int position) { - if (!TextUtils.equals(String.valueOf(IMLoginManager.get(mContext).getUserInfo().getId()), userID)) { - gameMicManager.refreshStreams(userID, false, position); - } else { - ToastUtil.show(WordUtil.isNewZh() ? "無法對本人靜音" : "Unable to mute myself"); - } - muteUser.remove(userID); - } - - @Override - public void mute(String userID, int position) { - muteUser.add(userID); - if (!TextUtils.equals(String.valueOf(IMLoginManager.get(mContext).getUserInfo().getId()), userID)) { - gameMicManager.refreshStreams(userID, true, position); - } else { - ToastUtil.show(WordUtil.isNewZh() ? "無法對本人靜音" : "Unable to mute myself"); - } - - } - - @Override - public void viewInformation(SudGameUserModel sudGameUserModel) { - LiveUserDialogFragment fragment = new LiveUserDialogFragment(); - Bundle bundle = new Bundle(); - bundle.putString(Constants.LIVE_UID, "uid"); - bundle.putString(Constants.STREAM, ""); - bundle.putString(Constants.TO_UID, sudGameUserModel.getId() + ""); - fragment.setArguments(bundle); - fragment.show(((SudRyGameActivity) mContext).getSupportFragmentManager(), "LiveUserDialogFragment"); - } - }); - userList.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false)); - userList.setAdapter(sudGameUserListAdapter); - if (mCreateSudRoomModel != null) { - roomName.setText(mCreateSudRoomModel.getRoomName()); - roomNumber.setText(mCreateSudRoomModel.getSudGameRoomId()); - } - - ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.exit), new ViewClicksAntiShake.ViewClicksCallBack() { - @Override - public void onViewClicks() { - gameViewModel.onDestroy(); - finish(); - } - }); - ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.sud_history), new ViewClicksAntiShake.ViewClicksCallBack() { - @Override - public void onViewClicks() { - - new XPopup.Builder(mContext) - .enableDrag(false) - .asCustom(new LiveSudGameHistoryPopup(mContext, customSidebarChildModels)).show(); - } - }); - - ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.game_seat), new ViewClicksAntiShake.ViewClicksCallBack() { - @Override - public void onViewClicks() { - if (imOff && gameMicManager != null) { - if (mProcessResultUtil.checkPermissions(new String[]{Manifest.permission.RECORD_AUDIO})) { - if (publishDefault) { - disable = true; - // 设置禁用麦克风采集 - RCRTCEngine.getInstance().getDefaultAudioStream().setMicrophoneDisable(disable); -// ImgLoader.display(mContext, R.mipmap.icon_game_close_wheat, gameCloseWheat); - gameMicManager.unPublishStreams(); - } else { - if (sudGameUserListAdapter.isMicMax()) { - ToastUtil.show(WordUtil.isNewZh() ? "上麥人數最大7人" : "The maximum number of people on the microphone is 7"); - } else { - gameMicManager.publishDefaultAVStream(); - } - - } - } else { - mProcessResultUtil.requestPermissions(new String[]{Manifest.permission.RECORD_AUDIO}, new Runnable() { - @Override - public void run() { - - } - }); - } - } - - - } - }); - ViewClicksAntiShake.clicksAntiShake(gameCloseWheat, new ViewClicksAntiShake.ViewClicksCallBack() { - @Override - public void onViewClicks() { - if (imOff && gameMicManager != null) { - - gameCloseWheat.post(new Runnable() { - @Override - public void run() { - if (disable) { - disable = false; - // 设置禁用麦克风采集 - RCRTCEngine.getInstance().getDefaultAudioStream().setMicrophoneDisable(disable); - ImgLoader.display(mContext, R.mipmap.icon_game_open_wheat, gameCloseWheat); - LiveNetManager.get(mContext) - .onMic(mLiveUid, new HttpCallback() { - @Override - public void onSuccess(HttpCallbackModel data) { - - } - - @Override - public void onError(String error) { - - } - }); - ToastUtil.show(WordUtil.isNewZh() ? "麥克風已開啟" : "Microphone turned on"); - } else { - disable = true; - // 设置禁用麦克风采集 - RCRTCEngine.getInstance().getDefaultAudioStream().setMicrophoneDisable(disable); - ImgLoader.display(mContext, R.mipmap.icon_game_close_wheat, gameCloseWheat); - LiveNetManager.get(mContext) - .offMic(mLiveUid, new HttpCallback() { - @Override - public void onSuccess(HttpCallbackModel data) { - - } - - @Override - public void onError(String error) { - - } - }); - ToastUtil.show(WordUtil.isNewZh() ? "麥克風已關閉" : "Microphone turned off"); - } - } - }); - - - } - - - } - }); - ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.game_review_input), new ViewClicksAntiShake.ViewClicksCallBack() { - @Override - public void onViewClicks() { - new XPopup.Builder(mContext) - .enableDrag(false) - .asCustom(new SudGameInputPopupWindow(mContext, new SudGameInputPopupWindow.SudGameInputCallBack() { - @Override - public void sendMessage(String textMessage) { - gameMicManager.sendMessage(textMessage); - } - })) - .show(); - } - }); - - gameViewModel.gameViewLiveData.observe(this, new Observer() { - @Override - public void onChanged(View view) { - if (view == null) { // 在关闭游戏时,把游戏View给移除 - gameContainer.removeAllViews(); - } else { // 把游戏View添加到容器内 - gameContainer.addView(view, FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT); - - } - - } - }); - // 加载游戏,参数定义可查看BaseGameViewModel.switchGame()方法注释 - // 游戏配置 - GameConfigModel gameConfigModel = gameViewModel.getGameConfigModel(); - gameConfigModel.ui.ping.hide = true; // 配置不隐藏ping值 - gameConfigModel.ui.level.hide = true; // 配置不隐藏ping值 - gameConfigModel.ui.lobby_game_setting.hide = true; // 配置不隐藏ping值 - gameConfigModel.ui.gameSettle.hide = true;//是否隐藏结算界面(false: 显示; true: 隐藏,默认为 false) - - gameConfigModel.ui.lobby_players.custom = true; - gameConfigModel.ui.join_btn.custom = true; - gameConfigModel.ui.game_settle_again_btn.custom = true; - gameConfigModel.ui.start_btn.custom = true; - - - // SudMGP平台64bit游戏ID - gameViewModel.switchGame((Activity) mContext, mLiveUid, mInteractionID); -// gameViewModel.sudFSTAPPDecorator.notifyAPPCommonSelfIn(true, -1, true, 1); -// gameViewModel.sudFSTAPPDecorator.notifyAPPCommonSelfCaptain(String.valueOf(IMLoginManager.get(mContext).getUserInfo().getId())); -// ViewClicksAntiShake.clicksAntiShake(gameTitle, new ViewClicksAntiShake.ViewClicksCallBack() { -// @Override -// public void onViewClicks() { -// -// } -// }); - // 设置游戏安全操作区域 - GameViewInfoModel.GameViewRectModel gameViewRectModel = new GameViewInfoModel.GameViewRectModel(); - gameViewRectModel.left = 0; - gameViewRectModel.top = DpUtil.dp2px(180);//游戏安全区域 - gameViewRectModel.right = 0; - gameViewRectModel.bottom = DpUtil.dp2px(155); - gameViewModel.gameViewRectModel = gameViewRectModel; - - //初始化结算弹窗 - sudGameDoubleDialog = new SudGameDoubleDialog(this);//双人游戏 - sudGameMultipleDialog = new SudGameMultipleDialog(this);//多人游戏 - sudLoadDialog = new SudLoadDialog(this);//加载弹窗 - - //游戏结算结束 - gameViewModel.listMutableLiveData.observe(this, sudSettleBeans -> { - if (sudLoadDialog.getClickStatus() == 0) { - sudLoadDialog.dismiss(); - if (gameViewModel.getSudGameScoreBean().getGame_mode() == 1) { - //双人游戏 - sudGameDoubleDialog.setSudSettleList(sudSettleBeans); - sudGameDoubleDialog.showDialog(); - } else { - //多人游戏 - sudGameMultipleDialog.setSudSettleList(sudSettleBeans); - sudGameMultipleDialog.showDialog(); - } - } - }); - - //加载弹窗监听 - sudLoadDialog.setOnDismissListener(() -> { - if (sudLoadDialog.getClickStatus() == 2){ - Bus.get().post(new CheckRemainingBalanceEvent(null).setSudMGPMGState(SudMGPMGState.MG_COMMON_SELF_CLICK_GAME_SETTLE_AGAIN_BTN).setSubReady(false)); - } - }); - } - - @Subscribe(threadMode = ThreadMode.MAIN) - public void onCheckRemainingBalanceEvent(CheckRemainingBalanceEvent event) { - switch (event.getSudMGPMGState()) { - case SudMGPMGState.MG_COMMON_SELF_CLICK_JOIN_BTN: - case SudMGPMGState.MG_COMMON_SELF_CLICK_GAME_SETTLE_AGAIN_BTN: - //获取筹码信息,检查是否足够 - LiveNetManager.get(mContext).getScore(mCreateSudRoomModel.getSudGameRoomId(), new HttpCallback() { - @Override - public void onSuccess(SudGameScoreBean data) { - if (data.getGolden_bean_remaining_balance() == 1) { - gameViewModel.setSudGameScoreBean(data); - gameViewModel.sudFSTAPPDecorator.notifyAPPCommonSelfIn(true, event.getSeatIndex(), true, 1); - gameViewModel.sudFSTAPPDecorator.notifyAPPCommonSelfReady(event.getSubReady()); - } else { - if (IMLoginManager.get(mContext).getLocaleLanguage() == Locale.SIMPLIFIED_CHINESE) { - ToastUtil.show("貨幣数量不足 "); - } else { - ToastUtil.show("Insufficient number of currency"); - } - - } -// ToastUtil.show(data.toString()); - - } - - @Override - public void onError(String error) { - if (IMLoginManager.get(mContext).getLocaleLanguage() == Locale.SIMPLIFIED_CHINESE) { - ToastUtil.show("貨幣数量不足 "); - } else { - ToastUtil.show("Insufficient number of currency"); - } - - } - }); - break; - case SudMGPMGState.MG_COMMON_GAME_SETTLE: - //结算状态 - gameViewModel.sudFSTAPPDecorator.notifyAPPCommonSelfIn(false, event.getSeatIndex(), true, 1); - sudLoadDialog.setClickStatus(0); - sudLoadDialog.setDouble(gameViewModel.getSudGameScoreBean().getGame_mode()); - sudLoadDialog.showDialog(); - //获取用户信息 - LiveNetManager.get(mContext).getSudGameInfo(mCreateSudRoomModel.getSudGameRoomId(), new HttpCallback>() { - @Override - public void onSuccess(List data) { - if (!data.isEmpty()){ - gameViewModel.setSudGameInfoBeanList(data); - gameViewModel.sudGameRank(event.getMgCommonGameSettle()); - }else { - ToastUtil.show(getString(R.string.net_error)); - } - } - - @Override - public void onError(String error) { - ToastUtil.show(error); - } - }); - break; - case SudMGPMGState.MG_COMMON_SELF_CLICK_START_BTN: - //点击开始游戏 - LiveNetManager.get(mContext).gameStartCheckRemainingBalance(mCreateSudRoomModel.getSudGameId(), - mCreateSudRoomModel.getSudGameRoomId(), new - HttpCallback() { - @Override - public void onSuccess(CheckRemainingBalance data) { - if (data.getStatus() == 1) { - gameViewModel.sudFSTAPPDecorator.notifyAPPCommonSelfPlaying(true); - } else { - - } - - } - - @Override - public void onError(String error) { - ToastUtil.show(error); - } - }); - break; - case SudMGPMGState.MG_COMMON_GAME_STATE: - LiveNetManager.get(mContext).deductMoney(mCreateSudRoomModel.getSudGameRoomId()); - break; - } - - } - - @Override - public void onJoinRoomSuccess(RCRTCRoom rcrtcRoom) { - LiveNetManager.get(mContext).getRoomMicData(mLiveUid, new HttpCallback>() { - @Override - public void onSuccess(List data) { - - gameMicManager.refreshStreams(data); - sudGameUserListAdapter.refreshSudGameUserList(data, muteUser); - } - - @Override - public void onError(String error) { - ToastUtil.show(error); - } - }); - // 主动订阅远端用户发布的资源 -// gameMicManager.subscribeAVStream(); - } - - @Override - public void onJoinRoomFailed(RTCErrorCode rtcErrorCode) { - ToastUtil.show("加入失败 " + rtcErrorCode.toString()); - } - - @Override - public void onPublishSuccess() { - runOnUiThread(new Runnable() { - @Override - public void run() { - ImgLoader.display(mContext, WordUtil.isNewZh() ? R.mipmap.icon_game_hang_up : R.mipmap.icon_game_hang_up_en, gameSeat); - publishDefault = true; - gameCloseWheat.setVisibility(View.VISIBLE); - disable = false; - // 设置禁用麦克风采集 - RCRTCEngine.getInstance().getDefaultAudioStream().setMicrophoneDisable(disable); - ImgLoader.display(mContext, R.mipmap.icon_game_open_wheat, gameCloseWheat); - } - }); - - LiveNetManager.get(mContext) - .joinMic(mLiveUid, new HttpCallback() { - @Override - public void onSuccess(HttpCallbackModel data) { - - } - - @Override - public void onError(String error) { - - } - }); - } - - @Override - public void onPublishFailed() { - ToastUtil.show(WordUtil.isNewZh() ? "語音加入失敗" : "Voice joining failed"); - } - - @Override - public void onSubscribeSuccess(List inputStreamList) { -// ToastUtil.show("订阅成功 "); - } - - @Override - public void onSubscribeFailed() { - ToastUtil.show("订阅失败 "); - } - - @Override - public void onSubscribeSuccess(String userID, boolean mute, int position) { - runOnUiThread(new Runnable() { - @Override - public void run() { - if (mute) { - ToastUtil.show(WordUtil.isNewZh() ? "已靜音該用戶" : "The user has been muted"); - } else { - ToastUtil.show(WordUtil.isNewZh() ? "已取消該用戶靜音" : "The user has been unmuted"); - } - sudGameUserListAdapter.muteUser(userID, mute, position); - } - }); - - } - - @Override - public void onSubscribeFailed(String userID) { - ToastUtil.show("订阅失败 "); - } - - @Override - public void onUserJoined(RCRTCRemoteUser rcrtcRemoteUser) { - - } - - @Override - public void onUserLeft(RCRTCRemoteUser rcrtcRemoteUser) { - - } - - @Override - public void insertItem(SudGameChatImModel sudGameChatImModel) { - mLiveChatAdapter.insertItem(sudGameChatImModel); - } - - @Override - public void refreshSudGameUserList(List personList) { - sudGameUserListAdapter.refreshSudGameUserList(personList, muteUser); - } - - @Override - public void onUnPublishStreamsSuccess() { - runOnUiThread(new Runnable() { - @Override - public void run() { - ImgLoader.display(mContext, WordUtil.isNewZh() ? R.mipmap.icon_game_seat : R.mipmap.icon_game_seat_en, gameSeat); - publishDefault = false; - gameCloseWheat.setVisibility(View.INVISIBLE); - } - }); - LiveNetManager.get(mContext) - .leaveMic(mLiveUid, new HttpCallback() { - @Override - public void onSuccess(HttpCallbackModel data) { - - } - - @Override - public void onError(String error) { - - } - }); - - } - - @Override - public void onUnPublishStreamsFailed() { - - } - - @Subscribe(threadMode = ThreadMode.MAIN) - public void onSudGameSocketImEvent(SudGameSocketImEvent event) { - gameMicManager.processingMessage(event); - } - - @Subscribe(threadMode = ThreadMode.MAIN) - public void onSudGameUserModel(SudGameUserModel model) { - if (model.isNullUser()) { - if (!publishDefault) { - if (mProcessResultUtil.checkPermissions(new String[]{Manifest.permission.RECORD_AUDIO})) { - if (sudGameUserListAdapter.isMicMax()) { - ToastUtil.show(WordUtil.isNewZh() ? "上麥人數最大7人" : "The maximum number of people on the microphone is 7"); - } else { - gameMicManager.publishDefaultAVStream(); - } - - } else { - mProcessResultUtil.requestPermissions(new String[]{Manifest.permission.RECORD_AUDIO}, new Runnable() { - @Override - public void run() { - - } - }); - } - - } else { - ToastUtil.show(WordUtil.isNewZh() ? "已經是上麥狀態" : "It is already in the wheat state"); - } - - } - } - - @Subscribe(threadMode = ThreadMode.MAIN) - public void onSudGameStatus(SubGameEvent event) { - if (event.getType() == 0) { - Log.i("游戏回调", "onGameStateChange: event :" + event.toString()); - if (event.getModel().getCode() == 1001 || event.getModel().getCode() == 1002) { - JSONObject jsonObject = new JSONObject(); - jsonObject.put("result", 0); - gameViewModel.sudFSTAPPDecorator.notifyStateChange(SudMGPAPPState.APP_COMMON_GAME_CREATE_ORDER_RESULT, jsonObject.toString()); - } - } - } -} diff --git a/live/src/main/java/com/yunbao/live/activity/SudSwGameActivity.java b/live/src/main/java/com/yunbao/live/activity/SudSwGameActivity.java index 34b03d4a9..ae5ad483c 100644 --- a/live/src/main/java/com/yunbao/live/activity/SudSwGameActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/SudSwGameActivity.java @@ -79,11 +79,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Locale; -import cn.rongcloud.rtc.api.RCRTCEngine; -import cn.rongcloud.rtc.api.RCRTCRemoteUser; -import cn.rongcloud.rtc.api.RCRTCRoom; -import cn.rongcloud.rtc.api.stream.RCRTCInputStream; -import cn.rongcloud.rtc.base.RTCErrorCode; import io.agora.beautyapi.faceunity.agora.SWAuManager; import io.rong.imlib.IRongCoreCallback; import io.rong.imlib.IRongCoreEnum; @@ -108,7 +103,6 @@ public class SudSwGameActivity extends AbsActivity implements GameSwMicManager.M private ProcessResultUtil mProcessResultUtil; private List muteUser = new ArrayList<>(); private boolean imOff; - private boolean isSw = CommonAppConfig.getInstance().getConfig().isSw(); private SudGameDoubleDialog sudGameDoubleDialog;//双人游戏弹窗 private SudGameMultipleDialog sudGameMultipleDialog;//多人游戏弹窗 private SudLoadDialog sudLoadDialog;//加载弹窗 @@ -150,8 +144,6 @@ public class SudSwGameActivity extends AbsActivity implements GameSwMicManager.M } }); - // 设置禁用麦克风采集 - //RCRTCEngine.getInstance().getDefaultAudioStream().setMicrophoneDisable(disable); ImgLoader.display(mContext, R.mipmap.icon_game_close_wheat, gameCloseWheat); gameCloseWheat.setVisibility(View.INVISIBLE); @@ -160,8 +152,6 @@ public class SudSwGameActivity extends AbsActivity implements GameSwMicManager.M @Override public void onSuccess(RoomMicStatusModel data) { gameMicManager = new GameSwMicManager(); - gameMicManager.attachView(SudSwGameActivity.this); - gameMicManager.config(SudSwGameActivity.this); //初始化声网引擎 SWAuManager.get().initRtcEngineAudio(mContext); //语音 @@ -196,13 +186,8 @@ public class SudSwGameActivity extends AbsActivity implements GameSwMicManager.M chatList.setVisibility(View.GONE); } gameMicManager.setmRoomID(mLiveUid); - if (isSw) { - SWAuManager.get().joinAudioRoom("v" + mLiveUid, CommonAppConfig.SWToken, Integer.parseInt(CommonAppConfig.getInstance().getUid())); - onJoinRoomSuccess(null); - onJoinSuccess(); - } else { - gameMicManager.joinRoom(mLiveUid, imOff); - } + SWAuManager.get().joinAudioRoom("v" + mLiveUid, CommonAppConfig.SWToken, Integer.parseInt(CommonAppConfig.getInstance().getUid())); + onJoinSuccess(); } @Override @@ -242,7 +227,7 @@ public class SudSwGameActivity extends AbsActivity implements GameSwMicManager.M @Override protected void onDestroy() { - if(isActivityGame){ + if (isActivityGame) { RandomSudGameManager.getManager().destroy(); } LiveNetManager.get(mContext).leaveMic(mLiveUid, new HttpCallback() { @@ -256,11 +241,8 @@ public class SudSwGameActivity extends AbsActivity implements GameSwMicManager.M } }); - if (isSw) { - SWAuManager.get().exitChannelAll(); - } + SWAuManager.get().exitChannelAll(); if (gameMicManager != null) { - gameMicManager.leaveRoom(); gameMicManager.detachView(); } @@ -308,13 +290,9 @@ public class SudSwGameActivity extends AbsActivity implements GameSwMicManager.M @Override public void unMute(String userID, int position) { if (!TextUtils.equals(String.valueOf(IMLoginManager.get(mContext).getUserInfo().getId()), userID)) { - if (isSw) { - //靜音 - SWAuManager.get().setMicAudio(Integer.parseInt(userID), false); - onSubscribeSuccess(userID, false, position); - } else { - gameMicManager.refreshStreams(userID, false, position); - } + //靜音 + SWAuManager.get().setMicAudio(Integer.parseInt(userID), false); + onSubscribeSuccess(userID, false, position); } else { ToastUtil.show(WordUtil.isNewZh() ? "無法對本人靜音" : "Unable to mute myself"); } @@ -325,13 +303,9 @@ public class SudSwGameActivity extends AbsActivity implements GameSwMicManager.M public void mute(String userID, int position) { muteUser.add(userID); if (!TextUtils.equals(String.valueOf(IMLoginManager.get(mContext).getUserInfo().getId()), userID)) { - if (isSw) { - //开启声音 - SWAuManager.get().setMicAudio(Integer.parseInt(userID), true); - onSubscribeSuccess(userID, true, position); - } else { - gameMicManager.refreshStreams(userID, true, position); - } + //开启声音 + SWAuManager.get().setMicAudio(Integer.parseInt(userID), true); + onSubscribeSuccess(userID, true, position); } else { ToastUtil.show(WordUtil.isNewZh() ? "無法對本人靜音" : "Unable to mute myself"); } @@ -378,26 +352,16 @@ public class SudSwGameActivity extends AbsActivity implements GameSwMicManager.M if (publishDefault) { disable = true; // 设置禁用麦克风采集 - if (isSw) { - //下麥 - SWAuManager.get().setMicAn(false); - onUnPublishStreamsSuccess(); - } else { - RCRTCEngine.getInstance().getDefaultAudioStream().setMicrophoneDisable(disable); -// ImgLoader.display(mContext, R.mipmap.icon_game_close_wheat, gameCloseWheat); - gameMicManager.unPublishStreams(); - } + //下麥 + SWAuManager.get().setMicAn(false); + onUnPublishStreamsSuccess(); } else { if (sudGameUserListAdapter.isMicMax()) { ToastUtil.show(WordUtil.isNewZh() ? "上麥人數最大7人" : "The maximum number of people on the microphone is 7"); } else { //上麦 - if (isSw) { - SWAuManager.get().setMicAn(true); - onPublishSuccess(); - } else { - gameMicManager.publishDefaultAVStream(); - } + SWAuManager.get().setMicAn(true); + onPublishSuccess(); } } } else { @@ -422,11 +386,7 @@ public class SudSwGameActivity extends AbsActivity implements GameSwMicManager.M if (disable) { disable = false; // 设置禁用麦克风采集 - if (isSw) { - SWAuManager.get().setMicAn(true); - } else { - RCRTCEngine.getInstance().getDefaultAudioStream().setMicrophoneDisable(disable); - } + SWAuManager.get().setMicAn(true); ImgLoader.display(mContext, R.mipmap.icon_game_open_wheat, gameCloseWheat); LiveNetManager.get(mContext).onMic(mLiveUid, new HttpCallback() { @Override @@ -442,12 +402,7 @@ public class SudSwGameActivity extends AbsActivity implements GameSwMicManager.M ToastUtil.show(WordUtil.isNewZh() ? "麥克風已開啟" : "Microphone turned on"); } else { disable = true; - // 设置禁用麦克风采集 - if (isSw) { - SWAuManager.get().setMicAn(false); - } else { - RCRTCEngine.getInstance().getDefaultAudioStream().setMicrophoneDisable(disable); - } + SWAuManager.get().setMicAn(false); ImgLoader.display(mContext, R.mipmap.icon_game_close_wheat, gameCloseWheat); LiveNetManager.get(mContext).offMic(mLiveUid, new HttpCallback() { @Override @@ -553,29 +508,28 @@ public class SudSwGameActivity extends AbsActivity implements GameSwMicManager.M Bus.get().post(new CheckRemainingBalanceEvent(null).setSudMGPMGState(SudMGPMGState.MG_COMMON_SELF_CLICK_GAME_SETTLE_AGAIN_BTN).setSubReady(false)); } }); - LiveNetManager.get(mContext) - .checkGameForActivity(gameViewModel.getGameRoomId(), new HttpCallback<>() { - @Override - public void onSuccess(SudGameActivityInfoRoomBean data) { - isActivityGame = data.getIsActivity() == 1; - if (isActivityGame) { - sudGameDoubleDialog.setActivityGame(); - sudLoadDialog.setActivityGame(); - } - if (isActivityGame) { - RandomSudGameManager.getManager().setGameViewModel(gameViewModel); - } - //通知活动游戏 - if (isActivityGame) { - RandomSudGameManager.getManager().onInitGame(mCreateSudRoomModel); - } - } + LiveNetManager.get(mContext).checkGameForActivity(gameViewModel.getGameRoomId(), new HttpCallback<>() { + @Override + public void onSuccess(SudGameActivityInfoRoomBean data) { + isActivityGame = data.getIsActivity() == 1; + if (isActivityGame) { + sudGameDoubleDialog.setActivityGame(); + sudLoadDialog.setActivityGame(); + } + if (isActivityGame) { + RandomSudGameManager.getManager().setGameViewModel(gameViewModel); + } + //通知活动游戏 + if (isActivityGame) { + RandomSudGameManager.getManager().onInitGame(mCreateSudRoomModel); + } + } - @Override - public void onError(String error) { + @Override + public void onError(String error) { - } - }); + } + }); } @@ -632,8 +586,8 @@ public class SudSwGameActivity extends AbsActivity implements GameSwMicManager.M LiveNetManager.get(mContext).checkGameForActivity(mCreateSudRoomModel.getSudGameRoomId(), new HttpCallback() { @Override public void onSuccess(SudGameActivityInfoRoomBean data) { - isActivityGame=data.getIsActivity()==1; - if(isActivityGame) { + isActivityGame = data.getIsActivity() == 1; + if (isActivityGame) { sudLoadDialog.setActivityGame(); sudGameDoubleDialog.setActivityGame(); } @@ -677,12 +631,11 @@ public class SudSwGameActivity extends AbsActivity implements GameSwMicManager.M } private void showDialog() { - DialogUitl.showSimpleDialog(mContext, WordUtil.isNewZh() ? "結算超時\n請前往活動頁面查看本局結果" : - "Settlement timed out\nPlease check the result on the event page Confirm.", new DialogUitl.SimpleCallback() { + DialogUitl.showSimpleDialog(mContext, WordUtil.isNewZh() ? "結算超時\n請前往活動頁面查看本局結果" : "Settlement timed out\nPlease check the result on the event page Confirm.", new DialogUitl.SimpleCallback() { @Override public void onConfirmClick(Dialog dialog, String content) { dialog.dismiss(); - if(sudLoadDialog.isShow()){ + if (sudLoadDialog.isShow()) { sudLoadDialog.dismiss(); } } @@ -695,25 +648,24 @@ public class SudSwGameActivity extends AbsActivity implements GameSwMicManager.M showDialog(); return; } - LiveNetManager.get(mContext) - .ballClearanceTableGetResultScore(mCreateSudRoomModel.getSudGameRoomId(), new HttpCallback<>() { - @Override - public void onSuccess(List data) { - if (data.isEmpty() && isActivityGame) { - new Handler(Looper.getMainLooper()).postDelayed(() -> { - loadScore(infoBean, index - 1); - }, 500); - return; - } - gameViewModel.setSudGameInfoBeanList(infoBean); - gameViewModel.sudGameRank(event.getMgCommonGameSettle(data));//结算游戏 - } + LiveNetManager.get(mContext).ballClearanceTableGetResultScore(mCreateSudRoomModel.getSudGameRoomId(), new HttpCallback<>() { + @Override + public void onSuccess(List data) { + if (data.isEmpty() && isActivityGame) { + new Handler(Looper.getMainLooper()).postDelayed(() -> { + loadScore(infoBean, index - 1); + }, 500); + return; + } + gameViewModel.setSudGameInfoBeanList(infoBean); + gameViewModel.sudGameRank(event.getMgCommonGameSettle(data));//结算游戏 + } - @Override - public void onError(String error) { + @Override + public void onError(String error) { - } - }); + } + }); } @Override @@ -753,30 +705,6 @@ public class SudSwGameActivity extends AbsActivity implements GameSwMicManager.M } } - - @Override - public void onJoinRoomSuccess(RCRTCRoom rcrtcRoom) { - LiveNetManager.get(mContext).getRoomMicData(mLiveUid, new HttpCallback>() { - @Override - public void onSuccess(List data) { - gameMicManager.refreshStreams(data); - sudGameUserListAdapter.refreshSudGameUserList(data, muteUser); - } - - @Override - public void onError(String error) { - ToastUtil.show(error); - } - }); - // 主动订阅远端用户发布的资源 -// gameMicManager.subscribeAVStream(); - } - - @Override - public void onJoinRoomFailed(RTCErrorCode rtcErrorCode) { - ToastUtil.show("加入失败 " + rtcErrorCode.toString()); - } - @Override public void onPublishSuccess() { runOnUiThread(new Runnable() { @@ -786,8 +714,6 @@ public class SudSwGameActivity extends AbsActivity implements GameSwMicManager.M publishDefault = true; gameCloseWheat.setVisibility(View.VISIBLE); disable = false; - // 设置禁用麦克风采集 - RCRTCEngine.getInstance().getDefaultAudioStream().setMicrophoneDisable(disable); ImgLoader.display(mContext, R.mipmap.icon_game_open_wheat, gameCloseWheat); } }); @@ -805,21 +731,6 @@ public class SudSwGameActivity extends AbsActivity implements GameSwMicManager.M }); } - @Override - public void onPublishFailed() { - ToastUtil.show(WordUtil.isNewZh() ? "語音加入失敗" : "Voice joining failed"); - } - - @Override - public void onSubscribeSuccess(List inputStreamList) { -// ToastUtil.show("订阅成功 "); - } - - @Override - public void onSubscribeFailed() { - ToastUtil.show("订阅失败 "); - } - @Override public void onSubscribeSuccess(String userID, boolean mute, int position) { runOnUiThread(new Runnable() { @@ -836,31 +747,6 @@ public class SudSwGameActivity extends AbsActivity implements GameSwMicManager.M } - @Override - public void onSubscribeFailed(String userID) { - ToastUtil.show("订阅失败 "); - } - - @Override - public void onUserJoined(RCRTCRemoteUser rcrtcRemoteUser) { - - } - - @Override - public void onUserLeft(RCRTCRemoteUser rcrtcRemoteUser) { - - } - - @Override - public void insertItem(SudGameChatImModel sudGameChatImModel) { - mLiveChatAdapter.insertItem(sudGameChatImModel); - } - - @Override - public void refreshSudGameUserList(List personList) { - sudGameUserListAdapter.refreshSudGameUserList(personList, muteUser); - } - @Override public void onUnPublishStreamsSuccess() { runOnUiThread(new Runnable() { @@ -885,14 +771,8 @@ public class SudSwGameActivity extends AbsActivity implements GameSwMicManager.M } - @Override - public void onUnPublishStreamsFailed() { - - } - @Subscribe(threadMode = ThreadMode.MAIN) public void onSudGameSocketImEvent(SudGameSocketImEvent event) { - gameMicManager.processingMessage(event); } @Subscribe(threadMode = ThreadMode.MAIN) diff --git a/live/src/main/java/com/yunbao/live/adapter/FreePkRecyclerAdapter.java b/live/src/main/java/com/yunbao/live/adapter/FreePkRecyclerAdapter.java index 24633465c..2ffcd0cec 100644 --- a/live/src/main/java/com/yunbao/live/adapter/FreePkRecyclerAdapter.java +++ b/live/src/main/java/com/yunbao/live/adapter/FreePkRecyclerAdapter.java @@ -27,7 +27,6 @@ import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.utils.WordUtil; import com.yunbao.common.views.weight.ViewClicksAntiShake; import com.yunbao.live.R; -import com.yunbao.live.activity.LiveRyAnchorActivity; import com.yunbao.live.activity.LiveSwAnchorActivity; import java.util.Arrays; @@ -168,8 +167,6 @@ public class FreePkRecyclerAdapter extends RefreshAdapter { if (yaoqing.size() < 5) { if(mContext instanceof LiveSwAnchorActivity){ ((LiveSwAnchorActivity) mContext).linkDrMicAnchorApply(bean.getId(), bean.getId()); - }else{ - ((LiveRyAnchorActivity) mContext).linkDrMicAnchorApply(bean.getId(), bean.getId()); } } else { ToastUtil.show(WordUtil.isNewZh() ? "多人PK最大參與人數為4人" : "The maximum number of participants in a multiplayer PK is 4 people"); @@ -205,10 +202,6 @@ public class FreePkRecyclerAdapter extends RefreshAdapter { if(mContext instanceof LiveSwAnchorActivity){ ((LiveSwAnchorActivity) mContext).linkMicAnchorApply(bean.getId(), bean.getId(), false); - }else{ - ((LiveRyAnchorActivity) mContext).linkMicAnchorApply(bean.getId(), bean.getId(), - ((LiveRyAnchorActivity) mContext).buildLinkMicJSON().toString() - ); } } } else { diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveLinkMicListDialogFragment.java b/live/src/main/java/com/yunbao/live/dialog/LiveLinkMicListDialogFragment.java index 1b30576b6..b5103be2c 100644 --- a/live/src/main/java/com/yunbao/live/dialog/LiveLinkMicListDialogFragment.java +++ b/live/src/main/java/com/yunbao/live/dialog/LiveLinkMicListDialogFragment.java @@ -29,8 +29,6 @@ import com.yunbao.common.utils.Bus; import com.yunbao.common.utils.DpUtil; import com.yunbao.common.utils.ToastUtil; import com.yunbao.live.R; -import com.yunbao.live.activity.LiveAnchorActivity; -import com.yunbao.live.activity.LiveRyAnchorActivity; import com.yunbao.live.activity.LiveSwAnchorActivity; import com.yunbao.live.adapter.LivePkAdapter; import com.yunbao.live.bean.LivePkBean; @@ -354,22 +352,16 @@ public class LiveLinkMicListDialogFragment extends AbsDialogFragment implements // ToastUtil.show("多人"); if(mContext instanceof LiveSwAnchorActivity){ ((LiveSwAnchorActivity) mContext).linkDrMicAnchorApply(bean.getUid(), bean.getStream()); - }else{ - ((LiveRyAnchorActivity) mContext).linkDrMicAnchorApply(bean.getUid(), bean.getStream()); } }else { // ToastUtil.show("单人"); if(mContext instanceof LiveSwAnchorActivity){ ((LiveSwAnchorActivity) mContext).linkMicAnchorApply(bean.getUid(), bean.getStream()); - }else{ - ((LiveRyAnchorActivity) mContext).linkMicAnchorApply(bean.getUid(), bean.getStream()); } } }else{ if(mContext instanceof LiveSwAnchorActivity){ ((LiveSwAnchorActivity) mContext).linkMicAnchorApply(bean.getUid(), bean.getStream()); - }else{ - ((LiveRyAnchorActivity) mContext).linkMicAnchorApply(bean.getUid(), bean.getStream()); } } dismiss(); diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveNewFunctionDialogFragment.java b/live/src/main/java/com/yunbao/live/dialog/LiveNewFunctionDialogFragment.java index 863c0e2c1..daeb4326f 100644 --- a/live/src/main/java/com/yunbao/live/dialog/LiveNewFunctionDialogFragment.java +++ b/live/src/main/java/com/yunbao/live/dialog/LiveNewFunctionDialogFragment.java @@ -37,7 +37,6 @@ import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.utils.WordUtil; import com.yunbao.common.views.LiveAnchorMessageCustomPopup; import com.yunbao.live.R; -import com.yunbao.live.activity.LiveRyAnchorActivity; import com.yunbao.live.activity.LiveSwAnchorActivity; import com.yunbao.live.interfaces.LiveFunctionClickListener; @@ -160,8 +159,6 @@ public class LiveNewFunctionDialogFragment extends AbsDialogFragment implements // }else{ if (mContext instanceof LiveSwAnchorActivity) { ((LiveSwAnchorActivity) mContext).setBtnFunctionDark(); - } else { - ((LiveRyAnchorActivity) mContext).setBtnFunctionDark(); } // } super.onDestroy(); @@ -224,8 +221,6 @@ public class LiveNewFunctionDialogFragment extends AbsDialogFragment implements public void run() { if (mContext instanceof LiveSwAnchorActivity) { ((LiveSwAnchorActivity) (mContext)).mLiveRoomViewHolder.initAnchorSayData(); - } else { - ((LiveRyAnchorActivity) (mContext)).mLiveRoomViewHolder.initAnchorSayData(); } } }, 1000); diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveOldUserDialogFragment.java b/live/src/main/java/com/yunbao/live/dialog/LiveOldUserDialogFragment.java index a6e869833..63b833bac 100644 --- a/live/src/main/java/com/yunbao/live/dialog/LiveOldUserDialogFragment.java +++ b/live/src/main/java/com/yunbao/live/dialog/LiveOldUserDialogFragment.java @@ -25,7 +25,6 @@ import com.opensource.svgaplayer.SVGAParser; import com.opensource.svgaplayer.SVGAVideoEntity; import com.yunbao.common.CommonAppConfig; import com.yunbao.common.Constants; -import com.yunbao.common.bean.LevelBean; import com.yunbao.common.bean.LiveBean; import com.yunbao.common.bean.NewLevelModel; import com.yunbao.common.bean.UserBean; @@ -47,8 +46,6 @@ import com.yunbao.common.utils.ToastUtil; import com.yunbao.live.R; import com.yunbao.live.activity.LiveActivity; import com.yunbao.live.activity.LiveReportActivity; -import com.yunbao.live.activity.LiveRyAnchorActivity; -import com.yunbao.live.activity.LiveSwAnchorActivity; import com.yunbao.live.bean.ImpressBean; import com.yunbao.live.custom.MyTextView; import com.yunbao.live.utils.LiveTextRender; diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveWishListDialogFragment.java b/live/src/main/java/com/yunbao/live/dialog/LiveWishListDialogFragment.java index 616fdd1f0..b53aa84b2 100644 --- a/live/src/main/java/com/yunbao/live/dialog/LiveWishListDialogFragment.java +++ b/live/src/main/java/com/yunbao/live/dialog/LiveWishListDialogFragment.java @@ -20,8 +20,6 @@ import com.yunbao.common.utils.DpUtil; import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.utils.WordUtil; import com.yunbao.live.R; -import com.yunbao.live.activity.LiveAnchorActivity; -import com.yunbao.live.activity.LiveRyAnchorActivity; import com.yunbao.live.activity.LiveSwAnchorActivity; import com.yunbao.live.adapter.LiveWishListAdapter; import com.yunbao.live.bean.LiveWishlistBean; @@ -195,8 +193,6 @@ public class LiveWishListDialogFragment extends AbsDialogFragment implements OnI Log.e("ry",getTag()); if(mContext instanceof LiveSwAnchorActivity){ fragment.show(((LiveSwAnchorActivity) mContext).getSupportFragmentManager(), "LiveGiftDialogFragment"); - }else{ - fragment.show(((LiveRyAnchorActivity) mContext).getSupportFragmentManager(), "LiveGiftDialogFragment"); } } diff --git a/live/src/main/java/com/yunbao/live/dialog/RandomPkDialogFragment.java b/live/src/main/java/com/yunbao/live/dialog/RandomPkDialogFragment.java index 53f09285d..c5582c607 100644 --- a/live/src/main/java/com/yunbao/live/dialog/RandomPkDialogFragment.java +++ b/live/src/main/java/com/yunbao/live/dialog/RandomPkDialogFragment.java @@ -22,7 +22,6 @@ import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.utils.WordUtil; import com.yunbao.live.R; import com.yunbao.common.manager.RandomPkManager; -import com.yunbao.live.activity.LiveRyAnchorActivity; import com.yunbao.live.activity.LiveSwAnchorActivity; import com.yunbao.common.http.LiveHttpUtil; @@ -269,7 +268,7 @@ public class RandomPkDialogFragment extends AbsDialogFragment implements View.On RandomPkManager.getInstance().exitPk(); return; } - LiveHttpUtil.getMicList(isSw?LiveSwAnchorActivity.mLiveUid: LiveRyAnchorActivity.mLiveUid, 0, new HttpCallback() { + LiveHttpUtil.getMicList(LiveSwAnchorActivity.mLiveUid, 0, new HttpCallback() { @Override public void onSuccess(int code, String msg, String[] info) { System.out.println("code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info)); diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java deleted file mode 100644 index 039232dcc..000000000 --- a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java +++ /dev/null @@ -1,2778 +0,0 @@ -package com.yunbao.live.presenter; - -import static com.lzy.okgo.utils.HttpUtils.runOnUiThread; -import static com.yunbao.common.Constants.SOCKET_LINK_MIC_PK; -import static com.yunbao.common.Constants.SOCKET_LIVE_DRPK; -import static com.yunbao.live.activity.LiveRyAnchorActivity.PKing; -import static com.yunbao.live.activity.LiveRyAnchorActivity.isDRPK; -import static com.yunbao.live.views.LivePushRyViewHolder.btn_close; -import static com.yunbao.live.views.LivePushRyViewHolder.contexts; -import static com.yunbao.live.views.LivePushRyViewHolder.rcrtcLiveInfo; -import static com.yunbao.live.views.LivePushRyViewHolder.rtcRoom; -import static cn.rongcloud.rtc.core.RendererCommon.ScalingType.SCALE_ASPECT_FILL; - -import android.app.Dialog; -import android.content.Context; -import android.graphics.Bitmap; -import android.graphics.Canvas; -import android.graphics.Color; -import android.graphics.Paint; -import android.graphics.drawable.ColorDrawable; -import android.os.Handler; -import android.os.Looper; -import android.os.Message; -import android.os.SystemClock; -import android.text.Html; -import android.text.TextUtils; -import android.util.Log; -import android.view.Gravity; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.PopupWindow; -import android.widget.RelativeLayout; -import android.widget.TextView; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.tencent.trtc.TRTCCloud; -import com.yunbao.common.CommonAppConfig; -import com.yunbao.common.bean.LiveInfoModel; -import com.yunbao.common.bean.UserBean; -import com.yunbao.common.event.AnchorInfoEvent; -import com.yunbao.common.glide.ImgLoader; -import com.yunbao.common.http.HttpCallback; -import com.yunbao.common.http.HttpClient; -import com.yunbao.common.http.LiveHttpUtil; -import com.yunbao.common.http.live.LiveNetManager; -import com.yunbao.common.manager.IMLoginManager; -import com.yunbao.common.manager.IMRTCManager; -import com.yunbao.common.manager.RandomPkManager; -import com.yunbao.common.manager.imrongcloud.RongcloudIMManager; -import com.yunbao.common.utils.Bus; -import com.yunbao.common.utils.DialogUitl; -import com.yunbao.common.utils.DpUtil; -import com.yunbao.common.utils.L; -import com.yunbao.common.utils.ScreenDimenUtil; -import com.yunbao.common.utils.StringUtil; -import com.yunbao.common.utils.ToastUtil; -import com.yunbao.common.utils.WordUtil; -import com.yunbao.live.R; -import com.yunbao.live.activity.LiveAudienceActivity; -import com.yunbao.live.activity.LiveRyAnchorActivity; -import com.yunbao.live.bean.LivePKUserListBean; -import com.yunbao.live.custom.ProgressTextView; -import com.yunbao.live.event.LiveAudienceEvent; -import com.yunbao.live.interfaces.ILiveLinkMicViewHolder; -import com.yunbao.live.socket.SocketRyClient; -import com.yunbao.live.socket.SocketRyLinkMicPkUtil; -import com.yunbao.live.socket.SocketSendBean; -import com.yunbao.live.views.LiveLinkMicPkViewHolder; -import com.yunbao.live.views.LivePushRyViewHolder; -import com.yunbao.live.views.LiveRoomViewHolder; - -import org.greenrobot.eventbus.EventBus; - -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Date; -import java.util.List; -import java.util.Locale; -import java.util.Timer; -import java.util.TimerTask; - -import cn.rongcloud.rtc.api.RCRTCEngine; -import cn.rongcloud.rtc.api.RCRTCMixConfig; -import cn.rongcloud.rtc.api.RCRTCOtherRoom; -import cn.rongcloud.rtc.api.RCRTCRemoteUser; -import cn.rongcloud.rtc.api.callback.IRCRTCOtherRoomEventsListener; -import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback; -import cn.rongcloud.rtc.api.callback.IRCRTCResultDataCallback; -import cn.rongcloud.rtc.api.stream.RCRTCInputStream; -import cn.rongcloud.rtc.api.stream.RCRTCVideoInputStream; -import cn.rongcloud.rtc.api.stream.RCRTCVideoStreamConfig; -import cn.rongcloud.rtc.api.stream.RCRTCVideoView; -import cn.rongcloud.rtc.base.RCRTCMediaType; -import cn.rongcloud.rtc.base.RCRTCRoomType; -import cn.rongcloud.rtc.base.RCRTCStream; -import cn.rongcloud.rtc.base.RTCErrorCode; -import io.rong.imlib.IRongCallback; -import io.rong.imlib.RongIMClient; -import io.rong.imlib.model.Conversation; -import io.rong.message.TextMessage; - -//import cn.rongcloud.rtc.jni.video.RCRect; - -/** - * Created by cxf on 2018/11/16. - * 主播与主播PK逻辑 - */ - -public class LiveRyLinkMicPkPresenter extends AbsLinkMicPkPresenter implements View.OnClickListener { - - private static final int WHAT_PK_WAIT_RECEIVE = 0;//收到pk申请等待 what - private static final int WHAT_PK_WAIT_SEND = 1;//发送pk申请等待 what - private static final int WHAT_PK_TIME = 2;//pk时间变化 what - private static final int WHAT_PK_TIME2 = 22;//pk时间变化 what - private static final int LINK_MIC_COUNT_MAX = 10; - private static int PK_TIME_MAX = 60 * 15;//pk时间 15分钟 - private static final int PK_TIME_MAX_2 = 60;//惩罚时间 1分钟 - private Context mContext; - private View mRoot; - private boolean mIsAnchor;//自己是否是主播 - private SocketRyClient mSocketRyClient; - private ViewGroup mPkContainer; - - private boolean mAcceptPk;//是否接受连麦 - private String mApplyStream;//正在申请Pk的主播的stream - private String mLiveUid;//自己主播的uid - private String mUrl;//主播的头像 - private ProgressTextView mLinkMicWaitProgress; - private int mPkWaitCount;//Pk弹窗等待倒计时Live - private int mPkTimeCount;//pk时间 - private PopupWindow mPkPopWindow; - private Handler mHandler; - private LiveLinkMicPkViewHolder mLiveLinkMicPkViewHolder; - private String mPkTimeString1; - private String mPkTimeString2; - private boolean mPkSend;//pk请求是否已经发送 - private int mPkSendWaitCount;//发送pk请求后的等待时间 - private String mSelfStream; - private int mPkTimeFromServer; - public static TRTCCloud mTRTCCloud1; - private View detailsView1, detailsView2, detailsView3, detailsView4; - private LinearLayout detailsLinearLayout1, detailsLinearLayout2, detailsLinearLayout3, detailsLinearLayout4; - private LinearLayout linearGrade1, linearGrade2, linearGrade3, linearGrade4; - private TextView textPkName1, textPkName2, textPkName3, textPkName4; - private TextView textGrade1, textGrade2, textGrade3, textGrade4; - private ImageView imageGrade1, imageGrade2, imageGrade3, imageGrade4; - - public LivePushRyViewHolder livePushRyViewHolder; - - public static List inputStreamList = new ArrayList<>(); - public static List inputStreamList1 = new ArrayList<>(); - private boolean DRInitiator = false;//是否是duorenPK发起人 - - public LiveRyLinkMicPkPresenter setDRInitiator(boolean DRInitiator) { - this.DRInitiator = DRInitiator; - return this; - } - - private IRCRTCOtherRoomEventsListener otherRoomEventsListener = new IRCRTCOtherRoomEventsListener() { - - @Override - public void onRemoteUserPublishResource(RCRTCOtherRoom room, RCRTCRemoteUser remoteUser, List streams) { - } - - @Override - public void onRemoteUserMuteAudio(RCRTCOtherRoom room, RCRTCRemoteUser remoteUser, RCRTCInputStream stream, boolean mute) { - } - - @Override - public void onRemoteUserMuteVideo(RCRTCOtherRoom room, RCRTCRemoteUser remoteUser, RCRTCInputStream stream, boolean mute) { - } - - @Override - public void onRemoteUserUnpublishResource(RCRTCOtherRoom room, RCRTCRemoteUser remoteUser, List streams) { - } - - @Override - public void onUserJoined(RCRTCOtherRoom room, RCRTCRemoteUser remoteUser) { - } - - @Override - public void onUserLeft(RCRTCOtherRoom room, RCRTCRemoteUser remoteUser) { - } - - @Override - public void onUserOffline(RCRTCOtherRoom room, RCRTCRemoteUser remoteUser) { - RCRTCEngine.getInstance().leaveOtherRoom(room.getRoomId(), true, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - } - }); - } - - @Override - public void onLeaveRoom(RCRTCOtherRoom room, int reasonCode) { - Log.d("RYM_DG", "Other onLeaveRoom: room = " + room.getRoomId()); - } - }; - - public LiveRyLinkMicPkPresenter(Context context, ILiveLinkMicViewHolder linkMicViewHolder, boolean isAnchor, View root) { - super(false); - mContext = context; - mIsAnchor = isAnchor; - mRoot = root; - mPkContainer = linkMicViewHolder.getPkContainer(); - mPkTimeString1 = ""; - mPkTimeString2 = mContext.getString(R.string.live_pk_time_2); - //从本地取数据 - String pkTime = CommonAppConfig.getInstance().getAnchorPkTime(); - if (!pkTime.isEmpty()) { - try { - int time = Integer.parseInt(pkTime) * 60; - if (time > 0) { - PK_TIME_MAX = time; - } - } catch (Exception e) { - e.printStackTrace(); - } - } - Log.d("PK_TIME_MAX", "" + PK_TIME_MAX); - mHandler = new Handler() { - @Override - public void handleMessage(Message msg) { - switch (msg.what) { - case WHAT_PK_WAIT_RECEIVE: - onApplyPkWait(); - break; - case WHAT_PK_WAIT_SEND: - onSendPkWait(); - break; - case WHAT_PK_TIME: - changePkTime(); - break; - - } - } - }; - - } - - - - - - public LiveRyLinkMicPkPresenter(Context context, LivePushRyViewHolder linkMicViewHolder, boolean isAnchor, View root) { - super(false); - mContext = context; - mIsAnchor = isAnchor; - mRoot = root; - mPkContainer = linkMicViewHolder.getPkContainer(); - livePushRyViewHolder = linkMicViewHolder; - mPkTimeString1 = ""; - mPkTimeString2 = mContext.getString(R.string.live_pk_time_2); - //从本地取数据 - String pkTime = CommonAppConfig.getInstance().getAnchorPkTime(); - if (!pkTime.isEmpty()) { - try { - int time = Integer.parseInt(pkTime) * 60; - if (time > 0) { - PK_TIME_MAX = time; - } - } catch (Exception e) { - e.printStackTrace(); - } - } - Log.d("PK_TIME_MAX", "" + PK_TIME_MAX); - mHandler = new Handler() { - @Override - public void handleMessage(Message msg) { - switch (msg.what) { - case WHAT_PK_WAIT_RECEIVE: - onApplyPkWait(); - break; - case WHAT_PK_WAIT_SEND: - onSendPkWait(); - break; - case WHAT_PK_TIME2: - pkCountdownTimer(); - break; - case WHAT_PK_TIME: - changePkTime(); - break; - } - } - }; - - } - - public void setSocketRyClient(SocketRyClient SocketRyClient) { - mSocketRyClient = SocketRyClient; - } - - public void setLiveUid(String liveUid, String url) { - Log.e("liveUid", liveUid); - mLiveUid = liveUid; - mUrl = url; - } - - - /** - * 申请pk弹窗倒计时 - */ - private void onApplyPkWait() { - mPkWaitCount--; - if (mPkWaitCount >= 0) { - if (mLinkMicWaitProgress != null) { - mLinkMicWaitProgress.setProgress(mPkWaitCount); - if (mHandler != null) { - mHandler.sendEmptyMessageAtTime(WHAT_PK_WAIT_RECEIVE, getNextSecondTime()); - } - } - } else { - if (mPkPopWindow != null) { - mPkPopWindow.dismiss(); - } - } - } - - /** - * 发送pk申请后等待倒计时 - */ - private void onSendPkWait() { - mPkSendWaitCount--; - if (mPkSendWaitCount >= 0) { - nextSendPkWaitCountDown(); - } else { - hideSendPkWait(); - if (mIsAnchor) { - ((LiveRyAnchorActivity) mContext).setPkBtnVisible(true); - } - } - } - - /** - * 进入下一次pk申请等待倒计时 - */ - private void nextSendPkWaitCountDown() { - if (mLiveLinkMicPkViewHolder != null) { - mLiveLinkMicPkViewHolder.setPkWaitProgress(mPkSendWaitCount); - } - if (mHandler != null) { - mHandler.sendEmptyMessageAtTime(WHAT_PK_WAIT_SEND, getNextSecondTime()); - } - } - - /** - * 隐藏pk申请等待 - */ - private void hideSendPkWait() { - mPkSend = false; - if (mHandler != null) { - mHandler.removeMessages(WHAT_PK_WAIT_SEND); - } - if (mLiveLinkMicPkViewHolder != null) { - mLiveLinkMicPkViewHolder.setPkWaitProgressVisible(false); - } - } - - /** - * 进入下一次pk倒计时 - */ - int i = 0; - - private void nextPkTimeCountDown(int is) { - - if (mHandler != null) { - mHandler.sendEmptyMessageAtTime(WHAT_PK_TIME, getNextSecondTime()); - } - if (mLiveLinkMicPkViewHolder != null) { - String s = mIsPkEnd ? mPkTimeString2 : mPkTimeString1; - String s1 = StringUtil.getDurationText(mPkTimeCount * 1000); - Log.i("tag23333", mPkTimeCount + "mPkTimeCount" + s1 + "is" + is); - if (i == 1 && s1.equals("00:01")) { - s1 = "00:00"; - i = 0; - } - if (rtcRoom != null) { - ScreenDimenUtil util = ScreenDimenUtil.getInstance(); - int mScreenWdith = util.getScreenWdith(); - LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, mScreenWdith * 720 / 960); - params.weight = 1; - params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); - livePushRyViewHolder.camera.setLayoutParams(params); - livePushRyViewHolder.mPreView1.setLayoutParams(params); - } - - Log.i("tts2", s1); - mLiveLinkMicPkViewHolder.setTime(s + " " + s1); - if (s1.equals("00:01") && mIsAnchor && !s.contains("懲罰")) { - HttpClient.getInstance().get("Livepk.endPK", "Livepk.endPK") - .params("uid", CommonAppConfig.getInstance().getUid()) - .params("addtime", "00:00") - .params("type", "0") - .params("sign", "1") - .execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - if (code == 0) { - JSONObject datas = JSONObject.parseObject(info[0]); - - SocketSendBean seed_msg = new SocketSendBean() - .param("_method_", SOCKET_LINK_MIC_PK) - .param("action", 9) - .param("msgtype", 10) - .param("win_uid", datas.getString("win_uid")) - .param("uid", CommonAppConfig.getInstance().getUid()); - seed_msg.create(); - String pkUid = datas.getString("pkuid"); - Log.i("seed", seed_msg.mResult.toString()); - - Log.e("ry1", datas.getString("win_uid") + "VVVVVV" + datas.getString("pkuid")); - - HttpClient.getInstance().post("Tx.sendmsgzs2", "Tx.sendmsgzs2") - .params("GroupId", "g" + pkUid) - .params("jsonstr", seed_msg.mResult.toString()) - .execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - HttpClient.getInstance().post("Tx.sendmsgzs2", "Tx.sendmsgzs2") - .params("GroupId", "g" + CommonAppConfig.getInstance().getUid()) - .params("jsonstr", seed_msg.mResult.toString()) - .execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - - } - }); - } - }); - - } - } - }); - } - - } - } - - - /** - * pk时间倒计时 - */ - private void changePkTime() { - if (mPkTimeCount < 0) return; - mPkTimeCount--; - Log.i("vvvs", "mPkTimeCount:" + mPkTimeCount); - if (mPkTimeCount >= 0) {// - nextPkTimeCountDown(1); - if (mContext instanceof LiveAudienceActivity) { - ((LiveAudienceActivity) mContext).setPkStatus(true); - } - } else { - if (mIsPkEnd) { - onLinkMicPkClose(0); - if (mIsAnchor) { - ((LiveRyAnchorActivity) mContext).setPkBtnVisible(true); - } - if (mContext instanceof LiveAudienceActivity) { - ((LiveAudienceActivity) mContext).setPkStatus(false); - } - //如果PK结束Im没有发送关闭PK的消息,倒计时结束自动关闭 -// if (mLiveLinkMicPkViewHolder != null) { -// mLiveLinkMicPkViewHolder.removeFromParent(); -// mLiveLinkMicPkViewHolder.release(); -// } -// mLiveLinkMicPkViewHolder = null; - } - } - } - - /** - * 获取下一秒钟的时间 - */ - private long getNextSecondTime() { - long now = SystemClock.uptimeMillis(); - return now + (1000 - now % 1000); - } - - /** - * 发起主播PK申请 - */ - public void applyLinkMicPk(String pkUid, String stream) { - if (mPkSend) { - ToastUtil.show(mContext.getString(R.string.link_mic_apply_waiting)); - return; - } - if (mIsPk) { - ToastUtil.show(mContext.getString(R.string.live_link_mic_cannot_pk)); - return; - } - mPkSend = true; - SocketRyLinkMicPkUtil.linkMicPkApply(mSocketRyClient, pkUid, stream); - ToastUtil.show(mContext.getString(R.string.link_mic_apply_pk)); - - if (mLiveLinkMicPkViewHolder == null) { - mLiveLinkMicPkViewHolder = new LiveLinkMicPkViewHolder(mContext, mPkContainer); - mLiveLinkMicPkViewHolder.addToParent(); - mLiveLinkMicPkViewHolder.setIsAnchor(mIsAnchor); - - } - mLiveLinkMicPkViewHolder.setPkWaitProgressVisible(true); - mPkSendWaitCount = LINK_MIC_COUNT_MAX; - nextSendPkWaitCountDown(); - if (mIsAnchor) { - ((LiveRyAnchorActivity) mContext).setPkBtnVisible(false); - } - } - - /** - * 主播与主播PK 主播收到其他主播发过来的多人PK申请同意了的回调 - */ - - public void onLinkDRMicPkApplyOk(UserBean u) { - /** - * 加入副房间 - * - * 前提必须已经 通过 {@link RCRTCEngine#joinRoom(String, RCRTCRoomType, IRCRTCResultDataCallback)} 或 {@link RCRTCEngine#joinRoom(String, IRCRTCResultDataCallback)} 加入了主房间 - * - * @param roomId 房间 ID ,长度 64 个字符,可包含:`A-Z`、`a-z`、`0-9`、`+`、`=`、`-`、`_` - * @param callBack 加入房间回调 - * @group 房间管理 - */ - RCRTCEngine.getInstance().joinOtherRoom("" + u.getId(), new IRCRTCResultDataCallback() { - @Override - public void onSuccess(RCRTCOtherRoom rcrtcOtherRoom) { - rcrtcOtherRoom.registerOtherRoomEventsListener(otherRoomEventsListener); - runOnUiThread(new Runnable() { - @Override - public void run() { - //遍历远端用户列表 - for (int i = 0; i < rcrtcOtherRoom.getRemoteUsers().size(); i++) { - //遍历远端用户发布的资源列表 - for (RCRTCInputStream stream : rcrtcOtherRoom.getRemoteUsers().get(i).getStreams()) { - if (stream.getMediaType() == RCRTCMediaType.VIDEO) { - //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 - - if (i == 1) { - //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 - RCRTCVideoView remoteView = new RCRTCVideoView(mContext); - ((RCRTCVideoInputStream) stream).setVideoView(remoteView); - livePushRyViewHolder.mPreView1.setVisibility(View.VISIBLE); - //todo 本demo只演示添加1个远端用户的视图 - livePushRyViewHolder.mPreView1.removeAllViews(); - remoteView.setScalingType(SCALE_ASPECT_FILL); - livePushRyViewHolder.mPreView1.addView(remoteView); - - } else if (i == 2) { - //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 -// RCRTCVideoView remoteView = new RCRTCVideoView(mContext); -// ((RCRTCVideoInputStream) stream).setVideoView(remoteView); -// //todo 本demo只演示添加1个远端用户的视图 -// LivePushRyViewHolder.dr2_preview.removeAllViews(); -// remoteView.setScalingType(SCALE_ASPECT_FILL); -// LivePushRyViewHolder.dr2_preview.addView(remoteView); - } else if (i == 3) { - //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 -// RCRTCVideoView remoteView = new RCRTCVideoView(mContext); -// ((RCRTCVideoInputStream) stream).setVideoView(remoteView); -// //todo 本demo只演示添加1个远端用户的视图 -// LivePushRyViewHolder.dr3_preview.removeAllViews(); -// remoteView.setScalingType(SCALE_ASPECT_FILL); -// LivePushRyViewHolder.dr3_preview.addView(remoteView); - } else if (i == 4) { - //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 -// RCRTCVideoView remoteView = new RCRTCVideoView(mContext); -// ((RCRTCVideoInputStream) stream).setVideoView(remoteView); -// //todo 本demo只演示添加1个远端用户的视图 -// LivePushRyViewHolder.dr4_preview.removeAllViews(); -// remoteView.setScalingType(SCALE_ASPECT_FILL); -// LivePushRyViewHolder.dr4_preview.addView(remoteView); - } - //如果要订阅所有远端用户的流。保存所有流信息,方便后面统一订阅 - inputStreamList.add(stream); - } - //如果要订阅所有远端用户的流。保存所有流信息,方便后面统一订阅 - inputStreamList1.add(stream); - } - } - //开始订阅资源 - rtcRoom.getLocalUser().subscribeStreams(inputStreamList1, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.i("ry", "订阅资源成功"); - - RCRTCMixConfig config = new RCRTCMixConfig(); - RCRTCMixConfig.MediaConfig mediaConfig = new RCRTCMixConfig.MediaConfig(); - config.setMediaConfig(mediaConfig); - //视频输出配置 - RCRTCMixConfig.MediaConfig.VideoConfig videoConfig = new RCRTCMixConfig.MediaConfig.VideoConfig(); - mediaConfig.setVideoConfig(videoConfig); - //大流视频的输出参数 - RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout normal = new RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout(); - videoConfig.setVideoLayout(normal); - //推荐宽、高、帧率参数值可以通过默认视频流的配置获取,也可以根据实际需求来自定义设置 - //如不设置宽高值则服务端将使用默认宽高 360 * 640 - //例:发布的视频分辨率为720 * 1280,如果不设置则观众端看到的视频分辨率为 360 * 640, - //所以如果想让观众端看到的视频分辨率和发布视频分辨率一致,则应从发布的视频流中获取分辨率配置并设置到 mediaConfig 中 - RCRTCVideoStreamConfig defaultVideoConfig = RCRTCEngine.getInstance().getDefaultVideoStream().getVideoConfig(); - int fps = defaultVideoConfig.getVideoFps().getFps(); - int width = 960; - int height = 720; - normal.setWidth(width); //视频宽 - normal.setHeight(height); //视频高 - normal.setFps(fps); //视频帧率 - - //1. 设置自适应合流布局模式 - config.setLayoutMode(RCRTCMixConfig.MixLayoutMode.ADAPTIVE); - //2. 合流画布设置 - if (rcrtcLiveInfo != null) { - rcrtcLiveInfo.setMixConfig(config, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.e("ry", "混成功" + u.getId()); - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.e("ry", "混失败" + errorCode); - - } - }); - } else { - Log.w("PkDebug", "PK合流失败,rcrtcLiveInfo为空"); - } - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - Log.i("ry", "订阅资源失败: " + rtcErrorCode.getReason()); - ToastUtil.show(mContext.getString(R.string.live_pk_link_error)); - } - }); - } - }); - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - Log.i("ry", "加入其他房间失败 :" + rtcErrorCode.getReason()); - } - }); - - } - - - - /** - * 主播与主播PK PK主播发过来的已经接受 - */ - public void onLinkMicToPk(UserBean u) { - EventBus.getDefault().post(new AnchorInfoEvent(false, u.getId(), u.getUserNiceName(), u.getAvatar())); - Log.e("eve", u.getId() + ""); - /** - * 加入副房间 - * - * 前提必须已经 通过 {@link RCRTCEngine#joinRoom(String, RCRTCRoomType, IRCRTCResultDataCallback)} 或 {@link RCRTCEngine#joinRoom(String, IRCRTCResultDataCallback)} 加入了主房间 - * - * @param roomId 房间 ID ,长度 64 个字符,可包含:`A-Z`、`a-z`、`0-9`、`+`、`=`、`-`、`_` - * @param callBack 加入房间回调 - * @group 房间管理 - */ - RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_START); - RCRTCEngine.getInstance().joinOtherRoom(u.getId(), new IRCRTCResultDataCallback() { - @Override - public void onSuccess(RCRTCOtherRoom rcrtcOtherRoom) { - rcrtcOtherRoom.registerOtherRoomEventsListener(otherRoomEventsListener); - new Handler(Looper.getMainLooper()).post(new Runnable() { - public void run() { - //遍历远端用户列表 - for (int i = 0; i < rcrtcOtherRoom.getRemoteUsers().size(); i++) { - //遍历远端用户发布的资源列表 - for (RCRTCInputStream stream : rcrtcOtherRoom.getRemoteUsers().get(i).getStreams()) { - Log.e("ry", stream.getMediaType() + "类型"); - if (stream.getMediaType() == RCRTCMediaType.VIDEO) { - //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 - RCRTCVideoView remoteView = new RCRTCVideoView(contexts); - ((RCRTCVideoInputStream) stream).setVideoView(remoteView); - //todo 本demo只演示添加1个远端用户的视图 - livePushRyViewHolder.mPreView1.removeAllViews(); - remoteView.setScalingType(SCALE_ASPECT_FILL); - livePushRyViewHolder.mPreView1.addView(remoteView); - } - //如果要订阅所有远端用户的流。保存所有流信息,方便后面统一订阅 - inputStreamList.add(stream); - - - RCRTCMixConfig config = new RCRTCMixConfig(); - RCRTCMixConfig.MediaConfig mediaConfig = new RCRTCMixConfig.MediaConfig(); - config.setMediaConfig(mediaConfig); -//视频输出配置 - RCRTCMixConfig.MediaConfig.VideoConfig videoConfig = new RCRTCMixConfig.MediaConfig.VideoConfig(); - mediaConfig.setVideoConfig(videoConfig); -//大流视频的输出参数 - RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout normal = new RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout(); - videoConfig.setVideoLayout(normal); -//推荐宽、高、帧率参数值可以通过默认视频流的配置获取,也可以根据实际需求来自定义设置 -//如不设置宽高值则服务端将使用默认宽高 360 * 640 -//例:发布的视频分辨率为720 * 1280,如果不设置则观众端看到的视频分辨率为 360 * 640, -//所以如果想让观众端看到的视频分辨率和发布视频分辨率一致,则应从发布的视频流中获取分辨率配置并设置到 mediaConfig 中 - RCRTCVideoStreamConfig defaultVideoConfig = RCRTCEngine.getInstance().getDefaultVideoStream().getVideoConfig(); - int fps = defaultVideoConfig.getVideoFps().getFps(); - int width = 960; - int height = 720; - normal.setWidth(width); //视频宽 - normal.setHeight(height); //视频高 - normal.setFps(fps); //视频帧率 - - //1. 设置自适应合流布局模式 - config.setLayoutMode(RCRTCMixConfig.MixLayoutMode.ADAPTIVE); - //2. 合流画布设置 - if (rcrtcLiveInfo == null) { - Log.w("PkDebug", "PK合流失败,rcrtcLiveInfo为空"); - } - rcrtcLiveInfo.setMixConfig(config, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.e("ry", "混成功13"); - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.e("ry", "混失败" + errorCode); - - } - }); - } - } - //开始订阅资源 - rtcRoom.getLocalUser().subscribeStreams(inputStreamList, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.i("ry", "订阅资源成功"); - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - Log.i("ry", "订阅资源失败: " + rtcErrorCode.getReason()); - ToastUtil.show(mContext.getString(R.string.live_pk_link_error)); - } - }); - } - }); - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - Log.i("ry", "11111加入其他房间失败 :" + rtcErrorCode.getReason()); - } - }); - LivePushRyViewHolder.btn_close.setVisibility(View.VISIBLE); - LiveRyAnchorActivity.isDRPK = 1; - ScreenDimenUtil util = ScreenDimenUtil.getInstance(); - int mScreenWdith = util.getScreenWdith(); - LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, mScreenWdith * 720 / 960); - params.weight = 1; - params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); - livePushRyViewHolder.camera.setLayoutParams(params); - livePushRyViewHolder.mPreView1.setLayoutParams(params); - livePushRyViewHolder.mPreView1.setVisibility(View.VISIBLE); - L.eSw("4444444444444444444444444444"); - final SocketSendBean msg1 = new SocketSendBean() - .param("_method_", SOCKET_LINK_MIC_PK) - .param("action", 4) - .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) - .param("pkuid", u.getId()) - .param("uid", CommonAppConfig.getInstance().getUid()) - .param("pkhead", u.getAvatar()) - .param("pkname", u.getUserNiceName()); - msg1.create(); - - Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; - TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); - io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain("g" + CommonAppConfig.getInstance().getUid(), conversationType, messageContent); - - RongcloudIMManager.sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { - @Override - public void onAttached(io.rong.imlib.model.Message message) { - - } - - @Override - public void onSuccess(io.rong.imlib.model.Message message) { - Log.e("tx", "发送成功"); - } - - @Override - public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { - Log.e("tx", "发送失败" + errorCode.getMessage()); - - } - }); - - } - - @Override - protected void isPK(UserBean bean) { - ScreenDimenUtil util = ScreenDimenUtil.getInstance(); - int mScreenWdith = util.getScreenWdith(); - LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, mScreenWdith * 720 / 960); - params.weight = 1; - params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); - livePushRyViewHolder.camera.setLayoutParams(params); - livePushRyViewHolder.mPreView1.setLayoutParams(params); - livePushRyViewHolder.mPreView1.setVisibility(View.VISIBLE); - LivePushRyViewHolder.btn_close.setVisibility(View.VISIBLE); - LiveRyAnchorActivity.isDRPK = 1; - - JSONObject msg1 = new JSONObject(); - msg1.put("uid", CommonAppConfig.getInstance().getUid()); - msg1.put("pkuid", CommonAppConfig.getInstance().getUid()); - msg1.put("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatarThumb()); - msg1.put("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); - EventBus.getDefault().post(new AnchorInfoEvent(false, bean.getId(), bean.getUserNiceName(), bean.getAvatar())); - - if (bean != null && bean.isRandomPk()) { - msg1.put("random_pk", bean.isRandomPk() ? 1 : 0); - msg1.put("is_ladders", bean.getRankPkImgUrl()); - } - System.out.println("PK回执 = " + msg1.toString()); - IMRTCManager.getInstance().responseJoinOtherRoom(mApplyUid, true, msg1.toString(), new IRCRTCResultCallback() { - @Override - public void onSuccess() { - RCRTCEngine.getInstance().joinOtherRoom(mApplyUid, new IRCRTCResultDataCallback() { - @Override - public void onSuccess(RCRTCOtherRoom rcrtcOtherRoom) { - rcrtcOtherRoom.registerOtherRoomEventsListener(otherRoomEventsListener); - ToastUtil.show(WordUtil.isNewZh() ? "接受成功" : "Success"); - new Handler(Looper.getMainLooper()).post(new Runnable() { - public void run() { - for (int i = 0; i < rcrtcOtherRoom.getRemoteUsers().size(); i++) { - //遍历远端用户发布的资源列表 - for (RCRTCInputStream stream : rcrtcOtherRoom.getRemoteUsers().get(i).getStreams()) { - if (stream.getMediaType() == RCRTCMediaType.VIDEO) { - //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 - RCRTCVideoView remoteView = new RCRTCVideoView(contexts); - ((RCRTCVideoInputStream) stream).setVideoView(remoteView); - //todo 本demo只演示添加1个远端用户的视图 - livePushRyViewHolder.mPreView1.removeAllViews(); - remoteView.setScalingType(SCALE_ASPECT_FILL); - livePushRyViewHolder.mPreView1.addView(remoteView); - } - //如果要订阅所有远端用户的流。保存所有流信息,方便后面统一订阅 - inputStreamList.add(stream); - } - } - - Log.e("ry", "asa" + inputStreamList.size()); - //开始订阅资源 - rtcRoom.getLocalUser().subscribeStreams(inputStreamList, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.i("ry", "订阅资源成功"); - List streams = new ArrayList<>(); - streams.add(RCRTCEngine.getInstance().getDefaultVideoStream()); - RCRTCMixConfig config = new RCRTCMixConfig(); - RCRTCMixConfig.MediaConfig mediaConfig = new RCRTCMixConfig.MediaConfig(); - config.setMediaConfig(mediaConfig); -//视频输出配置 - RCRTCMixConfig.MediaConfig.VideoConfig videoConfig = new RCRTCMixConfig.MediaConfig.VideoConfig(); - mediaConfig.setVideoConfig(videoConfig); -//大流视频的输出参数 - RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout normal = new RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout(); - videoConfig.setVideoLayout(normal); -//推荐宽、高、帧率参数值可以通过默认视频流的配置获取,也可以根据实际需求来自定义设置 -//如不设置宽高值则服务端将使用默认宽高 360 * 640 -//例:发布的视频分辨率为720 * 1280,如果不设置则观众端看到的视频分辨率为 360 * 640, -//所以如果想让观众端看到的视频分辨率和发布视频分辨率一致,则应从发布的视频流中获取分辨率配置并设置到 mediaConfig 中 - RCRTCVideoStreamConfig defaultVideoConfig = RCRTCEngine.getInstance().getDefaultVideoStream().getVideoConfig(); - int fps = defaultVideoConfig.getVideoFps().getFps(); - int width = 960; - int height = 720; - normal.setWidth(width); //视频宽 - normal.setHeight(height); //视频高 - normal.setFps(fps); //视频帧率 - - //1. 设置自适应合流布局模式 - config.setLayoutMode(RCRTCMixConfig.MixLayoutMode.ADAPTIVE); - //2. 合流画布设置 - rcrtcLiveInfo.setMixConfig(config, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.e("ry", "混成功14"); - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.e("ry", "混失败" + errorCode); - - } - }); - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - Log.i("ry", "订阅资源失败: " + rtcErrorCode); - ToastUtil.show(mContext.getString(R.string.live_pk_link_error)); - } - }); - } - }); - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - Log.e("ry", mApplyUid + "加入其他房间失败 :" + rtcErrorCode); - Log.i("ry", mApplyUid + "加入其他房间失败 :" + rtcErrorCode); - } - }); - - new Handler(Looper.getMainLooper()).post(new Runnable() { - public void run() { - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.UN_LEAVELIVE)); - LiveRyAnchorActivity.isDRPK = 1; - LivePushRyViewHolder.btn_close.setVisibility(View.VISIBLE); - SocketRyLinkMicPkUtil.linkMicPkAccept(mSocketRyClient, mApplyUid, mApplyUrl, mApplyNmae); - EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.UP_PK_TWO).setObject(mApplyUid)); - onLinkMicPkStart(mApplyUid, 2); - } - }); - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - ToastUtil.show("接受失败"); - } - }); - - } - - @Override - protected void onDRPkApply(UserBean u) { - HttpClient.getInstance().get("Livepk.changeLive", "Livepk.changeLive") - .params("uid", CommonAppConfig.getInstance().getUid()) - .params("pkuid", u.getId()) - .params("type", "1") - .params("sign", "1") - .execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msgs, String[] info) { - if (code == 0) { - Log.i("多人PK", "1code = " + code + ", msgs = " + msgs + ", info = " + Arrays.deepToString(info) + " mApplyUid = " + mApplyUid); - HttpClient.getInstance().get("live.getdrnum", "live.getdrnum") - .execute(new HttpCallback() { - - @Override - public void onSuccess(int code, String msg, String[] info) { - Log.i(TAG, "code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info)); - if (info.length > 0) { - - JSONObject datas = JSONObject.parseObject(info[0]); - boolean agree = true; - if (datas.getIntValue("pk_num_day") <= 0) { - ToastUtil.show("多人PK次数已用完"); - agree = false; - } - boolean finalAgree = agree; - IMRTCManager.getInstance().responseJoinOtherRoom(mApplyUid, agree, SOCKET_LIVE_DRPK, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - if (finalAgree == true) { - HttpClient.getInstance().get("live.joinDRPKroom", "live.joinDRPKroom") - .params("uid", CommonAppConfig.getInstance().getUid()) - .params("roomid", u.getId()) - .execute(new HttpCallback() { - - @Override - public void onSuccess(int code, String msg, String[] info) { - Log.i("多人PK", "code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info)); - - final SocketSendBean msg1 = new SocketSendBean() - .param("_method_", SOCKET_LIVE_DRPK) - .param("action", 10) - .param("uid", CommonAppConfig.getInstance().getUid()); - msg1.create(); - String targetId = "g" + CommonAppConfig.getInstance().getUid(); - Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; - TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); - io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); - - RongcloudIMManager.sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { - @Override - public void onAttached(io.rong.imlib.model.Message message) { - - } - - @Override - public void onSuccess(io.rong.imlib.model.Message message) { - Log.e("ry", "发送成功"); - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(msg1.mResult.toString() + ""); - } - } - - @Override - public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { - Log.e("ry", "发送失敗"); - } - }); - if (info.length == 0) { - return; - } - JSONObject obj = JSONObject.parseObject(info[0]); - JSONArray users = obj.getJSONArray("userlist"); - - //添加水印 -// RCRTCRect rect = new RCRTCRect(0.5f, 0.5f, 0.2f); -// RCRTCEngine.getInstance().getDefaultVideoStream().setWatermark(fromText(50, mNameText), rect); - dRjoinOtherRoom(u.getId(), 1); - - for (int i = 0; i < users.size(); i++) { - JSONObject user = users.getJSONObject(i); - Log.e("ry", mApplyUid + "VS" + user.getString("id") + "列表"); - if (!user.getString("id").equals(CommonAppConfig.getInstance().getUid())) { - if (!user.getString("id").equals(CommonAppConfig.getInstance().getUid()) && !user.getString("id").equals(u.getId())) { - /** - * 向指定用户发送跨房间连麦请求 - *

- * 1: inviterAutoMix为true时: - * - * 1.1:如果被邀请方在加入邀请方房间之前发布了资源,当被邀请方加入邀请者房间成功后,服务器会把被邀请方流资源合并到邀请方视图 ·(默认仅悬浮布局合流)上。 - * - * 1.2:如果被邀请方在加入邀请方房间之前没有发布过资源,将会在被邀请方发布资源成功后,服务器会把被邀请方流资源合并到邀请方视图(默认仅悬浮布局合流)上。 - * - * 2:无论为true或false,双方都可以使用{@link RCRTCLiveInfo#setMixConfig(RCRTCMixConfig, IRCRTCResultCallback)} 方法主动设置合流布局。一旦主动设置过合流布局,后续音视频直播过程中设置的自动合流参数将失效。 - *

- */ - IMRTCManager.getInstance().requestJoinOtherRoom(user.getString("id"), false, "LiveDRPK1", new IRCRTCResultCallback() { - @Override - public void onSuccess() { - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - - } - }); - } - } - } - //收起整蛊列表 - if(mLiveRoomViewHolder!=null){ - mLiveRoomViewHolder.closePrankView(); - } - } - }); - } - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - ToastUtil.show("接受失败"); - } - }); - } else { - ToastUtil.show(msg); - } - } - - }); - - - } - } - }); - - /*LiveHttpUtil.livePkCheckLive(u.getId(), "", "", new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - if (code == 0 && info.length > 0) { - JSONObject obj = JSON.parseObject(info[0]); - if (obj != null) { - if (obj.getString("ispk").equals("0")) { - - - }else{ - ToastUtil.show(mContext.getString(R.string.pking_over)); - } - } - } - }});*/ - } - - @Override - protected void onDRPkTimeout(UserBean u) { - IMRTCManager.getInstance().responseJoinOtherRoom(u.getId(), false, "extra", new IRCRTCResultCallback() { - - @Override - public void onFailed(RTCErrorCode errorCode) { - - } - - @Override - public void onSuccess() { - final SocketSendBean msg1 = new SocketSendBean() - .param("_method_", SOCKET_LINK_MIC_PK) - .param("action", 8); - msg1.create(); - - String targetId = u.getId(); - Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; - TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); - io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); - - RongcloudIMManager.sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { - @Override - public void onAttached(io.rong.imlib.model.Message message) { - - } - - @Override - public void onSuccess(io.rong.imlib.model.Message message) { - Log.e("ry", "发送成功"); - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(msg1.mResult.toString() + ""); - } - } - - @Override - public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { - Log.e("ry", "发送失敗" + mApplyUid); - } - }); - } - }); - } - - @Override - protected void onDRPkRefuse(UserBean u) { - IMRTCManager.getInstance().responseJoinOtherRoom(u.getId(), false, "extra", new IRCRTCResultCallback() { - - @Override - public void onFailed(RTCErrorCode errorCode) { - - } - - @Override - public void onSuccess() { - final SocketSendBean msg1 = new SocketSendBean() - .param("_method_", SOCKET_LINK_MIC_PK) - .param("action", 3); - msg1.create(); - - String targetId = u.getId(); - Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; - TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); - io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); - - RongcloudIMManager.sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { - @Override - public void onAttached(io.rong.imlib.model.Message message) { - - } - - @Override - public void onSuccess(io.rong.imlib.model.Message message) { - Log.e("ry", "发送成功"); - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(msg1.mResult.toString() + ""); - } - } - - @Override - public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { - Log.e("ry", "发送失敗"); - } - }); - } - }); - } - - @Override - protected void onPkApply(UserBean u) { - LiveHttpUtil.livePkCheckLive(u.getId(), "", "", new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - if (code == 0 && info.length > 0) { - JSONObject obj = JSON.parseObject(info[0]); - if (obj != null) { - if (obj.getString("ispk").equals("0")) { - isPKTmp(u); - } else { - ToastUtil.show(mContext.getString(R.string.pking_over)); - } - } - } - } - }); - } - - @Override - protected void onPkTimeout(UserBean u) { - rtcRoom.getLocalUser().responseJoinOtherRoom(u.getId(), u.getId(), false, false, "extra", new IRCRTCResultCallback() { - - @Override - public void onFailed(RTCErrorCode errorCode) { - - } - - @Override - public void onSuccess() { - final SocketSendBean msg1 = new SocketSendBean() - .param("_method_", SOCKET_LINK_MIC_PK) - .param("action", 8); - msg1.create(); - - String targetId = u.getId(); - Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; - TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); - io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); - - RongcloudIMManager.sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { - @Override - public void onAttached(io.rong.imlib.model.Message message) { - - } - - @Override - public void onSuccess(io.rong.imlib.model.Message message) { - - Log.e("ry", "发送成功"); - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(msg1.mResult.toString() + ""); - } - } - - @Override - public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { - Log.e("ry", "发送失敗" + u.getId()); - } - }); - } - }); - } - - @Override - protected void onPkRefuse(UserBean u) { - onPkTimeoutTmp(u); - } - - //与用户连麦 - public void setUserMic(String liveid) { - JSONObject msg1 = new JSONObject(); - msg1.put("uid", CommonAppConfig.getInstance().getUid()); - msg1.put("pkuid", CommonAppConfig.getInstance().getUid()); - msg1.put("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatarThumb()); - msg1.put("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); - - rtcRoom.getLocalUser().responseJoinOtherRoom(liveid, liveid, true, true, msg1.toString(), new IRCRTCResultCallback() { - @Override - public void onSuccess() { - RCRTCEngine.getInstance().joinOtherRoom(liveid, new IRCRTCResultDataCallback() { - @Override - public void onSuccess(RCRTCOtherRoom rcrtcOtherRoom) { - rcrtcOtherRoom.registerOtherRoomEventsListener(otherRoomEventsListener); - ToastUtil.show(WordUtil.isNewZh() ? "接受成功" : "Success"); - new Handler(Looper.getMainLooper()).post(new Runnable() { - public void run() { - Log.e("ry", liveid + "来了!!!!" + rcrtcOtherRoom.getRemoteUsers().size()); - for (int i = 0; i < rcrtcOtherRoom.getRemoteUsers().size(); i++) { - //遍历远端用户发布的资源列表 - for (RCRTCInputStream stream : rcrtcOtherRoom.getRemoteUsers().get(i).getStreams()) { - Log.e("ry", stream.getMediaType() + "rcrtcOtherRoom成功 :" + rcrtcOtherRoom.getRemoteUsers().size()); - if (stream.getMediaType() == RCRTCMediaType.AUDIO) { - //音频只需要订阅 - inputStreamList.add(stream); - } - } - } - - Log.e("ry", "asa" + inputStreamList.size()); - //开始订阅资源 - rtcRoom.getLocalUser().subscribeStreams(inputStreamList, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - - - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - Log.e("ry", "订阅资源失败: " + rtcErrorCode); - ToastUtil.show(mContext.getString(R.string.live_pk_link_error)); - } - }); - } - }); - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - Log.e("ry", liveid + "加入其他房间失败 :" + rtcErrorCode); - Log.i("ry", liveid + "加入其他房间失败 :" + rtcErrorCode); - } - }); - - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - ToastUtil.show("接受失败"); - } - }); - } - - /** - * 显示申请PK的弹窗 - */ - @Override - protected void showApplyDialog(UserBean u) { - mIsApplyDialogShow = true; - mAcceptPk = false; - View v = LayoutInflater.from(mContext).inflate(R.layout.dialog_link_mic_pk_wait, null); - mLinkMicWaitProgress = v.findViewById(R.id.pk_wait_progress); - v.findViewById(R.id.btn_refuse).setOnClickListener(this); - v.findViewById(R.id.btn_accept).setOnClickListener(this); - mPkWaitCount = LINK_MIC_COUNT_MAX; - mPkPopWindow = new PopupWindow(v, DpUtil.dp2px(280), ViewGroup.LayoutParams.WRAP_CONTENT, true); - mPkPopWindow.setBackgroundDrawable(new ColorDrawable()); - mPkPopWindow.setOutsideTouchable(true); - mPkPopWindow.setOnDismissListener(new PopupWindow.OnDismissListener() { - @Override - public void onDismiss() { - if (mHandler != null) { - mHandler.removeMessages(WHAT_PK_WAIT_RECEIVE); - } - if (mAcceptPk) { - onPkApplyTmp(u); - } else { - if (mPkWaitCount < 0) { - onPkTimeoutTmp(u); - - } - mApplyUid = null; - mApplyStream = null; - } - mIsApplyDialogShow = false; - mLinkMicWaitProgress = null; - mPkPopWindow = null; - } - }); - mPkPopWindow.showAtLocation(mRoot, Gravity.CENTER, 0, 0); - if (mHandler != null) { - mHandler.sendEmptyMessageAtTime(WHAT_PK_WAIT_RECEIVE, getNextSecondTime()); - } - } - - - public static Bitmap fromText(float textSize, String text) { - Paint paint = new Paint(); - paint.setTextSize(textSize); - paint.setTextAlign(Paint.Align.LEFT); - paint.setColor(Color.BLACK); - - Paint.FontMetricsInt fm = paint.getFontMetricsInt(); - int width = (int) paint.measureText(text); - int height = fm.descent - fm.ascent; - - Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); - Canvas canvas = new Canvas(bitmap); - canvas.drawText(text, 0, fm.leading - fm.ascent, paint); - canvas.save(); - - return bitmap; - } - - private String TAG = "多人PK"; - - /** - * 退出多人PK - */ - public void leaveDRRoom() { - //清理PK上面对方的头像 - EventBus.getDefault().post(new AnchorInfoEvent(true, "", "", "")); - Log.e("ry", "退出多人OKKK" + inputStreamList.size()); - isDRPK = 0; - runOnUiThread(new Runnable() { - @Override - public void run() { - if (btn_close != null) { - btn_close.setVisibility(View.GONE); - } - } - }); - - for (int i = 0; i < inputStreamList.size(); i++) { - Log.e("ry", "退出多人ID" + inputStreamList.get(i).getUserId()); - //退出副房间 - RCRTCEngine.getInstance().leaveOtherRoom(inputStreamList.get(i).getUserId(), true, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.e("ry", "退出多人成功"); - - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - Log.e("ry", "退出多人失败" + rtcErrorCode); - - } - }); - } - - - RCRTCMixConfig config = new RCRTCMixConfig(); - RCRTCMixConfig.MediaConfig mediaConfig = new RCRTCMixConfig.MediaConfig(); - config.setMediaConfig(mediaConfig); -//视频输出配置 - RCRTCMixConfig.MediaConfig.VideoConfig videoConfig = new RCRTCMixConfig.MediaConfig.VideoConfig(); - mediaConfig.setVideoConfig(videoConfig); -//大流视频的输出参数 - RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout normal = new RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout(); - videoConfig.setVideoLayout(normal); -//推荐宽、高、帧率参数值可以通过默认视频流的配置获取,也可以根据实际需求来自定义设置 -//如不设置宽高值则服务端将使用默认宽高 360 * 640 -//例:发布的视频分辨率为720 * 1280,如果不设置则观众端看到的视频分辨率为 360 * 640, -//所以如果想让观众端看到的视频分辨率和发布视频分辨率一致,则应从发布的视频流中获取分辨率配置并设置到 mediaConfig 中 - RCRTCVideoStreamConfig defaultVideoConfig = RCRTCEngine.getInstance().getDefaultVideoStream().getVideoConfig(); - int fps = defaultVideoConfig.getVideoFps().getFps(); - int width = 720; - int height = 1280; - normal.setWidth(width); //视频宽 - normal.setHeight(height); //视频高 - normal.setFps(fps); //视频帧率 - - //2. 合流画布设置 - //(请参照画布和声音配置示例代码) - //3. 假设以画布设置的宽高为 300 * 300为例(应以真实设置的宽高为准),设置每个视频流小窗口的坐标及宽高 - ArrayList list = new ArrayList<>(); - config.setCustomLayouts(list); - //user1的视频流 - RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout1 = new RCRTCMixConfig.CustomLayoutList.CustomLayout(); - list.add(videoLayout1); - videoLayout1.setVideoStream(RCRTCEngine.getInstance().getDefaultVideoStream()); // RCRTCStream#MediaType 必须是Video - videoLayout1.setX(0); //X 坐标 - videoLayout1.setY(0); //Y 坐标 - videoLayout1.setWidth(720); // 视频窗口的宽 - videoLayout1.setHeight(1280); // 视频窗口的高 - //2. 合流画布设置 - if (rcrtcLiveInfo != null) { - rcrtcLiveInfo.setMixConfig(config, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.e("ry", "混成功15"); - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.e("ry", "混失败" + errorCode); - - } - }); - - } - - leaveHandler.post(leaveRunnable); - - } - - private Handler leaveHandler = new Handler(Looper.getMainLooper()); - private Runnable leaveRunnable = new Runnable() { - @Override - public void run() { - //恢复全屏画面 - LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); - params.topMargin = 0; - livePushRyViewHolder.camera.setLayoutParams(params); - livePushRyViewHolder.dr_pk_view.setVisibility(View.GONE); - inputStreamList.clear(); - inputStreamList1.clear(); - //删除之前其他主播的画面 - livePushRyViewHolder.dr1_preview.removeAllViews(); - livePushRyViewHolder.dr3_preview.removeAllViews(); - livePushRyViewHolder.cameraPreview3.removeAllViews(); - leaveHandler.removeCallbacks(leaveRunnable); - livePushRyViewHolder.timeTitle.setVisibility(View.GONE); - livePushRyViewHolder.mPreView.removeView(detailsView1); - livePushRyViewHolder.cameraPreview3.setVisibility(View.GONE); - } - }; - - /** - * 随机PK拒绝对话框 - */ - @Override - protected void showPkDialog(UserBean u) { - new DialogUitl.Builder(mContext) - .setHtmlCode(Html.fromHtml( - "有人向您发起PK请求。
" + - "若拒绝PK,将会10分钟内不会再收到任何随机PK请求。" - )) - .setConfirmString("接受") - .setCancelString("拒絕") - .setView(R.layout.dialog_live_random_pk) - .setSimpleCallbackView(new DialogUitl.SimpleCallbackView() { - boolean clickCancel = false; - String titleVal; - TimerTask task; - - @Override - public void onShow(Dialog dialog, View title, View context, View confirmBtn, View cancelBtn) { - task = new TimerTask() { - int time = 11; - final Handler handler = new Handler(Looper.getMainLooper()); - - @Override - public void run() { - if (titleVal == null) { - titleVal = ((TextView) title).getText().toString(); - } - handler.post(() -> ((TextView) title).setText(titleVal + " " + time)); - if (time-- == 0) { - handler.post(() -> showClose(dialog, title, context, confirmBtn, cancelBtn)); - cancel(); - } - } - }; - new Timer().schedule(task, 1000, 1000); - } - - @Override - public void onConfirmClick(Dialog dialog, View title, View context, View confirmBtn, View cancelBtn) { - dialog.dismiss(); - task.cancel(); - apply(); - } - - @Override - public void onCancel(Dialog dialog, View title, View context, View confirmBtn, View cancelBtn) { - if (!clickCancel) { - titleVal = "拒絕PK提示"; - ((TextView) context).setText(Html.fromHtml( - "若拒絕PK,將會關閉你的隨機PK開關。
" + - "並且10分鍾不會收到任何隨機PK請求。
" - )); - ((TextView) cancelBtn).setText("堅持拒絕"); - clickCancel = true; - return; - } - showClose(dialog, title, context, confirmBtn, cancelBtn); - } - - void showClose(Dialog dialog, View title, View context, View confirmBtn, View cancelBtn) { - task.cancel(); - String title1="您因拒絕隨機PK,被限制關閉中"; - String content="隨機PK可打開時間:"; - if(!WordUtil.isNewZh()){ - title1="Can't start a PK for now due to the earlier rejection of other pk"; - content="Available again at:"; - } - ((TextView) title).setText(title1); - ((TextView) confirmBtn).setText(WordUtil.isNewZh()?"确定":"Sure"); - ((TextView) context).setText(content + new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault()).format(new Date(System.currentTimeMillis() + 7200000)));//7200000ms=120m=2h - ((TextView) context).setTextSize(12); - ((TextView) context).setTextColor(Color.parseColor("#999999")); - refusePk(u); - cancelBtn.setVisibility(View.GONE); - confirmBtn.setOnClickListener(v -> { - dialog.dismiss(); - }); - } - - - void apply() { - isPKTmp(u); - } - }) - .build().show(); - } - - private void refusePk(UserBean u) { - IMRTCManager.getInstance().responseJoinOtherRoom(u.getId(), false, "extra_randm_pk", new IRCRTCResultCallback() { - - @Override - public void onFailed(RTCErrorCode errorCode) { - - } - - @Override - public void onSuccess() { - final SocketSendBean msg1 = new SocketSendBean() - .param("_method_", SOCKET_LINK_MIC_PK) - // .param("randomPk",u.isRandomPk()+"") - .param("action", 3); - msg1.create(); - - String targetId = u.getId(); - Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; - TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); - io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); - - RongcloudIMManager.sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { - @Override - public void onAttached(io.rong.imlib.model.Message message) { - - } - - @Override - public void onSuccess(io.rong.imlib.model.Message message) { - Log.e("ry", "发送成功"); - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(msg1.mResult.toString() + ""); - } - } - - @Override - public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { - Log.e("ry", "发送失敗" + u.getId()); - } - }); - } - }); - - LiveNetManager.get(mContext).setBanRandomPK(null); - } - - /** - * 显示申请多人PK的弹窗 - */ - @Override - protected void showDRApplyDialog(UserBean u) { - mApplyUid = u.getId(); - mIsApplyDialogShow = true; - mAcceptPk = false; - View v = LayoutInflater.from(mContext).inflate(R.layout.dialog_link_mic_pk_wait, null); - mLinkMicWaitProgress = v.findViewById(R.id.pk_wait_progress); - v.findViewById(R.id.btn_refuse).setOnClickListener(this); - v.findViewById(R.id.btn_accept).setOnClickListener(this); - mPkWaitCount = LINK_MIC_COUNT_MAX; - mPkPopWindow = new PopupWindow(v, DpUtil.dp2px(280), ViewGroup.LayoutParams.WRAP_CONTENT, true); - mPkPopWindow.setBackgroundDrawable(new ColorDrawable()); - mPkPopWindow.setOutsideTouchable(true); - mPkPopWindow.setOnDismissListener(new PopupWindow.OnDismissListener() { - @Override - public void onDismiss() { - if (mHandler != null) { - mHandler.removeMessages(WHAT_PK_WAIT_RECEIVE); - } - if (mAcceptPk) { - onDRPkApplyTmp(u); - - } else { - if (mPkWaitCount < 0) { - onDRPkTimeoutTmp(u); - - } else { - onDRPkRefuseTmp(u); - } - mApplyUid = null; - mApplyStream = null; - } - mIsApplyDialogShow = false; - mLinkMicWaitProgress = null; - mPkPopWindow = null; - } - }); - mPkPopWindow.showAtLocation(mRoot, Gravity.CENTER, 0, 0); - if (mHandler != null) { - mHandler.sendEmptyMessageAtTime(WHAT_PK_WAIT_RECEIVE, getNextSecondTime()); - } - } - - - //多人PK接受申请画 加入副房间 - public void dRjoinOtherRoom(String uid, int i) { - Log.e("ry", uid + "洒洒" + i + "VVVV" + i); - mApplyUid = uid; - RCRTCEngine.getInstance().joinOtherRoom(mApplyUid, new IRCRTCResultDataCallback() { - @Override - public void onSuccess(RCRTCOtherRoom rcrtcOtherRoom) { - rcrtcOtherRoom.registerOtherRoomEventsListener(otherRoomEventsListener); - new Handler(Looper.getMainLooper()).post(new Runnable() { - public void run() { - //把多人PK的View显示出来 - if (livePushRyViewHolder.dr_pk_view.getVisibility() == View.GONE) { - ScreenDimenUtil util = ScreenDimenUtil.getInstance(); - int mScreenWdith = util.getScreenWdith(); - LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, mScreenWdith * 720 / 960); - params.weight = 1; - params.topMargin = DpUtil.dp2px(123); - livePushRyViewHolder.dr_pk_view.setLayoutParams(params); - livePushRyViewHolder.camera.setLayoutParams(params); - livePushRyViewHolder.dr_pk_view.setVisibility(View.VISIBLE); - livePushRyViewHolder.dr1_preview.setVisibility(View.GONE); - livePushRyViewHolder.dr2_preview.setVisibility(View.GONE); - livePushRyViewHolder.dr3_preview.setVisibility(View.GONE); - livePushRyViewHolder.dr4_preview.setVisibility(View.GONE); - detailsView1 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); - detailsLinearLayout1 = detailsView1.findViewById(R.id.lin_pk1); - linearGrade1 = detailsView1.findViewById(R.id.linear_grade1); - imageGrade1 = detailsView1.findViewById(R.id.image_grade1); - textGrade1 = detailsView1.findViewById(R.id.text_grade1); - imageGrade1.setTag(String.valueOf(IMLoginManager.get(mContext).getUserInfo().getId())); - livePushRyViewHolder.mPreView.addView(detailsView1); - detailsLinearLayout1.setVisibility(View.VISIBLE); - linearGrade1.setVisibility(View.GONE); - } - - Log.e("ry", "多人接受成功" + mApplyUid); - ToastUtil.show(WordUtil.isNewZh() ? "接受成功" : "Success"); - //遍历远端用户列表 - for (int i = 0; i < rcrtcOtherRoom.getRemoteUsers().size(); i++) { - Log.e("ry", rcrtcOtherRoom.getRemoteUsers().get(i).getUserId() + "收到rcrtcOtherRoom" + rcrtcOtherRoom.getRemoteUsers().size()); - //遍历远端用户发布的资源列表 - for (RCRTCInputStream stream : rcrtcOtherRoom.getRemoteUsers().get(i).getStreams()) { - Log.e("ry", i + "收到" + stream.getMediaType() + "实打实打算" + rcrtcOtherRoom.getRemoteUsers().get(i).getUserId()); - if (stream.getMediaType() == RCRTCMediaType.VIDEO) { - if (inputStreamList.size() == 0) { - livePushRyViewHolder.dr1_preview.setVisibility(View.VISIBLE); - //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 - RCRTCVideoView remoteView = new RCRTCVideoView(mContext); - ((RCRTCVideoInputStream) stream).setVideoView(remoteView); - //todo 本demo只演示添加1个远端用户的视图 - livePushRyViewHolder.dr1_preview.removeAllViews(); - remoteView.setScalingType(SCALE_ASPECT_FILL); - livePushRyViewHolder.dr1_preview.addView(remoteView); - - - LiveNetManager.get(mContext).getLiveInfo(uid, new com.yunbao.common.http.base.HttpCallback() { - @Override - public void onSuccess(LiveInfoModel data) { - detailsView2 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); - detailsLinearLayout2 = detailsView2.findViewById(R.id.lin_pk2); - linearGrade2 = detailsView2.findViewById(R.id.linear_grade2); - textPkName2 = detailsView2.findViewById(R.id.text_pk_name2); - imageGrade2 = detailsView2.findViewById(R.id.image_grade2); - textGrade2 = detailsView2.findViewById(R.id.text_grade2); - imageGrade2.setTag(String.valueOf(uid)); - textPkName2.setText(data.getUserNicename()); - livePushRyViewHolder.dr1_preview.addView(detailsView2); - detailsLinearLayout2.setVisibility(View.VISIBLE); - linearGrade2.setVisibility(View.GONE); - } - - @Override - public void onError(String error) { - ToastUtil.show(WordUtil.isNewZh() ? "抱歉!出錯了!" : "i \\'m sorry! An error occurred"); - } - }); - - } else if (inputStreamList.size() == 1) { - livePushRyViewHolder.dr3_preview.setVisibility(View.VISIBLE); - //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 - RCRTCVideoView remoteView = new RCRTCVideoView(mContext); - ((RCRTCVideoInputStream) stream).setVideoView(remoteView); - //todo 本demo只演示添加1个远端用户的视图 - livePushRyViewHolder.dr3_preview.removeAllViews(); - remoteView.setScalingType(SCALE_ASPECT_FILL); - livePushRyViewHolder.dr3_preview.addView(remoteView); - LiveNetManager.get(mContext).getLiveInfo(uid, new com.yunbao.common.http.base.HttpCallback() { - @Override - public void onSuccess(LiveInfoModel data) { - detailsView4 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); - detailsLinearLayout4 = detailsView4.findViewById(R.id.lin_pk4); - linearGrade4 = detailsView4.findViewById(R.id.linear_grade4); - textPkName4 = detailsView4.findViewById(R.id.text_pk_name4); - imageGrade4 = detailsView4.findViewById(R.id.image_grade4); - textGrade4 = detailsView4.findViewById(R.id.text_grade4); - imageGrade4.setTag(uid); - textPkName4.setText(data.getUserNicename()); - livePushRyViewHolder.dr3_preview.addView(detailsView4); - detailsLinearLayout4.setVisibility(View.VISIBLE); - linearGrade4.setVisibility(View.GONE); - } - - @Override - public void onError(String error) { - - } - }); - } else if (inputStreamList.size() == 2) { - livePushRyViewHolder.cameraPreview3.setVisibility(View.VISIBLE); - //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 - RCRTCVideoView remoteView = new RCRTCVideoView(mContext); - ((RCRTCVideoInputStream) stream).setVideoView(remoteView); - //todo 本demo只演示添加1个远端用户的视图 - livePushRyViewHolder.cameraPreview3.removeAllViews(); - remoteView.setScalingType(SCALE_ASPECT_FILL); - livePushRyViewHolder.cameraPreview3.addView(remoteView); - - LiveNetManager.get(mContext).getLiveInfo(uid, new com.yunbao.common.http.base.HttpCallback() { - @Override - public void onSuccess(LiveInfoModel data) { - detailsView3 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); - detailsLinearLayout3 = detailsView3.findViewById(R.id.lin_pk3); - linearGrade3 = detailsView3.findViewById(R.id.linear_grade3); - textPkName3 = detailsView3.findViewById(R.id.text_pk_name3); - imageGrade3 = detailsView3.findViewById(R.id.image_grade3); - textGrade3 = detailsView3.findViewById(R.id.text_grade3); - imageGrade3.setTag(uid); - textPkName3.setText(data.getUserNicename()); - livePushRyViewHolder.cameraPreview3.addView(detailsView3); - detailsLinearLayout3.setVisibility(View.VISIBLE); - linearGrade3.setVisibility(View.GONE); - } - - @Override - public void onError(String error) { - - } - }); - } - inputStreamList.add(stream); - } - inputStreamList1.add(stream); - } - } - //开始订阅资源 - rtcRoom.getLocalUser().subscribeStreams(inputStreamList1, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.i("ry", "订阅资源成功"); - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - Log.i("ry", "订阅资源失败: " + rtcErrorCode.getReason()); - ToastUtil.show(mContext.getString(R.string.live_pk_link_error)); - } - }); - //2. 合流画布设置 - rcrtcLiveInfo.setMixConfig(create_Custom_MixConfig(false, inputStreamList), new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.e("ry", "222混成功"); - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.e("ry", "混失败" + errorCode); - - } - }); - //收起整蛊列表 - if(mLiveRoomViewHolder!=null){ - mLiveRoomViewHolder.closePrankView(); - } - - } - }); - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - Log.e("ry", mApplyUid + "加入其他房间失败 :" + rtcErrorCode); - Log.i("ry", mApplyUid + "加入其他房间失败 :" + rtcErrorCode); - } - }); - } - - /** - * 多人PK PK主播发过来的已经接受 - */ - public void onDRLinkMicToPk(String u) { - Log.e("eve", u + ""); - /** - * 加入副房间 - * - * 前提必须已经 通过 {@link RCRTCEngine#joinRoom(String, RCRTCRoomType, IRCRTCResultDataCallback)} 或 {@link RCRTCEngine#joinRoom(String, IRCRTCResultDataCallback)} 加入了主房间 - * - * @param roomId 房间 ID ,长度 64 个字符,可包含:`A-Z`、`a-z`、`0-9`、`+`、`=`、`-`、`_` - * @param callBack 加入房间回调 - * @group 房间管理 - */ - - RCRTCEngine.getInstance().joinOtherRoom(u, new IRCRTCResultDataCallback() { - @Override - public void onSuccess(RCRTCOtherRoom rcrtcOtherRoom) { - rcrtcOtherRoom.registerOtherRoomEventsListener(otherRoomEventsListener); - new Handler(Looper.getMainLooper()).post(new Runnable() { - public void run() { - - if (livePushRyViewHolder.dr_pk_view.getVisibility() == View.GONE) { - ScreenDimenUtil util = ScreenDimenUtil.getInstance(); - int mScreenWdith = util.getScreenWdith(); - LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, mScreenWdith * 720 / 960); - params.weight = 1; - params.topMargin = DpUtil.dp2px(123); - livePushRyViewHolder.dr_pk_view.setLayoutParams(params); - livePushRyViewHolder.camera.setLayoutParams(params); - livePushRyViewHolder.dr_pk_view.setVisibility(View.VISIBLE); - livePushRyViewHolder.dr1_preview.setVisibility(View.GONE); - livePushRyViewHolder.dr2_preview.setVisibility(View.GONE); - livePushRyViewHolder.dr3_preview.setVisibility(View.GONE); - livePushRyViewHolder.dr4_preview.setVisibility(View.GONE); - detailsView1 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); - detailsLinearLayout1 = detailsView1.findViewById(R.id.lin_pk1); - linearGrade1 = detailsView1.findViewById(R.id.linear_grade1); - imageGrade1 = detailsView1.findViewById(R.id.image_grade1); - textGrade1 = detailsView1.findViewById(R.id.text_grade1); - imageGrade1.setTag(String.valueOf(IMLoginManager.get(mContext).getUserInfo().getId())); - livePushRyViewHolder.mPreView.addView(detailsView1); - detailsLinearLayout1.setVisibility(View.VISIBLE); - linearGrade1.setVisibility(View.GONE); - } - - //遍历远端用户列表 - for (int i = 0; i < rcrtcOtherRoom.getRemoteUsers().size(); i++) { - //遍历远端用户发布的资源列表 - for (RCRTCInputStream stream : rcrtcOtherRoom.getRemoteUsers().get(i).getStreams()) { - Log.e("ry111", stream.getMediaType() + ""); - if (stream.getMediaType() == RCRTCMediaType.VIDEO) { - if (inputStreamList.size() == 0) { - livePushRyViewHolder.dr1_preview.setVisibility(View.VISIBLE); - //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 - RCRTCVideoView remoteView = new RCRTCVideoView(contexts); - ((RCRTCVideoInputStream) stream).setVideoView(remoteView); - //todo 本demo只演示添加1个远端用户的视图 - livePushRyViewHolder.dr1_preview.removeAllViews(); - remoteView.setScalingType(SCALE_ASPECT_FILL); - livePushRyViewHolder.dr1_preview.addView(remoteView); - LiveNetManager.get(mContext).getLiveInfo(u, new com.yunbao.common.http.base.HttpCallback() { - @Override - public void onSuccess(LiveInfoModel data) { - detailsView2 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); - detailsLinearLayout2 = detailsView2.findViewById(R.id.lin_pk2); - linearGrade2 = detailsView2.findViewById(R.id.linear_grade2); - textPkName2 = detailsView2.findViewById(R.id.text_pk_name2); - imageGrade2 = detailsView2.findViewById(R.id.image_grade2); - textGrade2 = detailsView2.findViewById(R.id.text_grade2); - imageGrade2.setTag(String.valueOf(u)); - textPkName2.setText(data.getUserNicename()); - livePushRyViewHolder.dr1_preview.addView(detailsView2); - detailsLinearLayout2.setVisibility(View.VISIBLE); - linearGrade2.setVisibility(View.GONE); - } - - @Override - public void onError(String error) { - - } - }); - } else if (inputStreamList.size() == 1) { - livePushRyViewHolder.dr3_preview.setVisibility(View.VISIBLE); - //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 - RCRTCVideoView remoteView = new RCRTCVideoView(contexts); - ((RCRTCVideoInputStream) stream).setVideoView(remoteView); - //todo 本demo只演示添加1个远端用户的视图 - livePushRyViewHolder.dr3_preview.removeAllViews(); - remoteView.setScalingType(SCALE_ASPECT_FILL); - livePushRyViewHolder.dr3_preview.addView(remoteView); - LiveNetManager.get(mContext).getLiveInfo(u, new com.yunbao.common.http.base.HttpCallback() { - @Override - public void onSuccess(LiveInfoModel data) { - detailsView4 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); - detailsLinearLayout4 = detailsView4.findViewById(R.id.lin_pk4); - linearGrade4 = detailsView4.findViewById(R.id.linear_grade4); - textPkName4 = detailsView4.findViewById(R.id.text_pk_name4); - imageGrade4 = detailsView4.findViewById(R.id.image_grade4); - textGrade4 = detailsView4.findViewById(R.id.text_grade4); - imageGrade4.setTag(u); - textPkName4.setText(data.getUserNicename()); - livePushRyViewHolder.dr3_preview.addView(detailsView4); - detailsLinearLayout4.setVisibility(View.VISIBLE); - linearGrade4.setVisibility(View.GONE); - } - - @Override - public void onError(String error) { - - } - }); - } else if (inputStreamList.size() == 2) { - livePushRyViewHolder.cameraPreview3.setVisibility(View.VISIBLE); - //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 - RCRTCVideoView remoteView = new RCRTCVideoView(contexts); - ((RCRTCVideoInputStream) stream).setVideoView(remoteView); - //todo 本demo只演示添加1个远端用户的视图 - livePushRyViewHolder.cameraPreview3.removeAllViews(); - remoteView.setScalingType(SCALE_ASPECT_FILL); - livePushRyViewHolder.cameraPreview3.addView(remoteView); - - LiveNetManager.get(mContext).getLiveInfo(u, new com.yunbao.common.http.base.HttpCallback() { - @Override - public void onSuccess(LiveInfoModel data) { - detailsView3 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); - detailsLinearLayout3 = detailsView3.findViewById(R.id.lin_pk3); - linearGrade3 = detailsView3.findViewById(R.id.linear_grade3); - textPkName3 = detailsView3.findViewById(R.id.text_pk_name3); - imageGrade3 = detailsView3.findViewById(R.id.image_grade3); - textGrade3 = detailsView3.findViewById(R.id.text_grade3); - imageGrade3.setTag(u); - textPkName3.setText(data.getUserNicename()); - livePushRyViewHolder.cameraPreview3.addView(detailsView3); - detailsLinearLayout3.setVisibility(View.VISIBLE); - linearGrade3.setVisibility(View.GONE); - } - - @Override - public void onError(String error) { - - } - }); - } - inputStreamList.add(stream); - - } - inputStreamList1.add(stream); - - - } - - //开始订阅资源 - rtcRoom.getLocalUser().subscribeStreams(inputStreamList1, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.i("ry", "订阅资源成功"); - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - Log.i("ry", "订阅资源失败: " + rtcErrorCode.getReason()); - ToastUtil.show(mContext.getString(R.string.live_pk_link_error)); - } - }); - - //2. 合流画布设置 - rcrtcLiveInfo.setMixConfig(create_Custom_MixConfig(false, inputStreamList), new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.e("ry", inputStreamList.size() + "混成功" + u); - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.e("ry", "混失败" + errorCode); - - } - }); - } - - } - }); - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - Log.i("ry", "加入其他房间失败 :" + rtcErrorCode.getReason()); - } - }); - - } - - - /** - * 创建自定义合流布局配置 - * - * @param isCrop 是否裁减画布 - * @param streams 必须为视频流列表 - * @return - */ - private RCRTCMixConfig create_Custom_MixConfig(boolean isCrop, List streams) { - Log.e("视频合流", streams.toString()); - Log.e("视频合流", "视频长度:" + streams.size()); - RCRTCMixConfig config = new RCRTCMixConfig(); - //1. 设置自定义合流布局模式 - config.setLayoutMode(RCRTCMixConfig.MixLayoutMode.CUSTOM); - RCRTCMixConfig.MediaConfig mediaConfig = new RCRTCMixConfig.MediaConfig(); - config.setMediaConfig(mediaConfig); - //视频输出配置 - RCRTCMixConfig.MediaConfig.VideoConfig videoConfig = new RCRTCMixConfig.MediaConfig.VideoConfig(); - mediaConfig.setVideoConfig(videoConfig); - //大流视频的输出参数 - RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout normal = new RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout(); - videoConfig.setVideoLayout(normal); - //推荐宽、高、帧率参数值可以通过默认视频流的配置获取,也可以根据实际需求来自定义设置 - //如不设置宽高值则服务端将使用默认宽高 360 * 640 - //例:发布的视频分辨率为720 * 1280,如果不设置则观众端看到的视频分辨率为 360 * 640, - //所以如果想让观众端看到的视频分辨率和发布视频分辨率一致,则应从发布的视频流中获取分辨率配置并设置到 mediaConfig 中 - RCRTCVideoStreamConfig defaultVideoConfig = RCRTCEngine.getInstance().getDefaultVideoStream().getVideoConfig(); - int fps = defaultVideoConfig.getVideoFps().getFps(); - int width = 960; - int height = 720; - normal.setWidth(width); //视频宽 - normal.setHeight(height); //视频高 - normal.setFps(fps); //视频帧率 - - //2. 合流画布设置 - //(请参照画布和声音配置示例代码) - //3. 假设以画布设置的宽高为 300 * 300为例(应以真实设置的宽高为准),设置每个视频流小窗口的坐标及宽高 - ArrayList list = new ArrayList<>(); - - if (streams.size() == 1) { - //user1的视频流 - RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout1 = new RCRTCMixConfig.CustomLayoutList.CustomLayout(); - videoLayout1.setVideoStream(RCRTCEngine.getInstance().getDefaultVideoStream()); // RCRTCStream#MediaType 必须是Video - videoLayout1.setX(0); //X 坐标 - videoLayout1.setY(0); //Y 坐标 - videoLayout1.setWidth(480); // 视频窗口的宽 - videoLayout1.setHeight(720); // 视频窗口的高 - list.add(videoLayout1); - - //user2的视频流 - RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout2 = new RCRTCMixConfig.CustomLayoutList.CustomLayout(); - videoLayout2.setVideoStream(streams.get(0)); // RCRTCStream#MediaType 必须是Video - videoLayout2.setX(480); //X 坐标 - videoLayout2.setY(0); //Y 坐标 - videoLayout2.setWidth(480); // 视频窗口的宽 - videoLayout2.setHeight(720); // 视频窗口的高 - list.add(videoLayout2); - - } else if (streams.size() == 2) { - //user1的视频流 - RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout1 = new RCRTCMixConfig.CustomLayoutList.CustomLayout(); - list.add(videoLayout1); - videoLayout1.setVideoStream(RCRTCEngine.getInstance().getDefaultVideoStream()); // RCRTCStream#MediaType 必须是Video - videoLayout1.setX(0); //X 坐标 - videoLayout1.setY(0); //Y 坐标 - videoLayout1.setWidth(480); // 视频窗口的宽 - videoLayout1.setHeight(720); // 视频窗口的高 - - //user2的视频流 - RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout2 = new RCRTCMixConfig.CustomLayoutList.CustomLayout(); - videoLayout2.setVideoStream(streams.get(0)); // RCRTCStream#MediaType 必须是Video - videoLayout2.setX(480); //X 坐标 - videoLayout2.setY(0); //Y 坐标 - videoLayout2.setWidth(480); // 视频窗口的宽 - videoLayout2.setHeight(360); // 视频窗口的高 - list.add(videoLayout2); - - //user3的视频流 - RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout3 = new RCRTCMixConfig.CustomLayoutList.CustomLayout(); - videoLayout3.setVideoStream(streams.get(1)); // RCRTCStream#MediaType 必须是Video - videoLayout3.setX(480); //X 坐标 - videoLayout3.setY(360); //Y 坐标 - videoLayout3.setWidth(480); // 视频窗口的宽 - videoLayout3.setHeight(360); // 视频窗口的高 - list.add(videoLayout3); - - } else if (streams.size() == 3) { - //user1的视频流 - RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout1 = new RCRTCMixConfig.CustomLayoutList.CustomLayout(); - videoLayout1.setVideoStream(RCRTCEngine.getInstance().getDefaultVideoStream()); // RCRTCStream#MediaType 必须是Video - videoLayout1.setX(0); //X 坐标 - videoLayout1.setY(0); //Y 坐标 - videoLayout1.setWidth(480); // 视频窗口的宽 - videoLayout1.setHeight(720); // 视频窗口的高 - list.add(videoLayout1); - - //user2的视频流 - RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout2 = new RCRTCMixConfig.CustomLayoutList.CustomLayout(); - videoLayout2.setVideoStream(streams.get(0)); // RCRTCStream#MediaType 必须是Video - videoLayout2.setX(480); //X 坐标 - videoLayout2.setY(0); //Y 坐标 - videoLayout2.setWidth(480); // 视频窗口的宽 - videoLayout2.setHeight(360); // 视频窗口的高 - list.add(videoLayout2); - - //user3的视频流 - RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout3 = new RCRTCMixConfig.CustomLayoutList.CustomLayout(); - videoLayout3.setVideoStream(streams.get(1)); // RCRTCStream#MediaType 必须是Video - videoLayout3.setX(480); //X 坐标 - videoLayout3.setY(360); //Y 坐标 - videoLayout3.setWidth(480); // 视频窗口的宽 - videoLayout3.setHeight(360); // 视频窗口的高 - list.add(videoLayout3); - - //user3的视频流 - RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout4 = new RCRTCMixConfig.CustomLayoutList.CustomLayout(); - videoLayout4.setVideoStream(streams.get(2)); // RCRTCStream#MediaType 必须是Video - videoLayout4.setX(0); //X 坐标 - videoLayout4.setY(360); //Y 坐标 - videoLayout4.setWidth(480); // 视频窗口的宽 - videoLayout4.setHeight(360); // 视频窗口的高 - list.add(videoLayout4); - } - config.setCustomLayouts(list); - return config; - } - - @Override - public void onClick(View v) { - int i = v.getId(); - if (i == R.id.btn_refuse) { - refuseLinkMic(); - - } else if (i == R.id.btn_accept) { - acceptLinkMic(); - - } - } - - /** - * 拒绝PK - */ - private void refuseLinkMic() { - if (mPkPopWindow != null) { - mPkPopWindow.dismiss(); - } - } - - /** - * 接受PK - */ - private void acceptLinkMic() { - mAcceptPk = true; - if (mPkPopWindow != null) { - mPkPopWindow.dismiss(); - } - } - - /** - * pk 进度发送变化 - * - * @param leftGift - * @param rightGift - */ - public void onPkProgressChanged(long leftGift, long rightGift, LivePKUserListBean bean) { - if (mLiveLinkMicPkViewHolder != null) { - mLiveLinkMicPkViewHolder.onProgressChanged(leftGift, rightGift, bean); - } - } - - /** - * 进房间的时候PK开始 - */ - public void onEnterRoomPkStart(String pkUid, long leftGift, long rightGift, int pkTime, LivePKUserListBean bean) { - mIsPk = true; - mIsPkEnd = false; - mPkUid = pkUid; - mApplyUid = null; - mApplyStream = null; - if (mLiveLinkMicPkViewHolder == null) { - mLiveLinkMicPkViewHolder = new LiveLinkMicPkViewHolder(mContext, mPkContainer); - mLiveLinkMicPkViewHolder.addToParent(); - mLiveLinkMicPkViewHolder.setIsAnchor(mIsAnchor); - - } - mLiveLinkMicPkViewHolder.showTime(); - mLiveLinkMicPkViewHolder.onEnterRoomPkStart(); - mLiveLinkMicPkViewHolder.onProgressChanged(leftGift, rightGift, bean); - mPkTimeCount = pkTime; - Log.d("mPkTimeCount1", "" + mPkTimeCount + ";mPkTimeFromServer=" + mPkTimeFromServer); - mPkTimeFromServer = pkTime; - nextPkTimeCountDown(2); - } - - /** - * 修改最终PK数据 - * - * @param leftGift 左边数据 - * @param rightGift 右边数据 - * @param bean 排位数据 - */ - public void onPkProgressEnd(long leftGift, long rightGift, LivePKUserListBean bean) { - if (mLiveLinkMicPkViewHolder != null) { - mLiveLinkMicPkViewHolder.onProgressChanged(leftGift, rightGift, bean, true); - } - } - - - /** - * 进房间的时候懲罰开始 - */ - public void onEnterRoomCFStart(String pkUid, long leftGift, long rightGift, int pkTime, LivePKUserListBean bean) { - mIsPk = true; - mIsPkEnd = true; - mPkUid = pkUid; - mApplyUid = null; - mApplyStream = null; - if (mLiveLinkMicPkViewHolder == null) { - mLiveLinkMicPkViewHolder = new LiveLinkMicPkViewHolder(mContext, mPkContainer); - mLiveLinkMicPkViewHolder.addToParent(); - mLiveLinkMicPkViewHolder.setIsAnchor(mIsAnchor); - - } - mLiveLinkMicPkViewHolder.showTime(); -// -1自己的主播输 0平 1自己的主播赢 - int p = 0; - if (leftGift < rightGift) { - p = -1; - } else if (leftGift > rightGift) { - p = 1; - } else if (leftGift == rightGift) { - p = 0; - } - mLiveLinkMicPkViewHolder.new_end(p); - - mLiveLinkMicPkViewHolder.onProgressChanged(leftGift, rightGift, bean); - mPkTimeCount = pkTime; - Log.d("mPkTimeCount1", "" + mPkTimeCount + ";mPkTimeFromServer=" + mPkTimeFromServer); -// mPkTimeFromServer=pkTime; - //恢复播放画面 - nextPkTimeCountDown(3); - } - - - /** - * 主播与主播PK 所有人收到PK开始的回调 - */ - public void onLinkMicPkStart(String pkUid, int i) { - Log.d("tag", i + "mPkTimeCount2"); - mIsPk = true; - hideSendPkWait(); - mIsPkEnd = false; - oldmPkUid = pkUid; - mPkUid = pkUid; - mApplyUid = null; - mApplyStream = null; - if (mLiveLinkMicPkViewHolder == null) { - mLiveLinkMicPkViewHolder = new LiveLinkMicPkViewHolder(mContext, mPkContainer); - mLiveLinkMicPkViewHolder.addToParent(); - mLiveLinkMicPkViewHolder.setIsAnchor(mIsAnchor); - if (mContext instanceof LiveAudienceActivity) { - ((LiveAudienceActivity) mContext).getmLivePlayViewHolder().setPkview(); - } - - } - mLiveLinkMicPkViewHolder.startAnim(); - EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.PK_TWO_START).setObject(pkUid)); - mLiveLinkMicPkViewHolder.showTime(); - mPkTimeCount = 100; - nextPkTimeCountDown(2); - if (mIsAnchor) { - ((LiveRyAnchorActivity) mContext).setPkBtnVisible(false); - mPkTimeCount = PK_TIME_MAX; - - } else { -// mPkTimeCount=mPkTimeFromServer; - mPkTimeCount = PK_TIME_MAX; - } - Log.d("mPkTimeCount2", "" + mPkTimeCount + ";mPkTimeFromServer=" + mPkTimeFromServer); - } - - - /** - * 主播与主播PK PK结果的回调 - */ - int s1 = 0; - - public void onLinkMicPkEnd(String winUid) { - Log.i("收", "9"); - - if (mIsPkEnd) { - return; - } - mIsPkEnd = true; - if (mHandler != null) { - mHandler.removeMessages(WHAT_PK_TIME); - } - if (mLiveLinkMicPkViewHolder != null) { - if (!TextUtils.isEmpty(winUid)) { - if ("0".equals(winUid)) { - mLiveLinkMicPkViewHolder.end(0); - mLiveLinkMicPkViewHolder.hideTime(); - if (mHandler != null) { - mHandler.postDelayed(new Runnable() { - @Override - public void run() { - onLinkMicPkClose(0); - if (mIsAnchor) { - ((LiveRyAnchorActivity) mContext).setPkBtnVisible(true); - } - } - }, 3000); - } - } else { - Log.e("ry1", winUid + "result"); - if (winUid.equals(mLiveUid)) { - mLiveLinkMicPkViewHolder.end(1); - } else { - mLiveLinkMicPkViewHolder.end(-1); - } - mPkTimeCount = PK_TIME_MAX_2;//进入惩罚时间 - nextPkTimeCountDown(5); - } - } - - } - } - - /** - * 主播与主播PK 断开连麦PK的回调 - */ - public void onLinkMicPkClose(int i) { - Log.e("ry", mPkUid + "aaaaqwqw" + i); - - PKing = false; - LiveRyAnchorActivity.isDRPK = 0; - -// //恢复播放画面 - if (i == 1) { - runOnUiThread(new Runnable() { - @Override - public void run() { - if (btn_close != null) { - btn_close.setVisibility(View.GONE); - } - } - }); -// inputStreamList.clear(); - RCRTCMixConfig config = new RCRTCMixConfig(); - RCRTCMixConfig.MediaConfig mediaConfig = new RCRTCMixConfig.MediaConfig(); - config.setMediaConfig(mediaConfig); - //视频输出配置 - RCRTCMixConfig.MediaConfig.VideoConfig videoConfig = new RCRTCMixConfig.MediaConfig.VideoConfig(); - mediaConfig.setVideoConfig(videoConfig); -//大流视频的输出参数 - RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout normal = new RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout(); - videoConfig.setVideoLayout(normal); -//推荐宽、高、帧率参数值可以通过默认视频流的配置获取,也可以根据实际需求来自定义设置 -//如不设置宽高值则服务端将使用默认宽高 360 * 640 -//例:发布的视频分辨率为720 * 1280,如果不设置则观众端看到的视频分辨率为 360 * 640, -//所以如果想让观众端看到的视频分辨率和发布视频分辨率一致,则应从发布的视频流中获取分辨率配置并设置到 mediaConfig 中 - RCRTCVideoStreamConfig defaultVideoConfig = RCRTCEngine.getInstance().getDefaultVideoStream().getVideoConfig(); - int fps = defaultVideoConfig.getVideoFps().getFps(); - int width = 720; - int height = 1280; - normal.setWidth(width); //视频宽 - normal.setHeight(height); //视频高 - normal.setFps(fps); //视频帧率 - - //1. 设置自适应合流布局模式 - config.setLayoutMode(RCRTCMixConfig.MixLayoutMode.ADAPTIVE); - //2. 合流画布设置 - if (rcrtcLiveInfo != null) { - rcrtcLiveInfo.setMixConfig(config, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.e("ry", "混成功16"); - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.e("ry", "混失败" + errorCode); - - } - }); - } - - runOnUiThread(new Runnable() { - public void run() { -// try { -// Thread.sleep(4000); - if (mContext instanceof LiveAudienceActivity && LiveAudienceActivity.getmLivePlayViewHolder() != null) { - LiveAudienceActivity.getmLivePlayViewHolder().setPkEndview(); - } -// } catch (InterruptedException e) { -// e.printStackTrace(); -// } - } - }); - - } - if (mHandler != null) { - mHandler.removeCallbacksAndMessages(null); - } - if (mPkPopWindow != null) { - mPkPopWindow.dismiss(); - } - mPkPopWindow = null; - mIsPk = false; - mIsPkEnd = false; - hideSendPkWait(); - mPkUid = null; - mApplyUid = null; - mApplyStream = null; - if (mLiveLinkMicPkViewHolder != null) { - mLiveLinkMicPkViewHolder.removeFromParent(); - mLiveLinkMicPkViewHolder.release(); - } - mLiveLinkMicPkViewHolder = null; - } - - /** - * 主播与主播Pk 对方主播拒绝Pk的回调 - */ - public void onLinkMicPkRefuse() { - hideSendPkWait(); - if (mIsAnchor) { - ((LiveRyAnchorActivity) mContext).setPkBtnVisible(true); - } - ToastUtil.show(mContext.getString(R.string.link_mic_refuse_pk)); - } - - /** - * 主播与主播Pk 对方主播无响应的回调 - */ - public void onLinkMicPkNotResponse() { - hideSendPkWait(); - if (mIsAnchor) { - ((LiveRyAnchorActivity) mContext).setPkBtnVisible(true); - } - ToastUtil.show(mContext.getString(R.string.link_mic_anchor_not_response_2)); - } - - /** - * 主播与主播Pk 对方主播正在忙的回调 - */ - public void onLinkMicPkBusy() { - hideSendPkWait(); - if (mIsAnchor) { - ((LiveRyAnchorActivity) mContext).setPkBtnVisible(true); - } - ToastUtil.show(mContext.getString(R.string.link_mic_anchor_busy_2)); - } - - - public void release() { - if (mHandler != null) { - mHandler.removeCallbacksAndMessages(null); - } - mHandler = null; - mSocketRyClient = null; - if (mLiveLinkMicPkViewHolder != null) { - mLiveLinkMicPkViewHolder.release(); - } - mLiveLinkMicPkViewHolder = null; - } - - - public void clearData() { - mIsApplyDialogShow = false; - mAcceptPk = false; - mIsPk = false; - mApplyUid = null; - mApplyStream = null; - mLiveUid = null; - mPkUid = null; - mPkWaitCount = 0; - mPkTimeCount = 0; - mIsPkEnd = false; - mPkSend = false; - mPkSendWaitCount = 0; - if (mHandler != null) { - mHandler.removeCallbacksAndMessages(null); - } - if (mLiveLinkMicPkViewHolder != null) { - mLiveLinkMicPkViewHolder.release(); - mLiveLinkMicPkViewHolder.removeFromParent(); - } - mLiveLinkMicPkViewHolder = null; - } - - - public void setSelfStream(String selfStream) { - mSelfStream = selfStream; - } - - /** - * 更新Pk分数 - */ - public void upDataPkScore(JSONArray pkScores, String uid, int time) { - String userID1 = (String) imageGrade1.getTag(); - String userID2 = (String) imageGrade2.getTag(); - String userID4 = (String) imageGrade4.getTag(); - if (livePushRyViewHolder.timeTitle.getVisibility() == View.GONE) { - mHandler.removeMessages(WHAT_PK_TIME2); - RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) livePushRyViewHolder.timeTitle.getLayoutParams(); - layoutParams.topMargin = DpUtil.dp2px(123); - livePushRyViewHolder.timeTitle.setLayoutParams(layoutParams); - livePushRyViewHolder.timeTitle.setVisibility(View.VISIBLE); - String pkTime = StringUtil.getDurationText(time * 1000); - livePushRyViewHolder.textTime.setText(String.format(mContext.getString(R.string.pk_time), pkTime)); - mPkTimeCount = time; - if (time > 0) { - String s1 = StringUtil.getDurationText(mPkTimeCount * 1000); - livePushRyViewHolder.textTime.setText(String.format(mContext.getString(R.string.pk_time), s1)); - mHandler.sendEmptyMessage(WHAT_PK_TIME2); - } - - } - int pkScoreSize = pkScores.size(); - if (pkScoreSize == 3) { - linearGrade1.setVisibility(View.VISIBLE); - linearGrade2.setVisibility(View.VISIBLE); - linearGrade4.setVisibility(View.VISIBLE); - //拿到原始数据 - for (int i = 0; i < pkScores.size(); i++) { - JSONObject score = pkScores.getJSONObject(i); - String userID = score.getString("id"); - long userScore = score.getLong("score"); - if (TextUtils.equals(userID, userID1)) { - textGrade1.setText(String.valueOf(userScore)); - if (!score.containsKey("paiming")) { - ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade1); - } else { - int ranking = score.getIntValue("paiming"); - switch (ranking) { - case 1: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade1); - break; - case 2: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no2, imageGrade1); - break; - case 3: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no3, imageGrade1); - break; - case 4: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no4, imageGrade1); - break; - } - } - } else if (TextUtils.equals(userID, userID2)) { - textGrade2.setText(String.valueOf(userScore)); - if (!score.containsKey("paiming")) { - ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade2); - } else { - int ranking = score.getIntValue("paiming"); - switch (ranking) { - case 1: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade2); - break; - case 2: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no2, imageGrade2); - break; - case 3: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no3, imageGrade2); - break; - case 4: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no4, imageGrade2); - break; - } - } - } else if (TextUtils.equals(userID, userID4)) { - textGrade4.setText(String.valueOf(userScore)); - if (!score.containsKey("paiming")) { - ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade4); - } else { - int ranking = score.getIntValue("paiming"); - switch (ranking) { - case 1: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade4); - break; - case 2: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no2, imageGrade4); - break; - case 3: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no3, imageGrade4); - break; - case 4: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no4, imageGrade4); - break; - } - } - } - } - } else { - String userID3 = (String) imageGrade3.getTag(); - linearGrade1.setVisibility(View.VISIBLE); - linearGrade2.setVisibility(View.VISIBLE); - linearGrade3.setVisibility(View.VISIBLE); - linearGrade4.setVisibility(View.VISIBLE); - //拿到原始数据 - for (int i = 0; i < pkScores.size(); i++) { - JSONObject score = pkScores.getJSONObject(i); - String userID = score.getString("id"); - long userScore = score.getLong("score"); - if (TextUtils.equals(userID, userID1)) { - textGrade1.setText(String.valueOf(userScore)); - if (!score.containsKey("paiming")) { - ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade1); - } else { - int ranking = score.getIntValue("paiming"); - switch (ranking) { - case 1: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade1); - break; - case 2: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no2, imageGrade1); - break; - case 3: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no3, imageGrade1); - break; - case 4: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no4, imageGrade1); - break; - } - } - } else if (TextUtils.equals(userID, userID2)) { - textGrade2.setText(String.valueOf(userScore)); - if (!score.containsKey("paiming")) { - ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade2); - } else { - int ranking = score.getIntValue("paiming"); - switch (ranking) { - case 1: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade2); - break; - case 2: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no2, imageGrade2); - break; - case 3: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no3, imageGrade2); - break; - case 4: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no4, imageGrade2); - break; - } - } - } else if (TextUtils.equals(userID, userID4)) { - textGrade4.setText(String.valueOf(userScore)); - if (!score.containsKey("paiming")) { - ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade4); - } else { - int ranking = score.getIntValue("paiming"); - switch (ranking) { - case 1: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade4); - break; - case 2: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no2, imageGrade4); - break; - case 3: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no3, imageGrade4); - break; - case 4: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no4, imageGrade4); - break; - } - } - } else if (TextUtils.equals(userID, userID3)) { - textGrade3.setText(String.valueOf(userScore)); - if (!score.containsKey("paiming")) { - ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade3); - } else { - int ranking = score.getIntValue("paiming"); - switch (ranking) { - case 1: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade3); - break; - case 2: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no2, imageGrade3); - break; - case 3: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no3, imageGrade3); - break; - case 4: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no4, imageGrade3); - break; - } - } - } - - } - } - - } - - - /** - * PK倒计时 - */ - private void pkCountdownTimer() { - - mPkTimeCount--; - if (mPkTimeCount > 0) {// - if (mHandler != null) { - String s1 = StringUtil.getDurationText(mPkTimeCount * 1000); - livePushRyViewHolder.textTime.setText(String.format(mContext.getString(R.string.pk_time), s1)); - mHandler.sendEmptyMessageAtTime(WHAT_PK_TIME2, getNextSecondTime()); - } - } else { - livePushRyViewHolder.timeTitle.setVisibility(View.GONE); - if (mHandler != null) { - mHandler.removeCallbacksAndMessages(null); - } - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.PK_TIME_COUNT)); -// endDRGif(); - if (DRInitiator) { - LiveNetManager.get(mContext).jieshuDRPK("" + IMLoginManager.get(mContext).getUserInfo().getId()); - } - } - } - - -} diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java index 2c25aac46..522d11312 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java @@ -8,7 +8,6 @@ import static com.yunbao.live.activity.LiveSwAnchorActivity.PKing; import static com.yunbao.live.activity.LiveSwAnchorActivity.isDRPK; import static com.yunbao.live.activity.LiveSwAnchorActivity.mLiveAnchorViewHolder; import static com.yunbao.live.views.LivePushSwViewHolder.btn_close; -import static com.yunbao.live.views.LivePushSwViewHolder.rtcRoom; import android.app.Dialog; import android.content.Context; @@ -35,21 +34,15 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.google.gson.Gson; -import com.tencent.imsdk.v2.V2TIMManager; -import com.tencent.imsdk.v2.V2TIMMessage; -import com.tencent.imsdk.v2.V2TIMSendCallback; import com.tencent.trtc.TRTCCloud; import com.yunbao.common.CommonAppConfig; -import com.yunbao.common.Constants; import com.yunbao.common.bean.UserBean; import com.yunbao.common.event.AnchorInfoEvent; -import com.yunbao.common.glide.ImgLoader; import com.yunbao.common.http.HttpCallback; import com.yunbao.common.http.HttpClient; import com.yunbao.common.http.LiveHttpUtil; import com.yunbao.common.http.live.LiveNetManager; import com.yunbao.common.manager.IMLoginManager; -import com.yunbao.common.manager.IMRTCManager; import com.yunbao.common.manager.RandomPkManager; import com.yunbao.common.utils.Bus; import com.yunbao.common.utils.DialogUitl; @@ -79,21 +72,11 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; -import java.util.HashMap; import java.util.List; import java.util.Locale; -import java.util.Map; import java.util.Timer; import java.util.TimerTask; -import cn.rongcloud.rtc.api.RCRTCEngine; -import cn.rongcloud.rtc.api.RCRTCMixConfig; -import cn.rongcloud.rtc.api.RCRTCOtherRoom; -import cn.rongcloud.rtc.api.RCRTCRemoteUser; -import cn.rongcloud.rtc.api.callback.IRCRTCOtherRoomEventsListener; -import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback; -import cn.rongcloud.rtc.api.stream.RCRTCInputStream; -import cn.rongcloud.rtc.base.RTCErrorCode; import io.agora.beautyapi.faceunity.agora.SWManager; import io.rong.imlib.IRongCallback; import io.rong.imlib.RongIMClient; @@ -151,8 +134,8 @@ public class LiveSwLinkMicPkPresenter extends AbsLinkMicPkPresenter implements V public LivePushSwViewHolder livePushSwViewHolder; - public static List inputStreamList = new ArrayList<>(); - public static List inputStreamList1 = new ArrayList<>(); +// public static List inputStreamList = new ArrayList<>(); +// public static List inputStreamList1 = new ArrayList<>(); private boolean DRInitiator = false;//是否是duorenPK发起人 private List drPkbeans = new ArrayList<>(); @@ -337,15 +320,6 @@ public class LiveSwLinkMicPkPresenter extends AbsLinkMicPkPresenter implements V s1 = "00:00"; i = 0; } - if (rtcRoom != null) { - ScreenDimenUtil util = ScreenDimenUtil.getInstance(); - int mScreenWdith = util.getScreenWdith(); - LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, mScreenWdith * 720 / 960); - params.weight = 1; - params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); - livePushSwViewHolder.camera.setLayoutParams(params); - livePushSwViewHolder.mPreView1.setLayoutParams(params); - } Log.i("tts2", s1); mLiveLinkMicPkViewHolder.setTime(s + " " + s1); @@ -863,86 +837,10 @@ public class LiveSwLinkMicPkPresenter extends AbsLinkMicPkPresenter implements V @Override protected void onDRPkTimeout(UserBean u) { - IMRTCManager.getInstance().responseJoinOtherRoom(u.getId(), false, "extra", new IRCRTCResultCallback() { - - @Override - public void onFailed(RTCErrorCode errorCode) { - - } - - @Override - public void onSuccess() { - final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 8); - msg1.create(); - - String targetId = u.getId(); - Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; - TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); - io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); - - RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { - @Override - public void onAttached(io.rong.imlib.model.Message message) { - - } - - @Override - public void onSuccess(io.rong.imlib.model.Message message) { - Log.e("ry", "发送成功"); - if (SocketSwClient.mSocketHandler != null) { - SocketSwClient.mSocketHandler.processBroadcast(msg1.mResult.toString() + ""); - } - } - - @Override - public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { - Log.e("ry", "发送失敗" + mApplyUid); - } - }); - } - }); } @Override protected void onDRPkRefuse(UserBean u) { - IMRTCManager.getInstance().responseJoinOtherRoom(u.getId(), false, "extra", new IRCRTCResultCallback() { - - @Override - public void onFailed(RTCErrorCode errorCode) { - - } - - @Override - public void onSuccess() { - final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 3); - msg1.create(); - - String targetId = u.getId(); - Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; - TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); - io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); - - RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { - @Override - public void onAttached(io.rong.imlib.model.Message message) { - - } - - @Override - public void onSuccess(io.rong.imlib.model.Message message) { - Log.e("ry", "发送成功"); - if (SocketSwClient.mSocketHandler != null) { - SocketSwClient.mSocketHandler.processBroadcast(msg1.mResult.toString() + ""); - } - } - - @Override - public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { - Log.e("ry", "发送失敗"); - } - }); - } - }); } @Override @@ -1054,7 +952,6 @@ public class LiveSwLinkMicPkPresenter extends AbsLinkMicPkPresenter implements V public void leaveDRRoom() { //清理PK上面对方的头像 EventBus.getDefault().post(new AnchorInfoEvent(true, "", "", "")); - Log.e("ry", "退出多人OKKK" + inputStreamList.size()); isDRPK = 0; DRPKing = -1; runOnUiThread(new Runnable() { @@ -1169,7 +1066,7 @@ public class LiveSwLinkMicPkPresenter extends AbsLinkMicPkPresenter implements V } private void refusePk(UserBean u) { - IMRTCManager.getInstance().responseJoinOtherRoom(u.getId(), false, "extra_randm_pk", new IRCRTCResultCallback() { + /*IMRTCManager.getInstance().responseJoinOtherRoom(u.getId(), false, "extra_randm_pk", new IRCRTCResultCallback() { @Override public void onFailed(RTCErrorCode errorCode) { @@ -1208,7 +1105,7 @@ public class LiveSwLinkMicPkPresenter extends AbsLinkMicPkPresenter implements V } }); } - }); + });*/ LiveNetManager.get(mContext).setBanRandomPK(null); } diff --git a/live/src/main/java/com/yunbao/live/socket/SocketRyChatUtil.java b/live/src/main/java/com/yunbao/live/socket/SocketRyChatUtil.java index 79c8b9310..985596deb 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketRyChatUtil.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketRyChatUtil.java @@ -66,8 +66,8 @@ public class SocketRyChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketRyClient.mSocketHandler != null) - SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + /* if (SocketRyClient.mSocketHandler != null) + SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + "");*/ } @Override @@ -131,9 +131,9 @@ public class SocketRyChatUtil { @Override public void onSuccess(Message message) { - if (SocketRyClient.mSocketHandler != null) { + /* if (SocketRyClient.mSocketHandler != null) { SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); - } + }*/ LiveNetManager.get(CommonAppContext.sInstance) .addChatCount(LiveActivity.mStream, new com.yunbao.common.http.base.HttpCallback() { @Override @@ -218,8 +218,8 @@ public class SocketRyChatUtil { } } }); - if (SocketRyClient.mSocketHandler != null) - SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + /*if (SocketRyClient.mSocketHandler != null) + SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + "");*/ } @Override @@ -267,9 +267,9 @@ public class SocketRyChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketRyClient.mSocketHandler != null) { + /* if (SocketRyClient.mSocketHandler != null) { SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); - } + }*/ } @Override @@ -406,9 +406,9 @@ public class SocketRyChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketRyClient.mSocketHandler != null) { + /*if (SocketRyClient.mSocketHandler != null) { SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); - } + }*/ } @Override @@ -476,9 +476,9 @@ public class SocketRyChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketRyClient.mSocketHandler != null) { + /* if (SocketRyClient.mSocketHandler != null) { SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); - } + }*/ } @Override @@ -523,9 +523,9 @@ public class SocketRyChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketRyClient.mSocketHandler != null) { + /* if (SocketRyClient.mSocketHandler != null) { SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); - } + }*/ } @Override @@ -560,9 +560,9 @@ public class SocketRyChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketRyClient.mSocketHandler != null) { + /* if (SocketRyClient.mSocketHandler != null) { SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); - } + }*/ } @Override @@ -603,8 +603,8 @@ public class SocketRyChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketRyClient.mSocketHandler != null) - SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + /* if (SocketRyClient.mSocketHandler != null) + SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + "");*/ } @Override @@ -640,9 +640,9 @@ public class SocketRyChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketRyClient.mSocketHandler != null) { + /* if (SocketRyClient.mSocketHandler != null) { SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); - } + }*/ } @Override @@ -680,9 +680,9 @@ public class SocketRyChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketRyClient.mSocketHandler != null) { + /*if (SocketRyClient.mSocketHandler != null) { SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); - } + }*/ } @Override @@ -786,9 +786,9 @@ public class SocketRyChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketRyClient.mSocketHandler != null) { + /*if (SocketRyClient.mSocketHandler != null) { SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); - } + }*/ } @Override @@ -834,9 +834,9 @@ public class SocketRyChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketRyClient.mSocketHandler != null) { + /*if (SocketRyClient.mSocketHandler != null) { SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); - } + }*/ LiveNetManager.get(CommonAppContext.sInstance) .addChatCount(LiveActivity.mStream, new com.yunbao.common.http.base.HttpCallback() { @Override diff --git a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java deleted file mode 100644 index 492773d4b..000000000 --- a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java +++ /dev/null @@ -1,1557 +0,0 @@ -package com.yunbao.live.socket; - -import static com.blankj.utilcode.util.SnackbarUtils.dismiss; -import static com.blankj.utilcode.util.ViewUtils.runOnUiThread; -import static com.yunbao.common.Constants.SOCKET_LIVE_MSG_TO_USER; -import static com.yunbao.live.activity.LiveRyAnchorActivity.isDRPK; -import static com.yunbao.live.bean.LiveChatBean.TYPE_TO_ANCHOR_PRANK_GIFT; -import static com.yunbao.live.views.LiveRoomViewHolder.getIsHot; - -import android.app.Activity; -import android.content.Context; -import android.os.Handler; -import android.os.Message; -import android.text.TextUtils; -import android.util.Log; -import android.view.View; -import android.widget.LinearLayout; -import android.widget.Toast; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.blankj.utilcode.util.GsonUtils; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.yunbao.common.CommonAppConfig; -import com.yunbao.common.CommonAppContext; -import com.yunbao.common.Constants; -import com.yunbao.common.bean.AiAutomaticSpeechModel; -import com.yunbao.common.bean.FansModel; -import com.yunbao.common.bean.GuardMaturityDateRemindModel; -import com.yunbao.common.bean.LinkMicUserBean; -import com.yunbao.common.bean.LiveUserGiftBean; -import com.yunbao.common.bean.MsgModel; -import com.yunbao.common.bean.PkRankBean; -import com.yunbao.common.bean.RedPacketInfoModel; -import com.yunbao.common.bean.RedPacketModel; -import com.yunbao.common.bean.SendMoneyLongModel; -import com.yunbao.common.bean.SocketModel; -import com.yunbao.common.bean.SudGameDateModel; -import com.yunbao.common.bean.UserBean; -import com.yunbao.common.bean.WishModel; -import com.yunbao.common.bean.XydCompleteModel; -import com.yunbao.common.event.AllServerNotifyEvent; -import com.yunbao.common.event.AllServerNotifyFFGGGDJANEvent; -import com.yunbao.common.event.CustomFullServiceNotifyEvent; -import com.yunbao.common.event.GiftWallIlluminateEvent; -import com.yunbao.common.event.QuickGiftingEvent; -import com.yunbao.common.event.SendBlindGiftEvent; -import com.yunbao.common.event.SendMoneyLongEndEvent; -import com.yunbao.common.http.HttpCallback; -import com.yunbao.common.http.HttpClient; -import com.yunbao.common.manager.IMRTCManager; -import com.yunbao.common.manager.MicUserManager; -import com.yunbao.common.manager.MicedUserManager; -import com.yunbao.common.manager.NewLevelManager; -import com.yunbao.common.manager.RandomPkManager; -import com.yunbao.common.utils.Bus; -import com.yunbao.common.utils.DialogUitl; -import com.yunbao.common.utils.L; -import com.yunbao.common.utils.ToastUtil; -import com.yunbao.common.utils.ToastUtils; -import com.yunbao.common.utils.WordUtil; -import com.yunbao.live.R; -import com.yunbao.live.activity.LiveAudienceActivity; -import com.yunbao.live.activity.LiveRyAnchorActivity; -import com.yunbao.live.adapter.LiveChatAdapter; -import com.yunbao.live.bean.LiveBuyGuardMsgBean; -import com.yunbao.live.bean.LiveChatBean; -import com.yunbao.live.bean.LiveDanMuBean; -import com.yunbao.live.bean.LiveEnterRoomBean; -import com.yunbao.live.bean.LiveGiftPrizePoolWinBean; -import com.yunbao.live.bean.LiveLuckGiftWinBean; -import com.yunbao.live.bean.LivePKUserListBean; -import com.yunbao.live.bean.LiveReceiveGiftBean; -import com.yunbao.live.bean.NewAllServerNotifyGuardEvent; -import com.yunbao.live.bean.SendQuickGiftModel; -import com.yunbao.live.event.LiveAnchorEvent; -import com.yunbao.live.event.LiveAudienceEvent; -import com.yunbao.live.views.LiveEndViewHolder; -import com.yunbao.live.views.LivePlayKsyViewHolder; -import com.yunbao.live.views.LivePlayRyViewHolder; -import com.yunbao.live.views.LivePushRyViewHolder; -import com.yunbao.live.views.LiveRoomViewHolder; - -import org.greenrobot.eventbus.EventBus; - -import java.lang.ref.WeakReference; -import java.util.List; - -import cn.rongcloud.rtc.api.RCRTCEngine; -import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback; -import cn.rongcloud.rtc.base.RTCErrorCode; -import io.rong.imlib.IRongCoreCallback; -import io.rong.imlib.IRongCoreEnum; -import io.rong.imlib.chatroom.base.RongChatRoomClient; - -public class SocketRyClient { - - private final String TAG = "socket"; - private String mLiveUid; - private String mStream; - public static SocketHandler mSocketHandler; - private Context mContext; - - public SocketRyClient(String mLiveUid, SocketMessageListener listener, Activity mContext) { - this.mContext = mContext; - mSocketHandler = new SocketHandler(listener); - mSocketHandler.setLiveUid(mLiveUid); - RongChatRoomClient.getInstance().joinChatRoom("g" + mLiveUid, -1, new IRongCoreCallback.OperationCallback() { - @Override - public void onSuccess() { - Log.i("tx", "加入成功"); - - } - - @Override - public void onError(IRongCoreEnum.CoreErrorCode coreErrorCode) { - Log.i("tx", "加入" + "失败" + coreErrorCode); - if (WordUtil.isNewZh()) { - ToastUtil.show("網絡不佳無法連接,請重新進入"); - } else { - ToastUtil.show("The network is not connected, please re-enter"); - } - } - }); - - } - - public void setLivePushRyViewHolder(LivePushRyViewHolder livePushRyViewHolder) { - if (mSocketHandler != null) { - mSocketHandler.setLivePushRyViewHolder(livePushRyViewHolder); - } - } - - public void disConnect() { -// V2TIMManager.getInstance(). - mLiveUid = null; - mStream = null; - mSocketHandler = null; - } - - public class SocketHandler extends Handler { - - private SocketMessageListener mListener; - private LivePushRyViewHolder livePushRyViewHolder; - private String mLiveUid; - - public SocketHandler(SocketMessageListener listener) { - mListener = new WeakReference<>(listener).get(); - } - - public void setLiveUid(String liveUid) { - mLiveUid = liveUid; - } - - public void setLivePushRyViewHolder(LivePushRyViewHolder livePushRyViewHolder) { - this.livePushRyViewHolder = livePushRyViewHolder; - } - - @Override - public void handleMessage(Message msg) { - if (mListener == null) { - return; - } - try { - switch (msg.what) { - case Constants.SOCKET_WHAT_CONN: - mListener.onConnect((Boolean) msg.obj); - break; - case Constants.SOCKET_WHAT_BROADCAST: - processBroadcast((String) msg.obj); - break; - case Constants.SOCKET_WHAT_DISCONN: - mListener.onDisConnect(); - break; - } - } catch (Exception e) { - e.printStackTrace(); - } - - } - - - public void processBroadcast(String socketMsg) { - L.e("收到socket--->" + socketMsg); - - Log.i("SocketRyClient", "socketMsg" + socketMsg); - - if (Constants.SOCKET_STOP_PLAY.equals(socketMsg)) { - mListener.onSuperCloseLive();//超管关闭房间 - return; - } - if (socketMsg.contains("LivePK_UnreadCount")) { - return; - } - SocketReceiveBean received = JSON.parseObject(socketMsg, SocketReceiveBean.class); - - JSONObject map = received.getMsg().getJSONObject(0); -// LogUtils.e("yqw=====>收到的socket:"+map.getString("_method_")+","+map.getString("ct")); - switch (map.getString("_method_")) { - //用户连麦 - case Constants.LIAN_MAI: - int actions = map.getIntValue("action"); - //主播邀请用户连麦消息 - if (actions == 1) { - EventBus.getDefault().post("inviteMic"); - //主播同意用户连麦申请 - } else if (actions == 4) { - EventBus.getDefault().post("UsertoRY"); - } else if (actions == 5) { - JSONObject mic_data = map.getJSONObject("ct"); - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.LINK_MIC_UPDATE_MIC_LIST) - .setObject(JSONArray.parseArray(mic_data.getJSONArray("userlist").toString(), LinkMicUserBean.class)) - ); - MicedUserManager.get().upDataMicUserList(JSONArray.parseArray(mic_data.getJSONArray("userlist").toString(), LinkMicUserBean.class)); - } else if (actions == 6) { - if (WordUtil.isNewZh()) { - ToastUtil.show("主播已關閉當前語音連麥功能"); - } else { - ToastUtil.show("The host has disabled the voice connection function"); - } - EventBus.getDefault().post("endMic"); - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.LINK_MIC_CLOSE) - .setObject(map.toJavaObject(LinkMicUserBean.class))); - } else if (actions == 8) { - if (WordUtil.isNewZh()) { - ToastUtil.show("您已被移出多人語音連麥"); - } else { - ToastUtil.show("You have been removed from Multi-Voice Connection"); - } - EventBus.getDefault().post("endMic"); - } else if (actions == 3) { - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.LINK_MIC) - .setObject(map.toJavaObject(LinkMicUserBean.class)) - ); - MicUserManager.get().upDataMicUser(map); - } else if (actions == 7) {//取消连麦 - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.LINK_MIC_CANCEL) - ); - MicUserManager.get().removeMiscUser(map); - } - break; - case Constants.UP_USER_LIST: - mListener.onUpUserList(map.getJSONObject("ct")); - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.LINK_MIC_UPDATE_AUDIENCE_LIST) - .setObject(JSON.parseArray(map.getJSONObject("ct").getString("userlist"), LiveUserGiftBean.class)) - ); - break; - case Constants.CARD: -// LiveLinkMicPresenter.setHD(map.getString("ct")); - break; - case Constants.SOCKET_SYSTEM://系统消息 - if (map.getString("ct").contains("甜蜜不停")) { - break; - } - UserBean us = CommonAppConfig.getInstance().getUserBean(); - if (map.getString("uid") != null && us != null && map.getString("uid").equals(us.getId())) { - int num = LiveAudienceActivity.fansNum + 1; - LiveRoomViewHolder.setFansNum(num); - } - if (map.getString("ct").contains("堅決維護青少年群體精神文明健康") || map.getString("ct").contains("click to register if you like. pdlive conducts")) { - systemChatMessage(map.getString("ct")); - } else { - if (!WordUtil.isNewZh() && map.getString("ct").contains("退出比賽") && map.getString("ct").contains("獲得勝利")) { - String ctTmp = map.getString("ct"); - ctTmp = ctTmp.replace("由於", "Due to") - .replace("退出比賽", "withdrawing from the competition") - .replace("獲得勝利", "won"); - map.put("ct", ctTmp); - } - systemChatMessage2(map.getString("ct")); - } - - int action21 = map.getIntValue("action"); - //主播離開 - if (action21 == 13 && map.getString("ct").contains("離開")) { - if (LivePlayKsyViewHolder.leave != null) { - LivePlayKsyViewHolder.leave.setVisibility(View.VISIBLE); - } - if (LivePlayRyViewHolder.leave != null) { - LivePlayRyViewHolder.leave.setVisibility(View.VISIBLE); - } - } else if (action21 == 13 && map.getString("ct").contains("回來")) { - if (LivePlayKsyViewHolder.leave != null) { - LivePlayKsyViewHolder.leave.setVisibility(View.GONE); - } - if (LivePlayRyViewHolder.leave != null) { - LivePlayRyViewHolder.leave.setVisibility(View.GONE); - } - } - break; - - case Constants.PrankSendData: - //整蛊礼物刷新 - L.e("整蛊礼物刷新 整蛊礼物刷新 整蛊礼物刷新"); - if (map.getIntValue("action") == 13 && map.getString("msgtype").equals("4")){ - String ctString = map.getString("ct"); - L.e("整蛊礼物刷新 整蛊礼物刷新 整蛊礼物刷新 "+ctString); - JsonElement jsonElement = JsonParser.parseString(ctString); - if (jsonElement == null) break; -// LogUtils.e("yqw=====>整蛊礼物列表:"+ctString); - JsonObject jsonObject = jsonElement.getAsJsonObject(); - String content = WordUtil.isNewZh() ? jsonObject.get("msg").getAsString() : jsonObject.get("msg_en").getAsString(); - if(jsonObject.get("is_complete")!=null){ - String is_complete = jsonObject.get("is_complete").getAsString(); //0.未达成整蛊需要的数量 1.已达成整蛊 - if(is_complete.equals("1")){ - String user_name = jsonObject.get("user_name").getAsString(); //用户昵称 - String prank_content = jsonObject.get("prank_content").getAsString(); //整蛊内容 - String gift_count = jsonObject.get("gift_count").getAsString(); // 礼物数量 - LiveChatBean chatBean = new LiveChatBean(); - chatBean.setUserNiceName(user_name); - chatBean.setGiftName(jsonObject.get("gift_name").getAsString()); - chatBean.setGiftname_en(jsonObject.get("gift_name_en").getAsString()); - chatBean.setHot_num(gift_count); - chatBean.setContent(prank_content); - chatBean.setType(TYPE_TO_ANCHOR_PRANK_GIFT); - mListener.onChat(chatBean, 1); - } - }else{ - if (!TextUtils.isEmpty(content)){ - systemChatMessage2(content); - } - } - if(CommonAppConfig.getInstance().getUid().equals(mLiveUid)&&"完成1次!".equals(jsonObject.get("msg").getAsString())){ - Toast toast = Toast.makeText(mContext,WordUtil.isNewZh()?jsonObject.get("msg").getAsString():jsonObject.get("msg_en").getAsString(),Toast.LENGTH_LONG); - toast.show(); - } - mListener.onUpdatePrankProgress(ctString); - } - break; - case Constants.SOCKET_KICK://踢人 - systemChatMessage2(map.getString("ct")); - mListener.onKick(map.getString("touid")); - break; - case Constants.SOCKET_SHUT_UP://禁言 - String ct = map.getString("ct"); - systemChatMessage2(ct); - mListener.onShutUp(map.getString("touid"), ct); - break; - case Constants.SOCKET_SEND_MSG://文字消息,点亮,用户进房间,这种混乱的设计是因为服务器端逻辑就是这样设计的,客户端无法自行修改 - wordLightEnterRoom(map, received); - L.e("收到socket---> 文字消息" + socketMsg); - break; - case Constants.SOCKET_LIGHT://飘心 - mListener.onLight(); - break; - case Constants.SOCKET_SEND_GIFT://送礼物 - sendGiftInSameRoom(map); - break; - -// case Constants.SOCKET_SEND_GIFT://送礼物 -// ////////pk -// break; - case Constants.SOCKET_LIVE_DRPK_RANDOM: - case Constants.SOCKET_LIVE_DRPK://多人PK - int action3 = map.getIntValue("action"); - //收到多人PK邀请 - if (action3 == 1) { - UserBean u = new UserBean(); - u.setUserNiceName(map.getString("uname")); - u.setId(map.getString("uid")); - mListener.onLinkDRMicPkApply(u); - } - //收到对方同意多人PK邀请 - else if (action3 == 2) { -// UserBean u = new UserBean(); -//// u.setUserNiceName(map.getString("uname")); -// u.setId(map.getString("uid")); -// mListener.onLinkDRMicPkApplyOk(u); - } else if (action3 == 6) {//开始Pk - if (LiveRoomViewHolder.mHandler != null) { - LiveRoomViewHolder.mHandler.removeCallbacksAndMessages(null); - } -// LiveRoomViewHolder.UpPkBar(map.getJSONArray("userlist"), mLiveUid, map.getIntValue("drpk_time")); - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.LEAVE_PK_SCORE) - .setPkScores(map.getJSONArray("userlist")) - .setUid(mLiveUid) - .setTime(map.getIntValue("drpk_time"))); - if (livePushRyViewHolder == null) { - // LiveAudienceActivity.getmLivePlayViewHolder().setPkview(); - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_VIEW) - ); - } - - - } else if (action3 == 5) { -// endDRGif(); - LiveRoomViewHolder.d_pk_view.setVisibility(View.GONE); - if (LiveRyAnchorActivity.mLiveAnchorViewHolder != null) { - LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); - params.topMargin = 0; - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.LEAVE_DR_ROOM)); - isDRPK = 0; - } else { - // LiveAudienceActivity.getmLivePlayViewHolder().setPkEndview(); - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_END_VIEW) - ); - - } - //創建了多人房間 - } else if (action3 == 3) { - /* if (LiveAudienceActivity.getmLivePlayViewHolder() != null) { - LiveAudienceActivity.getmLivePlayViewHolder().setPkview(); - }*/ - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_VIEW) - ); - isDRPK = 1; - } else if (action3 == 10) { - if (!map.getString("uid").equals(CommonAppConfig.getInstance().getUid())) { - // LiveAudienceActivity.getmLivePlayViewHolder().setPkview(); - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_VIEW) - ); - } - } - - break; - case Constants.SOCKET_ALL_SERVER_NOTIFY://全服通知 - int action2 = map.getIntValue("action"); - if (action2 == 71) { - LiveReceiveGiftBean receiveGiftBean = new LiveReceiveGiftBean(); - receiveGiftBean.setVipName(map.getString("ct")); - receiveGiftBean.setSendtype(map.getIntValue("action")); - receiveGiftBean.setAllServerNotify(true); - mListener.onSys(receiveGiftBean); - } else if (action2 == 61) {//赠送礼物 超级头条 - sendGiftByNotify(map); - } else if (action2 == 62) {//购买守护 -// buyGuardByNotify(map); -// }else if (action2 == 63){ - } else if (action2 == 63) {//购买vip - buyVipByNotify(map); - } else if (action2 == 64) {//购买靓号 - buyLiangNameByNotify(map); - } else if (action2 == 65) {//购买坐骑 - buyZuoJiByNotify(map); - } else if (action2 == 66) {//购买贵族 - buyVipByNotify(map); - } else if (action2 == 88) {//盲盒 - JSONObject mCt = map.getJSONObject("ct"); - String boxType = map.getString("box_type"); - String boxTypeName = ""; - if (TextUtils.equals(boxType, "1")) { - boxTypeName = WordUtil.isNewZh() ? "迷你盲盒" : "Mini blind box"; - } else if (TextUtils.equals(boxType, "2")) { - boxTypeName = WordUtil.isNewZh() ? "典藏盲盒" : "Collection blind box"; - } else { - boxTypeName = WordUtil.isNewZh() ? "PD盲盒" : "PD blind box"; - } - AllServerNotifyEvent allServerNotifyEvent - = new AllServerNotifyEvent() - .setBlindBoxId(map.getString("blind_box_id")) - .setBoxType(boxType) - .setBoxTypeName(boxTypeName) - .setDressName(WordUtil.isNewZh() ? map.getString("dress_name") : TextUtils.isEmpty(map.getString("dress_nameen")) ? map.getString("dress_name") : map.getString("dress_nameen")) - .setGiftNotification(map.getString("gift_notification")) - .setGiftName(WordUtil.isNewZh() ? mCt.getString("giftname") : mCt.getString("giftnameen")) - .setUserNiceName(map.getString("uname")) - .setGiftIcon(map.getString("gifticon")) - .setAnchorName(map.getString("ancherName")) - .setDisplaySrc(map.getString("display_src")); - Log.e("AllServerNotifyEvent", allServerNotifyEvent.toString()); - Log.e("AllServerNotifyEvent", map.toJSONString()); - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.BLIND_BOX) - .setAllServerNotifyEvent(allServerNotifyEvent)); - } else if (action2 == 89) {//红包 - JSONObject mCt = map.getJSONObject("ct"); - AllServerNotifyEvent allServerNotifyEvent - = new AllServerNotifyEvent() - .setUserNiceName(mCt.getString("user_nicename")) - .setGiftName(WordUtil.isNewZh() ? map.getString("giftname") : map.getString("giftname_en")) - .setGiftIcon(mCt.getString("gifticon")) - .setRedPacket(true); - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.BLIND_BOX) - .setAllServerNotifyEvent(allServerNotifyEvent)); - } else if (action2 == 90) { - NewAllServerNotifyGuardEvent notifyGuardEvent = GsonUtils.fromJson(map.toString(), NewAllServerNotifyGuardEvent.class); - Bus.get().post(notifyGuardEvent); - if(mLiveUid.equals(map.getString("liveuid"))){ - buyGuardInSameRoom(map); - } - } else if (action2 == 91) {//通用模板 - AllServerNotifyFFGGGDJANEvent notifyFFGGGDJANEvent = GsonUtils.fromJson(map.toString(), AllServerNotifyFFGGGDJANEvent.class); - Bus.get().post(notifyFFGGGDJANEvent); - } - break; - case Constants.SOCKET_SEND_BARRAGE://发弹幕 - LiveDanMuBean liveDanMuBean2 = new LiveDanMuBean(); - liveDanMuBean2.setAvatar(map.getString("uhead")); - liveDanMuBean2.setUserNiceName(map.getString("uname")); - liveDanMuBean2.setContent(map.getString("ct")); - if (map.containsKey("fansLevel")) { - liveDanMuBean2.setFensLevel(map.getInteger("fansLevel")); - } - mListener.onSendDanMu(liveDanMuBean2); - break; - case Constants.SOCKET_LEAVE_ROOM://离开房间 - UserBean u = JSON.parseObject(map.getString("ct"), UserBean.class); - mListener.onLeaveRoom(u); - break; - case Constants.SOCKET_LIVE_END://主播关闭直播 - int action = map.getIntValue("action"); - if (action == 18) { - mListener.onLiveEnd(); - LiveEndViewHolder.upData(map.getString("votes"), map.getString("length"), map.getIntValue("nums"), map.getString("uname")); - } else if (action == 19) { - mListener.onAnchorInvalid(); - } - //主播强制下播 - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.LIVE_END) - .setVotes(map.getString("votes")) - .setLength(map.getString("length")) - .setNums(map.getIntValue("nums")) - .setUname(map.getString("uname"))); - break; - case Constants.SOCKET_CHANGE_LIVE://主播切换计时收费类型 - mListener.onChangeTimeCharge(map.getIntValue("type_val")); - break; - case Constants.SOCKET_UPDATE_VOTES: - mListener.onUpdateVotes(map.getString("uid"), map.getString("votes"), map.getIntValue("isfirst")); - break; - case Constants.SOCKET_FAKE_FANS: - JSONObject obj = map.getJSONObject("ct"); - String s = obj.getJSONObject("data").getJSONArray("info").getJSONObject(0).getString("list"); - L.e("僵尸粉--->" + s); - List list = JSON.parseArray(s, LiveUserGiftBean.class); - mListener.addFakeFans(list); - break; - case Constants.SOCKET_SET_ADMIN://设置或取消管理员 - systemChatMessage2(map.getString("ct")); - mListener.onSetAdmin(map.getString("touid"), map.getIntValue("action")); - break; - case Constants.SUPER_VISION://设置或取消管理员 - systemChatMessage2(map.getString("ct")); - break; - case Constants.SOCKET_BUY_GUARD://购买守护 - buyGuardInSameRoom(map); - break; - case Constants.SOCKET_LINK_MIC://连麦 - processLinkMic(map); - break; - case Constants.SOCKET_LINK_MIC_ANCHOR://主播连麦 - processLinkMicAnchor(map); - break; - case Constants.SOCKET_LINK_MIC_PK://主播PK - processAnchorLinkMicPk(map); - break; - case Constants.SOCKET_RED_PACK://红包消息 - String uid = map.getString("uid"); - if (TextUtils.isEmpty(uid)) { - return; - } - LiveChatBean liveChatBean = new LiveChatBean(); - liveChatBean.setType(LiveChatBean.RED_PACK); - liveChatBean.setId(uid); - String name = uid.equals(mLiveUid) ? mContext.getString(R.string.live_anchor) : map.getString("uname"); - liveChatBean.setContent(name + map.getString("ct")); - mListener.onRedPack(liveChatBean); - break; - - case Constants.SOCKET_LUCK_WIN://幸运礼物中奖 - mListener.onLuckGiftWin(map.toJavaObject(LiveLuckGiftWinBean.class)); - break; - - case Constants.SOCKET_PRIZE_POOL_WIN://奖池中奖 - mListener.onPrizePoolWin(map.toJavaObject(LiveGiftPrizePoolWinBean.class)); - break; - case Constants.SOCKET_PRIZE_POOL_UP://奖池升级 - mListener.onPrizePoolUp(map.getString("uplevel")); - break; - case Constants.SOCKET_HOUR://小时榜 - liveChatBean = new LiveChatBean(); - liveChatBean.setId("-1"); - liveChatBean.setType(LiveChatAdapter.MSG_HOUR_RANK_CHANGE); - liveChatBean.setContent(map.getJSONObject("ct").getString("text")); - mListener.onHourRank(liveChatBean, map.getJSONObject("ct").getJSONObject("new_rank")); - break; - //游戏socket - case Constants.SOCKET_GAME_ZJH://游戏 智勇三张 - if (CommonAppConfig.GAME_ENABLE) { - mListener.onGameZjh(map); - } - break; - case Constants.SOCKET_GAME_HD://游戏 海盗船长 - if (CommonAppConfig.GAME_ENABLE) { - mListener.onGameHd(map); - } - break; - case Constants.SOCKET_GAME_ZP://游戏 幸运转盘 - if (CommonAppConfig.GAME_ENABLE) { - mListener.onGameZp(map); - } - break; - case Constants.SOCKET_GAME_NZ://游戏 开心牛仔 - if (CommonAppConfig.GAME_ENABLE) { - mListener.onGameNz(map); - } - break; - case Constants.SOCKET_GAME_EBB://游戏 二八贝 - if (CommonAppConfig.GAME_ENABLE) { - mListener.onGameEbb(map); - } - break; - case Constants.SOCKET_SEND_ACTIVE_MSG://新增,活动聊天显示 - sendActiveMsg(map, received); - break; - case Constants.SOCKET_PRANKTURNTABLE://新增,整蛊消息 - mListener.prankTurntable(map.getString("msgtype"), map.getIntValue("time"), JSON.parseObject(map.getString("ct"))); - String msgtype = map.getString("msgtype"); - JSONObject jsonObject = JSON.parseObject(map.getString("ct")); -// if ("1".equals(msgtype)) {//新年大作战活动 - LiveChatBean chatBean = new LiveChatBean(); - chatBean.setId(jsonObject.getString("uid")); - chatBean.setUserNiceName(jsonObject.getString("user_nicename")); - if ("1".equals(map.getString("msgtype"))) { - chatBean.setType(-3); - } else { - chatBean.setType(-4); - } - chatBean.setContent(jsonObject.getString("content")); - chatBean.setBubble(jsonObject.getString("display_src")); - chatBean.setMedal(jsonObject.getString("hope_nicename"));//做为拯救人名字 - chatBean.setAnchorName(jsonObject.getString("anchor_nicename")); - mListener.onChat(chatBean, 1); -// } - break; - case Constants.SOCKET_USEHOTCARD://新增,热度卡消息 -// mListener.prankTurntable(map.getString("msgtype"), map.getIntValue("time"), JSON.parseObject(map.getString("ct"))); - JSONObject jsonObject2 = JSON.parseObject(map.getString("ct")); - LiveChatBean chatBean2 = new LiveChatBean(); - chatBean2.setType(-6); - chatBean2.setBubble(jsonObject2.getString("system_bubble")); - chatBean2.setId(jsonObject2.getString("user_id")); - chatBean2.setUserNiceName(jsonObject2.getString("user_name")); - chatBean2.setHot_num(jsonObject2.getString("hot_num")); - chatBean2.setHot_card(jsonObject2.getString("hot_card")); - getIsHot(); - mListener.onChat(chatBean2, 1); - break; - case Constants.LOVE_CHECK://甜蜜 - JSONObject jsonObject3 = JSON.parseObject(map.getString("ct")); - LiveChatBean chatBean3 = new LiveChatBean(); - chatBean3.setType(-7); - chatBean3.setBubble(jsonObject3.getString("system_bubble")); - chatBean3.setId(jsonObject3.getString("user_id")); - chatBean3.setUserNiceName(jsonObject3.getString("user_name")); - chatBean3.setHot_num(jsonObject3.getString("gift_name")); - mListener.onChat(chatBean3, 1); - break; - case Constants.TRUMPET_NOTIFY://全站喇叭 - SocketModel model = GsonUtils.fromJson(socketMsg, SocketModel.class); - List msg = model.getMsg(); - if (msg.size() > 0) { -// EventBus.getDefault().post(msg.get(0)); - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.TRUMPET_NOTIFY) - .setMsgModel(msg.get(0))); - } - break; - case Constants.RECOMMEND_CARD_NOTIFY://推荐卡消息通知 - SocketModel recommendCardNotifyModel = GsonUtils.fromJson(socketMsg, SocketModel.class); - List recommendCardNotifyMsg = recommendCardNotifyModel.getMsg(); - if (recommendCardNotifyMsg.size() > 0) { - - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.RECOMMEND_CARD_NOTIFY) - .setMsgModel(recommendCardNotifyMsg.get(0))); - } - break; - case Constants.STAR_CHALLENGE_UPDATE://星级助力 -// SocketModel starChallengeModel = GsonUtils.fromJson(socketMsg, SocketModel.class); -// List starChallengeMsg = starChallengeModel.getMsg(); -// if (starChallengeMsg.size() > 0) { -// -// Bus.get().post(new LiveAudienceEvent() -// .setType(LiveAudienceEvent.LiveAudienceType.START_MESSAGE) -// .setMsgModel(starChallengeMsg.get(0))); -// } - break; - case Constants.AI_AUTOMATIC_SPEECH: - case Constants.AI_AUTOMATIC_SPEECH_LIVE: - //{"name_color":"#f19ec2","ai_name":"助手小小P","content":"@1 ","user_name":"1","icon":"https://downs.yaoulive.com/xzs_tab.png","system_bubble":"https://downs.yaoulive.com/xzs_qipao.9.png"} - AiAutomaticSpeechModel aiAutomaticSpeechModel = GsonUtils.fromJson(map.getString("ct"), AiAutomaticSpeechModel.class); - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.AI_AUTOMATIC_SPEECH) - .setAiAutomaticSpeechModel(aiAutomaticSpeechModel)); - break; - case Constants.STAR_CHALLENGE_UPGRADE_NOTIFY: - SocketModel starChallengeUpgradeNotify = GsonUtils.fromJson(socketMsg, SocketModel.class); - List starChallengeUpgradeNotifyMsg = starChallengeUpgradeNotify.getMsg(); - if (starChallengeUpgradeNotifyMsg.size() > 0) { - - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.STAR_CHALLENGE_UPGRADE_NOTIFY) - .setMsgModel(starChallengeUpgradeNotifyMsg.get(0))); - } - break; - case Constants.LuckyAngel: - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.LUCKY_ANGEL) - .setMsgModel(GsonUtils.fromJson(map.getJSONObject("ct").toString(), MsgModel.class))); - break; - case Constants.Lucky100Check: - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.LUCKY_100_CHECK) - .setMsgModel(GsonUtils.fromJson(map.getJSONObject("ct").toString(), MsgModel.class))); - break; - case Constants.PK_RANK_UPDATE: - Log.i("PK排位", map.toString()); - JSONObject item = map.getJSONObject("ct"); - PkRankBean pkRankBean = new PkRankBean(); - pkRankBean.setId(Integer.parseInt(item.getString("new_rank_id"))); - pkRankBean.setName(item.getString("new_rank_name")); - pkRankBean.setImg(item.getString("new_rank_img")); - pkRankBean.setNewRankNameEn(item.getString("new_rank_name_en")); - EventBus.getDefault().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.PK_RANK_UPDATE) - .setObject(pkRankBean)); - break; - case Constants.CUSTOM_FULL_SERVICE_NOTIFY: - Log.e("全服通知", map.toString()); - CustomFullServiceNotifyEvent customFullServiceNotifyEvent = GsonUtils.fromJson(map.toString(), CustomFullServiceNotifyEvent.class); - EventBus.getDefault().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.CUSTOM_FULL_SERVICE_NOTIFY) - .setCustomFullServiceNotifyEvent(customFullServiceNotifyEvent)); - break; - case Constants.XYD_COMPLETE: - -// xydComplete(map); - XydCompleteModel xydCompleteModel = GsonUtils.fromJson(map.toString(), XydCompleteModel.class); - EventBus.getDefault().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.XYD_COMPLETE) - .setXydCompleteModel(xydCompleteModel) - .setLiveReceiveGiftBean(JSON.parseObject(map.toString(), LiveReceiveGiftBean.class))); - break; - case "GuardSpecialEffect": - LiveReceiveGiftBean giftBean = JSON.parseObject(map.toString(), LiveReceiveGiftBean.class); - giftBean.setMedal_name(map.getString("medal_name")); - EventBus.getDefault().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.GuardSpecialEffect) - .setLiveReceiveGiftBean(giftBean)); - break; - case Constants.WISH_LIST_PROGRESS: - StringBuffer conString = new StringBuffer(); - conString.append(WordUtil.isNewZh() ? map.getString("msg") : map.getString("msg_en")); - EventBus.getDefault().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.WISH_LIST_PROGRESS) - .setWishListProgress(new WishModel() - .setWishlistProgress(map.getString("wishlist_progress")) - .setWishlistIcon(map.getString("wishlist_icon")) - .setWishlistName(map.getString("wishlist_name")) - .setWishlistNum(map.getString("wishlist_num")) - .setGiftType(map.getInteger("giftId")) - .setLuid(conString.toString())).setUname(map.getString("userName")).setLiveType(Integer.parseInt(map.getString("level")))); - break; - case Constants.LIVE_VOTE_CREATE: - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.VOTE_CREATE) - .setObject(map) - ); - break; - case Constants.LIVE_VOTE_END: - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.VOTE_END) - .setObject(map) - ); - EventBus.getDefault().post(new LiveAnchorEvent() - .setType(LiveAnchorEvent.LiveAnchorType.VOTE_ANCHOR_END) - .setObject(map) - ); - break; - case Constants.LIVE_VOTE_UPDATE: - //通知给观众 - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.VOTE_UPDATE) - .setObject(map) - ); - //通知给主播 - EventBus.getDefault().post(new LiveAnchorEvent() - .setType(LiveAnchorEvent.LiveAnchorType.VOTE_ANCHOR_UPDATE) - .setObject(map) - ); - break; - case Constants.LIVE_PK_END: - - mListener.onEndPk(map.getLong("uid"), - map.getLong("pkuid"), - map.getLong("uid_score"), - map.getLong("pkuid_score"), - JSONObject.parseObject(map.getJSONObject("ct").getJSONObject("pk_top_users").toJSONString(), LivePKUserListBean.class) - ); - break; - case Constants.RED_PACKET: - RedPacketModel redPacketModel = GsonUtils.fromJson(map.toString(), RedPacketModel.class); - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.RED_PACKET) - .setRedPacketModel(redPacketModel)); - break; - case Constants.RED_PACKET_SUPER_JACKPOT: - RedPacketInfoModel redPacketInfoModel = GsonUtils.fromJson(map.toString(), RedPacketInfoModel.class); - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.RED_PACKET_SUPER_JACKPOT) - .setRedPacketInfoModel(redPacketInfoModel)); - break; - case "GiftWallIlluminate": - Log.e("GiftWallIlluminate", map.toString()); - Bus.get().post(new GiftWallIlluminateEvent() - .setNewNumber(map.getInteger("new_number")) - .setMaxNumber(map.getInteger("max_number"))); - break; - case SOCKET_LIVE_MSG_TO_USER: - sendToUserMsg(map); - break; - case "SudGameCreateRoom": - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.SUD_GAME_CREATE_ROOM) - .setAvatar(WordUtil.isNewZh() ? map.getString("sud_game_name") : map.getString("sud_game_name_en")) - .setCreateSudRoomModel(GsonUtils.fromJson(map.toString(), SudGameDateModel.class))); - break; - case "sendQuickGift": - SendQuickGiftModel sendQuickGiftModel = GsonUtils.fromJson(map.toString(), SendQuickGiftModel.class); - StringBuffer stringBuffer = new StringBuffer(); - stringBuffer.append(sendQuickGiftModel.getUserNicename()) - .append(WordUtil.isNewZh() ? " 送出了 " : " sent ") - .append(sendQuickGiftModel.getQuickGiftNumber()) - .append(WordUtil.isNewZh() ? " 個小PD " : " small pandas "); - systemChatMessage2(stringBuffer.toString()); - Bus.get().post(new QuickGiftingEvent().setHotNum(sendQuickGiftModel.getHotNum())); - break; - case Constants.LIVE_PK_RANDOM_START: - item = map.getJSONObject("ct"); - item.getString("text"); - item.getString("pktt_img"); - item.getString("uid_win_continuity"); - item.getString("pkuid_win_continuity"); - pkRankBean = new PkRankBean(); - pkRankBean.setBlueVal(item.getString("pkuid_win_continuity")); - pkRankBean.setRedVal(item.getString("uid_win_continuity")); - pkRankBean.setPkTopImgUrl(item.getString("pktt_img")); - - EventBus.getDefault().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.PK_RANK_START) - .setObject(pkRankBean)); - break; - case "guardMaturityDateRemind": - GuardMaturityDateRemindModel maturityDateRemindModel = GsonUtils.fromJson(map.toString(), GuardMaturityDateRemindModel.class); - Bus.get().post(maturityDateRemindModel); - break; - case "SendMoneyLong": - SendMoneyLongModel sendMoneyLongModel = GsonUtils.fromJson(map.toString(), SendMoneyLongModel.class); - Bus.get().post(sendMoneyLongModel); - break; - case "SendMoneyLongEnd": - Bus.get().post(new SendMoneyLongEndEvent()); - break; - case Constants.SOCKET_LIVE_ANCHOR_PK_DIALOG: - item = map.getJSONObject("ct"); - //DialogUitl.showSimpleDialog(mContext,WordUtil.isNewZh()?item.getString("text"):item.getString("text_en"),null); - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.LIVE_DIALOG_ANCHOR_TIPS) - .setObject(WordUtil.isNewZh() ? item.getString("text") : item.getString("text_en"))); - break; - - } - } - - private void buyGuardInSameRoom(JSONObject map) { - if (TextUtils.isEmpty(map.getString("ancherName")) || TextUtils.isEmpty(map.getString("uname"))) - return; - String guardName = WordUtil.isNewZh() ? "星之守護" : "Star Guardian"; - switch (map.getIntValue("guard_type")) { - case 1: - guardName = WordUtil.isNewZh() ? "星之守護" : "Star Guardian"; - break; - case 2: - guardName = WordUtil.isNewZh() ? "王之守護" : "King Guardian"; - break; - case 3: - guardName = WordUtil.isNewZh() ? "神之守護" : "God Guardian"; - break; - } - String content = WordUtil.isNewZh() ? "%s在%s的直播間開通了%s" : "%s has been opened in %s live broadcast room %s"; - content = String.format(content, map.getString("uname"), map.getString("ancherName"), guardName); - LiveBuyGuardMsgBean buyGuardMsgBean = new LiveBuyGuardMsgBean(); - buyGuardMsgBean.setUid(map.getString("uid")); - buyGuardMsgBean.setUserName(content); - buyGuardMsgBean.setVotes(map.getString("votestotal")); - buyGuardMsgBean.setGuardNum(map.getIntValue("guard_nums")); - buyGuardMsgBean.setGuardType(map.getIntValue("guard_type")); - mListener.onBuyGuard(buyGuardMsgBean); - } - - private void buyGuardByNotify(JSONObject map) { - if (mLiveUid.equals(map.getString("liveuid"))) { -// buyGuardInSameRoom(map); - //同一直播间,玩家自己开通,也能看到全服通知 - String userId = CommonAppConfig.getInstance().getUid(); - String uid = map.getString("uid"); - if (userId.equals(uid)) { - LiveReceiveGiftBean receiveGiftBean = new LiveReceiveGiftBean(); - receiveGiftBean.setUserNiceName(map.getString("uname")); - receiveGiftBean.setAncherName(map.getString("ancherName")); - receiveGiftBean.setmLiveUId(mLiveUid); - receiveGiftBean.setRoomnum(map.getString("liveuid")); - receiveGiftBean.setmTypeBuyGuard(true); - receiveGiftBean.setUid(uid); - receiveGiftBean.setGuardType(map.getString("guard_type")); - receiveGiftBean.setSendtype(map.getIntValue("action")); - mListener.onSendGift(receiveGiftBean, null); - } - } else { - LiveReceiveGiftBean receiveGiftBean = new LiveReceiveGiftBean(); - receiveGiftBean.setUserNiceName(map.getString("uname")); - receiveGiftBean.setAncherName(map.getString("ancherName")); - receiveGiftBean.setmLiveUId(mLiveUid); - receiveGiftBean.setRoomnum(map.getString("liveuid")); - receiveGiftBean.setmTypeBuyGuard(true); - receiveGiftBean.setUid(map.getString("uid")); - receiveGiftBean.setGuardType(map.getString("guard_type")); - receiveGiftBean.setSendtype(map.getIntValue("action")); - mListener.onSendGift(receiveGiftBean, null); - } - } - - - private void buyZuoJiByNotify(JSONObject map) { - LiveReceiveGiftBean receiveGiftBean = new LiveReceiveGiftBean(); - receiveGiftBean.setUserNiceName(map.getString("nickname")); - receiveGiftBean.setCarName(map.getString("carname")); - receiveGiftBean.setSendtype(map.getIntValue("action")); - mListener.onBuyZuoji(receiveGiftBean); - } - - - private void buyLiangNameByNotify(JSONObject map) { - LiveReceiveGiftBean receiveGiftBean = new LiveReceiveGiftBean(); - receiveGiftBean.setUserNiceName(map.getString("nickname")); - receiveGiftBean.setLiangName(map.getString("liangname")); - receiveGiftBean.setSendtype(map.getIntValue("action")); - mListener.onBuyLiangName(receiveGiftBean); - } - - private void buyVipByNotify(JSONObject map) { - LiveReceiveGiftBean receiveGiftBean = new LiveReceiveGiftBean(); - receiveGiftBean.setUserNiceName(map.getString("nicename")); - receiveGiftBean.setVipName(map.getString("ct")); - receiveGiftBean.setAvatar(map.getString("notice")); - receiveGiftBean.setAllServerNotify(true); - receiveGiftBean.setmLiveUId(map.getString("anchorUid")); - receiveGiftBean.setGifUrl(map.getString("special_src")); - receiveGiftBean.setVipTime(map.getString("viplength")); - receiveGiftBean.setRoomnum(map.getString("anchorUid")); - receiveGiftBean.setAncherName(map.getString("ancherName")); - receiveGiftBean.setNobilityid(map.getString("nobilityid")); - receiveGiftBean.setNobilityname(map.getString("nobilityname")); - receiveGiftBean.setOpentype(map.getString("opentype")); - receiveGiftBean.setSendtype(map.getIntValue("action")); - receiveGiftBean.setSendtype(map.getIntValue("action")); - receiveGiftBean.setUname(map.getString("uname")); - receiveGiftBean.setUhead(map.getString("uhead")); - if (map.getString("notice").equals("1")) { - LiveRoomViewHolder.paygzGif(map.getString("special_src"), map.getString("anchorUid")); - } - mListener.onBuyVip(receiveGiftBean); - } - - private void sendActiveMsg(JSONObject map, SocketReceiveBean received) { - String msgtype = map.getString("msgtype"); - if ("1".equals(msgtype)) {//新年大作战活动 - LiveChatBean chatBean = new LiveChatBean(); - chatBean.setId(map.getString("uid")); - chatBean.setMedalLevelImageUrl(map.getString("monster_str"));//昵称暂时做为活动图片地址 - chatBean.setContent(map.getString("url"));//暂时做为活动链接地址 - chatBean.setUserNiceName(map.getString("activename")); - chatBean.setType(6); - mListener.onChat(chatBean, 0); - } - } - - /** - * 七日留存新用户主播端弹幕显示接口 - */ - private void sendToUserMsg(JSONObject map) { - LiveChatBean bean = new LiveChatBean(); - bean.setId(map.getString("uid")); - bean.setAtUserID(map.getString("toUserID")); - bean.setContent(map.getString("ct")); - bean.setType(LiveChatBean.TYPE_TO_USER_MSG); - bean.setUserNiceName(map.getString("user_nicename")); - bean.setToUid(CommonAppConfig.getInstance().getUid()); - mListener.onChat(bean, 1); - } - - private void wordLightEnterRoom(JSONObject map, SocketReceiveBean received) { - String msgtype = map.getString("msgtype"); - if ("2".equals(msgtype)) {//发言,点亮 - if ("409002".equals(received.getRetcode())) { - ToastUtil.show(WordUtil.isNewZh() ? "你已經被禁言" : "You\'ve been banned"); - return; - } - - //禁言别人,自己发言只能自己看到 - if ("409100".equals(received.getRetcode())) { - String uid = map.getString("uid"); - if (uid == null || !uid.equals(CommonAppConfig.getInstance().getUid())) { - return; - } - } - LiveChatBean chatBean = new LiveChatBean(); - chatBean.setId(map.getString("uid")); - chatBean.setUserNiceName(map.getString("uname")); - chatBean.setLevel(map.getIntValue("level")); - chatBean.setAnchor(map.getIntValue("isAnchor") == 1); - chatBean.setManager(map.getIntValue("usertype") == Constants.SOCKET_USER_TYPE_ADMIN); - chatBean.setContent(map.getString("ct")); - int heart = map.getIntValue("heart"); - chatBean.setHeart(heart); - if (heart > 0) { - chatBean.setType(LiveChatBean.LIGHT); - } - chatBean.setLiangName(map.getString("liangname")); - chatBean.setBubble(map.getString("bubble")); - chatBean.setMedal(map.getString("medal")); - chatBean.setMedal_new(map.getString("medal_new")); - chatBean.setMedal_new_en(map.getString("medal_new_en")); - chatBean.setVipType(map.getIntValue("vip_type")); - chatBean.setVipType(map.getIntValue("vip_type")); - chatBean.setMedal_honor(map.getString("medal_honor")); - chatBean.setGood_nub(map.getString("good_num")); - chatBean.setNobleId(map.getString("noble_id"));//貴族ID - chatBean.setStartColor(map.getString("startColor"));//昵称开始颜色 - chatBean.setEndColor(map.getString("endColor"));//昵称结束颜色 - chatBean.setContentColor(map.getString("contentColor"));//文字内容颜色 - chatBean.setAtUserName(map.getString("atUserName"));//@名字 - chatBean.setAtUserID(map.getString("atUserID"));//@ID - if (map.containsKey("guard_type") && !map.getString("guard_type").equals("undefined")) { - chatBean.setGuardType(map.getIntValue("guard_type")); - } - try { - //增加粉丝徽章信息 - chatBean.setMedalNmae(map.getString("medal_name")); - chatBean.setMedal_new_en(map.getString("medal_new_en")); - FansModel fansMedalBean = new NewLevelManager(mContext).getFansModel(map.getIntValue("medal_level")); - if (fansMedalBean != null) - chatBean.setMedalLevelImageUrl(fansMedalBean.getThumb()); - } catch (Exception e) { - e.printStackTrace(); - } - - if (!"".equals(map.getString("prankIcon")) && map.getString("prankIcon") != null) { - chatBean.setPrankIcon(map.getString("prankIcon")); - chatBean.setType(-5); - } - mListener.onChat(chatBean, 1); - } else if ("0".equals(msgtype)) {//用户进入房间 - JSONObject obj = JSON.parseObject(map.getString("ct")); - LiveUserGiftBean u = GsonUtils.fromJson(obj.toJSONString(), LiveUserGiftBean.class); - UserBean.Vip vip = new UserBean.Vip(); - int vipType = obj.getIntValue("vip_type"); - vip.setType(vipType); - u.setVip(vip); - UserBean.Car car = new UserBean.Car(); - car.setId(obj.getIntValue("car_id")); - car.setSwf(obj.getString("car_swf")); - car.setSwftime(obj.getFloatValue("car_swftime")); - car.setWords(obj.getString("car_words")); - u.setCar(car); - UserBean.Liang liang = new UserBean.Liang(); - String liangName = obj.getString("liangname"); - liang.setName(liangName); - u.setLiang(liang); - LiveChatBean chatBean = new LiveChatBean(); - chatBean.setType(LiveChatBean.ENTER_ROOM); - chatBean.setId(u.getId()); - chatBean.setMedal_honor(map.getString("medal_honor")); - chatBean.setGood_nub(map.getString("good_num")); - chatBean.setUserNiceName(u.getUserNiceName()); - chatBean.setLevel(u.getLevel()); - chatBean.setVipType(vipType); - chatBean.setLiangName(liangName); - chatBean.setBubble(obj.getString("bubble")); - chatBean.setMedal(obj.getString("medal")); - chatBean.setMedal_new(obj.getString("medal_new")); - chatBean.setMedal_new_en(obj.getString("medal_new_en")); - chatBean.setHot_num(obj.getString("hot_num")); - UserBean.DressBean dressBean = new UserBean.DressBean(); - dressBean.setAvatar_frame(obj.getString("avatar_frame")); - u.setDress(dressBean); - - chatBean.setManager(obj.getIntValue("usertype") == Constants.SOCKET_USER_TYPE_ADMIN); - chatBean.setContent(mContext.getString(R.string.live_enter_room)); - chatBean.setGuardType(obj.getIntValue("guard_type")); - chatBean.setNobleId(obj.getString("noble_id"));//貴族ID - chatBean.setStartColor(obj.getString("startColor"));//昵称开始颜色 - chatBean.setEndColor(obj.getString("endColor"));//昵称结束颜色 - chatBean.setContentColor(obj.getString("contentColor"));//文字内容颜色 - chatBean.setNobleIcon(obj.getString("noble_icon"));//貴族圖標 - chatBean.setBubbleSrc(obj.getString("bubbleSrc"));//氣泡 - //增加粉丝徽章信息 - chatBean.setMedalNmae(obj.getString("medal_name")); - chatBean.setUserNiceName(obj.getString("user_nicename"));//名字 - FansModel fansMedalBean = new NewLevelManager(mContext).getFansModel(map.getIntValue("medal_level")); - u.setFansLevel(obj.getIntValue("medal_level")); - u.setFansEnterRoomUrl(obj.getString("medal_backgroup_thumb")); - CommonAppConfig.getInstance().getUserBean().getDress().setMedal_new_en(obj.getString("medal_new_en")); - if (fansMedalBean != null) - chatBean.setMedalLevelImageUrl(fansMedalBean.getThumb()); - mListener.onEnterRoom(new LiveEnterRoomBean(u, chatBean)); - } - } - - //送礼物 全服通知 - private void sendGiftByNotify(JSONObject map) { - LiveReceiveGiftBean receiveGiftBean = JSON.parseObject(map.getString("ct"), LiveReceiveGiftBean.class); - receiveGiftBean.setAvatar(map.getString("uhead")); - receiveGiftBean.setUserNiceName(map.getString("uname")); - receiveGiftBean.setRoomnum(map.getString("roomnum")); - receiveGiftBean.setAncherName(map.getString("ancherName")); - receiveGiftBean.setHot_num(map.getString("hot_num")); - receiveGiftBean.setSendtype(map.getIntValue("action")); - receiveGiftBean.setmLiveUId(mLiveUid); - receiveGiftBean.setmTypeBuyGuard(false); - //全服通知时,不通知主播 - receiveGiftBean.setAllServerNotify(true); - LiveChatBean chatBean = new LiveChatBean(); - chatBean.setUserNiceName(receiveGiftBean.getUserNiceName()); - chatBean.setLevel(receiveGiftBean.getLevel()); - chatBean.setBubble(map.getString("bubble")); - chatBean.setMedal(map.getString("medal")); - chatBean.setId(map.getString("uid")); - chatBean.setMedal_honor(map.getString("medal_honor")); - chatBean.setGood_nub(map.getString("good_num")); - chatBean.setLiangName(map.getString("liangname")); - chatBean.setVipType(map.getIntValue("vip_type")); - chatBean.setType(LiveChatBean.GIFT); - //增加粉丝徽章信息 - chatBean.setMedalNmae(map.getString("medal_name")); - FansModel fansMedalBean = new NewLevelManager(mContext).getFansModel(map.getIntValue("medal_level")); - if (fansMedalBean != null) - chatBean.setMedalLevelImageUrl(fansMedalBean.getThumb()); - //聊天列表显示 玩家名 送 1 个 礼物名 - - if (CommonAppContext.lang.equals("chinese")) { - chatBean.setContent(mContext.getString(R.string.live_send_gift_1) + receiveGiftBean.getGiftCount() + mContext.getString(R.string.live_send_gift_2) + receiveGiftBean.getGiftName()); - } else { - chatBean.setContent(mContext.getString(R.string.live_send_gift_1) + " " + +receiveGiftBean.getGiftCount() + " " + mContext.getString(R.string.live_send_gift_2) + receiveGiftBean.getGiftnameen()); - } - - receiveGiftBean.setLiveChatBean(chatBean); - if (map.getIntValue("ifpk") == 1) { - if (!TextUtils.isEmpty(mLiveUid)) { - //获取PK排名数据 - LivePKUserListBean livePKUserListBean = JSON.parseObject(receiveGiftBean.getPkTopUsers(), LivePKUserListBean.class); - if (mLiveUid.equals(map.getString("roomnum"))) { - if (!mLiveUid.equals(map.getString("roomnum"))) { - mListener.onSendGift(receiveGiftBean, null); - } - //同一个直播间时才刷新pk - mListener.onSendGiftPk(map.getLongValue("pktotal1"), map.getLongValue("pktotal2"), livePKUserListBean); - } else { - if (!mLiveUid.equals(map.getString("roomnum"))) { - mListener.onSendGift(receiveGiftBean, null); - } - //同一个直播间时才刷新pk - if (mLiveUid.equals(map.getString("pkuid1")) || - mLiveUid.equals(map.getString("pkuid2"))) { - mListener.onSendGiftPk(map.getLongValue("pktotal2"), map.getLongValue("pktotal1"), livePKUserListBean); - } - } - } - } else { - if (!mLiveUid.equals(map.getString("roomnum"))) { - mListener.onSendGift(receiveGiftBean, null); - } - } - } - - private void xydComplete(JSONObject map) { - LiveReceiveGiftBean receiveGiftBean = new LiveReceiveGiftBean(); - receiveGiftBean.setAvatar(map.getString("uhead") + ""); - receiveGiftBean.setUserNiceName(map.getString("uname")); - receiveGiftBean.setRoomnum(map.getString("roomnum")); - receiveGiftBean.setAncherName(map.getString("ancherName")); - receiveGiftBean.setHot_num(map.getString("hot_num")); - receiveGiftBean.setDrpk_status(map.getString("drpk_status")); - receiveGiftBean.setGitType(map.getInteger("swftype ")); - receiveGiftBean.setmLiveUId(mLiveUid); - receiveGiftBean.setmTypeBuyGuard(false); - receiveGiftBean.setAllServerNotify(false); - receiveGiftBean.setGifUrl(map.getString("svg")); - LiveChatBean chatBean = new LiveChatBean(); - chatBean.setUserNiceName(receiveGiftBean.getUserNiceName()); - chatBean.setLevel(receiveGiftBean.getLevel()); - chatBean.setMedal_honor(map.getString("medal_honor")); - chatBean.setId(map.getString("uid")); - chatBean.setLiangName(map.getString("liangname")); - chatBean.setVipType(map.getIntValue("vip_type")); - chatBean.setBubble(map.getString("bubble")); - chatBean.setMedal(map.getString("medal")); - chatBean.setMedal_new(map.getString("medal_new")); - chatBean.setMedal_new_en(map.getString("medal_new_en")); - chatBean.setGood_nub(map.getString("good_num")); - chatBean.setType(LiveChatBean.GIFT); - if (map.get("guard_type") != null && !"".equals(map.get("guard_type")) && !"null".equals(map.get("guard_type"))) { - chatBean.setGuardType(map.getInteger("guard_type")); - } - if (CommonAppContext.lang.equals("chinese")) { - chatBean.setContent(mContext.getString(R.string.live_send_gift_1) + receiveGiftBean.getGiftCount() + mContext.getString(R.string.live_send_gift_2) + receiveGiftBean.getGiftName()); - } else { - chatBean.setContent(mContext.getString(R.string.live_send_gift_1) + " " + +receiveGiftBean.getGiftCount() + " " + mContext.getString(R.string.live_send_gift_2) + receiveGiftBean.getGiftnameen()); - - } - mListener.onSendGift(receiveGiftBean, null); - } - - // 玩家自己送礼物 - private void sendGiftInSameRoom(JSONObject map) { - String ctJson = map.getString("ct"); - SendBlindGiftEvent sendBlindGiftEvent = JSON.parseObject(ctJson, SendBlindGiftEvent.class); - LiveReceiveGiftBean receiveGiftBean = JSON.parseObject(map.getString("ct"), LiveReceiveGiftBean.class); - sendBlindGiftEvent.setUserNiceName(map.getString("uname")); - receiveGiftBean.setAvatar(map.getString("uhead") + ""); - receiveGiftBean.setUserNiceName(map.getString("uname")); - receiveGiftBean.setRoomnum(map.getString("roomnum")); - receiveGiftBean.setAncherName(map.getString("ancherName")); - receiveGiftBean.setHot_num(map.getString("hot_num")); - receiveGiftBean.setDrpk_status(map.getString("drpk_status")); - receiveGiftBean.setNamingCoin(map.getString("naming_live_name")); - receiveGiftBean.setNamingLiveName(map.getString("naming_live_name")); - receiveGiftBean.setNamingUid(map.getString("naming_uid")); - receiveGiftBean.setNamingLiveuid(map.getString("naming_liveuid")); - receiveGiftBean.setUser_naming_status(map.getInteger("user_naming_status")); - receiveGiftBean.setmLiveUId(mLiveUid); - receiveGiftBean.setmTypeBuyGuard(false); - receiveGiftBean.setAllServerNotify(false); - sendBlindGiftEvent.setGiftname_en(map.getString("giftname_en")); - //获取PK排名数据 - LivePKUserListBean livePKUserListBean = JSON.parseObject(receiveGiftBean.getPkTopUsers(), LivePKUserListBean.class); - - LiveChatBean chatBean = new LiveChatBean(); - chatBean.setUserNiceName(receiveGiftBean.getUserNiceName()); - chatBean.setLevel(receiveGiftBean.getLevel()); - chatBean.setMedal_honor(map.getString("medal_honor")); - chatBean.setId(map.getString("uid")); - chatBean.setLiangName(map.getString("liangname")); - chatBean.setVipType(map.getIntValue("vip_type")); - chatBean.setBubble(map.getString("bubble")); - chatBean.setMedal(map.getString("medal")); - chatBean.setMedal_new(map.getString("medal_new")); - chatBean.setMedal_new_en(map.getString("medal_new_en")); - chatBean.setGood_nub(map.getString("good_num")); - chatBean.setType(LiveChatBean.GIFT); - if (map.get("guard_type") != null && !"".equals(map.get("guard_type")) && !"null".equals(map.get("guard_type"))) { - chatBean.setGuardType(map.getInteger("guard_type")); - } - String special = ""; - if (sendBlindGiftEvent.getSpecialGift() == 1) { - if (WordUtil.isNewZh()) { - special = "送出" + receiveGiftBean.getGiftName() + sendBlindGiftEvent.getSpecialGiftName(); - } else { - special = "Send " + receiveGiftBean.getGiftName() + sendBlindGiftEvent.getSpecialGiftNameEn(); - } - chatBean.setContent(special); - } else { - if (WordUtil.isNewZh()) { - chatBean.setContent(mContext.getString(R.string.live_send_gift_1) + receiveGiftBean.getGiftCount() + mContext.getString(R.string.live_send_gift_2) + receiveGiftBean.getGiftName() + special); - } else { - chatBean.setContent(mContext.getString(R.string.live_send_gift_1) + " " + +receiveGiftBean.getGiftCount() + " " + mContext.getString(R.string.live_send_gift_2) + receiveGiftBean.getGiftnameen() + special); - } - } - //增加粉丝徽章信息 - chatBean.setMedalNmae(map.getString("medal_name")); - FansModel fansMedalBean = new NewLevelManager(mContext).getFansModel(map.getIntValue("medal_level")); - if (fansMedalBean != null) - chatBean.setMedalLevelImageUrl(fansMedalBean.getThumb()); - - receiveGiftBean.setLiveChatBean(chatBean); - - if (map.getIntValue("ifpk") == 1) { - try { - if (!TextUtils.isEmpty(mLiveUid)) { - if (mLiveUid.equals(map.getString("roomnum"))) { - mListener.onSendGift(receiveGiftBean, sendBlindGiftEvent); - mListener.onSendGiftPk(map.getLongValue("pktotal1"), map.getLongValue("pktotal2"), livePKUserListBean); - } else { - mListener.onSendGiftPk(map.getLongValue("pktotal2"), map.getLongValue("pktotal1"), livePKUserListBean); - } - } - } catch (Exception e) { - e.printStackTrace(); - } - - } else { - Log.i("tvvs", receiveGiftBean.getLiveChatBean().getContent()); - if (!TextUtils.isEmpty(sendBlindGiftEvent.getAction()) && TextUtils.equals("blind_box", sendBlindGiftEvent.getAction())) { - mListener.onSendGift(receiveGiftBean, sendBlindGiftEvent); - } else { - mListener.onSendGift(receiveGiftBean, null); - } - - } - if (map.getIntValue("drpk_status") == 1) { - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.LEAVE_PK_SCORE) - .setPkScores(map.getJSONArray("userlist")) - .setUid(mLiveUid) - .setTime(0)); -// LiveRoomViewHolder.UpPkBar(map.getJSONArray("userlist"), mLiveUid, 0); - } - - } - - /** - * 接收到系统消息,显示在聊天栏中 - */ - private void systemChatMessage(String content) { - LiveChatBean bean = new LiveChatBean(); - bean.setContent(content); - bean.setType(LiveChatBean.SYSTEM); - mListener.onChat(bean, 1); - } - - /** - * 接收到系统消息,显示在聊天栏中 - */ - private void systemChatMessage2(String content) { - LiveChatBean bean = new LiveChatBean(); - bean.setContent(content); - bean.setType(LiveChatBean.SYSTEM2); - mListener.onChat(bean, 1); - } - - /** - * 处理观众与主播连麦逻辑 - */ - private void processLinkMic(JSONObject map) { - int action = map.getIntValue("action"); - switch (action) { - case 1://主播收到观众连麦的申请 - UserBean u = new UserBean(); - u.setId(map.getString("uid")); - u.setUserNiceName(map.getString("uname")); - u.setAvatar(map.getString("uhead")); - u.setSex(map.getIntValue("sex")); - u.setLevel(map.getIntValue("level")); - mListener.onAudienceApplyLinkMic(u); - break; - case 2://观众收到主播同意连麦的消息 - if (map.getString("touid").equals(CommonAppConfig.getInstance().getUid())) { - mListener.onAnchorAcceptLinkMic(); - } - break; - case 3://观众收到主播拒绝连麦的消息 - if (map.getString("touid").equals(CommonAppConfig.getInstance().getUid())) { - mListener.onAnchorRefuseLinkMic(); - } - break; - case 4://所有人收到连麦观众发过来的流地址 - String uid = map.getString("uid"); - if (!TextUtils.isEmpty(uid) && !uid.equals(CommonAppConfig.getInstance().getUid())) { - mListener.onAudienceSendLinkMicUrl(uid, map.getString("uname"), map.getString("playurl")); - } - break; - case 5://连麦观众自己断开连麦 - mListener.onAudienceCloseLinkMic(map.getString("uid"), map.getString("uname")); - break; - case 6://主播断开已连麦观众的连麦 - mListener.onAnchorCloseLinkMic(map.getString("touid"), map.getString("uname")); - break; - case 7://已申请连麦的观众收到主播繁忙的消息 - if (map.getString("touid").equals(CommonAppConfig.getInstance().getUid())) { - mListener.onAnchorBusy(); - } - break; - case 8://已申请连麦的观众收到主播无响应的消息 - if (map.getString("touid").equals(CommonAppConfig.getInstance().getUid())) { - mListener.onAnchorNotResponse(); - } - break; - case 9://所有人收到已连麦的观众退出直播间消息 - mListener.onAudienceLinkMicExitRoom(map.getString("touid")); - break; - } - } - - /** - * 处理主播与主播连麦逻辑 - * - * @param map - */ - private void processLinkMicAnchor(JSONObject map) { - int action = map.getIntValue("action"); - switch (action) { - case 1://收到其他主播连麦的邀请的回调 - UserBean u = new UserBean(); - u.setId(map.getString("uid")); - u.setUserNiceName(map.getString("uname")); - u.setAvatar(map.getString("uhead")); - u.setSex(map.getIntValue("sex")); - u.setLevel(map.getIntValue("level")); - u.setLevelAnchor(map.getIntValue("level_anchor")); - mListener.onLinkMicAnchorApply(u, map.getString("stream")); - break; - case 3://对方主播拒绝连麦的回调 - mListener.onLinkMicAnchorRefuse(); - break; - case 4://所有人收到对方主播的播流地址的回调 - mListener.onLinkMicAnchorPlayUrl(map.getString("pkuid"), map.getString("pkpull")); - break; - case 5://断开连麦的回调 - mListener.onLinkMicAnchorClose(); - break; - case 7://对方主播正在忙的回调 - mListener.onLinkMicAnchorBusy(); - break; - case 8://对方主播无响应的回调 - mListener.onLinkMicAnchorNotResponse(); - break; - case 9://对方主播正在游戏 - mListener.onlinkMicPlayGaming(); - break; - } - } - - /** - * 处理主播与主播PK逻辑 - * - * @param map - */ - private void processAnchorLinkMicPk(JSONObject map) { - int action = map.getIntValue("action"); - Log.i("Socket", "action = " + action + " json = " + map.toString()); - L.eSw("RY RY RY RY "+map.toString()); - switch (action) { - case 1://收到对方主播PK回调 - UserBean u = new UserBean(); - u.setId(map.getString("uid")); - u.setUserNiceName(map.getString("pkname")); - u.setAvatar(map.getString("pkhead")); - mListener.onLinkMicPkApply(u, map.getString("stream"), 1); - break; - case 2://收到对方主播PK回调 - RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_START); - mListener.onLinkMicToPk(map.getString("uid"), map.getString("pkhead"), map.getString("pkname")); - mListener.onLinkMicPkStart(map.getString("uid"), map.getString("pkhead"), map.getString("pkname"), map.getString("is_ladders"));// mListener.onLinkMicPkStart(map.getString("uid")); - break; - case 3://对方主播拒绝PK的回调 - RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_REFUSE); - mListener.onLinkMicPkRefuse(); - break; - case 4://所有人收到PK开始址的回调 - // RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_START); - EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.PK_TWO_START).setObject(map.getString("pkuid"))); - mListener.onLinkMicPkStart(map.getString("pkuid"), map.getString("pkhead"), map.getString("pkname"), map.getString("is_ladders")); - break; - case 5://PK时候断开连麦的回调 -// if (rtcRoom != null) { - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.DISCONNEXT_PK_TIME)); - RCRTCEngine.getInstance().leaveOtherRoom(map.getString("pkuid"), true, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.e("ry", map.getString("pkuid") + "退出多人成功a as"); - - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - Log.e("ry", map.getString("pkuid") + "退asa出多人失败" + rtcErrorCode); - - } - }); - //断开连麦 - HttpClient.getInstance().post("livepk.setliveuserout", "livepk.setliveuserout") - .execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - - } - }); -// } - mListener.onLinkMicPkClose(1); - if (RandomPkManager.getInstance().isRandomModel()) { - RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_DEFAULT); - } - break; - case 7://对方主播正在忙的回调 - mListener.onLinkMicPkBusy(); - break; - case 8://对方主播无响应的回调 - mListener.onLinkMicPkNotResponse(); - break; - case 9://pk结束的回调 - mListener.onLinkMicPkEnd(map.getString("win_uid")); - EventBus.getDefault().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.LIVE_PK_END)); - break; - case 10://系统发起PK回调 - JSONObject msg1 = new JSONObject(); - msg1.put("type", "autoLivePK"); - msg1.put("uid", CommonAppConfig.getInstance().getUid()); - msg1.put("pkuid", CommonAppConfig.getInstance().getUid()); - msg1.put("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); - msg1.put("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()); - IMRTCManager.getInstance().requestJoinOtherRoom(map.getString("uid"), true, msg1.toString(), new IRCRTCResultCallback() { - @Override - public void onSuccess() { - if (WordUtil.isNewZh()) { - ToastUtil.show("邀请 " + map.getString("uid") + " 发送成功"); - } else { - ToastUtil.show("invite " + map.getString("uid") + " successful"); - } - runOnUiThread(new Runnable() { - @Override - public void run() { - dismiss(); - } - }); - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - runOnUiThread(new Runnable() { - @Override - public void run() { - dismiss(); - } - }); - //todo 安卓端状态码说明文档:https://docs.rongcloud.cn/v4/views/rtc/call/code/android.html - Log.e("ry", rtcErrorCode + "aaaaaa" + CommonAppConfig.getInstance().getUid() + "VDSSSS" + map.getString("uid")); - if (WordUtil.isNewZh()) { - ToastUtil.show("邀请 " + map.getString("uid") + " 发送失败 :" + rtcErrorCode); - } else { - ToastUtil.show("invite " + map.getString("uid") + " lose :" + rtcErrorCode); - } - } - }); - break; - } - } - } -} diff --git a/live/src/main/java/com/yunbao/live/socket/SocketRyLinkMicPkUtil.java b/live/src/main/java/com/yunbao/live/socket/SocketRyLinkMicPkUtil.java deleted file mode 100644 index 6049239b0..000000000 --- a/live/src/main/java/com/yunbao/live/socket/SocketRyLinkMicPkUtil.java +++ /dev/null @@ -1,211 +0,0 @@ -package com.yunbao.live.socket; - -import android.util.Log; - -import com.yunbao.common.CommonAppConfig; -import com.yunbao.common.Constants; -import com.yunbao.common.bean.UserBean; -import com.yunbao.common.http.HttpCallback; -import com.yunbao.common.http.HttpClient; -import com.yunbao.common.manager.imrongcloud.RongcloudIMManager; - -import io.rong.imlib.IRongCallback; -import io.rong.imlib.RongIMClient; -import io.rong.imlib.model.Conversation; -import io.rong.imlib.model.Message; -import io.rong.message.TextMessage; - -public class SocketRyLinkMicPkUtil { - /** - * 发起PK申请 - * - * @param pkUid 对方主播的uid - * @param stream 自己直播间的stream - */ - public static void linkMicPkApply(SocketRyClient client, String pkUid, String stream) { - if (client == null) { - return; - } - UserBean u = CommonAppConfig.getInstance().getUserBean(); - if (u == null) { - return; - } - } - - - /** - * 主播接受对方主播的Pk请求 - * - * @param pkUid 对方主播的uid - */ - public static void linkMicPkAccept(SocketRyClient client, String pkUid, String url, String name) { - HttpClient.getInstance().get("Livepk.changeLive", "Livepk.changeLive") - .params("uid", CommonAppConfig.getInstance().getUid()) - .params("pkuid", pkUid) - .params("type", "1") - .params("sign", "1") - .execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msgs, String[] info) { - if (code == 0) { - - HttpClient.getInstance().get("Livepk.setPK", "Livepk.setPK") - .params("uid", CommonAppConfig.getInstance().getUid()) - .params("pkuid", pkUid) - .params("type", "1") - .params("sign", "1") - .execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msgs, String[] info) { - if (code == 0) { - Log.e("ry",name+"啊啊"+url); - final SocketSendBean msg1 = new SocketSendBean() - .param("_method_", Constants.SOCKET_LINK_MIC_PK) - .param("action", 4) - .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) - .param("pkuid", pkUid) - .param("uid", CommonAppConfig.getInstance().getUid()) - .param("pkhead", url) - .param("pkname", name); - msg1.create(); - - Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; - TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); - Message message1 = Message.obtain("g" + CommonAppConfig.getInstance().getUid(), conversationType, messageContent); - - RongcloudIMManager.sendMessage(message1, null, null, new IRongCallback.ISendMessageCallback() { - @Override - public void onAttached(Message message) { - - } - - @Override - public void onSuccess(Message message) { - Log.i("tx", "发送成功"); - } - - @Override - public void onError(Message message, RongIMClient.ErrorCode errorCode) { - - } - }); - } - - } - }); - } - } - }); - - - } - - /** - * 主播接受对方主播的Pk请求 - * - * @param pkUid 对方主播的uid - */ - public static void linkMicDRPkAccept(String pkUid) { - - - } - - /** - * 主播拒绝其他主播的连麦请求 - */ - public static void linkMicPkRefuse(SocketRyClient client, String pkUid) { - if (client == null) { - return; - } - UserBean u = CommonAppConfig.getInstance().getUserBean(); - if (u == null) { - return; - } - final SocketSendBean msg = new SocketSendBean() - .param("_method_", Constants.SOCKET_LINK_MIC_PK) - .param("action", 3) - .param("msgtype", 0) - .param("uid", u.getId()) - .param("uname", u.getUserNiceName()) - .param("pkuid", pkUid) - .param("ct", ""); - - msg.create(); - - Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; - TextMessage messageContent = TextMessage.obtain(msg.mResult.toString()); - Message message = Message.obtain(pkUid, conversationType, messageContent); - - RongcloudIMManager.sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { - @Override - public void onAttached(Message message) { - - } - - @Override - public void onSuccess(Message message) { - Log.i("tx", "发送成功"); - } - - @Override - public void onError(Message message, RongIMClient.ErrorCode errorCode) { - - } - }); - - } - - - /** - * 主播断开连麦 - */ - public static void linkMicAnchorClose(SocketRyClient client, String pkUid) { - if (client == null) { - return; - } - UserBean u = CommonAppConfig.getInstance().getUserBean(); - if (u == null) { - return; - } -// client.send(new SocketSendBean() -// .param("_method_", Constants.SOCKET_LINK_MIC_PK) -// .param("action", 5) -// .param("msgtype", 0) -// .param("uid", u.getId()) -// .param("ct", "") -// .param("pkuid", pkUid) -// .param("uname", u.getUserNiceName())); - - - } - - /** - * 当收到主播连麦的请求时候主播正在忙 - */ - public static void linkMicPkBusy(SocketClient client, String pkUid) { - if (client == null) { - return; - } -// client.send(new SocketSendBean() -// .param("_method_", Constants.SOCKET_LINK_MIC_PK) -// .param("action", 7) -// .param("msgtype", 10) -// .param("pkuid", pkUid)); - } - - /** - * 当收到主播连麦的请求时候主播无响应 - */ - public static void linkMicPkNotResponse(SocketRyClient client, String pkUid) { - if (client == null) { - return; - } -// client.send(new SocketSendBean() -// .param("_method_", Constants.SOCKET_LINK_MIC_PK) -// .param("action", 8) -// .param("msgtype", 10) -// .param("pkuid", pkUid)); - } - - -} diff --git a/live/src/main/java/com/yunbao/live/views/LiveEndViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveEndViewHolder.java index 6b926c278..90301ec46 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveEndViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveEndViewHolder.java @@ -37,7 +37,6 @@ import com.yunbao.common.views.weight.ClipPathCircleImage; import com.yunbao.live.R; import com.yunbao.live.activity.LiveAnchorActivity; import com.yunbao.live.activity.LiveAudienceActivity; -import com.yunbao.live.activity.LiveRyAnchorActivity; import com.yunbao.live.activity.LiveSwAnchorActivity; import com.yunbao.live.adapter.SearchRecommendBodyAdapter; import com.yunbao.live.event.JumpUserHomeEvent; @@ -234,9 +233,7 @@ public class LiveEndViewHolder extends AbsViewHolder implements View.OnClickList goHomeUser.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if (mContext instanceof LiveRyAnchorActivity) { - ((LiveRyAnchorActivity) mContext).superBackPressed(); - } else if (mContext instanceof LiveAudienceActivity) { + if (mContext instanceof LiveAudienceActivity) { ((LiveAudienceActivity) mContext).exitLiveRoom(); } else if (mContext instanceof LiveSwAnchorActivity) { ((LiveSwAnchorActivity) mContext).superBackPressed(); @@ -271,9 +268,7 @@ public class LiveEndViewHolder extends AbsViewHolder implements View.OnClickList .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if (mContext instanceof LiveRyAnchorActivity) { - ((LiveRyAnchorActivity) mContext).superBackPressed(); - } else if (mContext instanceof LiveAudienceActivity) { + if (mContext instanceof LiveAudienceActivity) { ((LiveAudienceActivity) mContext).exitLiveRoom(); } else if (mContext instanceof LiveSwAnchorActivity) { ((LiveSwAnchorActivity) mContext).superBackPressed(); @@ -375,8 +370,6 @@ public class LiveEndViewHolder extends AbsViewHolder implements View.OnClickList ((LiveAudienceActivity) mContext).exitLiveRoom(); } else if (mContext instanceof LiveSwAnchorActivity) { ((LiveSwAnchorActivity) mContext).superBackPressed(); - } else if (mContext instanceof LiveRyAnchorActivity) { - ((LiveRyAnchorActivity) mContext).superBackPressed(); } Bus.get().post(new CloseEvent()); } @@ -467,8 +460,6 @@ public class LiveEndViewHolder extends AbsViewHolder implements View.OnClickList ((LiveAudienceActivity) mContext).exitLiveRoom(); } else if (mContext instanceof LiveSwAnchorActivity) { ((LiveSwAnchorActivity) mContext).superBackPressed(); - } else if (mContext instanceof LiveRyAnchorActivity) { - ((LiveRyAnchorActivity) mContext).superBackPressed(); } } } diff --git a/live/src/main/java/com/yunbao/live/views/LiveNewReadyRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveNewReadyRyViewHolder.java deleted file mode 100644 index 6def839ff..000000000 --- a/live/src/main/java/com/yunbao/live/views/LiveNewReadyRyViewHolder.java +++ /dev/null @@ -1,981 +0,0 @@ -package com.yunbao.live.views; - -import static com.yunbao.live.event.LiveAudienceEvent.LiveAudienceType.WISH_LIST_UPDATE; - -import android.app.Dialog; -import android.content.Context; -import android.graphics.drawable.Drawable; -import android.net.ConnectivityManager; -import android.net.NetworkInfo; -import android.os.Build; -import android.os.Bundle; -import android.os.Handler; -import android.os.Looper; -import android.text.Html; -import android.text.TextUtils; -import android.util.Log; -import android.view.View; -import android.view.ViewGroup; -import android.view.inputmethod.InputMethodManager; -import android.widget.EditText; -import android.widget.ImageView; -import android.widget.TextView; - -import androidx.constraintlayout.widget.ConstraintLayout; -import androidx.core.content.ContextCompat; - -import com.lxj.xpopup.XPopup; -import com.lxj.xpopup.core.BasePopupView; -import com.lxj.xpopup.interfaces.XPopupCallback; -import com.yunbao.common.CommonAppConfig; -import com.yunbao.common.Constants; -import com.yunbao.common.bean.IMLoginModel; -import com.yunbao.common.bean.LiveAnchorCallMeModel; -import com.yunbao.common.bean.LiveAnchorSayModel; -import com.yunbao.common.bean.LiveClassBean; -import com.yunbao.common.bean.LiveRoomTypeBean; -import com.yunbao.common.bean.UserBean; -import com.yunbao.common.event.LivePushRyEvent; -import com.yunbao.common.glide.ImgLoader; -import com.yunbao.common.http.HttpCallback; -import com.yunbao.common.http.LiveHttpConsts; -import com.yunbao.common.http.LiveHttpUtil; -import com.yunbao.common.interfaces.CommonCallback; -import com.yunbao.common.interfaces.ImageResultCallback; -import com.yunbao.common.interfaces.OnItemClickListener; -import com.yunbao.common.manager.IMLoginManager; -import com.yunbao.common.utils.Bus; -import com.yunbao.common.utils.DialogUitl; -import com.yunbao.common.utils.L; -import com.yunbao.common.utils.ProcessImageUtil; -import com.yunbao.common.utils.RouteUtil; -import com.yunbao.common.utils.StringUtil; -import com.yunbao.common.utils.ToastUtil; -import com.yunbao.common.utils.WordUtil; -import com.yunbao.common.views.AbsViewHolder; -import com.yunbao.common.views.LiveClarityCustomPopup; -import com.yunbao.common.views.LiveNewWishListPopup; -import com.yunbao.common.views.LiveOpenCustomPopup; -import com.yunbao.common.views.LiveRobotSettingCustomPopup; -import com.yunbao.common.views.weight.ViewClicksAntiShake; -import com.yunbao.faceunity.FaceManager; -import com.yunbao.live.R; -import com.yunbao.live.activity.LiveActivity; -import com.yunbao.live.activity.LiveRyAnchorActivity; -import com.yunbao.live.dialog.LiveAnchorEditCallMeDialog; -import com.yunbao.live.dialog.LiveAnchorSayPopDialog; -import com.yunbao.live.dialog.LiveFaceUnityDialogFragment; -import com.yunbao.live.dialog.LiveNewRoomClassDialogFragment; -import com.yunbao.live.dialog.LiveNewRoomTypeDialogFragment; -import com.yunbao.live.dialog.LiveTimeDialogFragment; -import com.yunbao.live.event.LiveAudienceEvent; - -import org.greenrobot.eventbus.Subscribe; -import org.greenrobot.eventbus.ThreadMode; - -import java.io.File; -import java.util.Locale; - -import cn.rongcloud.rtc.api.RCRTCEngine; -import cn.rongcloud.rtc.api.stream.RCRTCCameraOutputStream; -import cn.rongcloud.rtc.api.stream.RCRTCVideoStreamConfig; -import cn.rongcloud.rtc.base.RCRTCParamsType; - -public class LiveNewReadyRyViewHolder extends AbsViewHolder implements View.OnClickListener { - - private ConstraintLayout mAvatar, mRootView; - private TextView mCoverText; - private EditText mEditTitle; - private ProcessImageUtil mImageUtil; - private File mAvatarFile; - private TextView mLiveClass, anchorAgreement; - private TextView mLiveTypeTextView, liveClarity;//房间类型TextView - private TextView mLiveWishListTextView;//心愿单TextView - private int mLiveClassID;//直播频道id - private int mLiveType;//房间类型 - private int mLiveTypeVal;//房间密码,门票收费金额 - private int mLiveTimeCoin;//计时收费金额 - private boolean mOpenLocation = true; - private int mLiveSdk; - private LiveClassBean classBean; - private FaceManager manager; - private TextView faceTextView;//提示人脸未检测到的TextView - private ImageView imgClarity, selectorProtocol; - private int selectClarity = 1; - private LiveOpenCustomPopup liveOpenCustomPopup; - private boolean selector = true; - private String mLiveUid; - - public LiveNewReadyRyViewHolder(Context context, ViewGroup parentView, int liveSdk) { - super(context, parentView, liveSdk); - } - - @Override - protected void processArguments(Object... args) { - if (args.length > 0) { - mLiveSdk = (int) args[0]; - } - } - - @Override - protected int getLayoutId() { - return R.layout.view_new_live_ready; - } - - @Override - public void init() { - mRootView = (ConstraintLayout) findViewById(R.id.traceroute_rootview); - imgClarity = (ImageView) findViewById(R.id.img_clarity); - selectorProtocol = (ImageView) findViewById(R.id.selector_protocol); - liveClarity = (TextView) findViewById(R.id.live_clarity); - anchorAgreement = (TextView) findViewById(R.id.anchor_agreement); - mRootView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - InputMethodManager imm = (InputMethodManager) - mContext.getSystemService(Context.INPUT_METHOD_SERVICE); - imm.hideSoftInputFromWindow(view.getWindowToken(), 0); - } - }); - - mAvatar = (ConstraintLayout) findViewById(R.id.avatar); - mAvatar.setOnClickListener(this); - UserBean u = CommonAppConfig.getInstance().getUserBean(); - ImgLoader.displayDrawable(mContext, u.getAvatar(), new ImgLoader.DrawableCallback() { - @Override - public void onLoadSuccess(Drawable drawable) { - mAvatar.setBackground(drawable); - } - - @Override - public void onLoadFailed() { - - } - }); - mCoverText = (TextView) findViewById(R.id.cover_text); - mEditTitle = (EditText) findViewById(R.id.edit_title); - findViewById(R.id.btn_room_type).setOnClickListener(this); - mOpenLocation = true; - mLiveClass = (TextView) findViewById(R.id.live_class); - mLiveTypeTextView = (TextView) findViewById(R.id.text_room_type); - mLiveWishListTextView = (TextView) findViewById(R.id.text_wishlist); - faceTextView = (TextView) findViewById(R.id.faceTextView); - - mImageUtil = ((LiveActivity) mContext).getProcessImageUtil(); - mImageUtil.setImageResultCallback(new ImageResultCallback() { - - @Override - public void beforeCamera() { - ((LiveRyAnchorActivity) mContext).beforeCamera(); - } - - @Override - public void onSuccess(File file) { - if (file != null) { - ImgLoader.displayFileDrawable(mContext, file, new ImgLoader.DrawableCallback() { - @Override - public void onLoadSuccess(Drawable drawable) { - mAvatar.setBackground(drawable); - } - - @Override - public void onLoadFailed() { - - } - }); - if (mAvatarFile == null) { - mCoverText.setText(mContext.getString(R.string.live_cover_2)); - mCoverText.setBackground(ContextCompat.getDrawable(mContext, R.drawable.bg_live_cover)); - } - mAvatarFile = file; - } - } - - @Override - public void onFailure() { - } - }); - findViewById(R.id.btn_camera).setOnClickListener(this); - findViewById(R.id.btn_live_class).setOnClickListener(this); - findViewById(R.id.btn_close).setOnClickListener(this); - findViewById(R.id.btn_beauty).setOnClickListener(this); - findViewById(R.id.btn_robot).setOnClickListener(this); - findViewById(R.id.btn_start_live).setOnClickListener(this); - findViewById(R.id.btn_wishlist).setOnClickListener(this); - findViewById(R.id.btn_horizontally).setOnClickListener(this); - findViewById(R.id.anchor_agreement_layout).setOnClickListener(this); - findViewById(R.id.btn_live_anchor_say).setOnClickListener(this); - findViewById(R.id.btn_live_anchor_call_me).setOnClickListener(this); - - if (manager != null) { - manager.setFaceStatusChanged(new FaceManager.FaceStatusChanged() { - final Handler handler = new Handler(Looper.getMainLooper()); - - @Override - public void onFaceChanged(int num) { - handler.post(() -> { - if (num == 0) { - faceTextView.setVisibility(View.VISIBLE); - } else { - faceTextView.setVisibility(View.GONE); - } - }); - } - }); - //新美颜 - setFaceUnity(true); - - } - //设置清晰度 -// DeviceUtils.getMemory(mContext); //获取可用内存 -// DeviceUtils.getNetSpeed(mContext);//获取当前上传网速 -// Log.e("网速和内存", "内存:" + + " 网速:" + DeviceUtils.getNetSpeed(mContext)); - - IMLoginManager.get(mContext).setSelectClarity(selectClarity); - setSelectClarity(IMLoginManager.get(mContext).getSelectClarity()); - ViewClicksAntiShake - .clicksAntiShake( - findViewById(R.id.btn_live_clarity), () -> { - - LiveClarityCustomPopup liveClarityCustomPopup = - new LiveClarityCustomPopup(mContext, - IMLoginManager.get(mContext).getSelectClarity(), - IMLoginManager.get(mContext).getClarity() ? 0 : LiveClarityCustomPopup.BAN_1080, false); - new XPopup.Builder(mContext) - .setPopupCallback(new XPopupCallback() { - @Override - public void onCreated(BasePopupView popupView) { - - } - - @Override - public void beforeShow(BasePopupView popupView) { - - } - - @Override - public void onShow(BasePopupView popupView) { - - } - - @Override - public void onDismiss(BasePopupView popupView) { - setSelectClarity(liveClarityCustomPopup.getSelectClarity()); - } - - @Override - public void beforeDismiss(BasePopupView popupView) { - - } - - @Override - public boolean onBackPressed(BasePopupView popupView) { - return false; - } - - @Override - public void onKeyBoardStateChanged(BasePopupView popupView, int height) { - - } - - @Override - public void onDrag(BasePopupView popupView, int value, float percent, boolean upOrLeft) { - - } - - @Override - public void onClickOutside(BasePopupView popupView) { - - } - }) - .asCustom(liveClarityCustomPopup) - .show(); - }); - String keywordHtml2 = "" + mContext.getString(R.string.anchor_hint) + ""; - String contextHtml = "" + mContext.getString(R.string.anchor_agreement) + ""; - anchorAgreement.setText(Html.fromHtml(contextHtml + keywordHtml2)); - selectorProtocol.setPressed(true); - selectorProtocol.setSelected(true); - selector = selectorProtocol.isSelected(); - selectorProtocol.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - selector = !selector; - selectorProtocol.setSelected(selector); - } - }); - } - - private void setSelectClarity(int selectClarity) { - - this.selectClarity = selectClarity; - IMLoginManager.get(mContext).setSelectClarity(selectClarity); - switch (selectClarity) { - case 0: - imgClarity.setImageResource(R.mipmap.icon_sd); - liveClarity.setText(R.string.standard_clear); - break; - case 1: - imgClarity.setImageResource(R.mipmap.icon_hd); - liveClarity.setText(R.string.high_definition); - break; - case 2: - imgClarity.setImageResource(R.mipmap.icon_fhd); - liveClarity.setText(R.string.ultra_hd); - break; - } - if (liveOpenCustomPopup != null) { - liveOpenCustomPopup.setSelectClarity(selectClarity); - } - //設置開播分辨率 - RCRTCParamsType.RCRTCVideoResolution rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_480_848; - int minRate = 200; - int maxRate = 900; - switch (selectClarity) { - case 0: - rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_480_848; - minRate = 200; - maxRate = 900; - break; - case 1: - rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_720_1280; - minRate = 250; - maxRate = 2200; - break; - case 2: - rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_1080_1920; - minRate = 400; - maxRate = 4000; - break; - } - RCRTCVideoStreamConfig config = - RCRTCVideoStreamConfig.Builder.create() - .setMinRate(minRate) - .setMaxRate(maxRate) - .setVideoFps(RCRTCParamsType.RCRTCVideoFps.Fps_15) - .setVideoResolution(rcrtcVideoResolution) - .build(); - RCRTCEngine.getInstance().getDefaultVideoStream().setVideoConfig(config); - Log.e("切换分辨率", "时间戳" + System.currentTimeMillis()); - //重新发布一下流 - Bus.get().post(new LivePushRyEvent()); - } - - public void setManager(FaceManager manager) { - this.manager = manager; - } - - - @Override - public void onClick(View v) { - if (!canClick()) { - return; - } - int i = v.getId(); - if (i == R.id.avatar) { - setAvatar(); - - } else if (i == R.id.btn_camera) { - toggleCamera(); - } else if (i == R.id.btn_close) { - close(); - } else if (i == R.id.btn_live_class) { - chooseLiveClass(); - } else if (i == R.id.btn_beauty) { - //beauty();//momo美颜 - setFaceUnity(false); //新娱美颜 - } else if (i == R.id.btn_wishlist) { - //点击心愿单 - openWishListWindow(); - } else if (i == R.id.btn_room_type) { - chooseLiveType(); - } else if (i == R.id.btn_start_live) { - if (!selector) { - ToastUtil.show(mContext.getString(R.string.anchor_agreement_hint)); - return; - } - if (mLiveClassID == 0) { - ToastUtil.show(WordUtil.getNewString(R.string.live_choose_live_class)); - return; - } -// startLive(); - liveOpenCustomPopup = new LiveOpenCustomPopup(mContext, IMLoginManager.get(mContext).getSelectClarity(), classBean, liveRoomTypeBean) - .setSayStatus(IMLoginManager.get(mContext).getAnchorSayStatus()) - .setCallMeStatus(IMLoginManager.get(mContext).getAnchorCallStatus()) - .setCallBack(new LiveOpenCustomPopup.LiveOpenCallBack() { - @Override - - public void startLive(LiveRoomTypeBean liveRoomTypeModel, LiveClassBean classModel) { - if (classModel != null) { - classBean = classModel; - mLiveClassID = classBean.getId(); - } - liveRoomTypeBean = liveRoomTypeModel; - mLiveType = liveRoomTypeModel.getId(); - startLiveInit(); - liveOpenCustomPopup = null; - } - - @Override - public void selectClarity(int selectClarity) { - LiveClarityCustomPopup liveClarityCustomPopup = - new LiveClarityCustomPopup(mContext, - IMLoginManager.get(mContext).getSelectClarity(), - IMLoginManager.get(mContext).getClarity() ? 0 : LiveClarityCustomPopup.BAN_1080, false); - new XPopup.Builder(mContext) - .setPopupCallback(new XPopupCallback() { - @Override - public void onCreated(BasePopupView popupView) { - - } - - @Override - public void beforeShow(BasePopupView popupView) { - - } - - @Override - public void onShow(BasePopupView popupView) { - - } - - @Override - public void onDismiss(BasePopupView popupView) { - setSelectClarity(liveClarityCustomPopup.getSelectClarity()); - } - - @Override - public void beforeDismiss(BasePopupView popupView) { - - } - - @Override - public boolean onBackPressed(BasePopupView popupView) { - return false; - } - - @Override - public void onKeyBoardStateChanged(BasePopupView popupView, int height) { - - } - - @Override - public void onDrag(BasePopupView popupView, int value, float percent, boolean upOrLeft) { - - } - - @Override - public void onClickOutside(BasePopupView popupView) { - - } - }) - .asCustom(liveClarityCustomPopup) - .show(); - } - - @Override - public void openRobot() { - LiveRobotSettingCustomPopup liveRobotSettingCustomPopup = new LiveRobotSettingCustomPopup(mContext); - new XPopup.Builder(mContext) - .setPopupCallback(new XPopupCallback() { - @Override - public void onCreated(BasePopupView popupView) { - - } - - @Override - public void beforeShow(BasePopupView popupView) { - - } - - @Override - public void onShow(BasePopupView popupView) { - - } - - @Override - public void onDismiss(BasePopupView popupView) { - if (liveOpenCustomPopup != null) { - liveOpenCustomPopup.initDate(); - } - } - - @Override - public void beforeDismiss(BasePopupView popupView) { - - } - - @Override - public boolean onBackPressed(BasePopupView popupView) { - return false; - } - - @Override - public void onKeyBoardStateChanged(BasePopupView popupView, int height) { - - } - - @Override - public void onDrag(BasePopupView popupView, int value, float percent, boolean upOrLeft) { - - } - - @Override - public void onClickOutside(BasePopupView popupView) { - - } - }) - .asCustom(liveRobotSettingCustomPopup) - .show(); - } - - @Override - public void openLiveRoomType(LiveRoomTypeBean liveRoomTypeModel) { - liveRoomTypeBean = liveRoomTypeModel; - mLiveType = liveRoomTypeModel.getId(); - chooseLiveType(); - } - - @Override - public void openLiveClass(LiveClassBean classModel) { - if (classModel != null) { - classBean = classModel; - mLiveClassID = classBean.getId(); - } - chooseLiveClass(); - } - - @Override - public void openWishlist() { - //点击心愿单 - openWishListWindow(); - } - - @Override - public void openAnchorSay() { - openAnchorSayDialog(); - } - - @Override - public void openCallMe() { - openAnchorCallMeDialog(); - } - }); - new XPopup.Builder(mContext) - .asCustom(liveOpenCustomPopup) - .show(); - } else if (i == R.id.btn_locaiton) { - switchLocation(); - } else if (i == R.id.btn_horizontally) { - RCRTCCameraOutputStream cameraStream = RCRTCEngine.getInstance().getDefaultVideoStream(); - cameraStream.setPreviewMirror(!cameraStream.isPreviewMirror()); - } else if (i == R.id.btn_robot) { - new XPopup.Builder(mContext) - .asCustom(new LiveRobotSettingCustomPopup(mContext)) - .show(); - } else if (i == R.id.anchor_agreement_layout) { - String ct = Locale.getDefault().getLanguage(); - IMLoginModel model = IMLoginManager.get(mContext).getUserInfo(); - StringBuffer url = new StringBuffer(); - url.append(CommonAppConfig.HOST); - if (TextUtils.equals(ct, "zh")) { - url.append("/index.php?g=portal&m=page&a=index&id=671"); - } else { - url.append("/index.php?g=portal&m=page&a=index&id=672"); - } - url.append("&uid=") - .append(model.getId()) - .append("&token=") - .append(model.getToken()).append("&isZh=") - .append(WordUtil.isNewZh() ? "1" : 0); - RouteUtil.forwardLiveZhuangBanActivity(url.toString(), false); - } else if (i == R.id.btn_live_anchor_say) { - openAnchorSayDialog(); - } else if (i == R.id.btn_live_anchor_call_me) { - openAnchorCallMeDialog(); - } - } - - /** - * 新娱美颜 - */ - public void setFaceUnity(boolean init) { - LiveFaceUnityDialogFragment fragment = new LiveFaceUnityDialogFragment(mContext); - fragment.setManager(manager); - fragment.setDismissShowUi(mRootView); - if (mContext instanceof LiveRyAnchorActivity) { - fragment.show(((LiveRyAnchorActivity) mContext).getSupportFragmentManager(), "FaceUnity"); - mRootView.setVisibility(View.INVISIBLE); - if (init) { - fragment.dismiss(); - } - } - } - - /** - * 打开心愿单窗口 - */ - public void openWishListWindow() { -// LiveNewWishListDialogFragment fragment = new LiveNewWishListDialogFragment(); -// -// if (mContext instanceof LiveRyAnchorActivity) { -// fragment.show(((LiveRyAnchorActivity) mContext).getSupportFragmentManager(), "RY"); -// -// } - new XPopup.Builder(mContext) - .enableDrag(false) - .asCustom(new LiveNewWishListPopup((LiveRyAnchorActivity) mContext)) - .show(); - } - - public void openAnchorSayDialog() { - new LiveAnchorSayPopDialog(mContext).setLiveUid(mLiveUid).setOnItemClickListener(new OnItemClickListener() { - @Override - public void onItemClick(LiveAnchorSayModel bean, int position) { - if (liveOpenCustomPopup != null) { - liveOpenCustomPopup.setSayStatus(bean.getLivePreview().getIsShow() == 1); - } - } - }).showDialog(); - } - - public void openAnchorCallMeDialog() { - new LiveAnchorEditCallMeDialog(mContext).setLiveUid(mLiveUid).setOnItemClickListener(new OnItemClickListener() { - @Override - public void onItemClick(LiveAnchorCallMeModel bean, int position) { - if (liveOpenCustomPopup != null) { - liveOpenCustomPopup.setCallMeStatus(bean.getIsShow() == 1); - } - } - }).showDialog(); - } - - @Subscribe(threadMode = ThreadMode.MAIN) - public void updateStart(LiveAudienceEvent event) { - if (event.getType() == WISH_LIST_UPDATE) { - if (liveOpenCustomPopup != null) { - liveOpenCustomPopup.initDate(); - } - } - } - - /** - * 打开 关闭位置 - */ - private void switchLocation() { - if (mOpenLocation) { - new DialogUitl.Builder(mContext) - .setContent(mContext.getString(R.string.live_location_close_3)) - .setCancelable(true) - .setConfirmString(mContext.getString(R.string.live_location_close_2)) - .setClickCallback(new DialogUitl.SimpleCallback() { - - @Override - public void onConfirmClick(Dialog dialog, String content) { - toggleLocation(); - } - }) - .build() - .show(); - } else { - toggleLocation(); - } - } - - private void toggleLocation() { - mOpenLocation = !mOpenLocation; - } - - /** - * 设置头像 - */ - private void setAvatar() { - if (mLiveSdk == Constants.LIVE_SDK_TX) { - mImageUtil.getImageByAlbum(); - } else { - DialogUitl.showStringArrayDialog(mContext, new Integer[]{ - R.string.camera, R.string.alumb}, new DialogUitl.StringArrayDialogCallback() { - @Override - public void onItemClick(String text, int tag) { - if (tag == R.string.camera) { - mImageUtil.getImageByCamera(); - } else { - mImageUtil.getImageByAlbum(); - } - } - }); - } - } - - /** - * 切换镜头 - */ - private void toggleCamera() { - ((LiveRyAnchorActivity) mContext).toggleCamera(); - } - - /** - * 关闭 - */ - private void close() { - ((LiveRyAnchorActivity) mContext).endLives(); - } - - /** - * 选择直播频道 - */ - private void chooseLiveClass() { - /* try { - Intent intent = new Intent(mContext, LiveChooseClassActivity.class); - intent.putExtra(Constants.CLASS_ID, mLiveClassID); - mImageUtil.startActivityForResult(intent, mActivityResultCallback); - }catch (Exception e){ - - }*/ - - Bundle bundle = new Bundle(); - bundle.putInt(Constants.CLASS_ID, mLiveClassID); - LiveNewRoomClassDialogFragment fragment = new LiveNewRoomClassDialogFragment(); - fragment.setArguments(bundle); - fragment.setCallback(new CommonCallback() { - @Override - public void callback(LiveClassBean bean) { - classBean = bean; - mLiveClassID = classBean.getId(); - mLiveClass.setText(bean.getName()); - if (liveOpenCustomPopup != null) { - liveOpenCustomPopup.setClassBean(classBean); - } - } - }); - fragment.show(((LiveRyAnchorActivity) mContext).getSupportFragmentManager(), "LiveRoomTypeDialogFragment"); - - } - - /** - * 设置美颜 - */ - private void beauty() { - ((LiveRyAnchorActivity) mContext).beauty(); - // Intent intent = new Intent(mContext, Beauty360Activity3.class); - // mContext.startActivity(intent); - - } - - /** - * 选择直播类型 - */ - private LiveRoomTypeBean liveRoomTypeBean = new LiveRoomTypeBean(0, mContext.getString(R.string.live_room_public)); - - private void chooseLiveType() { - Bundle bundle = new Bundle(); - bundle.putInt(Constants.CHECKED_ID, mLiveType); - LiveNewRoomTypeDialogFragment fragment = new LiveNewRoomTypeDialogFragment(); - fragment.setArguments(bundle); - fragment.setCallback(new CommonCallback() { - @Override - public void callback(LiveRoomTypeBean bean) { - liveRoomTypeBean = bean; - switch (bean.getId()) { - case Constants.LIVE_TYPE_NORMAL: - onLiveTypeNormal(bean); - break; - case Constants.LIVE_TYPE_PWD: - onLiveTypePwd(bean); - break; - case Constants.LIVE_TYPE_PAY: - onLiveTypePay(bean); - break; - case Constants.LIVE_TYPE_TIME: - onLiveTypeTime(bean); - break; - } - if (liveOpenCustomPopup != null) { - liveOpenCustomPopup.setLiveRoomTypeBean(liveRoomTypeBean); - } - } - }); - fragment.show(((LiveRyAnchorActivity) mContext).getSupportFragmentManager(), "LiveRoomTypeDialogFragment"); - } - - /** - * 普通房间 - */ - private void onLiveTypeNormal(LiveRoomTypeBean bean) { - mLiveType = bean.getId(); - mLiveTypeTextView.setText(bean.getName()); - mLiveTypeVal = 0; - mLiveTimeCoin = 0; - } - - /** - * 密码房间 - */ - private void onLiveTypePwd(final LiveRoomTypeBean bean) { - DialogUitl.showSimpleInputDialog(mContext, mContext.getString(R.string.live_set_pwd), DialogUitl.INPUT_TYPE_NUMBER_PASSWORD, 8, new DialogUitl.SimpleCallback() { - @Override - public void onConfirmClick(Dialog dialog, String content) { - if (TextUtils.isEmpty(content)) { - ToastUtil.show(mContext.getString(R.string.live_set_pwd_empty)); - } else { - mLiveType = bean.getId(); - mLiveTypeTextView.setText(WordUtil.isNewZh() ? "密碼房" : "password room"); - if (StringUtil.isInt(content)) { - mLiveTypeVal = Integer.parseInt(content); - } - mLiveTimeCoin = 0; - dialog.dismiss(); - } - } - }); - } - - /** - * 付费房间 - */ - private void onLiveTypePay(final LiveRoomTypeBean bean) { - DialogUitl.showSimpleInputDialog(mContext, mContext.getString(R.string.live_set_fee), DialogUitl.INPUT_TYPE_NUMBER, 8, new DialogUitl.SimpleCallback() { - @Override - public void onConfirmClick(Dialog dialog, String content) { - if (TextUtils.isEmpty(content)) { - ToastUtil.show(mContext.getString(R.string.live_set_fee_empty)); - } else { - mLiveType = bean.getId(); - mLiveTypeTextView.setText(bean.getName()); - if (StringUtil.isInt(content)) { - mLiveTypeVal = Integer.parseInt(content); - } - mLiveTimeCoin = 0; - dialog.dismiss(); - } - } - }); - } - - /** - * 计时房间 - */ - private void onLiveTypeTime(final LiveRoomTypeBean bean) { - LiveTimeDialogFragment fragment = new LiveTimeDialogFragment(); - Bundle bundle = new Bundle(); - bundle.putInt(Constants.CHECKED_COIN, mLiveTimeCoin); - fragment.setArguments(bundle); - fragment.setCommonCallback(new CommonCallback() { - @Override - public void callback(Integer coin) { - mLiveType = bean.getId(); - mLiveTypeTextView.setText(bean.getName()); - mLiveTypeVal = coin; - mLiveTimeCoin = coin; - } - }); - fragment.show(((LiveRyAnchorActivity) mContext).getSupportFragmentManager(), "LiveTimeDialogFragment"); - } - - public void hide() { - if (mContentView != null && mContentView.getVisibility() == View.VISIBLE) { - mContentView.setVisibility(View.INVISIBLE); - } - } - - - public void show() { - if (mContentView != null && mContentView.getVisibility() != View.VISIBLE) { - mContentView.setVisibility(View.VISIBLE); - } - } - - /** - * 点击开始直播按钮 - */ - private void startLiveInit() { - if (isWifiProxy(mContext) || checkVPN((ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE))) { - ToastUtil.show(WordUtil.isNewZh() ? "檢測開啓了VPN或者代理,請先關閉VPN或者代理再開播。" : - "It is detected that VPN or proxy is turned on. Please turn off VPN or proxy before starting the broadcast."); - } else { - boolean startPreview = ((LiveRyAnchorActivity) mContext).isStartPreview(); -// if (!startPreview) { -// ToastUtil.show(R.string.please_wait); -// return; -// } - if (mLiveClassID == 0) { - ToastUtil.show(WordUtil.getNewString(R.string.live_choose_live_class)); - return; - } - createRoom(); - } - } - - private boolean isWifiProxy(Context context) { - final boolean IS_ICS_OR_LATER = Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH; - String proxyAddress; - int proxyPort; - if (IS_ICS_OR_LATER) { - proxyAddress = System.getProperty("http.proxyHost"); - String portStr = System.getProperty("http.proxyPort"); - proxyPort = Integer.parseInt((portStr != null ? portStr : "-1")); - } else { - proxyAddress = android.net.Proxy.getHost(context); - proxyPort = android.net.Proxy.getPort(context); - } - return (!TextUtils.isEmpty(proxyAddress)) && (proxyPort != -1); - } - - private boolean checkVPN(ConnectivityManager connMgr) { - //don't know why always returns null: - NetworkInfo networkInfo = connMgr.getNetworkInfo(ConnectivityManager.TYPE_VPN); - boolean isVpnConn = networkInfo == null ? false : networkInfo.isConnected(); - return isVpnConn; - } - - /** - * 请求创建直播间接口,开始直播 - */ - boolean isHttpBack = false; - - private void createRoom() { - if (!isHttpBack) { - isHttpBack = true; - if (mLiveClassID == 0) { - ToastUtil.show(WordUtil.getNewString(R.string.live_choose_live_class)); - return; - } - String title = mEditTitle.getText().toString().trim(); - LiveHttpUtil.newcreateRoom(title, mLiveClassID, mLiveType, mLiveTypeVal, mAvatarFile, IMLoginManager.get(mContext).getSelectClarity() + 1, false, new HttpCallback() { - @Override - public void onSuccess(int code, String msg, final String[] info) { - isHttpBack = false; - if (code == 0 && info.length > 0) { - L.e("开播", "createRoom------->" + info[0]); - final CommonAppConfig appConfig = CommonAppConfig.getInstance(); - UserBean u = appConfig.getUserBean(); - ((LiveRyAnchorActivity) mContext).startLiveSuccess(info[0], mLiveType, mLiveTypeVal); - } else { - ToastUtil.show(msg); - } - } - - @Override - public void onError() { - super.onError(); - isHttpBack = false; - } - }); - } else { - ToastUtil.show("請求中,請勿重複點擊"); - } - } - - public void release() { - mImageUtil = null; - } - - @Override - public void onDestroy() { - LiveHttpUtil.cancel(LiveHttpConsts.CREATE_ROOM); - } - - public void setLiveUid(String mLiveUid) { - this.mLiveUid = mLiveUid; - } -} diff --git a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java deleted file mode 100644 index e6a66e1e7..000000000 --- a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java +++ /dev/null @@ -1,1418 +0,0 @@ -package com.yunbao.live.views; - -import static com.lzy.okgo.utils.HttpUtils.runOnUiThread; - -import android.Manifest; -import android.app.Dialog; -import android.content.Context; -import android.graphics.Color; -import android.media.AudioManager; -import android.os.Build; -import android.os.Handler; -import android.os.Looper; -import android.text.TextUtils; -import android.util.Log; -import android.view.Gravity; -import android.view.View; -import android.view.ViewGroup; -import android.view.ViewParent; -import android.widget.FrameLayout; -import android.widget.ImageView; -import android.widget.RelativeLayout; -import android.widget.TextView; - -import com.google.android.exoplayer2.PlaybackException; -import com.google.android.exoplayer2.Player; -import com.google.android.exoplayer2.ui.StyledPlayerView; -import com.google.android.exoplayer2.video.VideoSize; -import com.lxj.xpopup.XPopup; -import com.lxj.xpopup.core.BasePopupView; -import com.lxj.xpopup.interfaces.XPopupCallback; -import com.lzf.easyfloat.EasyFloat; -import com.lzy.okserver.OkDownload; -import com.yunbao.common.bean.EnterRoomNewModel; -import com.yunbao.common.bean.UserBean; -import com.yunbao.common.dialog.LiveFontSizeSettingDialog; -import com.yunbao.common.http.HttpCallback; -import com.yunbao.common.http.HttpClient; -import com.yunbao.common.interfaces.OnItemClickListener; -import com.yunbao.common.manager.IMLoginManager; -import com.yunbao.common.utils.Bus; -import com.yunbao.common.utils.DialogUitl; -import com.yunbao.common.utils.DpUtil; -import com.yunbao.common.utils.L; -import com.yunbao.common.utils.MicStatusManager; -import com.yunbao.common.utils.ScreenDimenUtil; -import com.yunbao.common.utils.SpUtil; -import com.yunbao.common.utils.ToastUtil; -import com.yunbao.common.utils.WordUtil; -import com.yunbao.common.views.LiveClarityCustomPopup; -import com.yunbao.live.R; -import com.yunbao.live.activity.LiveActivity; -import com.yunbao.live.activity.LiveAudienceActivity; -import com.yunbao.live.event.LiveAudienceEvent; -import com.yunbao.live.utils.LiveExoPlayerManager; - -import org.greenrobot.eventbus.EventBus; -import org.greenrobot.eventbus.Subscribe; -import org.greenrobot.eventbus.ThreadMode; - -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Locale; - -import cn.rongcloud.rtc.api.RCRTCEngine; -import cn.rongcloud.rtc.api.RCRTCRemoteUser; -import cn.rongcloud.rtc.api.RCRTCRoom; -import cn.rongcloud.rtc.api.RCRTCRoomConfig; -import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback; -import cn.rongcloud.rtc.api.callback.IRCRTCResultDataCallback; -import cn.rongcloud.rtc.api.callback.IRCRTCRoomEventsListener; -import cn.rongcloud.rtc.api.callback.IRCRTCSwitchRoleCallback; -import cn.rongcloud.rtc.api.callback.IRCRTCSwitchRoleDataCallback; -import cn.rongcloud.rtc.api.callback.IRCRTCVideoInputFrameListener; -import cn.rongcloud.rtc.api.stream.RCRTCInputStream; -import cn.rongcloud.rtc.api.stream.RCRTCLiveInfo; -import cn.rongcloud.rtc.api.stream.RCRTCOutputStream; -import cn.rongcloud.rtc.api.stream.RCRTCVideoInputStream; -import cn.rongcloud.rtc.api.stream.RCRTCVideoStreamConfig; -import cn.rongcloud.rtc.api.stream.RCRTCVideoView; -import cn.rongcloud.rtc.base.RCRTCLiveRole; -import cn.rongcloud.rtc.base.RCRTCMediaType; -import cn.rongcloud.rtc.base.RCRTCParamsType; -import cn.rongcloud.rtc.base.RCRTCRemoteVideoFrame; -import cn.rongcloud.rtc.base.RCRTCRoomType; -import cn.rongcloud.rtc.base.RCRTCStreamType; -import cn.rongcloud.rtc.base.RTCErrorCode; -import cn.rongcloud.rtc.core.RendererCommon; - -public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { - - private static final String TAG = "LivePlayViewHolder"; - private ViewGroup mRoot; - private ViewGroup mSmallContainer; - private ViewGroup mLeftContainer; - private ViewGroup mRightContainer; - private RelativeLayout mPkContainer; - public StyledPlayerView mVideoView; - - private View mLoading, mLoading2; - private ImageView mCover; - private boolean mPaused;//是否切后台了 - private boolean mStarted;//是否开始了播放 - private boolean mEnd;//是否结束了播放 - public static ImageView leave; - - private boolean mPausedPlay;//是否被动暂停了播放 - public int landscape; //1h 2s - public Context contexts; - public FrameLayout ry_view; - - private static final int VIDEO_VERTICAL = 2; - private static final int VIDEO_HORIZONTAL = 1; - int videoLandscape = -1; // 视频方向,2=竖屏,1=横屏 - - static int vHeight;//视频高 - private TextView debugView; - private LiveExoPlayerManager mPlayer; - private boolean isPk = false; - private boolean userJoinLinkMic = false;//用户是否已加入房间 - - //0未申请1申请中2连麦中 - RCRTCRoom rcrtcRoom; - String purl, srcUrl; - - public int getLandscape() { - return landscape; - } - - public LivePlayRyViewHolder(Context context, ViewGroup parentView, int landscapes) { - super(context, parentView); - contexts = context; - landscape = landscapes; - Log.i("收收收", landscape + ""); - } - - - @Override - protected int getLayoutId() { - return R.layout.view_live_play_ksy; - } - - @Override - public void init() { - Log.i(TAG, "init: 初始化播放器ViewHolder"); - EventBus.getDefault().register(this); - Bus.getOn(this); - mRoot = (ViewGroup) findViewById(R.id.root); - mSmallContainer = (ViewGroup) findViewById(R.id.small_container); - mLeftContainer = (ViewGroup) findViewById(R.id.left_container); - mRightContainer = (ViewGroup) findViewById(R.id.right_container); - mPkContainer = (RelativeLayout) findViewById(R.id.pk_container); - mVideoView = (StyledPlayerView) findViewById(R.id.video_view); - ry_view = (FrameLayout) findViewById(R.id.ry_view); - leave = (ImageView) findViewById(R.id.leave); - mLoading = findViewById(R.id.loading); - mLoading2 = findViewById(R.id.loading2); - mCover = (ImageView) findViewById(R.id.cover); - ScreenDimenUtil util = ScreenDimenUtil.getInstance(); - int mScreenWdith = util.getScreenWdith(); - vHeight = mScreenWdith * 720 / 960; - - RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mPkContainer.getLayoutParams(); - params.height = vHeight; - mPkContainer.requestLayout(); - - mPlayer = new LiveExoPlayerManager(mContext); - mPlayer.setMainView(mVideoView); - mPlayer.setListener(new ExoPlayerListener()); - debugView = new TextView(mContext); - debugView.setBackgroundColor(Color.WHITE); - - } - - @Override - public void hideCover() { -// if (mCover != null) { -// if (mCover.getVisibility()==View.VISIBLE){ -//// new Handler().postDelayed(new Runnable() { -//// @Override -//// public void run() { -//// -//// } -//// },200); -// mCover.setVisibility(View.GONE); -// mLoading2.setVisibility(View.GONE); -// } -// -// -// } - } - - @Override - public void setCover(String coverUrl) { -// if (mCover != null) { -// mCover.setVisibility(View.VISIBLE); -// mLoading2.setVisibility(View.VISIBLE); -// ImgLoader.displayBlurLive(mContext, coverUrl, mCover, 400, 600); -// -// } - }// - - @Override - public synchronized void setLiveBeanLandscape(int landscape) { -// landscape=1; - Log.i(TAG, "setLiveBeanLandscape: " + landscape + " isPk: " + isPk); - this.landscape = landscape; - this.videoLandscape = landscape; - if (mPlayer != null) { - mPlayer.setViewResizeMode(landscape == VIDEO_VERTICAL); - } - - if (landscape == 2) { - Log.i(TAG, "还原9:16"); - RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); - params.height = RelativeLayout.LayoutParams.MATCH_PARENT; - params.topMargin = 0; - mVideoView.setLayoutParams(params); - mVideoView.requestLayout(); - - RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); - params1.height = RelativeLayout.LayoutParams.MATCH_PARENT; - params1.topMargin = 0; - ry_view.setLayoutParams(params1); - ry_view.requestLayout(); - RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) mCover.getLayoutParams(); - params2.height = RelativeLayout.LayoutParams.MATCH_PARENT; - params2.topMargin = 0; - mCover.setLayoutParams(params2); - mCover.requestLayout(); - - } else { - Log.i(TAG, "还原16:9"); - RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); - params.height = vHeight; - params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); - params.addRule(RelativeLayout.ALIGN_TOP); - mVideoView.setLayoutParams(params); - mVideoView.requestLayout(); - - RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); - params1.height = vHeight; - params1.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); - params1.addRule(RelativeLayout.ALIGN_TOP); - ry_view.setLayoutParams(params1); - ry_view.requestLayout(); - RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) mCover.getLayoutParams(); - params2.height = DpUtil.dp2px(270); - params2.topMargin = DpUtil.dp2px(120); - mCover.setLayoutParams(params2); - mCover.requestLayout(); - } - } - - @Override - public void setLiveEnterRoomNewModel(EnterRoomNewModel data) { - super.setLiveEnterRoomNewModel(data); - isPk = data.getEnterRoomInfo().getIsconnection().equals("1"); - if (isPk) { - setLiveBeanLandscape(1); - } - } - - /** - * 暂停播放 - */ - @Override - public void pausePlay() { - - } - - /** - * 暂停播放后恢复 - */ - @Override - public void resumePlay() { - if (!mPlayer.isPlaying()) { - new Handler(Looper.getMainLooper()) - .postDelayed(() -> { - mPlayer.replay(); - // ToastUtil.show("强制播放" + val); - }, 100); - } - } - - /** - * 开始播放 - * - * @param url 流地址 - */ - @Override - public void play(String url, int playModel) { - srcUrl = url; - PLAY_MODEL = playModel; - waitNextUrl = null; - Log.i(TAG, "play" + " url:" + url + " playModel: " + playModel + " landscape: " + landscape + " videoLandscape" + videoLandscape); - if (playModel != PLAY_MODEL_DEF && !url.contains(videoFps[0] + ".flv")) { - mPlayer.setViewResizeMode(landscape == VIDEO_VERTICAL); - if (landscape == VIDEO_VERTICAL && !isPk) { - url = url.replace(".flv", videoRatioVertical[playModel] + videoFps[0] + ".flv"); - } else if (landscape == VIDEO_HORIZONTAL || isPk) { - url = url.replace(".flv", videoRatioHorizontal[playModel] + videoFps[0] + ".flv"); - } - } else if (!url.contains(videoFps[0] + ".flv")) { - mPlayer.setViewResizeMode(false); - } - Log.e("purl121", url); - - if (TextUtils.isEmpty(url) || mVideoView == null) { - return; - } - - if (TextUtils.isEmpty(url) || mVideoView == null) { - return; - } - if (mPlayer.isPlaying()) { - mPlayer.stop(); - mPlayer.clearUrl(); - } - mPlayer.startUrl(url); - purl = url; - onPrepared(); - } - - @Override - public void switchStream(String url, int playModel) { - srcUrl = url; - PLAY_MODEL = playModel; - Log.i(TAG, "switchStream: " + " url:" + url + " playModel: " + playModel + " landscape: " + landscape + " videoLandscape = " + videoLandscape + " ispk = " + isPk + " bean = " + roomModel.getEnterRoomInfo().getIsconnection()); - if (playModel != PLAY_MODEL_DEF && !url.contains(videoFps[0] + ".flv")) { - mPlayer.setViewResizeMode(landscape == VIDEO_VERTICAL); - if (landscape == VIDEO_VERTICAL && !isPk) { - url = url.replace(".flv", videoRatioVertical[playModel] + videoFps[0] + ".flv"); - } else if (landscape == VIDEO_HORIZONTAL || isPk) { - url = url.replace(".flv", videoRatioHorizontal[playModel] + videoFps[0] + ".flv"); - } - } else if (!url.contains(videoFps[0] + ".flv")) { - mPlayer.setViewResizeMode(false); - } - Log.e("purl121", url); - - if (TextUtils.isEmpty(url) || mVideoView == null) { - return; - } - - - if (TextUtils.isEmpty(url) || mVideoView == null) { - return; - } - mPlayer.switchUrl(url); - purl = url; - } - - boolean tmpPk = false; - String waitNextUrl = null; - - @Override - public void switchStreamPk(boolean isPk) { - super.switchStreamPk(isPk); - Log.i(TAG, "switchStreamPk: isPk1" + isPk + " tmp = " + !tmpPk + " isPk2 = " + this.isPk); - if (this.isPk && tmpPk) return; - if (isPk && !tmpPk || this.isPk) { - mPlayer.setViewResizeMode(false); - String url; - if (PLAY_MODEL != -1) { - url = srcUrl.replace(".flv", videoRatioHorizontal[PLAY_MODEL] + videoFps[0] + ".flv"); - } else { - url = srcUrl.replace(".flv", videoRatioHorizontal[1] + videoFps[0] + ".flv"); - } - if (!tmpPk) { - waitNextUrl = url; - } - mPlayer.switchUrl(srcUrl); - tmpPk = true; - } else if (!isPk) { - tmpPk = false; - if (landscape == VIDEO_VERTICAL && PLAY_MODEL != -1) { - waitNextUrl = srcUrl.replace(".flv", videoRatioVertical[PLAY_MODEL] + videoFps[0] + ".flv"); - } else if (landscape == VIDEO_HORIZONTAL && PLAY_MODEL != -1) { - waitNextUrl = srcUrl.replace(".flv", videoRatioHorizontal[PLAY_MODEL] + videoFps[0] + ".flv"); - } else { - waitNextUrl = null; - } - mPlayer.switchUrl(srcUrl); - } - } - - @Override - public void clearFrame() { - super.clearFrame(); - mPlayer.clearFrame(); - RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); - params.height = ViewGroup.LayoutParams.WRAP_CONTENT; - params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); - params.addRule(RelativeLayout.ALIGN_TOP); - mVideoView.setLayoutParams(params); - mVideoView.requestLayout(); - - RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); - params1.height = ViewGroup.LayoutParams.WRAP_CONTENT; - params1.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); - params1.addRule(RelativeLayout.ALIGN_TOP); - ry_view.setLayoutParams(params1); - ry_view.requestLayout(); - RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) mCover.getLayoutParams(); - params2.height = DpUtil.dp2px(270); - params2.topMargin = DpUtil.dp2px(120); - mCover.setLayoutParams(params2); - mCover.requestLayout(); - } - - @Override - public void endPk() { - - } - - @Override - public void endpk(String liveUid) { - - } - - @Override - public void initSwEngine(String liveUid) { - - } - - @Override - public void removeLiveUid(String uid) { - - } - - @Override - public void release() { - mEnd = true; - mStarted = false; - if (mPlayer != null) { - mPlayer.stop(); - mPlayer.release(); - } - Bus.getOff(this); - EventBus.getDefault().unregister(this); - L.e(TAG, "release------->"); - } - - @Override - public void stopPlay() { - Log.i(TAG, "stopPlay: "); - if (mCover != null) { - mCover.setAlpha(1f); - if (mCover.getVisibility() != View.VISIBLE) { - mCover.setVisibility(View.VISIBLE); - } - } - if (mPlayer != null) { - mPlayer.stop(); - } - stopPlay2(); - } - - @Override - public void stopPlay2() { - - } - - @Override - public void setViewUP(int i) { - if (mVideoView == null) return; - Log.e("PK状态", "" + i); - RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); - params.height = vHeight; - params.topMargin = contexts.getResources().getDimensionPixelOffset(R.dimen.live_top); - params.addRule(RelativeLayout.ALIGN_TOP); - mVideoView.requestLayout(); - - RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); - params1.height = vHeight; - params1.topMargin = contexts.getResources().getDimensionPixelOffset(R.dimen.live_top); - params1.addRule(RelativeLayout.ALIGN_TOP); - ry_view.requestLayout(); - isPk = true; - if (mPlayer.getUrl().contains("848_24.flv") || mPlayer.getUrl().contains("1280_24.flv")) { - tmpPk = false; - switchStreamPk(true); - } - } - - /** - * 播放开始 - */ - public void onPrepared() { - if (mEnd) { - release(); - return; - } - int height; - if (videoLandscape == VIDEO_VERTICAL) { - height = ViewGroup.LayoutParams.MATCH_PARENT; - } else { - height = ViewGroup.LayoutParams.WRAP_CONTENT; - } - mPlayer.setViewResizeMode(landscape == VIDEO_VERTICAL); - if (landscape == 2) { - Log.i(TAG, "onPrepared:还原9:16 land=" + videoLandscape); - RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); - params.height = height; - params.topMargin = 0; - params.addRule(RelativeLayout.ALIGN_TOP); - mVideoView.setLayoutParams(params); - mVideoView.requestLayout(); - - RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); - params1.height = height; - params1.topMargin = 0; - ry_view.setLayoutParams(params1); - ry_view.requestLayout(); - RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) mCover.getLayoutParams(); - params2.height = height; - params2.topMargin = 0; - mCover.setLayoutParams(params2); - mCover.requestLayout(); - } else { - Log.i(TAG, "onPrepared:还原16:9"); - RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); - params.height = height; - params.topMargin = 0; - if (videoLandscape == VIDEO_HORIZONTAL) { - params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); - } - params.addRule(RelativeLayout.ALIGN_TOP); - mVideoView.setLayoutParams(params); - mVideoView.requestLayout(); - - RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); - params1.height = height; - params1.topMargin = 0; - params1.addRule(RelativeLayout.ALIGN_TOP); - if (videoLandscape == VIDEO_HORIZONTAL) { - params1.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); - } - ry_view.setLayoutParams(params1); - ry_view.requestLayout(); - RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) mCover.getLayoutParams(); - params2.height = height; - params2.topMargin = DpUtil.dp2px(120); - mCover.setLayoutParams(params2); - mCover.requestLayout(); - } - } - - @Override - public void setPkview() { - Log.i("收到socket--->", "变成16:9"); - String url = srcUrl; - isPk = true; - switchStreamPk(true); - RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); - params.height = vHeight; - params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); - params.addRule(RelativeLayout.ALIGN_TOP); - mVideoView.requestLayout(); - } - - @Override - public synchronized void setPkEndview() { - - Log.i("收收收", landscape + ""); - isPk = false; - tmpPk = false; - switchStreamPk(false); - if (landscape == 2) { - Log.i("收到socket--->", "还原9:16"); - RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); - params.height = RelativeLayout.LayoutParams.MATCH_PARENT; - params.topMargin = 0; - mVideoView.requestLayout(); - - } else { - RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); - params.height = vHeight; - params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); - params.addRule(RelativeLayout.ALIGN_TOP); - mVideoView.requestLayout(); - } -// if (detailsView != null) { -// mVideoView.removeView(detailsView); -// detailsView = null; -// } - } - - @Override - public void setDrMicInfo(UserBean u) { - - } - - public void removeDetailView() { -// if (detailsView != null) { -// mVideoView.removeView(detailsView); -// detailsView = null; -// } - } - - @Override - public void setPkView(String liveUid) { - - } - - @Override - public void claerDrPkInfoView() { - - } - - @Override - public void endLiveMic() { - - } - - @Override - public ViewGroup getSmallContainer() { - return mSmallContainer; - } - - - @Override - public ViewGroup getRightContainer() { - return mRightContainer; - } - - @Override - public ViewGroup getPkContainer() { - return mPkContainer; - } - - @Override - public void changeToLeft() { - if (mVideoView != null) { - - RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); - params.height = vHeight; -// params.height = mContext.getResources().getDimensionPixelOffset(R.dimen.live_view); - params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); - params.addRule(RelativeLayout.ALIGN_TOP); - mVideoView.requestLayout(); - - } - if (mLoading != null && mLeftContainer != null) { - ViewParent viewParent = mLoading.getParent(); - if (viewParent != null) { - ((ViewGroup) viewParent).removeView(mLoading); - } - FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(DpUtil.dp2px(24), DpUtil.dp2px(24)); - params.gravity = Gravity.CENTER; - mLoading.setLayoutParams(params); - mLeftContainer.addView(mLoading); - } - } - - @Override - public void changeToBig() { - if (mVideoView != null) { - RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); - mVideoView.setLayoutParams(params); - - } - if (mLoading != null && mRoot != null) { - ViewParent viewParent = mLoading.getParent(); - if (viewParent != null) { - ((ViewGroup) viewParent).removeView(mLoading); - } - RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(DpUtil.dp2px(24), DpUtil.dp2px(24)); - params.addRule(RelativeLayout.CENTER_IN_PARENT); - mLoading.setLayoutParams(params); - System.out.println(" changeToBig changeToBig changeToBig"+mLoading.getParent()); - if(mLoading.getParent()!=mRoot){ - mRoot.addView(mLoading); - } - } - } - - @Override - public void onResume() { - if (!mPausedPlay && mPaused && mVideoView != null) { -// mVideoView.runInForeground(); -// mVideoView.start(); - } - mPaused = false; -// if (mPlayer.isPlaying() == 1) { -// mPlayer.resumeVideo(); -// mPlayer.resumeAudio(); -// } - } - - @Override - public void onPause() { -// if (!mPausedPlay && mVideoView != null) { -// mVideoView.runInBackground(false); -// } -// mPaused = true; -// mPlayer.pauseVideo(); -// mPlayer.pauseAudio(); - } - - @Override - public void onDestroy() { - release(); - } - - //全屏 - @Override - public void fullScreen() { - RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); - params.height = RelativeLayout.LayoutParams.MATCH_PARENT; - params.topMargin = 0; - params.addRule(RelativeLayout.ALIGN_TOP); - mVideoView.requestLayout(); - } - - //小屏 - @Override - public void smallScreen() { - RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); - params.height = vHeight; - params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); - // mPlayer.setRenderRotation(V2TXLiveDef.V2TXLiveRotation.V2TXLiveRotation0); - params.addRule(RelativeLayout.ALIGN_TOP); - mVideoView.requestLayout(); - } - - - @Subscribe(threadMode = ThreadMode.MAIN) - public void onUpdata(String str) { - if ("UsertoRY".equals(str)) { - DialogUitl.showSimpleDialog(mContext, mContext.getString(R.string.mic_tag), new DialogUitl.SimpleCallback() { - @Override - public void onConfirmClick(Dialog dialog, String content) { - UsertoRY(); - dialog = null; - } - }); - - } else if ("inviteMic".equals(str)) { - String content = "邀請您進行語音連麥"; - String confirm = "接受"; - String cancel = "拒絕"; - if (!WordUtil.isNewZh()) { - content = "You are invited to join the voice connection"; - confirm = "accept"; - cancel = "cancel"; - } - DialogUitl.Builder builder = new DialogUitl.Builder(mContext) - .setContent(content) - .setTitle(mLiveBean.getUserNiceName()) - .setConfirmString(confirm) - .setCancelString(cancel) - .setView(R.layout.dialog_live_mic_invite) - .setClickCallback(new DialogUitl.SimpleCallback() { - @Override - public void onConfirmClick(Dialog dialog, String content) { - String[] permissions; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - permissions = new String[]{ - Manifest.permission.READ_MEDIA_IMAGES, - Manifest.permission.RECORD_AUDIO - }; - } else { - permissions = new String[]{ - Manifest.permission.READ_EXTERNAL_STORAGE, - Manifest.permission.WRITE_EXTERNAL_STORAGE, - Manifest.permission.RECORD_AUDIO - }; - } - LiveAudienceActivity.mProcessResultUtil.requestPermissions(permissions, new Runnable() { - @Override - public void run() { - UsertoRY(); - - } - }); - } - }); - builder.build().show(); - - } else if ("endMic".equals(str)) { - if (rcrtcRoom != null) { - // 开始切换为观众身份 - RCRTCEngine.getInstance().getRoom().getLocalUser().switchToAudience(new IRCRTCSwitchRoleCallback() { - - /** - * 当切换失败且SDK处于无法回退状态时回调,该角色已经无法使用当前角色继续进行音视频。 - * SDK内部会退出房间并清理所有资源,该用户只能重新加入房间才能继续音视频。 - */ - @Override - public void onKicked() { - - } - - @Override - public void onSuccess() { - Log.e("ry", "下麦成功"); - // 该用户切换为观众成功,可以以观众身份进行音视频 - //退出rtc播放 - leaveRoom(); - } - - /** - * 当切换失败且不影响当前角色继续音视频时回调 - * @param errorCode 失败错误码 - */ - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.e("ry", "下麦失败" + errorCode); - leaveRoom(); - } - - private void leaveRoom() { - RCRTCEngine.getInstance().leaveRoom(new IRCRTCResultCallback() { - @Override - public void onSuccess() { - userJoinLinkMic = false; - Log.e("ry", "退出多人房间成功"); - new Handler(Looper.getMainLooper()).post(new Runnable() { - public void run() { - if (WordUtil.isNewZh()) { - ToastUtil.show("已成功退出語音連麥"); - } else { - ToastUtil.show("You have successfully exited the voice connection"); - } - if (mPlayer.getNowPlayer() != null) { - mPlayer.play(); - Log.e("ry", mPlayer.isPlaying() + "purl" + purl); - if (!mPlayer.isPlaying()) { - mPlayer.switchUrl(purl); - } - ry_view.removeAllViews(); - ry_view.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT; - onPrepared(); - rcrtcRoom = null; - MicStatusManager.getInstance().clear(); - - resumePlay(); - } - - if (onMicCallback != null) { - onMicCallback.onMikUpdate(); - } - } - }); - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.e("ry", errorCode + "退出多人房间成功"); - userJoinLinkMic = false; - } - }); - - } - }); - } - } else if ("Debug".equals(str)) { - if (EasyFloat.isShow("Debug")) { - EasyFloat.dismiss("Debug"); - return; - } - EasyFloat.with(mContext) - .setDragEnable(true) - .setTag("Debug") - .setLayout(debugView) - .show(); - } - } - - @Subscribe(threadMode = ThreadMode.MAIN) - public void onOpenDrawer(LiveAudienceEvent event) { - if (event.getType() == LiveAudienceEvent.LiveAudienceType.LIVE_VIDEO) { - int ban = 0;//全模式都可以选择 - switch (roomModel.getClarityType() - 1) { - case PLAY_MODEL_720://仅允许720(高清),ban掉1080(超高清)模式 - ban = LiveClarityCustomPopup.BAN_1080; - break; - case -1://没有该字段 - case PLAY_MODEL_480://仅允许480(流畅),ban掉1080(超高清)和720(高清)模式 - ban = LiveClarityCustomPopup.BAN_720; - break; - - } - LiveClarityCustomPopup liveClarityCustomPopup = new LiveClarityCustomPopup(mContext, - IMLoginManager.get(mContext).getInt(PLAY_MODEL_KEY, PLAY_MODEL_ANCHOR), - ban, - true); - new XPopup.Builder(mContext) - .setPopupCallback(new XPopupCallback() { - @Override - public void onCreated(BasePopupView popupView) { - - } - - @Override - public void beforeShow(BasePopupView popupView) { - - } - - @Override - public void onShow(BasePopupView popupView) { - - } - - @Override - public void onDismiss(BasePopupView popupView) { - int selectClarity = liveClarityCustomPopup.getSelectClarity(); - if (selectClarity == PLAY_MODEL || selectClarity == IMLoginManager.get(mContext).getInt(LiveRoomPlayViewHolder.PLAY_MODEL_KEY, PLAY_MODEL_ANCHOR)) - return; - if (selectClarity == PLAY_MODEL_ANCHOR) { - switchStream(srcUrl, PLAY_MODEL_DEF); - setAudiencePlayModel(selectClarity); - } else { - switchStream(srcUrl, selectClarity); - } - IMLoginManager.get(mContext).put(LiveRoomPlayViewHolder.PLAY_MODEL_KEY, selectClarity); - showToast(); - } - - private void showToast() { - if (WordUtil.isNewZh()) { - DialogUitl.showToast(mContext, "設置成功\n" + - "正在為你轉換中", 3000); - } else { - DialogUitl.showToast(mContext, "successful\n" + - "It's being converted for you", 3000); - } - } - - @Override - public void beforeDismiss(BasePopupView popupView) { - - } - - @Override - public boolean onBackPressed(BasePopupView popupView) { - return false; - } - - @Override - public void onKeyBoardStateChanged(BasePopupView popupView, int height) { - - } - - @Override - public void onDrag(BasePopupView popupView, int value, float percent, boolean upOrLeft) { - - } - - @Override - public void onClickOutside(BasePopupView popupView) { - - } - }) - .asCustom(liveClarityCustomPopup) - .show(); - } else if (event.getType() == LiveAudienceEvent.LiveAudienceType.FONT_SIZE) { - int fount = 0; - try { - fount = Integer.parseInt(SpUtil.getStringValue("pd_live_room_fount_size")); - } catch (Exception ignored) { - - } - new LiveFontSizeSettingDialog(mContext, fount).setOnItemClickListener(new OnItemClickListener() { - @Override - public void onItemClick(Integer bean, int position) { - EventBus.getDefault().post(new LiveAudienceEvent() - .setNums(bean) - .setType(LiveAudienceEvent.LiveAudienceType.LIVE_FONT_SIZE)); - } - }).showDialog(); - } - } - - /** - * 把观众转换成主播 - */ - public List userinputStreamList = new ArrayList<>(); - - - public void UsertoRY() { - userinputStreamList.clear(); - Log.e("ry", "主播同意了UsertoRY"); - if (userJoinLinkMic) {//已经在房间内,不再joinRoom直接去连麦 - subscribeMic(rcrtcRoom); - return; - } - RCRTCRoomConfig roomConfig = RCRTCRoomConfig.Builder.create() - // 根据实际场景,选择音视频直播:LIVE_AUDIO_VIDEO 或音频直播:LIVE_AUDIO - .setRoomType(RCRTCRoomType.LIVE_AUDIO_VIDEO) - .setLiveRole(RCRTCLiveRole.AUDIENCE) - .build(); - RCRTCEngine.getInstance().joinRoom(LiveActivity.mLiveUid, roomConfig, new IRCRTCResultDataCallback() { - - - @Override - public void onSuccess(RCRTCRoom data) { - userJoinLinkMic = true; - rcrtcRoom = data; - subscribeMic(data); - - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.e("ry", LiveActivity.mLiveUid + errorCode + ""); - if (errorCode.getValue() == 50007) {//userJoinLinkMic可能失效,直接leaveRoom - userJoinLinkMic = false; - RCRTCEngine.getInstance().leaveRoom(new IRCRTCResultCallback() { - - @Override - public void onFailed(RTCErrorCode errorCode) { - - } - - @Override - public void onSuccess() { - UsertoRY(); - } - }); - } else { - ToastUtil.show("房间失败" + errorCode); - } - - } - }); - - - } - - private void subscribeMic(RCRTCRoom data) { - runOnUiThread(new Runnable() { - @Override - public void run() { - RCRTCEngine.getInstance().enableSpeaker(true); - //遍历远端用户发布的资源列表 - Log.i(TAG, "软件资源数量:" + data.getLiveStreams().size()); - for (RCRTCInputStream stream : data.getLiveStreams()) { - Log.i(TAG, "资源流 type: " + stream.getMediaType()); - if (stream.getMediaType() == RCRTCMediaType.VIDEO) { - //暂停播放 - mPlayer.stop(); - //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 - - //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 - RCRTCVideoView remoteView = new RCRTCVideoView(contexts); - ((RCRTCVideoInputStream) stream).setVideoView(remoteView); - //todo 本demo只演示添加1个远端用户的视图 - remoteView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); - remoteView.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT); - ry_view.addView(remoteView); - Log.e("ry", stream.getMediaType() + "rcrtcOtherRoom成功 :" + data.getLiveStreams().size()); - } - userinputStreamList.add(stream); - } - rcrtcRoom.getLocalUser().subscribeStreams(userinputStreamList, new IRCRTCResultCallback() { - - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.e("ry", userinputStreamList.size() + LiveActivity.mLiveUid + "订阅失败" + errorCode.toString()); - ToastUtil.show(mContext.getString(R.string.live_pk_link_error)); - } - - @Override - public void onSuccess() { - Log.e("ry", "订阅资源成功"); -// new Handler().postDelayed(new Runnable() { -// @Override -// public void run() { - toMic(); -// } -// }, 3000); - - } - }); - } - }); - } - - /** - * 主房间事件监听 - * 详细说明请参考文档:https://www.rongcloud.cn/docs/api/android/rtclib_v4/cn/rongcloud/rtc/api/callback/IRCRTCRoomEventsListener.html - */ - public IRCRTCRoomEventsListener roomEventsListener = new IRCRTCRoomEventsListener() { - @Override - public void onRemoteUserPublishResource(RCRTCRemoteUser rcrtcRemoteUser, List list) { - Log.e("ry", "远端来了" + list.size()); - //TODO 按需在此订阅远端用户发布的资源 - rcrtcRoom.getLocalUser().subscribeStreams(list, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.e("ry", "远端成功" + list.size()); - - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - Log.e("ry", "远端失败" + list.size()); - ToastUtil.show(mContext.getString(R.string.live_pk_link_error)); - } - }); - } - - @Override - public void onRemoteUserMuteAudio(RCRTCRemoteUser remoteUser, RCRTCInputStream stream, boolean mute) { - - } - - @Override - public void onRemoteUserMuteVideo(RCRTCRemoteUser remoteUser, RCRTCInputStream stream, boolean mute) { - - } - - @Override - public void onRemoteUserUnpublishResource(RCRTCRemoteUser remoteUser, List streams) { - - } - - @Override - public void onUserJoined(RCRTCRemoteUser remoteUser) { - - } - - @Override - public void onUserLeft(RCRTCRemoteUser remoteUser) { - - } - - @Override - public void onUserOffline(RCRTCRemoteUser remoteUser) { - - } - - @Override - public void onPublishLiveStreams(List streams) { - - } - - @Override - public void onUnpublishLiveStreams(List streams) { - - } - }; - - - public List userinputStreamList1 = new ArrayList<>(); - public List userinputStreamList2 = new ArrayList<>(); - - public void toMic() { - RCRTCEngine.getInstance().getDefaultAudioStream().setAudioQuality(RCRTCParamsType.AudioQuality.MUSIC, RCRTCParamsType.AudioScenario.MUSIC_CLASSROOM); - userinputStreamList1.clear(); - userinputStreamList2.clear(); - RCRTCParamsType.RCRTCVideoResolution rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_480_848; - int minRate = 200; - int maxRate = 900; - switch (IMLoginManager.get(mContext).getSelectClarity()) { - case 0: - rcrtcVideoResolution = landscape == 1 ? RCRTCParamsType.RCRTCVideoResolution.parseVideoResolution(960, 720) : RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_480_848; - minRate = landscape == 1 ? 900 : 200; - maxRate = landscape == 1 ? 700 : 900; - break; - case 1: - rcrtcVideoResolution = landscape == 1 ? RCRTCParamsType.RCRTCVideoResolution.parseVideoResolution(960, 720) : RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_720_1280; - minRate = landscape == 1 ? 900 : 250; - maxRate = landscape == 1 ? 700 : 2200; - break; - case 2: - rcrtcVideoResolution = landscape == 1 ? RCRTCParamsType.RCRTCVideoResolution.parseVideoResolution(960, 720) : RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_1080_1920; - minRate = landscape == 1 ? 900 : 400; - maxRate = landscape == 1 ? 700 : 4000; - break; - } - // 示例代码使用480x640分辨率演示 - RCRTCVideoStreamConfig config = RCRTCVideoStreamConfig - .Builder.create() - //设置分辨率 - .setVideoResolution(rcrtcVideoResolution) - //设置帧率 - .setVideoFps(RCRTCParamsType.RCRTCVideoFps.Fps_24) - //设置最小码率,480P下推荐200 - .setMinRate(minRate) - //设置最大码率,480P下推荐900 - .setMaxRate(maxRate) - .build(); - RCRTCEngine.getInstance().getDefaultVideoStream().setVideoConfig(config); -// 创建视图渲染视图 -// RCRTCVideoView videoView = new RCRTCVideoView(contexts); -// RCRTCEngine.getInstance().getDefaultVideoStream().setVideoView(videoView); -//TODO 示例代码使用获取本地默认视频流、音频流演示 - ArrayList streams = new ArrayList<>(); -// streams.add(RCRTCEngine.getInstance().getDefaultVideoStream()); - streams.add(RCRTCEngine.getInstance().getDefaultAudioStream()); - if (landscape == 1) { - new Handler(Looper.getMainLooper()).post(new Runnable() { - @Override - public void run() { - setLiveBeanLandscape(1); - } - }); - - } -// 开启摄像头 -// RCRTCEngine.getInstance().getDefaultVideoStream().startCamera(null); -// 开始切换为主播身份 - RCRTCEngine.getInstance().getRoom().getLocalUser().switchToBroadcaster(streams, new IRCRTCSwitchRoleDataCallback() { - /** - * 当切换失败且SDK处于无法回退状态时回调,该角色已经无法使用当前角色继续进行音视频。 - * SDK内部会退出房间并清理所有资源,该用户只能重新加入房间才能继续音视频。 - */ - @Override - public void onKicked() { - Log.e("ry", "切换onKicked"); - - } - - @Override - public void onSuccess(RCRTCLiveInfo data) { - rcrtcRoom.registerRoomListener(roomEventsListener); - //该用户切换为主播成功,可以以主播身份进行音视频 - Log.e("ry", "切换成功"); - new Handler(Looper.getMainLooper()).post(new Runnable() { - public void run() { - if (onMicCallback != null) { - onMicCallback.onMikUpdate(); - } - //遍历远端用户列表 - for (int i = 0; i < rcrtcRoom.getRemoteUsers().size(); i++) { - Log.e("ry", rcrtcRoom.getRemoteUsers().get(i).getUserId() + "收到rcrtcOtherRoom" + rcrtcRoom.getRemoteUsers().size()); - //遍历远端用户发布的资源列表 - for (RCRTCInputStream stream : rcrtcRoom.getRemoteUsers().get(i).getStreams()) { - Log.e("ry", i + "收到" + stream.getMediaType() + "实打实打算" + rcrtcRoom.getRemoteUsers().get(i).getUserId()); - if (stream.getMediaType() == RCRTCMediaType.VIDEO) { - if (userinputStreamList1.size() == 0) { - - //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 - RCRTCVideoView remoteView = new RCRTCVideoView(contexts); - ((RCRTCVideoInputStream) stream).setStreamType(RCRTCStreamType.NORMAL); - ((RCRTCVideoInputStream) stream).setVideoView(remoteView); - ((RCRTCVideoInputStream) stream).setVideoFrameListener(new IRCRTCVideoInputFrameListener() { - @Override - public void onFrame(RCRTCRemoteVideoFrame videoFrame) { - String debugText = " 2、安卓主播开播, 安卓用户申请连麦后 ,安卓用户这边底部画面不全 :" + videoFrame.getFrameType().name() + "\n" + - "rotation:" + videoFrame.getRotation() + "\n" + - "timestampNs:" + videoFrame.getTimestampNs() + "\n" + - "分辨率:" + videoFrame.getBuffer().getHeight() + "x" + videoFrame.getBuffer().getWidth() + "\n" + - "当前时间:" + new SimpleDateFormat("HH:mm:ss", Locale.CHINA).format(new Date()) + "\n"; - //Log.d("ry", "onFrame: " + debugText); - new Handler(Looper.getMainLooper()).post(() -> { - debugView.setText(debugText); - - }); - } - }); - //todo 本demo只演示添加1个远端用户的视图 - ry_view.removeAllViews(); - remoteView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); - remoteView.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FILL); - ry_view.addView(remoteView); - } - userinputStreamList1.add(stream); - } - userinputStreamList2.add(stream); - } - } - //开始订阅资源 - rcrtcRoom.getLocalUser().subscribeStreams(userinputStreamList2, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.e("ry", "订阅资源成功"); - MicStatusManager.getInstance().setMicData(MicStatusManager.MIC_TYPE_OPEN, LiveActivity.mLiveUid); - AudioManager audioManager = (AudioManager) contexts.getSystemService(Context.AUDIO_SERVICE); - RCRTCEngine.getInstance().enableSpeaker(true); - audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION); - audioManager.setSpeakerphoneOn(true); - - HttpClient.getInstance().get("live.joinDrLm", "live.joinDrLm") - .params("roomid", LiveActivity.mLiveUid) - .execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - Log.e("ry", code + "热热热"); - } - }); - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - Log.e("ry", "订阅资源失败: " + rtcErrorCode.getReason()); - ToastUtil.show(mContext.getString(R.string.live_pk_link_error)); - } - }); - } - }); - - - } - - /** - * 当切换失败且不影响当前角色继续音视频时回调 - * @param errorCode 失败错误码 - */ - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.e("ry", errorCode + "切换失败"); - - } - }); - } - - @Override - public void setLoadViewListener(LoadingListener listener) { - super.setLoadViewListener(listener); - } - - private void showLoadingDialog() { - if (PLAY_MODEL == PLAY_MODEL_480) return; - - new DialogUitl.Builder(mContext) - .setTitle("網絡提示") - .setContent("系統監測到您的網絡不穩定,對此將清晰度變成了流暢,您可以在側邊菜單中的「清晰度」選擇調回。") - .setView(R.layout.dialog_simple_tip) - .setClickCallback(new DialogUitl.SimpleCallback() { - @Override - public void onConfirmClick(Dialog dialog, String content) { - dialog.dismiss(); - } - }).build().show(); - PLAY_MODEL = PLAY_MODEL_480; - String url = srcUrl; - if (videoLandscape == VIDEO_VERTICAL) { - url = url.replace(".flv", videoRatioVertical[PLAY_MODEL_480] + videoFps[0] + ".flv"); - } else if (videoLandscape == VIDEO_HORIZONTAL) { - url = url.replace(".flv", videoRatioHorizontal[PLAY_MODEL_480] + videoFps[0] + ".flv"); - } - mPlayer.switchUrl(url); - } - - private class ExoPlayerListener implements Player.Listener { - String TAG = "播放流"; - - @Override - public void onPlayerError(PlaybackException error) { - Player.Listener.super.onPlayerError(error); - debugView.setText("播放出错code=" + error.errorCode + " msg=" + error.getErrorCodeName()); - } - - @Override - public void onVideoSizeChanged(VideoSize videoSize) { - Player.Listener.super.onVideoSizeChanged(videoSize); - Log.i(TAG, "onVideoSizeChanged: width = " + videoSize.width + " height = " + videoSize.height); - //ToastUtil.show("分辨率: 宽 = " + videoSize.width + " 高 = " + videoSize.height); - if (videoSize.height > videoSize.width) { - videoLandscape = VIDEO_VERTICAL; - } else { - videoLandscape = VIDEO_HORIZONTAL; - } - } - - @Override - public void onPlaybackStateChanged(int playbackState) { - Player.Listener.super.onPlaybackStateChanged(playbackState); - if (playbackState == Player.STATE_BUFFERING) { - //showLoadingDialog(); - mLoading.setVisibility(View.VISIBLE); - OkDownload.getInstance().pauseAll(); - Log.i(TAG, "onPlaybackStateChanged: 缓存中"); - } else { - mLoading.setVisibility(View.INVISIBLE); - Log.i(TAG, "onPlaybackStateChanged: 播放中"); - } - } - - @Override - public void onIsPlayingChanged(boolean isPlaying) { - Player.Listener.super.onIsPlayingChanged(isPlaying); - if (isPlaying) { - hideCover(); - mLoading.setVisibility(View.INVISIBLE); - Log.i(TAG, "onIsPlayingChanged: 开始播放 | waitNextUrl = " + waitNextUrl); - OkDownload.getInstance().startAll(); - if (loadingListener != null) { - loadingListener.onPlayer(); - } - if (waitNextUrl != null) { - mPlayer.switchUrl(waitNextUrl); - waitNextUrl = null; - } - } - } - } - - private int mPkTimeCount = 0; - - - public interface PlayViewLayoutInterface { - void playViewLayout(int width, int height); - } - - private PlayViewLayoutInterface layoutInterface; - - public void setLayoutInterface(PlayViewLayoutInterface layoutInterface) { - mVideoView.post(new Runnable() { - @Override - public void run() { - int width = mVideoView.getMeasuredWidth(); - int height = mVideoView.getMeasuredHeight(); - if (layoutInterface != null) { - layoutInterface.playViewLayout(width, height); - } - } - }); - } - - -} diff --git a/live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java index d7e1eed2a..fc8b62851 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java @@ -68,7 +68,6 @@ import org.greenrobot.eventbus.ThreadMode; import java.util.ArrayList; import java.util.List; -import cn.rongcloud.rtc.api.stream.RCRTCInputStream; import io.agora.beautyapi.faceunity.agora.SWAuManager; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.functions.Consumer; @@ -1083,10 +1082,8 @@ public class LivePlaySwViewHolder extends LiveRoomPlayViewHolder { /** * 把观众转换成主播 */ - public List userinputStreamList = new ArrayList<>(); public void UsertoRY() { - userinputStreamList.clear(); Log.e("ry", "主播同意了UsertoRY"); joinLiveMic(); } diff --git a/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java deleted file mode 100644 index 169b32dce..000000000 --- a/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java +++ /dev/null @@ -1,1108 +0,0 @@ -package com.yunbao.live.views; - -import static com.lzy.okgo.utils.HttpUtils.runOnUiThread; -import static com.yunbao.common.Constants.SOCKET_LINK_MIC_PK; -import static com.yunbao.common.Constants.SOCKET_LIVE_DRPK; -import static com.yunbao.live.activity.LiveActivity.mLiveRyLinkMicPkPresenter; -import static com.yunbao.live.event.LiveAudienceEvent.LiveAudienceType.LIVE_PK_END; -import static com.yunbao.live.event.LiveAudienceEvent.LiveAudienceType.LIVE_PK_ING; -import static com.yunbao.live.presenter.LiveRyLinkMicPkPresenter.inputStreamList; -import static com.yunbao.live.presenter.LiveRyLinkMicPkPresenter.inputStreamList1; -import static com.yunbao.live.presenter.LiveRyLinkMicPkPresenter.mPkUid; -import static cn.rongcloud.rtc.base.RCRTCLiveRole.BROADCASTER; - -import android.app.Dialog; -import android.content.Context; -import android.content.res.Resources; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.os.Bundle; -import android.os.Handler; -import android.os.Looper; -import android.util.Log; -import android.util.TypedValue; -import android.view.View; -import android.view.ViewGroup; -import android.widget.FrameLayout; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.TextView; - -import com.alibaba.fastjson.JSONObject; -import com.tencent.liteav.device.TXDeviceManager; -import com.tencent.rtmp.ITXLivePushListener; -import com.tencent.rtmp.TXLiveConstants; -import com.tencent.trtc.TRTCCloudDef; -import com.yunbao.common.CommonAppConfig; -import com.yunbao.common.Constants; -import com.yunbao.common.bean.HttpCallbackModel; -import com.yunbao.common.bean.UserBean; -import com.yunbao.common.event.AnchorInfoEvent; -import com.yunbao.common.event.LivePushRyEvent; -import com.yunbao.common.glide.ImgLoader; -import com.yunbao.common.http.HttpCallback; -import com.yunbao.common.http.HttpClient; -import com.yunbao.common.http.live.LiveNetManager; -import com.yunbao.common.manager.IMLoginManager; -import com.yunbao.common.manager.IMRTCManager; -import com.yunbao.common.manager.RandomPkManager; -import com.yunbao.common.manager.imrongcloud.RongcloudIMManager; -import com.yunbao.common.utils.Bus; -import com.yunbao.common.utils.DialogUitl; -import com.yunbao.common.utils.DpUtil; -import com.yunbao.common.utils.L; -import com.yunbao.common.utils.ToastUtil; -import com.yunbao.common.utils.WordUtil; -import com.yunbao.live.R; -import com.yunbao.live.activity.LiveActivity; -import com.yunbao.live.activity.LiveRyAnchorActivity; -import com.yunbao.live.event.LiveAudienceEvent; -import com.yunbao.common.http.LiveHttpConsts; -import com.yunbao.common.http.LiveHttpUtil; -import com.yunbao.live.momo.TencentTRTCBeautyManager; -import com.yunbao.live.presenter.LiveRyLinkMicPkPresenter; -import com.yunbao.live.socket.SocketRyClient; -import com.yunbao.live.socket.SocketSendBean; - -import org.greenrobot.eventbus.EventBus; -import org.greenrobot.eventbus.Subscribe; -import org.greenrobot.eventbus.ThreadMode; - -import java.util.ArrayList; -import java.util.List; - -import cn.rongcloud.rtc.api.RCRTCConfig; -import cn.rongcloud.rtc.api.RCRTCEngine; -import cn.rongcloud.rtc.api.RCRTCMixConfig; -import cn.rongcloud.rtc.api.RCRTCRemoteUser; -import cn.rongcloud.rtc.api.RCRTCRoom; -import cn.rongcloud.rtc.api.RCRTCRoomConfig; -import cn.rongcloud.rtc.api.callback.IRCRTCEngineEventListener; -import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback; -import cn.rongcloud.rtc.api.callback.IRCRTCResultDataCallback; -import cn.rongcloud.rtc.api.callback.IRCRTCRoomEventsListener; -import cn.rongcloud.rtc.api.stream.RCRTCInputStream; -import cn.rongcloud.rtc.api.stream.RCRTCLiveInfo; -import cn.rongcloud.rtc.api.stream.RCRTCVideoStreamConfig; -import cn.rongcloud.rtc.api.stream.RCRTCVideoView; -import cn.rongcloud.rtc.base.RCRTCParamsType; -import cn.rongcloud.rtc.base.RCRTCRoomType; -import cn.rongcloud.rtc.base.RCRTCVideoEventCode; -import cn.rongcloud.rtc.base.RTCErrorCode; -import cn.rongcloud.rtc.core.CameraVideoCapturer; -import cn.rongcloud.rtc.core.RendererCommon; -import io.rong.imlib.IRongCallback; -import io.rong.imlib.RongIMClient; -import io.rong.imlib.model.Conversation; -import io.rong.message.TextMessage; - -/** - * Created by cxf on 2018/10/7. - * 腾讯云直播推流 - */ - -public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITXLivePushListener { - - private int mMeiBaiVal;//基础美颜 美白 - private int mMoPiVal;//基础美颜 磨皮 - private int mHongRunVal;//基础美颜 红润 - private String mBgmPath;//背景音乐路径 - private Bitmap mFilterBmp; - - private TXDeviceManager mTXDeviceManager; - private TRTCCloudDef.TRTCParams mTRTCParams; - private Handler mMainHandler; - public TencentTRTCBeautyManager tencentTRTCBeautyManager; - public static Context contexts; - public static TextView btn_close; - public LinearLayout dr_pk_view; - public static RCRTCRoom rtcRoom; - public static RCRTCLiveInfo rcrtcLiveInfo; - - private ViewGroup liveActivityContainer; - public FrameLayout timeTitle; - public TextView textTime; - private TextView tv_avatarOther_name; - private ImageView avatarOther; - private LinearLayout goto_room_view; - private boolean isPk = false; - private boolean isNeedOpenCamera = false; - - //修改上面主播的头像 - @Subscribe(threadMode = ThreadMode.MAIN) - public void onUPAnchorInfo(AnchorInfoEvent e) { - Log.i(TAG, "onUPAnchorInfo: " + e); - if (e != null) { - if (!e.isClear()) { - tv_avatarOther_name.setText(e.getUserNiceName()); - tv_avatarOther_name.setTag(e.getUserNiceName()); - ImgLoader.displayAvatar(mContext, e.getAvatar(), avatarOther); - goto_room_view.setVisibility(View.VISIBLE); - } else { - goto_room_view.setVisibility(View.GONE); - - } - } - } - - - public LivePushRyViewHolder(Context context, ViewGroup parentView) { - super(context, parentView); - this.contexts = context; - EventBus.getDefault().register(this); - } - - @Override - protected int getLayoutId() { - return R.layout.view_live_push_ry; - } - - public void setLiveActivityContainer(ViewGroup liveActivityContainer) { - this.liveActivityContainer = liveActivityContainer; - } - - /** - * 主房间事件监听 - * 详细说明请参考文档:https://www.rongcloud.cn/docs/api/android/rtclib_v4/cn/rongcloud/rtc/api/callback/IRCRTCRoomEventsListener.html - */ - public IRCRTCRoomEventsListener roomEventsListener = new IRCRTCRoomEventsListener() { - @Override - public void onRemoteUserPublishResource(RCRTCRemoteUser rcrtcRemoteUser, List list) { - Log.e("ry", "远端来了" + list.size()); - //TODO 按需在此订阅远端用户发布的资源 - rtcRoom.getLocalUser().subscribeStreams(list, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.e("ry", "远端成功" + list.size()); - - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - Log.e("ry", "远端失败" + list.size() + "|errorCode:" + rtcErrorCode.toString()); - ToastUtil.show(mContext.getString(R.string.live_pk_link_error)); - } - }); - } - - @Override - public void onRemoteUserMuteAudio(RCRTCRemoteUser rcrtcRemoteUser, RCRTCInputStream rcrtcInputStream, boolean b) { - } - - @Override - public void onRemoteUserMuteVideo(RCRTCRemoteUser rcrtcRemoteUser, RCRTCInputStream rcrtcInputStream, boolean b) { - } - - @Override - public void onRemoteUserUnpublishResource(RCRTCRemoteUser rcrtcRemoteUser, List list) { - } - - @Override - public void onUserJoined(RCRTCRemoteUser rcrtcRemoteUser) { - } - - @Override - public void onUserLeft(RCRTCRemoteUser rcrtcRemoteUser) { - } - - @Override - public void onUserOffline(RCRTCRemoteUser rcrtcRemoteUser) { - } - - @Override - public void onPublishLiveStreams(List list) { - } - - @Override - public void onUnpublishLiveStreams(List list) { - } - - @Override - public void onLeaveRoom(int i) { - } - - /** - * 收到邀请者的跨房间连麦通知 - * - * @param inviterRoomId 邀请者房间 Id - * @param inviterUserId 邀请者用户 Id - * @param extra 扩展字段,默认为空 - */ - @Override - public void onRequestJoinOtherRoom(String inviterRoomId, String inviterUserId, String extra) { - super.onRequestJoinOtherRoom(inviterRoomId, inviterUserId, extra); - runOnUiThread(new Runnable() { - @Override - public void run() { - Log.e("ry", inviterRoomId + extra + "Request"); - UserBean userBean = new UserBean(); - userBean.setId(inviterRoomId); - //收到邀请这个时候正在PK或连麦中 自动拒绝对方 - if (isPking() == true) { - - rtcRoom.getLocalUser().responseJoinOtherRoom(userBean.getId(), userBean.getId(), false, false, "extra", new IRCRTCResultCallback() { - - @Override - public void onFailed(RTCErrorCode errorCode) { - - } - - @Override - public void onSuccess() { - final SocketSendBean msg1 = new SocketSendBean() - .param("_method_", SOCKET_LINK_MIC_PK) - .param("action", 8); - msg1.create(); - - String targetId = userBean.getId(); - Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; - TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); - io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); - - RongcloudIMManager.sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { - @Override - public void onAttached(io.rong.imlib.model.Message message) { - - } - - @Override - public void onSuccess(io.rong.imlib.model.Message message) { - - Log.e("ry", "发送成功"); - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(msg1.mResult.toString() + ""); - } - } - - @Override - public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { - Log.e("ry", "发送失敗" + userBean.getId()); - } - }); - } - }); - - } else if (extra.equals(SOCKET_LIVE_DRPK)) { - //收到多人PK申请 - if (mLiveRyLinkMicPkPresenter != null) { - mLiveRyLinkMicPkPresenter.onLinkDRMicPkApply(userBean); - } else { - mLiveRyLinkMicPkPresenter = new LiveRyLinkMicPkPresenter(mContext, LivePushRyViewHolder.this, true, liveActivityContainer); - mLiveRyLinkMicPkPresenter.onLinkDRMicPkApply(userBean); - } - } else if (extra.equals("LiveDRPK1")) { - Log.e("ry", "LiveDRPK1"); - rtcRoom.getLocalUser().responseJoinOtherRoom(userBean.getId(), userBean.getId(), true, true, "LiveDRPK1", new IRCRTCResultCallback() { - @Override - public void onSuccess() { - mLiveRyLinkMicPkPresenter.dRjoinOtherRoom(userBean.getId(), 2); - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - - } - }); - } else { - if (extra.contains("autoLivePK")) { - UserBean userBean1 = new UserBean(); - if (!extra.equals("")) { - JSONObject map = JSONObject.parseObject(extra); - userBean1.setId(map.getString("uid")); - userBean1.setUserNiceName(map.getString("pkname")); - userBean1.setAvatar(map.getString("pkhead")); - } else { - userBean1.setId(inviterRoomId); - userBean1.setUserNiceName("null"); - userBean1.setAvatar("null"); - } - mLiveRyLinkMicPkPresenter.onLinkMicPkApply(userBean1, "", 1); - } else { - Log.e("ry", extra); - /* - * { - * "pkhead": "https://downs.yaoulive.com/20220906170849_79c553dc1319fb5c215e06e01674eba4?imageView2/2/w/600/h/600", - * "pkname": "用户_98274", - * "pkuid": "98274", - * "randomPk": true, - * "uid": "98274" - * } - */ - UserBean userBean1 = new UserBean(); - if (!extra.equals("")) { - JSONObject map = JSONObject.parseObject(extra); - userBean1.setAvatar(map.getString("pkhead")); - userBean1.setUserNiceName(map.getString("pkname")); - userBean1.setRandomPk(map.containsKey("random_pk") && map.getString("random_pk").equals("1")); - userBean1.setRankPkImgUrl(map.containsKey("is_ladders") ? map.getString("is_ladders") : null); - userBean1.setId(map.getString("uid")); - userBean1.setUserNiceName(map.getString("pkname")); - userBean1.setAvatar(map.getString("pkhead")); - } else { - userBean1.setId(inviterRoomId); - userBean1.setUserNiceName("null"); - userBean1.setAvatar("null"); - } - //收到单人PK申请 - mLiveRyLinkMicPkPresenter.onLinkMicPkApply(userBean1, "", 0); - } - } - } - }); - } - - /** - * 收到邀请者的取消跨房间连麦通知 - * - * @param inviterRoomId 邀请者房间 Id - * @param inviterUserId 邀请者用户 Id - * @param extra 扩展字段,默认为空 - */ - @Override - public void onCancelRequestOtherRoom(String inviterRoomId, String inviterUserId, String extra) { - super.onCancelRequestOtherRoom(inviterRoomId, inviterUserId, extra); - } - - /** - * 收到被邀请者的跨房间连麦响应 - *

- * 1.如果被邀请者同意请求,邀请者房间和被邀请者房间中所有人会收到通知。 - * - * 2.如果被邀请者拒绝请求,仅邀请者收到通知。 - *

- * - * @param inviterRoomId 邀请者房间 Id - * @param inviterUserId 邀请者用户 Id - * @param inviteeRoomId 被邀请者房间 Id - * @param inviteeUserId 被邀请者用户 Id - * @param agree 被邀请者是否同意连麦请求 - * @param extra 扩展字段,默认为空 - */ - @Override - public void onResponseJoinOtherRoom(String inviterRoomId, String inviterUserId, String inviteeRoomId, String inviteeUserId, boolean agree, String extra) { - super.onResponseJoinOtherRoom(inviterRoomId, inviterUserId, inviteeRoomId, inviteeUserId, agree, extra); - IMRTCManager.getInstance().callPkSuccess(inviterRoomId); - runOnUiThread(new Runnable() { - @Override - public void run() { - Log.e("ry", inviterRoomId + extra + "Response" + agree); - if (agree == false) { -// ToastUtil.show(inviteeUserId+(agree?" 同意":" 拒绝")+"了你的邀请!"); - } else if (agree == true && extra.equals(SOCKET_LIVE_DRPK)) { - mLiveRyLinkMicPkPresenter.onDRLinkMicToPk(inviteeRoomId); - } else if (extra.equals("LiveDRPK1")) { - mLiveRyLinkMicPkPresenter.dRjoinOtherRoom(inviteeRoomId, 3); - } else { - Log.e("ry", extra); - UserBean userBean1 = new UserBean(); - if (!extra.equals("")) { - JSONObject map = JSONObject.parseObject(extra); - userBean1.setId(map.getString("uid")); - userBean1.setUserNiceName(map.getString("pkname")); - userBean1.setAvatar(map.getString("pkhead")); - } else { - userBean1.setId(inviterRoomId); - userBean1.setUserNiceName("null"); - userBean1.setAvatar("null"); - } - //单人PK,减掉次数 - if (!RandomPkManager.getInstance().isRandomModel()) { - LiveNetManager.get(mContext).setFreePkNum(new com.yunbao.common.http.base.HttpCallback() { - @Override - public void onSuccess(HttpCallbackModel data) { - - } - - @Override - public void onError(String error) { - ToastUtil.show(WordUtil.isNewZh()?"抱歉!出錯了!":"i \\'m sorry! An error occurred"); - } - }); - - } - mLiveRyLinkMicPkPresenter.onLinkMicToPk(userBean1); - mLiveRyLinkMicPkPresenter.onLinkMicPkStart(inviteeRoomId, 3); - EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.UP_PK_TWO).setObject(userBean1.getId())); - } - } - }); - } - - @Override - public void onKickedByServer() { - super.onKickedByServer(); - } - - /** - * 收到结束跨房间连麦的通知,需要在此处调用 {@link RCRTCEngine#leaveOtherRoom(String, boolean, IRCRTCResultCallback)} 决定是否与对端结束连麦(停止合流) - * - * @param roomId 结束连麦的房间 Id - * @param userId 发起结束连麦的用户 id - */ - @Override - public void onFinishOtherRoom(String roomId, String userId) { - super.onFinishOtherRoom(roomId, userId); - Log.e("ry", roomId + "房间是" + userId); - RCRTCEngine.getInstance().leaveOtherRoom(roomId, true, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.e("ry", roomId + "退出啊房间成功" + userId); - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.e("ry", roomId + "退出啊房间失败" + userId); - - } - }); - - - if (mLiveRyLinkMicPkPresenter != null) { - mLiveRyLinkMicPkPresenter.leaveDRRoom(); - } - } - - /** - * 加入的副房间,连接断开。 - */ - @Override - public void onOtherRoomConnectionError(String otherRoomId) { - super.onOtherRoomConnectionError(otherRoomId); - } - }; - - - @Override - public void init() { - super.init(); - Bus.getOn(this); - mPreView = (FrameLayout) findViewById(R.id.camera_preview); - camera = (LinearLayout) findViewById(R.id.camera); - mPreView1 = (FrameLayout) findViewById(R.id.camera_preview1); - cameraPreview3 = (FrameLayout) findViewById(R.id.camera_preview3); - dr1_preview = (FrameLayout) findViewById(R.id.dr1_preview); - dr2_preview = (FrameLayout) findViewById(R.id.dr2_preview); - dr3_preview = (FrameLayout) findViewById(R.id.dr3_preview); - dr4_preview = (FrameLayout) findViewById(R.id.dr4_preview); - leave = (ImageView) findViewById(R.id.leave); - dr_pk_view = (LinearLayout) findViewById(R.id.dr_pk_view); - timeTitle = (FrameLayout) findViewById(R.id.time_title); - textTime = (TextView) findViewById(R.id.text_time); - dr_pk_view.setVisibility(View.GONE); - cameraPreview3.setVisibility(View.GONE); - btn_close = (TextView) findViewById(R.id.btn_close); - tv_avatarOther_name = (TextView) findViewById(R.id.tv_avatarOther_name); - avatarOther = (ImageView) findViewById(R.id.avatarOther); - goto_room_view = (LinearLayout) findViewById(R.id.goto_room_view); - goto_room_view.setVisibility(View.GONE); - mMainHandler = new Handler(Looper.getMainLooper()); - btn_close.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - DialogUitl.showSimpleDialog(mContext, WordUtil.isNewZh() ? "是否要斷開連麥?" : "Do you want to disconnect Link?", new DialogUitl.SimpleCallback() { - @Override - public void onConfirmClick(Dialog dialog, String content) { - Log.i("PK----->", "updateSub: " + isPk + "|"); - aheadOfScheduleEndPK(mPkUid, CommonAppConfig.getInstance().getUserBean().getUserNiceName(), (String) tv_avatarOther_name.getTag()); - //断开连麦 - LiveRyAnchorActivity.isDRPK = 0; - HttpClient.getInstance().post("livepk.setliveuserout", "livepk.setliveuserout") - .execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - } - }); - - - HttpClient.getInstance().get("Livepk.endPK", "Livepk.endPK") - .params("uid", CommonAppConfig.getInstance().getUid()) - .params("addtime", "1") - .params("type", "1") - .params("sign", "1") - .execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - if (code == 0) { - JSONObject datas = JSONObject.parseObject(info[0]); - String pkUid = datas.getString("pkuid"); - //退出副房间 - RCRTCEngine.getInstance().leaveOtherRoom(pkUid, true, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.e("ry", "退出房间成功" + pkUid); - new Handler(Looper.getMainLooper()).post(new Runnable() { - public void run() { - mPreView1.removeAllViews(); - mPreView1.setVisibility(View.GONE); - inputStreamList.clear(); - inputStreamList1.clear(); - changeToBig(); - //清理PK上面对方的头像 - EventBus.getDefault().post(new AnchorInfoEvent(true, "", "", "")); - closeButtonGone(); - } - }); - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - Log.e("ry", pkUid + "退出房间s失败" + rtcErrorCode); - } - }); - - - SocketSendBean seed_msg = new SocketSendBean() - .param("_method_", Constants.SOCKET_LINK_MIC_PK) - .param("action", 9) - .param("msgtype", 10) - .param("win_uid", datas.getString("win_uid")) - .param("uid", CommonAppConfig.getInstance().getUid()); - seed_msg.create(); - Log.i("seed", seed_msg.mResult.toString()); - HttpClient.getInstance().get("Tx.sendmsgzs2", "Tx.sendmsgzs2") - .params("GroupId", "g" + pkUid) - .params("jsonstr", seed_msg.mResult.toString()) - .execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - - HttpClient.getInstance().get("Tx.sendmsgzs2", "Tx.sendmsgzs2") - .params("GroupId", "g" + CommonAppConfig.getInstance().getUid()) - .params("jsonstr", seed_msg.mResult.toString()) - .execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - - SocketSendBean seed_msgs = new SocketSendBean() - .param("_method_", Constants.SOCKET_LINK_MIC_PK) - .param("action", 5) - .param("msgtype", 10) - .param("uname", "1") - .param("uimg", "1") - .param("pkuid", LiveRyLinkMicPkPresenter.oldmPkUid) - .param("uid", CommonAppConfig.getInstance().getUid()); - seed_msgs.create(); - Log.i("seed", seed_msgs.mResult.toString()); - - HttpClient.getInstance().get("Tx.sendmsgzs2", "Tx.sendmsgzs2") - .params("GroupId", "g" + LiveRyLinkMicPkPresenter.oldmPkUid) - .params("jsonstr", seed_msgs.mResult.toString()) - .execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - HttpClient.getInstance().get("Tx.sendmsgzs2", "Tx.sendmsgzs2") - .params("GroupId", "g" + CommonAppConfig.getInstance().getUid()) - .params("jsonstr", seed_msgs.mResult.toString()) - .execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - - } - }); - } - }); - } - }); - } - }); - - } - - } - }); - - - } - }); - } - }); - - // 构建 RoomConfig,指定房间类型和主播身份: - RCRTCRoomConfig roomConfig = RCRTCRoomConfig.Builder.create() - // 根据实际场景,选择音视频直播:LIVE_AUDIO_VIDEO 或音频直播:LIVE_AUDIO - .setRoomType(RCRTCRoomType.LIVE_AUDIO_VIDEO) - .setLiveRole(BROADCASTER) - .build(); - - - //调用 RCRTCEngine 下的 joinRoom 方法创建并加入一个直播房间: - final CommonAppConfig appConfig = CommonAppConfig.getInstance(); - - RCRTCEngine.getInstance().joinRoom(appConfig.getUid(), roomConfig, new IRCRTCResultDataCallback() { - @Override - public void onFailed(RTCErrorCode errorCode) { - ToastUtil.show("开播失败" + errorCode); - } - - @Override - public void onSuccess(final RCRTCRoom room) { - - // 保存房间对象 - rtcRoom = room; - IMRTCManager.getInstance().setRtcRoom(room); - - new Handler(Looper.getMainLooper()).post(new Runnable() { - public void run() { - - RCRTCConfig config = RCRTCConfig.Builder.create() - //是否硬解码 - .enableHardwareDecoder(true) - //是否硬编码 - .enableHardwareEncoder(true) - .build(); - - - RCRTCEngine.getInstance().init(contexts, config); - RCRTCEngine.getInstance().getDefaultAudioStream().setAudioQuality(RCRTCParamsType.AudioQuality.MUSIC_HIGH, RCRTCParamsType.AudioScenario.MUSIC_CHATROOM); - //設置開播分辨率 - RCRTCParamsType.RCRTCVideoResolution rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_480_848; - int minRate = 200; - int maxRate = 900; - switch (IMLoginManager.get(mContext).getSelectClarity()) { - case 0: - rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_480_848; - minRate = 200; - maxRate = 900; - break; - case 1: - rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_720_1280; - minRate = 250; - maxRate = 2200; - break; - case 2: - rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_1080_1920; - minRate = 400; - maxRate = 4000; - break; - } - - RCRTCVideoStreamConfig videoConfigBuilder = RCRTCVideoStreamConfig.Builder.create() - //设置分辨率 - .setVideoResolution(rcrtcVideoResolution) - //设置帧率 - .setVideoFps(RCRTCParamsType.RCRTCVideoFps.Fps_24) - //设置最小码率,480P下推荐200 - .setMinRate(minRate) - //设置最大码率,480P下推荐900 - .setMaxRate(maxRate) - .build(); - - // 创建本地视频显示视图 - RCRTCEngine.getInstance().getDefaultVideoStream().setVideoConfig(videoConfigBuilder); - RCRTCEngine.getInstance().getDefaultVideoStream().enableTinyStream(false); - RCRTCVideoView rongRTCVideoView = new RCRTCVideoView(contexts); - rongRTCVideoView.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FILL); - RCRTCEngine.getInstance().getDefaultVideoStream().setVideoView(rongRTCVideoView); - RCRTCEngine.getInstance().getDefaultVideoStream().startCamera(new IRCRTCResultDataCallback() { - @Override - public void onSuccess(Boolean data) { - //设置摄像头最大缩放比例 - boolean zoom = RCRTCEngine.getInstance().getDefaultVideoStream().setCameraZoomFactor(1.0f); - // ToastUtil.show("设置比例="+zoom); - Log.i("摄像头", "onSuccess: 打开摄像头"); - isNeedOpenCamera = false; - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.i("摄像头", "onFailed: 打开摄像头失败 " + errorCode); - } - }); - RCRTCEngine.getInstance().registerEventListener(new IRCRTCEngineEventListener() { - @Override - public void onKicked(String roomId, RCRTCParamsType.RCRTCKickedReason kickedReason) { - - } - - @Override - public void onError(RTCErrorCode errorCode) { - super.onError(errorCode); - Log.i("摄像头", "onError: 错误码" + errorCode); - } - - @Override - public void onLocalVideoEventNotify(RCRTCVideoEventCode event) { - super.onLocalVideoEventNotify(event); - Log.i("摄像头", "onLocalVideoEventNotify: 本地视频事件" + event.code); - if (event.code == 3) { - isNeedOpenCamera = true; - } - } - }); - //设置摄像头最大缩放比例 - // RCRTCEngine.getInstance().getDefaultVideoStream().setCameraZoomFactor(RCRTCEngine.getInstance().getDefaultVideoStream().getCameraMaxZoomFactor()); - mPreView.addView(rongRTCVideoView); - tencentTRTCBeautyManager = new TencentTRTCBeautyManager(mContext); - - //加入房间成功后可以通过 RCRTCLocalUser 对象发布本地默认音视频流,包括:麦克风采集的音频和摄像头采集的视频。 - RCRTCEngine.getInstance().getDefaultVideoStream().setEncoderMirror(true); - if (rtcRoom == null || rtcRoom.getLocalUser() == null) { - if (room == null || room.getLocalUser() == null) { - ToastUtil.show("开播失败 请稍后再试,错误代码:room is null"); - ((LiveRyAnchorActivity) mContext).endLives(); - return; - } - rtcRoom = room; - IMRTCManager.getInstance().setRtcRoom(room); - } - rtcRoom.getLocalUser().publishDefaultLiveStreams(new IRCRTCResultDataCallback() { - @Override - public void onSuccess(RCRTCLiveInfo rcrtcLiveInfo1) { - rcrtcLiveInfo = rcrtcLiveInfo1; - - room.registerRoomListener(roomEventsListener); - - //美颜 -// new Handler(Looper.getMainLooper()).post(new Runnable() { -// public void run() { -// //旧美颜不需要了 -// -// -// } -// }); - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - Log.e("ry", "rtcErrorCode" + rtcErrorCode); - } - }); - } - - }); - - - } - }); - } - - - @Override - public void changeToLeft() { - if (mPreView != null) { - FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mPreView.getLayoutParams(); - params.width = mPreView.getWidth() / 2; - params.height = DpUtil.dp2px(250); - params.topMargin = DpUtil.dp2px(130); - camera.setLayoutParams(params); - } - } - - @Override - public void changeToBig() { - if (camera != null) { - LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) camera.getLayoutParams(); - params.width = ViewGroup.LayoutParams.MATCH_PARENT; - params.height = ViewGroup.LayoutParams.MATCH_PARENT; - params.topMargin = 0; - camera.setLayoutParams(params); - } - if (mPreView1.getVisibility() == View.VISIBLE) { - mPreView1.removeAllViews(); - mPreView1.setVisibility(View.GONE); - inputStreamList.clear(); - inputStreamList1.clear(); - } - } - - public void closeButtonGone() { - btn_close.setVisibility(View.GONE); - } - - @Override - public void toggleCamera() { - if (mCameraFront) { - mCameraFront = false; - } else { - mCameraFront = true; - } - RCRTCEngine.getInstance().getDefaultVideoStream().switchCamera(new CameraVideoCapturer.CameraSwitchHandler() { - @Override - public void onCameraSwitchDone(boolean isFrontCamera) { - - } - - @Override - public void onCameraSwitchError(String errorDescription) { - - } - }); - } - - /** - * 打开关闭闪光灯 - */ - @Override - public void toggleFlash() { - if (mCameraFront) { - ToastUtil.show(mContext.getString(R.string.live_open_flash)); - return; - } - - } - - /** - * 开始推流 - * - * @param pushUrl 推流地址 - */ - @Override - public void startPush(String pushUrl) { - if (rcrtcLiveInfo != null) { - rcrtcLiveInfo.addPublishStreamUrl(pushUrl, new IRCRTCResultDataCallback() { - @Override - public void onSuccess(String[] data) { - //强制设置开播后cdn的尺寸竖屏,因为有时候PK异常退出,cdn没有还原竖屏。 - if (rtcRoom != null) { - RCRTCMixConfig config = new RCRTCMixConfig(); - RCRTCMixConfig.MediaConfig mediaConfig = new RCRTCMixConfig.MediaConfig(); - config.setMediaConfig(mediaConfig); - //视频输出配置 - RCRTCMixConfig.MediaConfig.VideoConfig videoConfig = new RCRTCMixConfig.MediaConfig.VideoConfig(); - mediaConfig.setVideoConfig(videoConfig); - //大流视频的输出参数 - RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout normal = new RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout(); - - //推荐宽、高、帧率参数值可以通过默认视频流的配置获取,也可以根据实际需求来自定义设置 - //如不设置宽高值则服务端将使用默认宽高 360 * 640 - //例:发布的视频分辨率为720 * 1280,如果不设置则观众端看到的视频分辨率为 360 * 640, - //所以如果想让观众端看到的视频分辨率和发布视频分辨率一致,则应从发布的视频流中获取分辨率配置并设置到 mediaConfig 中 - //設置開播分辨率 - //設置開播分辨率 - RCRTCParamsType.RCRTCVideoResolution rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_480_848; - int minRate = 200; - int maxRate = 900; - switch (IMLoginManager.get(mContext).getSelectClarity()) { - case 0: - rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_480_848; - break; - case 1: - rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_720_1280; - break; - case 2: - rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_1080_1920; - break; - } - int width = rcrtcVideoResolution.getWidth(); - int height = rcrtcVideoResolution.getHeight(); - normal.setWidth(width); //视频宽 - normal.setHeight(height); //视频高 - normal.setFps(15); //视频帧率 - videoConfig.setVideoLayout(normal); - //2. 合流画布设置 - //(请参照画布和声音配置示例代码) - //3. 假设以画布设置的宽高为 300 * 300为例(应以真实设置的宽高为准),设置每个视频流小窗口的坐标及宽高 - ArrayList list = new ArrayList<>(); - config.setCustomLayouts(list); - //user1的视频流 - RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout1 = new RCRTCMixConfig.CustomLayoutList.CustomLayout(); - list.add(videoLayout1); - videoLayout1.setVideoStream(RCRTCEngine.getInstance().getDefaultVideoStream()); // RCRTCStream#MediaType 必须是Video - videoLayout1.setX(0); //X 坐标 - videoLayout1.setY(0); //Y 坐标 - videoLayout1.setWidth(720); // 视频窗口的宽 - videoLayout1.setHeight(1280); // 视频窗口的高 - //2. 合流画布设置 - rcrtcLiveInfo.setMixConfig(config, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.e("ry", "混成功12"); - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.e("ry", "混失败" + errorCode); - - } - }); - } - - - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - } - }); - startCountDown(); - } else { - ToastUtil.show("请稍后,准备中...."); - } - } - - public boolean isPking() { - if (btn_close != null) { - return btn_close.getVisibility() == View.VISIBLE; - } - return false; - } - - @Override - public void onPause() { - mPaused = true; - - } - - @Override - public void onResume() { - mPaused = false; - Log.i("摄像头", "onResume: " + isNeedOpenCamera); - if(isNeedOpenCamera){ - RCRTCEngine.getInstance().getDefaultVideoStream().startCamera(new IRCRTCResultDataCallback() { - @Override - public void onSuccess(Boolean data) { - //设置摄像头最大缩放比例 - boolean zoom = RCRTCEngine.getInstance().getDefaultVideoStream().setCameraZoomFactor(1.0f); - // ToastUtil.show("设置比例="+zoom); - Log.i("摄像头", "onSuccess: 打开摄像头"); - isNeedOpenCamera = false; - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.i("摄像头", "onFailed: 打开摄像头失败 " + errorCode); - } - }); - } - } - - @Override - public void startBgm(String path) { - mBgmPath = path; - - - } - - @Override - public void pauseBgm() { - - } - - @Override - public void resumeBgm() { - - } - - @Override - public void stopBgm() { - mBgmPath = null; - } - - - @Override - public void release() { - super.release(); - Bus.getOff(this); - LiveHttpUtil.cancel(LiveHttpConsts.LINK_MIC_TX_MIX_STREAM); - rtcRoom = null; - } - - @Override - public void onPushEvent(int e, Bundle bundle) { - if (e == TXLiveConstants.PUSH_ERR_OPEN_CAMERA_FAIL) { - ToastUtil.show(mContext.getString(R.string.live_push_failed_1)); - - } else if (e == TXLiveConstants.PUSH_ERR_OPEN_MIC_FAIL) { - ToastUtil.show(mContext.getString(R.string.live_push_failed_2)); - - } else if (e == TXLiveConstants.PUSH_ERR_NET_DISCONNECT || e == TXLiveConstants.PUSH_ERR_INVALID_ADDRESS) { - L.e(TAG, "网络断开,推流失败------>"); - - } else if (e == TXLiveConstants.PUSH_WARNING_HW_ACCELERATION_FAIL) { - L.e(TAG, "不支持硬件加速------>"); - - } else if (e == TXLiveConstants.PUSH_EVT_FIRST_FRAME_AVAILABLE) {//预览成功 - L.e(TAG, "mStearm--->初始化完毕"); - if (mLivePushListener != null) { - mLivePushListener.onPreviewStart(); - } - } else if (e == TXLiveConstants.PUSH_EVT_PUSH_BEGIN) {//推流成功 - L.e(TAG, "mStearm--->推流成功"); - if (!mStartPush) { - mStartPush = true; - if (mLivePushListener != null) { - mLivePushListener.onPushStart(); - } - } - } - } - - @Override - public void onNetStatus(Bundle bundle) { - - } - - private void aheadOfScheduleEndPK(String pkUid, String uname, String pkname) { - if (!isPk) { - return; - } - String ct = "由於 " + uname + " 退出比賽," + pkname + " 獲得勝利"; - - SocketSendBean seed_msg = new SocketSendBean() - .param("_method_", Constants.SOCKET_SYSTEM) - .param("action", 1) - .param("ct", ct); - seed_msg.create(); - - - HttpClient.getInstance().get("Tx.sendmsgzs2", "Tx.sendmsgzs2") - .params("GroupId", "g" + pkUid) - .params("jsonstr", seed_msg.mResult.toString()) - .execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - HttpClient.getInstance().post("Tx.sendmsgzs2", "Tx.sendmsgzs2") - .params("GroupId", "g" + CommonAppConfig.getInstance().getUid()) - .params("jsonstr", seed_msg.mResult.toString()) - .execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - - } - }); - } - }); - } - - private Bitmap decodeResource(Resources resources, int id) { - TypedValue value = new TypedValue(); - resources.openRawResource(id, value); - BitmapFactory.Options opts = new BitmapFactory.Options(); - opts.inTargetDensity = value.density; - return BitmapFactory.decodeResource(resources, id, opts); - } - - public static String getLiveStream() { - return ((LiveActivity) contexts).getStream(); - } - - private String getTxAppId() { - return ((LiveActivity) mContext).getTxAppId(); - } - - @Subscribe(threadMode = ThreadMode.MAIN) - public void setSelectClarity(LivePushRyEvent event) { - if (rtcRoom != null) - rtcRoom.getLocalUser().publishDefaultLiveStreams(new IRCRTCResultDataCallback() { - @Override - public void onSuccess(RCRTCLiveInfo rcrtcLiveInfo1) { - rcrtcLiveInfo = rcrtcLiveInfo1; - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - Log.e("ry", "rtcErrorCode" + rtcErrorCode); - } - }); - } - - @Subscribe(threadMode = ThreadMode.MAIN) - public void updateSub(LiveAudienceEvent event) { - if (event.getType() == LIVE_PK_END) { - isPk = false; - } else if (event.getType() == LIVE_PK_ING) { - isPk = true; - } - Log.i("PK----->", "updateSub: " + isPk + "|" + event.getType()); - } -} diff --git a/live/src/main/java/com/yunbao/live/views/LivePushSwViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePushSwViewHolder.java index add57ceb0..8026028e3 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePushSwViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePushSwViewHolder.java @@ -3,8 +3,6 @@ package com.yunbao.live.views; import static com.yunbao.live.activity.LiveActivity.mLiveSwLinkMicPkPresenter; import static com.yunbao.live.event.LiveAudienceEvent.LiveAudienceType.LIVE_PK_END; import static com.yunbao.live.event.LiveAudienceEvent.LiveAudienceType.LIVE_PK_ING; -import static com.yunbao.live.presenter.LiveSwLinkMicPkPresenter.inputStreamList; -import static com.yunbao.live.presenter.LiveSwLinkMicPkPresenter.inputStreamList1; import static com.yunbao.live.presenter.LiveSwLinkMicPkPresenter.mPkUid; import android.app.Activity; @@ -62,14 +60,6 @@ import org.greenrobot.eventbus.ThreadMode; import java.util.ArrayList; import java.util.List; -import cn.rongcloud.rtc.api.RCRTCEngine; -import cn.rongcloud.rtc.api.RCRTCMixConfig; -import cn.rongcloud.rtc.api.RCRTCRoom; -import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback; -import cn.rongcloud.rtc.api.callback.IRCRTCResultDataCallback; -import cn.rongcloud.rtc.api.stream.RCRTCLiveInfo; -import cn.rongcloud.rtc.base.RCRTCParamsType; -import cn.rongcloud.rtc.base.RTCErrorCode; import io.agora.beautyapi.faceunity.agora.SWAuManager; import io.agora.beautyapi.faceunity.agora.SWManager; import io.rong.imlib.IRongCallback; @@ -93,8 +83,8 @@ public class LivePushSwViewHolder extends AbsRyLivePushViewHolder implements ITX public static Context contexts; public static TextView btn_close; public LinearLayout dr_pk_view; - public static RCRTCRoom rtcRoom; - public static RCRTCLiveInfo rcrtcLiveInfo; +// public static RCRTCRoom rtcRoom; +// public static RCRTCLiveInfo rcrtcLiveInfo; private ViewGroup liveActivityContainer; public FrameLayout timeTitle; public TextView textTime; @@ -441,8 +431,8 @@ public class LivePushSwViewHolder extends AbsRyLivePushViewHolder implements ITX if (mPreView1.getVisibility() == View.VISIBLE) { mPreView1.removeAllViews(); mPreView1.setVisibility(View.GONE); - inputStreamList.clear(); - inputStreamList1.clear(); +// inputStreamList.clear(); +// inputStreamList1.clear(); } } @@ -505,23 +495,6 @@ public class LivePushSwViewHolder extends AbsRyLivePushViewHolder implements ITX mPaused = false; Log.i("摄像头", "onResume: " + isNeedOpenCamera); swManager.resetCamera(); - if (isNeedOpenCamera) { - /*RCRTCEngine.getInstance().getDefaultVideoStream().startCamera(new IRCRTCResultDataCallback() { - @Override - public void onSuccess(Boolean data) { - //设置摄像头最大缩放比例 - boolean zoom = RCRTCEngine.getInstance().getDefaultVideoStream().setCameraZoomFactor(1.0f); - // ToastUtil.show("设置比例="+zoom); - Log.i("摄像头", "onSuccess: 打开摄像头"); - isNeedOpenCamera = false; - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.i("摄像头", "onFailed: 打开摄像头失败 " + errorCode); - } - });*/ - } } @Override @@ -553,7 +526,7 @@ public class LivePushSwViewHolder extends AbsRyLivePushViewHolder implements ITX onDestroy(); SWManager.get().release(); LiveHttpUtil.cancel(LiveHttpConsts.LINK_MIC_TX_MIX_STREAM); - rtcRoom = null; +// rtcRoom = null; } @Override @@ -631,7 +604,7 @@ public class LivePushSwViewHolder extends AbsRyLivePushViewHolder implements ITX @Subscribe(threadMode = ThreadMode.MAIN) public void setSelectClarity(LivePushRyEvent event) { - if (rtcRoom != null) + /* if (rtcRoom != null) rtcRoom.getLocalUser().publishDefaultLiveStreams(new IRCRTCResultDataCallback() { @Override public void onSuccess(RCRTCLiveInfo rcrtcLiveInfo1) { @@ -642,7 +615,7 @@ public class LivePushSwViewHolder extends AbsRyLivePushViewHolder implements ITX public void onFailed(RTCErrorCode rtcErrorCode) { Log.e("ry", "rtcErrorCode" + rtcErrorCode); } - }); + });*/ } public void setEnableBeauty(boolean flag) { diff --git a/live/src/main/java/com/yunbao/live/views/LiveReadyRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveReadyRyViewHolder.java deleted file mode 100644 index 6e26b6276..000000000 --- a/live/src/main/java/com/yunbao/live/views/LiveReadyRyViewHolder.java +++ /dev/null @@ -1,528 +0,0 @@ -package com.yunbao.live.views; - -import android.app.Dialog; -import android.content.Context; -import android.content.Intent; -import android.os.Bundle; -import androidx.core.content.ContextCompat; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; -import android.text.TextUtils; -import android.view.View; -import android.view.ViewGroup; -import android.view.inputmethod.InputMethodManager; -import android.widget.EditText; -import android.widget.ImageView; -import android.widget.RelativeLayout; -import android.widget.TextView; - -import com.yunbao.common.CommonAppConfig; -import com.yunbao.common.Constants; -import com.yunbao.common.bean.UserBean; -import com.yunbao.common.glide.ImgLoader; -import com.yunbao.common.http.HttpCallback; -import com.yunbao.common.interfaces.ActivityResultCallback; -import com.yunbao.common.interfaces.CommonCallback; -import com.yunbao.common.interfaces.ImageResultCallback; -import com.yunbao.common.utils.DialogUitl; -import com.yunbao.common.utils.L; -import com.yunbao.common.utils.ProcessImageUtil; -import com.yunbao.common.utils.StringUtil; -import com.yunbao.common.utils.ToastUtil; -import com.yunbao.common.utils.WordUtil; -import com.yunbao.common.views.AbsViewHolder; -import com.yunbao.live.R; -import com.yunbao.live.activity.LiveActivity; -import com.yunbao.live.activity.LiveChooseClassActivity; -import com.yunbao.live.activity.LiveRyAnchorActivity; -import com.yunbao.live.adapter.LiveReadyShareAdapter; -import com.yunbao.common.bean.LiveRoomTypeBean; -import com.yunbao.live.dialog.LiveRoomTypeDialogFragment; -import com.yunbao.live.dialog.LiveTimeDialogFragment; -import com.yunbao.live.dialog.LiveWishListDialogFragment; -import com.yunbao.common.http.LiveHttpConsts; -import com.yunbao.common.http.LiveHttpUtil; - -import java.io.File; - -import cn.rongcloud.rtc.api.RCRTCEngine; -import cn.rongcloud.rtc.api.stream.RCRTCCameraOutputStream; - -public class LiveReadyRyViewHolder extends AbsViewHolder implements View.OnClickListener { - - private ImageView mAvatar; - private TextView mCoverText; - private EditText mEditTitle; - private RecyclerView mLiveShareRecyclerView; - private LiveReadyShareAdapter mLiveShareAdapter; - private ProcessImageUtil mImageUtil; - private File mAvatarFile; - private TextView mCity; - private ImageView mLocationImg; - private TextView mLiveClass; - private TextView mLiveTypeTextView;//房间类型TextView - private TextView mLiveWishListTextView;//心愿单TextView - private int mLiveClassID;//直播频道id - private int mLiveType;//房间类型 - private int mLiveTypeVal;//房间密码,门票收费金额 - private int mLiveTimeCoin;//计时收费金额 - private ActivityResultCallback mActivityResultCallback; - private CommonCallback mLiveTypeCallback; - private boolean mOpenLocation = true; - private int mLiveSdk; - - public LiveReadyRyViewHolder(Context context, ViewGroup parentView, int liveSdk) { - super(context, parentView, liveSdk); - } - - @Override - protected void processArguments(Object... args) { - if (args.length > 0) { - mLiveSdk = (int) args[0]; - } - } - - @Override - protected int getLayoutId() { - return R.layout.view_live_ready; - } - - @Override - public void init() { - RelativeLayout traceroute_rootview = (RelativeLayout)findViewById(R.id.traceroute_rootview); - traceroute_rootview.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - InputMethodManager imm = (InputMethodManager) - mContext.getSystemService(Context.INPUT_METHOD_SERVICE); - imm.hideSoftInputFromWindow(view.getWindowToken(), 0); - } - }); - mAvatar = (ImageView) findViewById(R.id.avatar); - UserBean u = CommonAppConfig.getInstance().getUserBean(); - ImgLoader.displayAvatar(mContext, u.getAvatar(), mAvatar); - mCoverText = (TextView) findViewById(R.id.cover_text); - mEditTitle = (EditText) findViewById(R.id.edit_title); - mCity = (TextView) findViewById(R.id.city); - mCity.setText(CommonAppConfig.getInstance().getCity()); - mLocationImg = (ImageView) findViewById(R.id.location_img); - findViewById(R.id.btn_locaiton).setOnClickListener(this); - findViewById(R.id.btn_live_class).setOnClickListener(this); - mOpenLocation = true; - mLiveClass = (TextView) findViewById(R.id.live_class); - mLiveTypeTextView = (TextView) findViewById(R.id.btn_room_type); - findViewById(R.id.btn_horizontally).setOnClickListener(this); - mLiveWishListTextView= (TextView) findViewById(R.id.btn_wishlist); - mLiveShareRecyclerView = (RecyclerView) findViewById(R.id.recyclerView); - mLiveShareRecyclerView.setHasFixedSize(true); - mLiveShareRecyclerView.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false)); - mLiveShareAdapter = new LiveReadyShareAdapter(mContext); - mLiveShareRecyclerView.setAdapter(mLiveShareAdapter); - mImageUtil = ((LiveActivity) mContext).getProcessImageUtil(); - mImageUtil.setImageResultCallback(new ImageResultCallback() { - - @Override - public void beforeCamera() { - ((LiveRyAnchorActivity) mContext).beforeCamera(); - } - - @Override - public void onSuccess(File file) { - if (file != null) { - ImgLoader.display(mContext, file, mAvatar); - if (mAvatarFile == null) { - mCoverText.setText(mContext.getString(R.string.live_cover_2)); - mCoverText.setBackground(ContextCompat.getDrawable(mContext, R.drawable.bg_live_cover)); - } - mAvatarFile = file; - } - } - - @Override - public void onFailure() { - } - }); - findViewById(R.id.avatar_group).setOnClickListener(this); - findViewById(R.id.btn_camera).setOnClickListener(this); - findViewById(R.id.btn_close).setOnClickListener(this); - findViewById(R.id.btn_beauty).setOnClickListener(this); - findViewById(R.id.btn_start_live).setOnClickListener(this); - mLiveTypeTextView.setOnClickListener(this); - mLiveWishListTextView.setOnClickListener(this); - mActivityResultCallback = new ActivityResultCallback() { - @Override - public void onSuccess(Intent intent) { - mLiveClassID = intent.getIntExtra(Constants.CLASS_ID, 0); - mLiveClass.setText(intent.getStringExtra(Constants.CLASS_NAME)); - } - }; - mLiveTypeCallback = new CommonCallback() { - @Override - public void callback(LiveRoomTypeBean bean) { - switch (bean.getId()) { - case Constants.LIVE_TYPE_NORMAL: - onLiveTypeNormal(bean); - break; - case Constants.LIVE_TYPE_PWD: - onLiveTypePwd(bean); - break; - case Constants.LIVE_TYPE_PAY: - onLiveTypePay(bean); - break; - case Constants.LIVE_TYPE_TIME: - onLiveTypeTime(bean); - break; - } - } - }; - - } - - @Override - public void onClick(View v) { - if (!canClick()) { - return; - } - int i = v.getId(); - if (i == R.id.avatar_group) { - setAvatar(); - - } else if (i == R.id.btn_camera) { - toggleCamera(); - } else if (i == R.id.btn_close) { - close(); - } else if (i == R.id.btn_live_class) { - chooseLiveClass(); - } else if (i == R.id.btn_beauty) { - beauty(); - }else if (i == R.id.btn_wishlist) { - //点击心愿单 - openWishListWindow(); - } else if (i == R.id.btn_room_type) { - chooseLiveType(); - } else if (i == R.id.btn_start_live) { - startLive(); - - } else if (i == R.id.btn_locaiton) { - switchLocation(); - }else if(i == R.id.btn_horizontally){ - RCRTCCameraOutputStream cameraStream = RCRTCEngine.getInstance().getDefaultVideoStream(); - cameraStream.setPreviewMirror(!cameraStream.isPreviewMirror()); - } - } - - - /** - * 打开心愿单窗口 - */ - public void openWishListWindow() { - LiveWishListDialogFragment fragment = new LiveWishListDialogFragment(); - - if (mContext instanceof LiveRyAnchorActivity){ - fragment.show(((LiveRyAnchorActivity) mContext).getSupportFragmentManager(), "RY"); - } - } - - /** - * 打开 关闭位置 - */ - private void switchLocation() { - if (mOpenLocation) { - new DialogUitl.Builder(mContext) - .setContent(mContext.getString(R.string.live_location_close_3)) - .setCancelable(true) - .setConfirmString(mContext.getString(R.string.live_location_close_2)) - .setClickCallback(new DialogUitl.SimpleCallback() { - - @Override - public void onConfirmClick(Dialog dialog, String content) { - toggleLocation(); - } - }) - .build() - .show(); - } else { - toggleLocation(); - } - } - - private void toggleLocation() { - mOpenLocation = !mOpenLocation; - if (mLocationImg != null) { - mLocationImg.setImageResource(mOpenLocation ? R.mipmap.address_choice : R.mipmap.icon_live_ready_location_0); - } - if (mCity != null) { - mCity.setText(mOpenLocation ? CommonAppConfig.getInstance().getCity() :mContext.getString(R.string.live_location_close)); - } - } - - /** - * 设置头像 - */ - private void setAvatar() { - if (mLiveSdk == Constants.LIVE_SDK_TX) { - mImageUtil.getImageByAlbum(); - } else { - DialogUitl.showStringArrayDialog(mContext, new Integer[]{ - R.string.camera, R.string.alumb}, new DialogUitl.StringArrayDialogCallback() { - @Override - public void onItemClick(String text, int tag) { - if (tag == R.string.camera) { - mImageUtil.getImageByCamera(); - } else { - mImageUtil.getImageByAlbum(); - } - } - }); - } - } - - /** - * 切换镜头 - */ - private void toggleCamera() { - ((LiveRyAnchorActivity) mContext).toggleCamera(); - } - - /** - * 关闭 - */ - private void close() { - ((LiveRyAnchorActivity) mContext).endLives(); - } - - /** - * 选择直播频道 - */ - private void chooseLiveClass() { - try { - Intent intent = new Intent(mContext, LiveChooseClassActivity.class); - intent.putExtra(Constants.CLASS_ID, mLiveClassID); - mImageUtil.startActivityForResult(intent, mActivityResultCallback); - }catch (Exception e){ - - } - - } - - /** - * 设置美颜 - */ - private void beauty() { - ((LiveRyAnchorActivity) mContext).beauty(); -// Intent intent = new Intent(mContext, Beauty360Activity3.class); -// mContext.startActivity(intent); - - } - - /** - * 选择直播类型 - */ - private void chooseLiveType() { - Bundle bundle = new Bundle(); - bundle.putInt(Constants.CHECKED_ID, mLiveType); - LiveRoomTypeDialogFragment fragment = new LiveRoomTypeDialogFragment(); - fragment.setArguments(bundle); - fragment.setCallback(mLiveTypeCallback); - fragment.show(((LiveRyAnchorActivity) mContext).getSupportFragmentManager(), "LiveRoomTypeDialogFragment"); - } - - /** - * 普通房间 - */ - private void onLiveTypeNormal(LiveRoomTypeBean bean) { - mLiveType = bean.getId(); - mLiveTypeTextView.setText(bean.getName()); - mLiveTypeVal = 0; - mLiveTimeCoin = 0; - } - - /** - * 密码房间 - */ - private void onLiveTypePwd(final LiveRoomTypeBean bean) { - DialogUitl.showSimpleInputDialog(mContext,mContext.getString(R.string.live_set_pwd), DialogUitl.INPUT_TYPE_NUMBER_PASSWORD, 8, new DialogUitl.SimpleCallback() { - @Override - public void onConfirmClick(Dialog dialog, String content) { - if (TextUtils.isEmpty(content)) { - ToastUtil.show(mContext.getString(R.string.live_set_pwd_empty)); - } else { - mLiveType = bean.getId(); - mLiveTypeTextView.setText(bean.getName()); - if (StringUtil.isInt(content)) { - mLiveTypeVal = Integer.parseInt(content); - } - mLiveTimeCoin = 0; - dialog.dismiss(); - } - } - }); - } - - /** - * 付费房间 - */ - private void onLiveTypePay(final LiveRoomTypeBean bean) { - DialogUitl.showSimpleInputDialog(mContext,mContext.getString(R.string.live_set_fee), DialogUitl.INPUT_TYPE_NUMBER, 8, new DialogUitl.SimpleCallback() { - @Override - public void onConfirmClick(Dialog dialog, String content) { - if (TextUtils.isEmpty(content)) { - ToastUtil.show(mContext.getString(R.string.live_set_fee_empty)); - } else { - mLiveType = bean.getId(); - mLiveTypeTextView.setText(bean.getName()); - if (StringUtil.isInt(content)) { - mLiveTypeVal = Integer.parseInt(content); - } - mLiveTimeCoin = 0; - dialog.dismiss(); - } - } - }); - } - - /** - * 计时房间 - */ - private void onLiveTypeTime(final LiveRoomTypeBean bean) { - LiveTimeDialogFragment fragment = new LiveTimeDialogFragment(); - Bundle bundle = new Bundle(); - bundle.putInt(Constants.CHECKED_COIN, mLiveTimeCoin); - fragment.setArguments(bundle); - fragment.setCommonCallback(new CommonCallback() { - @Override - public void callback(Integer coin) { - mLiveType = bean.getId(); - mLiveTypeTextView.setText(bean.getName()); - mLiveTypeVal = coin; - mLiveTimeCoin = coin; - } - }); - fragment.show(((LiveRyAnchorActivity) mContext).getSupportFragmentManager(), "LiveTimeDialogFragment"); - } - - public void hide() { - if (mContentView != null && mContentView.getVisibility() == View.VISIBLE) { - mContentView.setVisibility(View.INVISIBLE); - } - } - - - public void show() { - if (mContentView != null && mContentView.getVisibility() != View.VISIBLE) { - mContentView.setVisibility(View.VISIBLE); - } - } - - /** - * 点击开始直播按钮 - */ - private void startLive() { - boolean startPreview = ((LiveRyAnchorActivity) mContext).isStartPreview(); -// if (!startPreview) { -// ToastUtil.show(R.string.please_wait); -// return; -// } - if (mLiveClassID == 0) { - ToastUtil.show(WordUtil.getNewString(R.string.live_choose_live_class)); - return; - } - if (mLiveShareAdapter != null) { - String type = mLiveShareAdapter.getShareType(); - if (!TextUtils.isEmpty(type)) { -// ((LiveActivity) mContext).shareLive(type, new MobCallback() { -// @Override -// public void onSuccess(Object data) { -// -// } -// -// @Override -// public void onError() { -// -// } -// -// @Override -// public void onCancel() { -// -// } -// -// @Override -// public void onFinish() { -// createRoom(); -// } -// }); - } else { - createRoom(); - } - } else { - createRoom(); - } - } - - /** - * 请求创建直播间接口,开始直播 - */ - boolean isHttpBack = false; - private void createRoom() { - if(isHttpBack == false) { - isHttpBack = true; - if (mLiveClassID == 0) { - ToastUtil.show(WordUtil.getNewString(R.string.live_choose_live_class)); - return; - } - String title = mEditTitle.getText().toString().trim(); - LiveHttpUtil.newcreateRoom(title, mLiveClassID, mLiveType, mLiveTypeVal, mAvatarFile,0, false,new HttpCallback() { - @Override - public void onSuccess(int code, String msg, final String[] info) { - if (code == 0 && info.length > 0) { - L.e("开播", "createRoom------->" + info[0]); - isHttpBack = false; - final CommonAppConfig appConfig = CommonAppConfig.getInstance(); - UserBean u = appConfig.getUserBean(); - - ((LiveRyAnchorActivity) mContext).startLiveSuccess(info[0], mLiveType, mLiveTypeVal); -// -// RongChatRoomClient.getInstance().joinChatRoom("g" + appConfig.getUid(), -1, new IRongCoreCallback.OperationCallback() { -// @Override -// public void onSuccess() { -// Log.i("tx","创建成功"); -// ((LiveAnchorActivity) mContext).startLiveSuccess(info[0], mLiveType, mLiveTypeVal); -// } -// -// @Override -// public void onError(IRongCoreEnum.CoreErrorCode coreErrorCode) { -// Log.i("tx",code+"创建失败"+coreErrorCode); -// if(code == 10025){ -// ((LiveAnchorActivity) mContext).startLiveSuccess(info[0], mLiveType, mLiveTypeVal); -// }else{ -// ToastUtil.show("开播失败,联系客服。"); -// } -// } -// }); - } else { - ToastUtil.show(msg); - } - } - - @Override - public void onError() { - super.onError(); - isHttpBack = false; - } - }); - }else { - ToastUtil.show("請求中,請勿重複點擊"); - } - } - - public void release() { - mImageUtil = null; - mActivityResultCallback = null; - mLiveTypeCallback = null; - } - - @Override - public void onDestroy() { - LiveHttpUtil.cancel(LiveHttpConsts.CREATE_ROOM); - } -} diff --git a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java index 9e811c460..0c194b062 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java @@ -54,8 +54,6 @@ import com.bumptech.glide.load.resource.gif.GifDrawable; import com.bumptech.glide.request.RequestListener; import com.bumptech.glide.request.RequestOptions; import com.bumptech.glide.request.target.Target; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; import com.google.gson.reflect.TypeToken; import com.google.gson.Gson; import com.lxj.xpopup.XPopup; @@ -69,7 +67,6 @@ import com.opensource.svgaplayer.SVGAImageView; import com.opensource.svgaplayer.SVGAParser; import com.opensource.svgaplayer.SVGAVideoEntity; import com.yunbao.common.bean.PrankProgressBean; -import com.yunbao.common.fragment.GiftWallMainTab1Fragment; import com.yunbao.common.utils.DebugUtils; import com.yunbao.common.utils.L; import com.yunbao.common.utils.MobclickAgent; @@ -130,12 +127,10 @@ import com.yunbao.common.interfaces.OnItemClickListener; import com.yunbao.common.manager.IMLoginManager; import com.yunbao.common.manager.NewLevelManager; import com.yunbao.common.manager.RandomPkManager; -import com.yunbao.common.utils.AppManager; import com.yunbao.common.utils.Bus; import com.yunbao.common.utils.DeviceUtils; import com.yunbao.common.utils.DialogUitl; import com.yunbao.common.utils.DpUtil; -import com.yunbao.common.utils.L; import com.yunbao.common.utils.LiveRoomCheckLivePresenter; import com.yunbao.common.utils.MicStatusManager; import com.yunbao.common.utils.RouteUtil; @@ -158,10 +153,8 @@ import com.yunbao.live.R; import com.yunbao.live.activity.LiveActivity; import com.yunbao.live.activity.LiveAnchorActivity; import com.yunbao.live.activity.LiveAudienceActivity; -import com.yunbao.live.activity.LiveRyAnchorActivity; import com.yunbao.live.activity.LiveSwAnchorActivity; import com.yunbao.live.activity.ZhuangBanActivity; -import com.yunbao.live.adapter.ComboAdapter; import com.yunbao.live.adapter.LiveChatAdapter; import com.yunbao.live.adapter.LiveRoomFastMessageRecyclerViewAdapter; import com.yunbao.live.adapter.LiveUserAdapter; @@ -203,7 +196,6 @@ import com.yunbao.live.presenter.LiveLightAnimPresenter; import com.yunbao.live.utils.LiveRoomVoteManager; import com.yunbao.live.utils.LiveTextRender; import com.yunbao.live.utils.LoadDian9TuUtil; -import com.yunbao.live.utils.ZeusKt; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; @@ -226,8 +218,6 @@ import io.rong.imlib.RongIMClient; import io.rong.imlib.model.Conversation; import io.rong.imlib.model.UserInfo; -import com.bumptech.glide.load.resource.gif.GifDrawable; - import pl.droidsonroids.gif.GifImageView; /** @@ -1365,7 +1355,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis topBanner1 = (Banner) findViewById(R.id.top_banner1); topBanner2 = (Banner) findViewById(R.id.top_banner2); - if (LivePushTxViewHolder.mTRTCCloud != null || LivePushSwViewHolder.rtcRoom != null) { + if (LivePushTxViewHolder.mTRTCCloud != null ) { fans_btn.setVisibility(View.GONE); } mPkRankTopIcon.setVisibility(View.GONE); @@ -1456,8 +1446,6 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis liveHDDialogFragment.setArguments(bundle1); if(mContext instanceof LiveAudienceActivity){ liveHDDialogFragment.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "LiveHDDialogFragment"); - }else if(mContext instanceof LiveRyAnchorActivity){ - liveHDDialogFragment.show(((LiveRyAnchorActivity) mContext).getSupportFragmentManager(), "LiveHDDialogFragment"); }else if(mContext instanceof LiveSwAnchorActivity){ liveHDDialogFragment.show(((LiveSwAnchorActivity) mContext).getSupportFragmentManager(), "LiveHDDialogFragment"); } @@ -1474,14 +1462,10 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis } }); fragment.setmLiveUid(mLiveUid); - if(mContext instanceof LiveRyAnchorActivity){ - fragment.show(((LiveRyAnchorActivity)mContext).getSupportFragmentManager(), "LivePrankDialogFragment"); - }else if(mContext instanceof LiveSwAnchorActivity){ + if(mContext instanceof LiveSwAnchorActivity){ fragment.show(((LiveSwAnchorActivity)mContext).getSupportFragmentManager(), "LivePrankDialogFragment"); } - if(mContext instanceof LiveRyAnchorActivity){ - com.yunbao.live.activity.LiveRyAnchorActivity.mLiveAnchorViewHolder.closeMenuRed(); - }else if(mContext instanceof LiveSwAnchorActivity){ + if(mContext instanceof LiveSwAnchorActivity){ com.yunbao.live.activity.LiveSwAnchorActivity.mLiveAnchorViewHolder.closeMenuRed(); } }else{ @@ -1707,7 +1691,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis findViewById(R.id.btn_follow).setVisibility(View.GONE); findViewById(R.id.live_rank_pk).setVisibility(View.GONE); } - if (mContext instanceof LiveRyAnchorActivity ||mContext instanceof LiveSwAnchorActivity) { + if (mContext instanceof LiveSwAnchorActivity) { findViewById(R.id.open_sidebar).setVisibility(View.GONE); findViewById(R.id.btn_follow).setVisibility(View.GONE); findViewById(R.id.live_rank_pk).setVisibility(View.GONE); @@ -2188,7 +2172,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis layoutParams.topMargin = DpUtil.dp2px(240); dragonImmediateParticipation.setLayoutParams(layoutParams); } - if (dragonImmediateParticipationTime.getVisibility() == View.VISIBLE && mContext instanceof LiveRyAnchorActivity || mContext instanceof LiveSwAnchorActivity) { + if (dragonImmediateParticipationTime.getVisibility() == View.VISIBLE && mContext instanceof LiveSwAnchorActivity) { RelativeLayout.LayoutParams layoutParamsredPacket = (RelativeLayout.LayoutParams) redPacket.getLayoutParams(); layoutParamsredPacket.topMargin = DpUtil.dp2px(160); redPacket.setLayoutParams(layoutParamsredPacket); @@ -2197,7 +2181,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis layoutParams.topMargin = DpUtil.dp2px(240); dragonImmediateParticipationTime.setLayoutParams(layoutParams); } - if (mContext instanceof LiveRyAnchorActivity || mContext instanceof LiveSwAnchorActivity) { + if (mContext instanceof LiveSwAnchorActivity) { if (dragonImmediateParticipationTime.getVisibility() == View.GONE) { RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) redPacket.getLayoutParams(); layoutParams.topMargin = DpUtil.dp2px(160); @@ -2220,7 +2204,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis redSchedule.setText(stringBuffer.toString()); openRedPacket.setText(String.format(mContext.getString(R.string.open_red_packet), mRedPacketModel.getRedPacketCount() + "")); } - if (IMLoginManager.get(mContext).getUserInfo().anchorUserType() && (mContext instanceof LiveSwAnchorActivity || mContext instanceof LiveRyAnchorActivity)) { + if (IMLoginManager.get(mContext).getUserInfo().anchorUserType() && (mContext instanceof LiveSwAnchorActivity )) { anchorTimeHandler.removeCallbacks(anchorTimeRunnable); anchorTimeHandler.post(anchorTimeRunnable); } @@ -2232,7 +2216,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis @Override public void onViewClicks() { - if (!(mContext instanceof LiveSwAnchorActivity || mContext instanceof LiveRyAnchorActivity)) { + if (!(mContext instanceof LiveSwAnchorActivity )) { LiveNetManager.get(mContext).redPacketInfo(mLiveUid, redPacketModel.getRedPacketId(), new com.yunbao.common.http.base.HttpCallback() { @Override public void onSuccess(RedPacketInfoModel data) { @@ -2359,7 +2343,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis if (d_pk_view != null) { d_pk_view.setVisibility(View.GONE); } - if (LivePushTxViewHolder.mTRTCCloud != null || LivePushSwViewHolder.rtcRoom != null) { + if (LivePushTxViewHolder.mTRTCCloud != null ) { fans_btn.setVisibility(View.GONE); } mRedVal.setVisibility(View.GONE); @@ -3429,7 +3413,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis bundle.putString("toUid", toUid); bundle.putInt("isAttention", isAttention); bundle.putBoolean("isLive", isAnchor); - bundle.putBoolean("SBW", !(mContext instanceof LiveSwAnchorActivity || mContext instanceof LiveRyAnchorActivity)); + bundle.putBoolean("SBW", !(mContext instanceof LiveSwAnchorActivity )); giftWallDialog.setArguments(bundle); giftWallDialog.show(((AbsActivity) mContext).getSupportFragmentManager(), "GiftWallDialog"); @@ -3795,7 +3779,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis //直播间 粉丝排行榜 openMedalRankWindow(); } else if (i == R.id.btn_guard) { - ((LiveActivity) mContext).openNewGuardListWindow((mContext instanceof LiveSwAnchorActivity || mContext instanceof LiveRyAnchorActivity)); + ((LiveActivity) mContext).openNewGuardListWindow((mContext instanceof LiveSwAnchorActivity)); } else if (i == R.id.btn_red_pack) { ((LiveActivity) mContext).openRedPackListWindow(); @@ -3803,13 +3787,13 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis ((LiveActivity) mContext).openPrizePoolWindow(); } else if (i == R.id.user_more) { MobclickAgent.onEvent(mContext, "live_room_audience_list", "直播间上面点观众列表按钮"); - ((LiveActivity) mContext).openUserMoreListWindow(1, false, false, mContext instanceof LiveSwAnchorActivity || mContext instanceof LiveRyAnchorActivity); + ((LiveActivity) mContext).openUserMoreListWindow(1, false, false, mContext instanceof LiveSwAnchorActivity); } else if (i == R.id.hot_btn) { - ((LiveActivity) mContext).openUserMoreListWindow(1, false, false, mContext instanceof LiveSwAnchorActivity || mContext instanceof LiveRyAnchorActivity); + ((LiveActivity) mContext).openUserMoreListWindow(1, false, false, mContext instanceof LiveSwAnchorActivity ); } else if (i == R.id.noble_seat) { MobclickAgent.onEvent(mContext, "live_room_noble", "贵族按钮"); - ((LiveActivity) mContext).openUserMoreListWindow(1, false, true, mContext instanceof LiveSwAnchorActivity || mContext instanceof LiveRyAnchorActivity); + ((LiveActivity) mContext).openUserMoreListWindow(1, false, true, mContext instanceof LiveSwAnchorActivity ); } else if (i == R.id.btn_close) { // if (sudGameMin!=null&&sudGameMin.getVisibility()==View.VISIBLE) { // new XPopup.Builder(mContext) @@ -3842,7 +3826,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis } else if (i == R.id.user_guard) { MobclickAgent.onEvent(mContext, "anchor_avatar_guard", "守护按钮"); // ((LiveActivity) mContext).openUserMoreListWindow(2, true); - ((LiveActivity) mContext).openNewGuardListWindow(mContext instanceof LiveSwAnchorActivity || mContext instanceof LiveRyAnchorActivity); + ((LiveActivity) mContext).openNewGuardListWindow(mContext instanceof LiveSwAnchorActivity ); } if (i == R.id.lt_trickery) { showTrickeryDialog(); @@ -3867,7 +3851,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis * @param in 展示的view */ private void changeMsgView(View out, View in) { - if (mContext instanceof LiveSwAnchorActivity || mContext instanceof LiveRyAnchorActivity) { + if (mContext instanceof LiveSwAnchorActivity ) { return; } if (in.getVisibility() == View.VISIBLE) { @@ -4098,24 +4082,6 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis LiveSwAnchorActivity.backIndex = 1; ((LiveSwAnchorActivity) mContext).onBackPressed(); } - } else if (mContext instanceof LiveRyAnchorActivity) { - if (forAct == 1) { - //是否关注0==没关注 - if (isAttention == 0) { - if (isStayRoomfive) { - showFollowDialog(mNameText, mAvatarUrl, mContext); - } else { - LiveRyAnchorActivity.backIndex = 1; - ((LiveRyAnchorActivity) mContext).onBackPressed(); - } - } else { - LiveRyAnchorActivity.backIndex = 1; - ((LiveRyAnchorActivity) mContext).onBackPressed(); - } - } else { - LiveRyAnchorActivity.backIndex = 1; - ((LiveRyAnchorActivity) mContext).onBackPressed(); - } } } @@ -5241,7 +5207,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis lt_trickster_salvation.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if (mContext instanceof LiveSwAnchorActivity || mContext instanceof LiveRyAnchorActivity) { + if (mContext instanceof LiveSwAnchorActivity) { dialog.dismiss(); return; } diff --git a/live/src/main/java/com/yunbao/live/views/LiveRyAnchorViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveRyAnchorViewHolder.java index c40d4f83d..1eb4b86d8 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRyAnchorViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRyAnchorViewHolder.java @@ -46,7 +46,6 @@ import com.yunbao.common.utils.StringUtil; import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.utils.WordUtil; import com.yunbao.live.R; -import com.yunbao.live.activity.LiveRyAnchorActivity; import com.yunbao.live.activity.LiveSwAnchorActivity; import com.yunbao.live.activity.ZhuangBanActivity; import com.yunbao.live.bean.WishlistModel; @@ -222,8 +221,6 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { if (PKing == false) { if (isSw) { ((LiveSwAnchorActivity) mContext).openLinkMicAnchorWindow(true); - } else { - ((LiveRyAnchorActivity) mContext).openLinkMicAnchorWindow(true); } } else { ToastUtil.show(WordUtil.isNewZh() ? "您已在PK中" : "You are already in the PK"); @@ -300,8 +297,6 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { private void close() { if (isSw) { ((LiveSwAnchorActivity) mContext).closeLive(); - } else { - ((LiveRyAnchorActivity) mContext).closeLive(); } } @@ -320,8 +315,6 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { } if (isSw) { ((LiveSwAnchorActivity) mContext).showFunctionDialog(); - } else { - ((LiveRyAnchorActivity) mContext).showFunctionDialog(); } } @@ -357,8 +350,6 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { private void applyLinkMicPk() { if (isSw) { ((LiveSwAnchorActivity) mContext).applyLinkMicPk(); - } else { - ((LiveRyAnchorActivity) mContext).applyLinkMicPk(); } } diff --git a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java index b01ac66e1..ce19b0fab 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -15,7 +15,6 @@ import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.Button; import android.widget.FrameLayout; import android.widget.ImageView; @@ -28,10 +27,8 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.blankj.utilcode.util.GsonUtils; import com.lzf.easyfloat.EasyFloat; -import com.lzf.easyfloat.enums.ShowPattern; import com.lzf.easyfloat.permission.PermissionUtils; import com.lzf.easyfloat.utils.LifecycleUtils; -import com.yunbao.common.dialog.DebugDialog; import com.yunbao.common.manager.imrongcloud.RongcloudIMManager; import com.yunbao.common.utils.DebugUtils; import com.yunbao.common.utils.MobclickAgent; @@ -76,7 +73,6 @@ import com.yunbao.common.http.LiveHttpUtil; import com.yunbao.common.http.live.LiveNetManager; import com.yunbao.common.manager.IMLoginManager; import com.yunbao.common.manager.OpenAdManager; -import com.yunbao.common.utils.AppManager; import com.yunbao.common.utils.Bus; import com.yunbao.common.utils.DialogUitl; import com.yunbao.common.utils.L; @@ -109,27 +105,20 @@ import com.yunbao.live.event.LiveAudienceEvent; import com.yunbao.live.event.LiveOpenSuccessEvent; import com.yunbao.live.presenter.LiveLinkMicAnchorPresenter; import com.yunbao.live.presenter.LiveLinkMicPresenter; -import com.yunbao.live.presenter.LiveRyLinkMicPkPresenter; import com.yunbao.live.presenter.LiveSwLinkMicPkPresenter; import com.yunbao.live.socket.SocketClient; import com.yunbao.live.socket.SocketMessageListener; import com.yunbao.live.socket.SocketRyChatUtil; -import com.yunbao.live.socket.SocketRyClient; import com.yunbao.live.socket.SocketSwChatUtil; import com.yunbao.live.socket.SocketSwClient; import com.yunbao.live.socket.SocketSendBean; import com.yunbao.live.utils.LiveImDeletUtil; -import com.yunbao.live.utils.LiveTextRender; import org.greenrobot.eventbus.EventBus; import java.util.ArrayList; import java.util.List; -import cn.rongcloud.rtc.api.RCRTCEngine; -import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback; -import cn.rongcloud.rtc.api.callback.IRCRTCSwitchRoleCallback; -import cn.rongcloud.rtc.base.RTCErrorCode; import io.agora.beautyapi.faceunity.agora.LiveFloatView; import io.agora.beautyapi.faceunity.agora.SWAuManager; import io.rong.imlib.IRongCallback; @@ -181,7 +170,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe //主播与主播PK逻辑 private LiveSwLinkMicPkPresenter mLiveSwLinkMicPkPresenter; - private LiveRyLinkMicPkPresenter mLiveRyLinkMicPkPresenter; +// private LiveRyLinkMicPkPresenter mLiveRyLinkMicPkPresenter; //直播间的类型 普通 密码 门票 计时等 @@ -191,7 +180,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe //直播结束页面 private LiveEndViewHolder mLiveEndViewHolder; private SocketSwClient mSocketSwClient; - private SocketRyClient mSocketRyClient; +// private SocketRyClient mSocketRyClient; private SocketClient mSocketClient; private String mDanmuPrice;//弹幕价格 @@ -368,11 +357,6 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe public void run() { try { Log.e("ImgLoader1", data.getAvatar()); - if (mLiveRyLinkMicPkPresenter != null) { - mLiveRyLinkMicPkPresenter.clearData(); - mLiveRyLinkMicPkPresenter.release(); - mLiveRyLinkMicPkPresenter = null; - } if (mLiveSwLinkMicPkPresenter != null) { mLiveSwLinkMicPkPresenter.clearData(); @@ -400,7 +384,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe if (isSw) { mLivePlayViewHolder = new LivePlaySwViewHolder(mContext, playContainer, mLiveBean.getLandscape()); } else { - mLivePlayViewHolder = new LivePlayRyViewHolder(mContext, playContainer, 1); +// mLivePlayViewHolder = new LivePlayRyViewHolder(mContext, playContainer, 1); } mLiveRoomViewHolder = new LiveRoomViewHolder(false, 1, mContext, mContainer, mSecondPage.findViewById(R.id.gift_gif), mSecondPage.findViewById(R.id.gift_svga), mContainerWrap, mContext.getWindowManager(), isSw); @@ -411,8 +395,8 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mLiveSwLinkMicPkPresenter = new LiveSwLinkMicPkPresenter(mContext, mLivePlayViewHolder, false, null); mLiveSwLinkMicPkPresenter.setmLiveRoomViewHolder(mLiveRoomViewHolder); } else { - mLiveRyLinkMicPkPresenter = new LiveRyLinkMicPkPresenter(mContext, mLivePlayViewHolder, false, null); - mLiveRyLinkMicPkPresenter.setmLiveRoomViewHolder(mLiveRoomViewHolder); +// mLiveRyLinkMicPkPresenter = new LiveRyLinkMicPkPresenter(mContext, mLivePlayViewHolder, false, null); +// mLiveRyLinkMicPkPresenter.setmLiveRoomViewHolder(mLiveRoomViewHolder); } mLivePlayViewHolder.initSwEngine(mLiveBean.getUid()); mLivePlayViewHolder.addToParent(); @@ -440,16 +424,12 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mLiveSwLinkMicPkPresenter.setmLiveRoomViewHolder(mLiveRoomViewHolder); } } else { - if (mLiveRyLinkMicPkPresenter == null) { - mLiveRyLinkMicPkPresenter = new LiveRyLinkMicPkPresenter(mContext, mLivePlayViewHolder, false, null); - mLiveRyLinkMicPkPresenter.setmLiveRoomViewHolder(mLiveRoomViewHolder); - } } //去除主播离开画面 - if (LivePlayRyViewHolder.leave != null) { + /* if (LivePlayRyViewHolder.leave != null) { LivePlayRyViewHolder.leave.setVisibility(View.GONE); - } + }*/ if (LivePlaySwViewHolder.leave != null) { LivePlaySwViewHolder.leave.setVisibility(View.GONE); } @@ -489,13 +469,13 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe if (isSw) { mLiveSwLinkMicPkPresenter.setLiveUid(data.getUid(), ""); } else { - mLiveRyLinkMicPkPresenter.setLiveUid(data.getUid(), ""); +// mLiveRyLinkMicPkPresenter.setLiveUid(data.getUid(), ""); } if (isSw) { mSocketSwClient = new SocketSwClient(mLiveBean.getUid(), PortraitLiveManager.this, mContext); } else { - mSocketRyClient = new SocketRyClient(mLiveBean.getUid(), PortraitLiveManager.this, mContext); +// mSocketRyClient = new SocketRyClient(mLiveBean.getUid(), PortraitLiveManager.this, mContext); } if (mLiveLinkMicPresenter != null) { mLiveLinkMicPresenter.setSocketClient(mSocketClient); @@ -676,9 +656,6 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe if (LivePlaySwViewHolder.leave != null) { LivePlaySwViewHolder.leave.setVisibility(View.VISIBLE); } - if (LivePlayRyViewHolder.leave != null) { - LivePlayRyViewHolder.leave.setVisibility(View.VISIBLE); - } } //判断是否有连麦,要显示连麦窗口 String linkMicUid = data.getEnterRoomInfo().getLinkmicUid(); @@ -757,7 +734,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe if (isSw) { mLiveSwLinkMicPkPresenter.onEnterRoomPkStart(pkUid, pkInfo.getLongValue("pk_gift_liveuid"), pkInfo.getLongValue("pk_gift_pkuid"), pkInfo.getIntValue("pk_time"), livePKUserListBean); } else { - mLiveRyLinkMicPkPresenter.onEnterRoomPkStart(pkUid, pkInfo.getLongValue("pk_gift_liveuid"), pkInfo.getLongValue("pk_gift_pkuid"), pkInfo.getIntValue("pk_time"), livePKUserListBean); +// mLiveRyLinkMicPkPresenter.onEnterRoomPkStart(pkUid, pkInfo.getLongValue("pk_gift_liveuid"), pkInfo.getLongValue("pk_gift_pkuid"), pkInfo.getIntValue("pk_time"), livePKUserListBean); } isShowPrank = false; } else if (!pkInfo.getString("end_pk_time").equals("0")) { @@ -776,7 +753,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe if (isSw) { mLiveSwLinkMicPkPresenter.onEnterRoomCFStart(pkUid, pkInfo.getLongValue("pk_gift_liveuid"), pkInfo.getLongValue("pk_gift_pkuid"), pkInfo.getIntValue("end_pk_time"), livePKUserListBean); } else { - mLiveRyLinkMicPkPresenter.onEnterRoomCFStart(pkUid, pkInfo.getLongValue("pk_gift_liveuid"), pkInfo.getLongValue("pk_gift_pkuid"), pkInfo.getIntValue("end_pk_time"), livePKUserListBean); +// mLiveRyLinkMicPkPresenter.onEnterRoomCFStart(pkUid, pkInfo.getLongValue("pk_gift_liveuid"), pkInfo.getLongValue("pk_gift_pkuid"), pkInfo.getIntValue("end_pk_time"), livePKUserListBean); } isShowPrank = false; } else { @@ -949,10 +926,6 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mLiveRoomViewHolder.clearData(); mLiveRoomViewHolder.countDownTimerTrickery = null; } - if (mLiveRyLinkMicPkPresenter != null) { - mLiveRyLinkMicPkPresenter.clearData(); - mLiveRyLinkMicPkPresenter.release(); - } if (mLiveSwLinkMicPkPresenter != null) { mLiveSwLinkMicPkPresenter.clearData(); mLiveSwLinkMicPkPresenter.release(); @@ -962,7 +935,6 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mLiveRoomViewHolder = null; mLiveLinkMicPresenter = null; mLiveLinkMicAnchorPresenter = null; - mLiveRyLinkMicPkPresenter = null; mLiveSwLinkMicPkPresenter = null; mLivePlayViewHolder = null; } @@ -990,10 +962,6 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mLiveRoomViewHolder.cancelAllAnim(); } //断开socket - if (mSocketRyClient != null) { - mSocketRyClient.disConnect(); - mSocketRyClient = null; - } if (mSocketSwClient != null) { mSocketSwClient.disConnect(); mSocketSwClient = null; @@ -1010,11 +978,6 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mLiveLinkMicAnchorPresenter.clearData(); mLiveLinkMicAnchorPresenter.release(); } - if (mLiveRyLinkMicPkPresenter != null) { - mLiveRyLinkMicPkPresenter.clearData(); - mLiveRyLinkMicPkPresenter.release(); - mLiveRyLinkMicPkPresenter = null; - } if (mLiveSwLinkMicPkPresenter != null) { mLiveSwLinkMicPkPresenter.clearData(); mLiveSwLinkMicPkPresenter.release(); @@ -1048,7 +1011,6 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mLiveRoomViewHolder = null; mLiveLinkMicPresenter = null; mLiveLinkMicAnchorPresenter = null; - mLiveRyLinkMicPkPresenter = null; if (PermissionUtils.checkPermission(mContext) && !kick) { LiveFloatView.getInstance() .cacheLiveData(mLiveBean, mLiveType, isSw, mLiveTypeVal) @@ -1218,16 +1180,16 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe } } } else { - if (RCRTCEngine.getInstance().getRoom() == null || RCRTCEngine.getInstance().getRoom().getLocalUser() == null) { + /* if (RCRTCEngine.getInstance().getRoom() == null || RCRTCEngine.getInstance().getRoom().getLocalUser() == null) { return; } ToastUtil.show("下麥中,稍等....."); RCRTCEngine.getInstance().getRoom().getLocalUser().switchToAudience(new IRCRTCSwitchRoleCallback() { - /** + *//** * 当切换失败且SDK处于无法回退状态时回调,该角色已经无法使用当前角色继续进行音视频。 * SDK内部会退出房间并清理所有资源,该用户只能重新加入房间才能继续音视频。 - */ + *//* @Override public void onKicked() { @@ -1270,16 +1232,16 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe } - /** + *//** * 当切换失败且不影响当前角色继续音视频时回调 * @param errorCode 失败错误码 - */ + *//* @Override public void onFailed(RTCErrorCode errorCode) { Log.e("ry", "下麦失败" + errorCode); } - }); + });*/ } } @@ -1526,9 +1488,9 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mLiveSwLinkMicPkPresenter.onPkProgressChanged(leftGift, rightGift, bean); } } else { - if (mLiveRyLinkMicPkPresenter != null) { + /* if (mLiveRyLinkMicPkPresenter != null) { mLiveRyLinkMicPkPresenter.onPkProgressChanged(leftGift, rightGift, bean); - } + }*/ } } @@ -1543,13 +1505,13 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe } } } else { - if (mLiveRyLinkMicPkPresenter != null) { + /*if (mLiveRyLinkMicPkPresenter != null) { if (mLiveUid.equals(leftUid + "")) { mLiveRyLinkMicPkPresenter.onPkProgressEnd(left, right, bean); } else { mLiveRyLinkMicPkPresenter.onPkProgressEnd(right, left, bean); } - } + }*/ } } @@ -1809,11 +1771,11 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe linkMicPkStartHandler.postDelayed(linkMicPkStartRunnable, 4000);//3秒后执行Runnable中的run方法 } } else { - if (mLiveRyLinkMicPkPresenter != null && mLiveRoomViewHolder != null) { + /* if (mLiveRyLinkMicPkPresenter != null && mLiveRoomViewHolder != null) { mLiveRoomViewHolder.pkHandler = true; mLiveRyLinkMicPkPresenter.onLinkMicPkStart(pkUid, 1); linkMicPkStartHandler.postDelayed(linkMicPkStartRunnable, 4000);//3秒后执行Runnable中的run方法 - } + }*/ } if (mLivePlayViewHolder != null) { @@ -1846,12 +1808,12 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe } } } else { - if (mLiveRyLinkMicPkPresenter != null) { + /* if (mLiveRyLinkMicPkPresenter != null) { mLiveRyLinkMicPkPresenter.onLinkMicPkClose(i); if (mLiveRoomViewHolder != null) { mLiveRoomViewHolder.resetViewGone(); } - } + }*/ } if (mLiveRoomViewHolder != null) { mLivePlayViewHolder.setLiveBeanLandscape(landscape); @@ -1885,10 +1847,10 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe //mLiveRoomViewHolder.setDelOtherInfo(); } } else { - if (mLiveRyLinkMicPkPresenter != null) { + /* if (mLiveRyLinkMicPkPresenter != null) { mLiveRyLinkMicPkPresenter.onLinkMicPkEnd(winUid); //mLiveRoomViewHolder.setDelOtherInfo(); - } + }*/ } } @@ -2086,11 +2048,6 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mEnd = true; //断开socket - if (mSocketRyClient != null) { - mSocketRyClient.disConnect(); - mSocketRyClient = null; - } - if (mSocketSwClient != null) { mSocketSwClient.disConnect(); mSocketSwClient = null; diff --git a/main/src/main/java/com/yunbao/main/activity/MainActivity.java b/main/src/main/java/com/yunbao/main/activity/MainActivity.java index b002e65f9..edb4ead4a 100644 --- a/main/src/main/java/com/yunbao/main/activity/MainActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/MainActivity.java @@ -155,8 +155,6 @@ import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; -import cn.rongcloud.rtc.api.RCRTCConfig; -import cn.rongcloud.rtc.api.RCRTCEngine; import io.agora.beautyapi.faceunity.agora.LiveFloatView; import io.agora.beautyapi.faceunity.agora.SWAuManager; import io.reactivex.Observer; @@ -280,10 +278,6 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene Height = mDisplay.getHeight(); // IMLib 初始化 RongIMClient.init(this, RongcloudIMManager.RONG_IM_KEY, true); - // RTCLib 初始化 - RCRTCConfig.Builder config = RCRTCConfig.Builder.create(); - config.enableEncoderTexture(false);//新娱美颜 需要关闭这个 - RCRTCEngine.getInstance().init(MainActivity.this, config.build()); //推送跳直播间 if (getIntent().getStringExtra("liveid") != null) { LiveHttpUtil.getLiveInfo(getIntent().getStringExtra("liveid") + "", new HttpCallback() { diff --git a/main/src/main/java/com/yunbao/main/activity/SettingActivity.java b/main/src/main/java/com/yunbao/main/activity/SettingActivity.java index b1af4fb45..5565cea25 100644 --- a/main/src/main/java/com/yunbao/main/activity/SettingActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/SettingActivity.java @@ -53,7 +53,6 @@ import java.io.File; import java.util.Arrays; import java.util.List; -import cn.rongcloud.rtc.api.RCRTCEngine; import io.rong.imlib.RongIMClient; /** @@ -354,7 +353,6 @@ public class SettingActivity extends AbsActivity implements OnItemClickListener< private void logout() { IMLoginManager.get(this).logout(this); CommonAppConfig.getInstance().clearLoginInfo(); - RCRTCEngine.getInstance().unInit(); RongIMClient.getInstance().logout(); Intent intent = new Intent(SettingActivity.this, EntryActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); diff --git a/main/src/main/java/com/yunbao/main/dialog/MainStartDialogFragment.java b/main/src/main/java/com/yunbao/main/dialog/MainStartDialogFragment.java index ef1e11ec5..4b5f68ad5 100644 --- a/main/src/main/java/com/yunbao/main/dialog/MainStartDialogFragment.java +++ b/main/src/main/java/com/yunbao/main/dialog/MainStartDialogFragment.java @@ -38,7 +38,6 @@ import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.utils.WordUtil; import com.yunbao.live.LiveConfig; import com.yunbao.live.activity.LiveAnchorActivity; -import com.yunbao.live.activity.LiveRyAnchorActivity; import com.yunbao.live.activity.LiveSwAnchorActivity; import com.yunbao.live.bean.LiveKsyConfigBean; import com.yunbao.main.R; @@ -246,8 +245,6 @@ public class MainStartDialogFragment extends AbsDialogFragment implements View.O try { if (code == 201) { //声网 LiveSwAnchorActivity.forward(mContext, Constants.LIVE_SDK_SW, JSON.parseObject(obj.getString("android"), LiveKsyConfigBean.class)); - } else if (code == 200) {//融云 - LiveRyAnchorActivity.forward(mContext, obj.getIntValue("live_sdk"), JSON.parseObject(obj.getString("android"), LiveKsyConfigBean.class)); } } catch (Exception e) {