From 6a4ac352032fc8798eb2e2b4291553ac7d8b2b5c Mon Sep 17 00:00:00 2001 From: Martin <13046765170@163.com> Date: Sat, 18 May 2024 14:36:35 +0800 Subject: [PATCH] =?UTF-8?q?add[=E5=A3=B0=E6=9C=9B=E5=8D=87=E7=BA=A7-AB?= =?UTF-8?q?=E9=9D=A2]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/shayu/phonelive/AppContext.java | 10 +- .../java/com/yunbao/common/Constants.java | 4 +- .../common/activity/WebViewActivity.java | 4 +- .../common/bean/AiAutomaticSpeechModel.java | 14 + .../yunbao/common/bean/CheckLiveModel.java | 10 + .../yunbao/common/bean/EnterRoomNewModel.java | 1 + .../common/event/SendBlindGiftEvent.java | 29 + .../com/yunbao/common/http/LiveHttpUtil.java | 12 +- .../imrongcloud/RongcloudIMManager.java | 91 +- .../com/yunbao/common/utils/AppManager.java | 9 + .../com/yunbao/common/utils/DialogUitl.java | 9 + .../utils/JavascriptInterfaceUtils.java | 4 +- .../utils/LiveRoomCheckLivePresenter.java | 15 +- .../com/yunbao/common/utils/RouteUtil.java | 24 +- .../common/views/SudGameListViewHolder.java | 4 +- .../faceunity/agora/LiveFloatView.java | 2 +- live/src/main/AndroidManifest.xml | 5 + .../yunbao/live/activity/LiveActivity.java | 128 +- .../live/activity/LiveAnchorActivity.java | 5 +- .../live/activity/LiveAudienceActivity.java | 469 ++-- .../live/activity/LiveRyAnchorActivity.java | 191 +- .../live/activity/LiveSwAnchorActivity.java | 1939 ++++++++++++++ .../live/activity/LiveTRTCAnchorActivity.java | 2 +- .../live/activity/PDLIiveChatActivity.java | 4 +- .../live/activity/WebViewActivityMedal.java | 4 +- .../live/activity/ZhuangBanActivity.java | 4 +- .../adapter/AnchorUserMicInfoAdapter.java | 4 +- .../live/adapter/FreePkRecyclerAdapter.java | 25 +- .../live/adapter/LiveFunctionAdapter.java | 5 +- .../com/yunbao/live/bean/LiveChatBean.java | 10 + .../live/dialog/FreePkDialogFragment.java | 6 + .../live/dialog/LiveBeautyDialogFragment.java | 2 - .../dialog/LiveFunctionDialogFragment.java | 5 +- .../live/dialog/LiveGameDialogFragment.java | 10 +- .../live/dialog/LiveHDDialogFragment.java | 8 +- .../live/dialog/LiveInputDialogFragment.java | 4 +- .../dialog/LiveLinkMicListDialogFragment.java | 26 +- .../dialog/LiveNewFunctionDialogFragment.java | 67 +- .../dialog/LiveNewGuardBuyDialogFragment.java | 4 +- .../dialog/LiveNewWishListDialogFragment.java | 13 +- .../dialog/LiveOldUserDialogFragment.java | 2 +- .../live/dialog/LiveUserDialogFragment.java | 6 +- .../dialog/LiveUserMoreDialogFragment.java | 4 +- .../dialog/LiveWishListDialogFragment.java | 5 +- .../live/dialog/RandomPkDialogFragment.java | 6 +- .../yunbao/live/event/LiveAudienceEvent.java | 3 +- .../live/presenter/LiveGiftAnimPresenter.java | 2 +- .../presenter/LiveRyLinkMicPkPresenter.java | 1390 ++++++---- .../presenter/LiveSwLinkMicPkPresenter.java | 2324 +++++++++++++++++ .../yunbao/live/socket/SocketRyChatUtil.java | 51 +- .../yunbao/live/socket/SocketRyClient.java | 422 +-- .../live/socket/SocketRyLinkMicPkUtil.java | 6 +- .../yunbao/live/socket/SocketSwClient.java | 1441 ++++++++++ .../live/socket/SocketSwLinkMicPkUtil.java | 210 ++ .../live/utils/LiveRoomVoteManager.java | 6 +- .../live/views/LiveAudienceViewHolder.java | 1 - .../yunbao/live/views/LiveEndViewHolder.java | 22 +- .../live/views/LiveNewReadyRyViewHolder.java | 56 +- .../live/views/LiveNewReadySwViewHolder.java | 963 +++++++ .../live/views/LivePlayKsyViewHolder.java | 41 +- .../yunbao/live/views/LivePlayListener.java | 2 +- .../live/views/LivePlayRyViewHolder.java | 746 +++--- .../live/views/LivePlaySwViewHolder.java | 1504 +++++++++++ .../live/views/LivePlayTxViewHolder.java | 30 + .../views/LivePlayTxViewHolder_backup.java | 476 ---- .../live/views/LivePushRyViewHolder.java | 524 ++-- .../live/views/LivePushSwViewHolder.java | 731 ++++++ .../live/views/LiveReadyRyViewHolder.java | 24 +- .../live/views/LiveReadyViewHolder.java | 2 +- .../live/views/LiveRoomPlayViewHolder.java | 12 + .../yunbao/live/views/LiveRoomViewHolder.java | 44 +- .../live/views/LiveRyAnchorViewHolder.java | 21 +- .../live/views/PortraitLiveManager.java | 211 +- .../yunbao/live/views/SidebarViewHoler.java | 4 +- .../main/res/layout/view_live_play_ksy.xml | 101 +- .../src/main/res/layout/view_live_play_sw.xml | 169 ++ .../src/main/res/layout/view_live_push_ry.xml | 94 +- .../src/main/res/layout/view_live_push_sw.xml | 235 ++ .../yunbao/main/activity/EntryActivity.java | 4 +- .../main/activity/LiveClassActivity.java | 4 +- .../yunbao/main/activity/LoginActivity.java | 4 +- .../yunbao/main/activity/MainActivity.java | 12 +- .../main/activity/MyWebViewActivity.java | 4 +- .../main/activity/MyWebViewActivity2.java | 4 +- .../main/activity/RegisterActivity.java | 4 +- .../yunbao/main/activity/SearchActivity.java | 4 +- .../main/activity/WeekWebViewActivity.java | 4 +- .../main/activity/ZhuangBanActivity.java | 4 +- .../yunbao/main/adapter/SearchAdapter.java | 4 +- .../dialog/AnchorStartLiveNotifyDialog.java | 4 +- .../main/dialog/MainStartDialogFragment.java | 25 +- .../yunbao/main/dialog/OneLoginDialog.java | 6 +- .../fragment/MainHomeCommunityFragment.java | 4 +- .../views/AbsMainListChildViewHolder.java | 8 +- .../main/views/MainHomeLiveViewHolder.java | 8 +- .../main/views/MainMessageViewHolder.java | 4 +- .../main/views/UserHomeViewHolder2.java | 4 +- 97 files changed, 12448 insertions(+), 2740 deletions(-) create mode 100644 live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java create mode 100644 live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java create mode 100644 live/src/main/java/com/yunbao/live/socket/SocketSwClient.java create mode 100644 live/src/main/java/com/yunbao/live/socket/SocketSwLinkMicPkUtil.java create mode 100644 live/src/main/java/com/yunbao/live/views/LiveNewReadySwViewHolder.java create mode 100644 live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java delete mode 100644 live/src/main/java/com/yunbao/live/views/LivePlayTxViewHolder_backup.java create mode 100644 live/src/main/java/com/yunbao/live/views/LivePushSwViewHolder.java create mode 100644 live/src/main/res/layout/view_live_play_sw.xml create mode 100644 live/src/main/res/layout/view_live_push_sw.xml diff --git a/app/src/main/java/com/shayu/phonelive/AppContext.java b/app/src/main/java/com/shayu/phonelive/AppContext.java index 737efced5..cb28e9277 100644 --- a/app/src/main/java/com/shayu/phonelive/AppContext.java +++ b/app/src/main/java/com/shayu/phonelive/AppContext.java @@ -50,7 +50,7 @@ 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; import com.yunbao.live.views.RecommendLiveRoomProvider; @@ -209,8 +209,8 @@ public class AppContext extends CommonAppContext { if (content.getContent().contains("_method_")) { msg.obj = content.getContent(); //观众页面 - if (SocketRyClient.mSocketHandler != null && (TextUtils.equals("__system__", message.getTargetId()) || ("g" + PortraitLiveManager.liveID).contains(message.getTargetId()))) { - SocketRyClient.mSocketHandler.sendMessage(msg); + if (SocketSwClient.mSocketHandler != null && (TextUtils.equals("__system__", message.getTargetId()) || ("g" + PortraitLiveManager.liveID).contains(message.getTargetId()))) { + SocketSwClient.mSocketHandler.sendMessage(msg); } else if (content.getContent().contains("LivePK_anchorStartLiveNotify")) {//开播通知 SocketReceiveBean received = JSON.parseObject(content.getContent(), SocketReceiveBean.class); JSONObject map = received.getMsg().getJSONObject(0); @@ -222,8 +222,8 @@ public class AppContext extends CommonAppContext { Bus.get().post(sudGameSocketImEvent); } //主播页面 - if (TextUtils.isEmpty(PortraitLiveManager.liveID) && SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.sendMessage(msg); + if (TextUtils.isEmpty(PortraitLiveManager.liveID) && SocketSwClient.mSocketHandler != null) { + SocketSwClient.mSocketHandler.sendMessage(msg); } } else if (message.getConversationType() == Conversation.ConversationType.PRIVATE) {//私聊信息 diff --git a/common/src/main/java/com/yunbao/common/Constants.java b/common/src/main/java/com/yunbao/common/Constants.java index 4a3e42403..0893cd5ea 100644 --- a/common/src/main/java/com/yunbao/common/Constants.java +++ b/common/src/main/java/com/yunbao/common/Constants.java @@ -267,13 +267,15 @@ public class Constants { public static final String LIVE_PK_RANDOM_START="RankingStartRandomPK"; public static final int LIVE_SDK_KSY = 0;//金山推流 public static final int LIVE_SDK_TX = 1;//腾讯推流 - public static final int LIVE_SDK_SW = 2;//声网 + public static final String LIVE_SDK_IS_SW = "liveSdkIsSw"; //是否是聲網 public static final int LINK_MIC_TYPE_NORMAL = 0;//观众与主播连麦 public static final int LINK_MIC_TYPE_ANCHOR = 1;//主播与主播连麦 + public static final String SOCKET_LIVE_ANCHOR_PK_DIALOG="GuildCompetitionNotice";//公会赛弹窗 + //视频举报获取位置 public static int xIndex = 0; public static int yindex = 0; diff --git a/common/src/main/java/com/yunbao/common/activity/WebViewActivity.java b/common/src/main/java/com/yunbao/common/activity/WebViewActivity.java index aeec0100e..32ab753c1 100644 --- a/common/src/main/java/com/yunbao/common/activity/WebViewActivity.java +++ b/common/src/main/java/com/yunbao/common/activity/WebViewActivity.java @@ -424,7 +424,7 @@ public class WebViewActivity extends AbsActivity { LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class); new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { if (liveBean == null) { return; } @@ -440,7 +440,7 @@ public class WebViewActivity extends AbsActivity { } EventBus.getDefault().post(new LiveRoomChangeEvent(liveBean, liveType, Integer.parseInt(liveTypeVal))); } else { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveTypeVal), Integer.parseInt(liveSdk)); + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveTypeVal), Integer.parseInt(liveSdk),isSw); } finish(); } diff --git a/common/src/main/java/com/yunbao/common/bean/AiAutomaticSpeechModel.java b/common/src/main/java/com/yunbao/common/bean/AiAutomaticSpeechModel.java index 140e86000..e9b4d0f06 100644 --- a/common/src/main/java/com/yunbao/common/bean/AiAutomaticSpeechModel.java +++ b/common/src/main/java/com/yunbao/common/bean/AiAutomaticSpeechModel.java @@ -1,5 +1,6 @@ package com.yunbao.common.bean; +import com.alibaba.fastjson.annotation.JSONField; import com.google.gson.annotations.SerializedName; /** @@ -24,6 +25,9 @@ public class AiAutomaticSpeechModel extends BaseModel { //气泡背景 @SerializedName("system_bubble") private String systemBubble; + @SerializedName("icon_en") + @JSONField(name = "icon_en") + private String iconEn; public String getNameColor() { return nameColor; @@ -47,6 +51,16 @@ public class AiAutomaticSpeechModel extends BaseModel { return content; } + + public String getIconEn() { + return iconEn; + } + + public AiAutomaticSpeechModel setIconEn(String iconEn) { + this.iconEn = iconEn; + return this; + } + public AiAutomaticSpeechModel setContent(String content) { this.content = content; return this; diff --git a/common/src/main/java/com/yunbao/common/bean/CheckLiveModel.java b/common/src/main/java/com/yunbao/common/bean/CheckLiveModel.java index ccb6274c8..2d7d00c3e 100644 --- a/common/src/main/java/com/yunbao/common/bean/CheckLiveModel.java +++ b/common/src/main/java/com/yunbao/common/bean/CheckLiveModel.java @@ -13,6 +13,16 @@ public class CheckLiveModel extends BaseModel { private String typeMsg; @SerializedName("live_sdk") private String liveSdk; + @SerializedName("is_shengwang") + private String isShengwang; + + public String getIsShengwang() { + return isShengwang; + } + + public void setIsShengwang(String isShengwang) { + this.isShengwang = isShengwang; + } public static CheckLiveModel objectFromData(String str) { diff --git a/common/src/main/java/com/yunbao/common/bean/EnterRoomNewModel.java b/common/src/main/java/com/yunbao/common/bean/EnterRoomNewModel.java index 7ecda8f0f..bc915a619 100644 --- a/common/src/main/java/com/yunbao/common/bean/EnterRoomNewModel.java +++ b/common/src/main/java/com/yunbao/common/bean/EnterRoomNewModel.java @@ -41,6 +41,7 @@ public class EnterRoomNewModel extends BaseModel { private SudGameDateModel sudGameDateModel; @SerializedName("quick_gift_remaining_quantity") private int quickGiftRemainingQuantity;//剩余的小PD礼物数量 + @SerializedName("if_viewing_duration_complete") private int ifViewingDurationComplete;//通过观看时间获取小PD礼物的次数 @SerializedName("sendMoneyLongStatus") diff --git a/common/src/main/java/com/yunbao/common/event/SendBlindGiftEvent.java b/common/src/main/java/com/yunbao/common/event/SendBlindGiftEvent.java index 9c99fab9b..b02143652 100644 --- a/common/src/main/java/com/yunbao/common/event/SendBlindGiftEvent.java +++ b/common/src/main/java/com/yunbao/common/event/SendBlindGiftEvent.java @@ -115,6 +115,35 @@ public class SendBlindGiftEvent extends BaseModel { private String liveGiftNotify; @SerializedName("userNiceName") private String userNiceName; + @SerializedName("special_gift") + private int specialGift; + @SerializedName("special_gift_name") + private String specialGiftName; + @SerializedName("special_gift_name_en") + private String specialGiftNameEn; + public int getSpecialGift() { + return specialGift; + } + + public void setSpecialGift(int specialGift) { + this.specialGift = specialGift; + } + + public String getSpecialGiftName() { + return specialGiftName; + } + + public void setSpecialGiftName(String specialGiftName) { + this.specialGiftName = specialGiftName; + } + + public String getSpecialGiftNameEn() { + return specialGiftNameEn; + } + + public void setSpecialGiftNameEn(String specialGiftNameEn) { + this.specialGiftNameEn = specialGiftNameEn; + } public String getUserNiceName() { return userNiceName; diff --git a/common/src/main/java/com/yunbao/common/http/LiveHttpUtil.java b/common/src/main/java/com/yunbao/common/http/LiveHttpUtil.java index cc37ea45f..3f3ad5128 100644 --- a/common/src/main/java/com/yunbao/common/http/LiveHttpUtil.java +++ b/common/src/main/java/com/yunbao/common/http/LiveHttpUtil.java @@ -764,7 +764,7 @@ public class LiveHttpUtil { * @param file 封面图片文件 * @param callback */ - public static void newcreateRoom(String title, int liveClassId, int type, int typeVal, File file, int clarityType, HttpCallback callback) { + public static void newcreateRoom(String title, int liveClassId, int type, int typeVal, File file, int clarityType,boolean isSw, HttpCallback callback) { PostRequest request = HttpClient.getInstance().post("Live.createRoom2", LiveHttpConsts.CREATE_ROOM) .params("title", title) @@ -773,6 +773,7 @@ public class LiveHttpUtil { .params("landscape", "2") .params("class_type", "0") .params("type_val", typeVal) + .params("is_shengwang",isSw?1:0) .params("clarityType", clarityType); if (file != null) { request.params("file", file); @@ -817,6 +818,15 @@ public class LiveHttpUtil { .execute(callback); } + /** + * 获取是否是声网开播 + * @param callback + */ + public static void getIsSw(HttpCallback callback) { + HttpClient.getInstance().get("Tx.setRtcFirm", "Tx.setRtcFirm") + .execute(callback); + } + /** * 腾讯sdk 跟主播连麦时,获取主播的低延时流 */ diff --git a/common/src/main/java/com/yunbao/common/manager/imrongcloud/RongcloudIMManager.java b/common/src/main/java/com/yunbao/common/manager/imrongcloud/RongcloudIMManager.java index dec1d5638..1a7d1b023 100644 --- a/common/src/main/java/com/yunbao/common/manager/imrongcloud/RongcloudIMManager.java +++ b/common/src/main/java/com/yunbao/common/manager/imrongcloud/RongcloudIMManager.java @@ -15,9 +15,13 @@ import com.bumptech.glide.request.RequestOptions; import com.iflytek.cloud.SpeechConstant; import com.iflytek.cloud.SpeechUtility; import com.yunbao.common.CommonAppConfig; +import com.yunbao.common.R; import com.yunbao.common.bean.IMLoginModel; import com.yunbao.common.event.RongIMConnectionStatusEvent; import com.yunbao.common.manager.IMLoginManager; +import com.yunbao.common.utils.AppManager; +import com.yunbao.common.utils.ToastUtil; +import com.yunbao.common.utils.WordUtil; import org.greenrobot.eventbus.EventBus; @@ -25,6 +29,7 @@ import io.rong.imkit.GlideKitImageEngine; import io.rong.imkit.IMCenter; import io.rong.imkit.RongIM; import io.rong.imkit.config.RongConfigCenter; +import io.rong.imlib.IRongCallback; import io.rong.imlib.RongIMClient; import io.rong.imlib.model.Conversation; import io.rong.imlib.model.Message; @@ -112,12 +117,31 @@ public class RongcloudIMManager { } + public static void connectIM(Context context) { + connectIM(context, new RongIMClient.ConnectCallback() { + @Override + public void onSuccess(String t) { + + } + + @Override + public void onError(RongIMClient.ConnectionErrorCode e) { + + } + + @Override + public void onDatabaseOpened(RongIMClient.DatabaseOpenStatus code) { + + } + }); + } + /** * 连接融云服务器 * * @param context */ - public static void connectIM(Context context) { + public static void connectIM(Context context, RongIMClient.ConnectCallback callback) { MessageIMManager.get(context).addImRongCloudObserver(); MessageIMManager.get(context).getSystemMessages(); IMLoginModel userInfo = IMLoginManager.get(context).getUserInfo(); @@ -129,6 +153,7 @@ public class RongcloudIMManager { RongIM.connect(IMToken, 0, new RongIMClient.ConnectCallback() { @Override public void onSuccess(String s) { + callback.onSuccess(s); //连接成功,如果 onDatabaseOpened() 时没有页面跳转,也可在此时进行跳转。 Log.e(CLASSNAME, "onSuccess:" + s); isReady = true; @@ -138,6 +163,7 @@ public class RongcloudIMManager { @Override public void onError(RongIMClient.ConnectionErrorCode connectionErrorCode) { + callback.onError(connectionErrorCode); if (connectionErrorCode.equals(RongIMClient.ConnectionErrorCode.RC_CONN_TOKEN_EXPIRE)) { //从 APP 服务请求新 token,获取到新 token 后重新 connect() Log.e(CLASSNAME, "onError:(从 APP 服务请求新 token)" + RongIMClient.ConnectionErrorCode.RC_CONN_TOKEN_EXPIRE); @@ -152,6 +178,7 @@ public class RongcloudIMManager { @Override public void onDatabaseOpened(RongIMClient.DatabaseOpenStatus databaseOpenStatus) { + callback.onDatabaseOpened(databaseOpenStatus); if (RongIMClient.DatabaseOpenStatus.DATABASE_OPEN_SUCCESS.equals(databaseOpenStatus)) { //本地数据库打开,跳转到会话列表页面 Log.e(CLASSNAME, "onDatabaseOpened:(本地数据库打开)" + databaseOpenStatus); @@ -225,4 +252,66 @@ public class RongcloudIMManager { } + /** + * 发送消息失败重连次数,超过3就重新登录 + */ + private static int reconnectIndex = 0; + + public static void sendMessage(final Message message, final String pushContent, final String pushData, final IRongCallback.ISendMessageCallback callback) { + + RongIMClient.getInstance().sendMessage(message, pushContent, pushData, new IRongCallback.ISendMessageCallback() { + + @Override + public void onAttached(Message message) { + if (callback != null) { + callback.onAttached(message); + } + } + + @Override + public void onSuccess(Message message) { + reconnectIndex = 0; + if (callback != null) { + callback.onSuccess(message); + } + } + + @Override + public void onError(Message message, RongIMClient.ErrorCode errorCode) { + if (reconnectIndex > 2) { + reconnectIndex = 0; + ToastUtil.show(WordUtil.getNewString(R.string.login_invalid)); + EventBus.getDefault().post(new RongIMConnectionStatusEvent()); + return; + } + if (errorCode.code == 33000) { + reconnectIndex++; + connectIM(AppManager.getInstance().getMainActivity(), new RongIMClient.ConnectCallback() { + @Override + public void onSuccess(String t) { + sendMessage(message, pushContent, pushData, callback); + } + + @Override + public void onError(RongIMClient.ConnectionErrorCode e) { + sendMessage(message, pushContent, pushData, callback); + } + + @Override + public void onDatabaseOpened(RongIMClient.DatabaseOpenStatus code) { + if (RongIMClient.DatabaseOpenStatus.DATABASE_OPEN_ERROR.equals(code)) { + sendMessage(message, pushContent, pushData, callback); + } + + } + }); + } else { + if (callback != null) { + callback.onError(message, errorCode); + } + } + } + }); + } + } diff --git a/common/src/main/java/com/yunbao/common/utils/AppManager.java b/common/src/main/java/com/yunbao/common/utils/AppManager.java index 5bda4db57..44891e250 100644 --- a/common/src/main/java/com/yunbao/common/utils/AppManager.java +++ b/common/src/main/java/com/yunbao/common/utils/AppManager.java @@ -34,6 +34,15 @@ public class AppManager { activityStack.add(activity); } + public Activity getMainActivity() { + for (Activity activity : activityStack) { + if (activity.getClass().getSimpleName().contains("MainActivity")) { + return activity; + } + } + return null; + } + /** * 移除Activity */ diff --git a/common/src/main/java/com/yunbao/common/utils/DialogUitl.java b/common/src/main/java/com/yunbao/common/utils/DialogUitl.java index adf6ced3c..d7e7582ca 100644 --- a/common/src/main/java/com/yunbao/common/utils/DialogUitl.java +++ b/common/src/main/java/com/yunbao/common/utils/DialogUitl.java @@ -358,6 +358,7 @@ public class DialogUitl { private boolean mCancelable; private boolean mBackgroundDimEnabled;//显示区域以外是否使用黑色半透明背景 private boolean mInput;//是否是输入框的 + private boolean isShowCancelButton=true; private String mHint; private int mInputType; private int mLength; @@ -454,6 +455,11 @@ public class DialogUitl { return this; } + public Builder setShowCancelButton(boolean showCancelButton) { + isShowCancelButton = showCancelButton; + return this; + } + public Dialog build() { final Dialog dialog = new Dialog(mContext, mBackgroundDimEnabled ? R.style.dialog : R.style.dialog2); if (mView != 0) { @@ -498,6 +504,9 @@ public class DialogUitl { if (!TextUtils.isEmpty(mCancelString)) { btnCancel.setText(mCancelString); } + if(!isShowCancelButton){ + btnCancel.setVisibility(View.GONE); + } View.OnClickListener listener = new View.OnClickListener() { @Override public void onClick(View v) { diff --git a/common/src/main/java/com/yunbao/common/utils/JavascriptInterfaceUtils.java b/common/src/main/java/com/yunbao/common/utils/JavascriptInterfaceUtils.java index b4ca839b5..e4c61f85c 100644 --- a/common/src/main/java/com/yunbao/common/utils/JavascriptInterfaceUtils.java +++ b/common/src/main/java/com/yunbao/common/utils/JavascriptInterfaceUtils.java @@ -285,7 +285,7 @@ public class JavascriptInterfaceUtils { liveBean.setGiftId(giftId); new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { if (!"".endsWith(Constants.mStream)) { @@ -295,7 +295,7 @@ public class JavascriptInterfaceUtils { } EventBus.getDefault().post(new LiveRoomChangeEvent(liveBean, liveType, Integer.parseInt(liveTypeVal)).setLiveEnd(true)); } else { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveTypeVal), Integer.parseInt(liveSdk)); + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveTypeVal), Integer.parseInt(liveSdk),isSw); } androidGoBack(); } diff --git a/common/src/main/java/com/yunbao/common/utils/LiveRoomCheckLivePresenter.java b/common/src/main/java/com/yunbao/common/utils/LiveRoomCheckLivePresenter.java index 25796bdab..6c7d2d6f3 100644 --- a/common/src/main/java/com/yunbao/common/utils/LiveRoomCheckLivePresenter.java +++ b/common/src/main/java/com/yunbao/common/utils/LiveRoomCheckLivePresenter.java @@ -33,6 +33,7 @@ public class LiveRoomCheckLivePresenter { private LiveBean mLiveBean; private ActionListener mActionListener; private int mLiveSdk; + private boolean isSw; //搜索页面不提示密码 public static boolean isRoom = false; @@ -50,7 +51,7 @@ public class LiveRoomCheckLivePresenter { @Override public void forwardNormalRoom(CheckLiveModel model) { if (actionListener != null) { - actionListener.onLiveRoomChanged(liveUid, stream, model.getType(), model.getTypeVal(), model.getLiveSdk()); + actionListener.onLiveRoomChanged(liveUid, stream, model.getType(), model.getTypeVal(), model.getLiveSdk(),model.getIsShengwang().equals("1")); } } @@ -74,7 +75,7 @@ public class LiveRoomCheckLivePresenter { if (model.getTypeMsg().equalsIgnoreCase(password)) { dialog.dismiss(); if (actionListener != null) { - actionListener.onLiveRoomChanged(liveUid, stream, model.getType(), model.getTypeVal(), model.getLiveSdk()); + actionListener.onLiveRoomChanged(liveUid, stream, model.getType(), model.getTypeVal(), model.getLiveSdk(),model.getIsShengwang().equals("1")); } } else { ToastUtil.show(mContext.getString(R.string.live_password_error)); @@ -93,7 +94,7 @@ public class LiveRoomCheckLivePresenter { public void onSuccess(int code, String msg, String[] info) { if (code == 0) { if (actionListener != null) { - actionListener.onLiveRoomChanged(liveUid, stream, model.getType(), model.getTypeVal(), model.getLiveSdk()); + actionListener.onLiveRoomChanged(liveUid, stream, model.getType(), model.getTypeVal(), model.getLiveSdk(),model.getIsShengwang().equals("1")); } } else { ToastUtil.show(msg); @@ -139,6 +140,7 @@ public class LiveRoomCheckLivePresenter { mLiveTypeMsg = obj.getString("type_msg"); if (CommonAppConfig.LIVE_SDK_CHANGED) { mLiveSdk = obj.getIntValue("live_sdk"); + isSw= obj.getString("is_shengwang").equals("1"); } else { mLiveSdk = CommonAppConfig.LIVE_SDK_USED; } @@ -263,17 +265,16 @@ public class LiveRoomCheckLivePresenter { */ private void enterLiveRoom() { if (mActionListener != null) { - mActionListener.onLiveRoomChanged(mLiveBean, mLiveType, mLiveTypeVal, mLiveSdk); + mActionListener.onLiveRoomChanged(mLiveBean, mLiveType, mLiveTypeVal, mLiveSdk,isSw); } } - public interface ActionListener { - void onLiveRoomChanged(LiveBean liveBean, int liveType, int liveTypeVal, int liveSdk); + void onLiveRoomChanged(LiveBean liveBean, int liveType, int liveTypeVal, int liveSdk,boolean isSw); } public interface NewActionListener { - void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk); + void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw); void onCheckError(String contextError); } diff --git a/common/src/main/java/com/yunbao/common/utils/RouteUtil.java b/common/src/main/java/com/yunbao/common/utils/RouteUtil.java index a30f5f676..cc449286f 100644 --- a/common/src/main/java/com/yunbao/common/utils/RouteUtil.java +++ b/common/src/main/java/com/yunbao/common/utils/RouteUtil.java @@ -46,23 +46,25 @@ public class RouteUtil { public static final String PATH_RED_PACKET_LIST = "/main/RedPacketListActivity"; public static final String PATH_RED_PACKET_INFO = "/main/RedPacketInfoActivity"; public static final String PATH_RED_PACKET_USER = "/main/RedPacketUsersActivity"; - public static final String PATH_SELECT_AVATAR="/main/UserAvatarSelectActivity"; - public static final String PATH_BattlePassActivity="/main/BattlePassActivity"; - public static final String PATH_SudGameActivity="/live/SudGameActivity"; + public static final String PATH_SELECT_AVATAR = "/main/UserAvatarSelectActivity"; + public static final String PATH_BattlePassActivity = "/main/BattlePassActivity"; + public static final String PATH_SudGameActivity = "/live/SudGameActivity"; - public static final String PATH_COMMUNITY_Activity="/main/MainHomeCommunityActivity"; + public static final String PATH_COMMUNITY_Activity = "/main/MainHomeCommunityActivity"; public static void forwardCommunityActivity() { ARouter.getInstance().build(PATH_COMMUNITY_Activity) .navigation(); } + public static void forwardFansActivity(String uid) { ARouter.getInstance().build(PATH_FANSACTIVITY) .withString(Constants.TO_UID, uid) .navigation(); } - public static void forwardSudGameActivity(String CreateSudRoom,boolean isAn,boolean isHome) { + + public static void forwardSudGameActivity(String CreateSudRoom, boolean isAn, boolean isHome) { ARouter.getInstance().build(PATH_SudGameActivity) .withString("CreateSudRoom", CreateSudRoom) .withBoolean("CreateIsAn", isAn) @@ -218,7 +220,7 @@ public class RouteUtil { * 跳转到充值页面 */ public static void forwardMyCoin(Context context) { - String url = CommonAppConfig.HOST + "/index.php?g=Appapi&m=Mall&a=zhifu&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken()+ "&isZh=" + (WordUtil.isNewZh() ? "1" : 0); + String url = CommonAppConfig.HOST + "/index.php?g=Appapi&m=Mall&a=zhifu&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&isZh=" + (WordUtil.isNewZh() ? "1" : 0); ARouter.getInstance().build(PATH_COIN).withString("url", url).navigation(); } @@ -250,7 +252,7 @@ public class RouteUtil { /** * 打开直播页面 */ - public static void forwardLiveAudienceActivity(LiveBean mLiveBean, int mLiveType, int mLiveSDK, int mLiveTypeVal) { + public static void forwardLiveAudienceActivity(LiveBean mLiveBean, int mLiveType, int mLiveSDK, int mLiveTypeVal, boolean isSw) { if (MicStatusManager.getInstance().isMic(mLiveBean.getUid())) { MicStatusManager.getInstance().showDownMicDialog(CommonAppContext.activityWeakReference.get()); return; @@ -260,7 +262,9 @@ public class RouteUtil { .withParcelable(Constants.LIVE_BEAN, mLiveBean) .withInt(Constants.LIVE_TYPE, mLiveType) .withInt(Constants.LIVE_SDK, mLiveSDK) + .withBoolean(Constants.LIVE_SDK_IS_SW, isSw) .withInt(Constants.LIVE_TYPE_VAL, mLiveTypeVal); + if (mLiveBean.getParams() != null) { for (String key : mLiveBean.getParams().keySet()) { postcard.withString(key, mLiveBean.getParams().get(key)); @@ -269,14 +273,14 @@ public class RouteUtil { postcard.navigation(); } - public static void forwardGiftWallActivity(String mStream, String mAnchorName, String mLiveUid, String mAvatarUrl, int isAttention,boolean isLive) { + public static void forwardGiftWallActivity(String mStream, String mAnchorName, String mLiveUid, String mAvatarUrl, int isAttention, boolean isLive) { ARouter.getInstance().build(PATH_GIFT_WALL) .withString(Constants.LIVE_UID, mLiveUid) .withString(Constants.STREAM, mStream) .withString("mAnchorName", mAnchorName) .withString("mAvatarUrl", mAvatarUrl) .withInt("isAttention", isAttention) - .withBoolean("isLive",isLive) + .withBoolean("isLive", isLive) .navigation(); } @@ -354,7 +358,7 @@ public class RouteUtil { /** * 战令 */ - public static void forwardBattlePass(){ + public static void forwardBattlePass() { ARouter.getInstance().build(PATH_BattlePassActivity) .navigation(); } diff --git a/common/src/main/java/com/yunbao/common/views/SudGameListViewHolder.java b/common/src/main/java/com/yunbao/common/views/SudGameListViewHolder.java index 7c390f6d2..0eff03c05 100644 --- a/common/src/main/java/com/yunbao/common/views/SudGameListViewHolder.java +++ b/common/src/main/java/com/yunbao/common/views/SudGameListViewHolder.java @@ -131,8 +131,8 @@ public class SudGameListViewHolder extends RecyclerView.ViewHolder { LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class); new LiveRoomCheckLivePresenter(itemView.getContext(), liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal),isSw); new Handler().postDelayed(new Runnable() { @Override public void run() { diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/LiveFloatView.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/LiveFloatView.java index e09f22338..7a336a381 100644 --- a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/LiveFloatView.java +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/LiveFloatView.java @@ -336,7 +336,7 @@ public class LiveFloatView implements Function1 { public void onSuccess(int code, String msg, String[] info) { if (code == 0) { - RouteUtil.forwardLiveAudienceActivity(mLiveBean, mLiveType, mLiveSDK, mLiveTypeVal); + RouteUtil.forwardLiveAudienceActivity(mLiveBean, mLiveType, mLiveSDK, mLiveTypeVal,mLiveSDK == Constants.LIVE_SDK_SW); } else { //判断是否有直播悬浮窗,有直接关闭 diff --git a/live/src/main/AndroidManifest.xml b/live/src/main/AndroidManifest.xml index 1af89a691..2f80c2ebd 100644 --- a/live/src/main/AndroidManifest.xml +++ b/live/src/main/AndroidManifest.xml @@ -97,10 +97,15 @@ + + + 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 51dd79c30..0cf2630cc 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveActivity.java @@ -83,10 +83,12 @@ 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.SocketSwClient; import com.yunbao.live.utils.LoadDian9TuUtil; import com.yunbao.live.views.AbsLiveViewHolder; import com.yunbao.live.views.LiveAddImpressViewHolder; @@ -125,9 +127,13 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL protected LiveEndViewHolder mLiveEndViewHolder; protected LiveLinkMicPresenter mLiveLinkMicPresenter;//观众与主播连麦逻辑 protected LiveLinkMicAnchorPresenter mLiveLinkMicAnchorPresenter;//主播与主播连麦逻辑 - protected LiveLinkMicPkPresenter mLiveLinkMicPkPresenter;//主播与主播PK逻辑 - public static LiveRyLinkMicPkPresenter mLiveRyLinkMicPkPresenter;//主播与主播PK逻辑 + protected LiveLinkMicPkPresenter mLiveLinkMicPkPresenter;//主播与主播PK逻辑 腾讯 + public static LiveRyLinkMicPkPresenter mLiveRyLinkMicPkPresenter;//主播与主播PK逻辑 融云 + + public static LiveSwLinkMicPkPresenter mLiveSwLinkMicPkPresenter;//主播与主播PK逻辑 声网 public SocketClient mSocketClient; + public SocketSwClient mSocketSwClient; + public SocketRyClient mSocketRyClient; protected LiveBean mLiveBean; @@ -160,6 +166,8 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL protected List mAudienceList = new ArrayList<>(); protected LiveMicAnchorDialogFragment.OnMicListener micListener = null; + public boolean isSw; + @Override protected void main() { getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); @@ -393,18 +401,29 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL if (mLiveRyLinkMicPkPresenter != null) { mLiveRyLinkMicPkPresenter.onPkProgressChanged(leftGift, rightGift, bean); } - + if (mLiveSwLinkMicPkPresenter != null) { + mLiveSwLinkMicPkPresenter.onPkProgressChanged(leftGift, rightGift, bean); + } } @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 + "")) { + mLiveSwLinkMicPkPresenter.onPkProgressEnd(left, right, bean); + } else { + mLiveSwLinkMicPkPresenter.onPkProgressEnd(right, left, bean); + } + } } /** @@ -669,6 +688,10 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL if (mLiveRyLinkMicPkPresenter != null) { mLiveRyLinkMicPkPresenter.onLinkMicPkClose(1); } + + if (mLiveSwLinkMicPkPresenter != null) { + mLiveSwLinkMicPkPresenter.onLinkMicPkClose(1); + } // } @@ -728,12 +751,20 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL @Override public void onLinkMicPkStart(final String pkUid, final String pkhead, final String pkname, String isLadders) { if (mContext instanceof LiveAudienceActivity) return; - L.eSw( "pkUid = " + pkUid + ", pkhead = " + pkhead + ", pkname = " + pkname + ", isLadders = " + isLadders); - if (mLiveRyLinkMicPkPresenter != null && mLiveRoomViewHolder != null) { - mLiveRyLinkMicPkPresenter.onLinkMicPkStart(pkUid, 1); - pr = new pkRunnable(pkUid, pkhead, pkname, isLadders); - mHandler.postDelayed(pr, 4000);//3秒后执行Runnable中的run方法 + L.eSw("pkUid = " + pkUid + ", pkhead = " + pkhead + ", pkname = " + pkname + ", isLadders = " + isLadders); + if (isSw) { + if (mLiveSwLinkMicPkPresenter != null && mLiveRoomViewHolder != null) { + mLiveSwLinkMicPkPresenter.onLinkMicPkStart(pkUid, 1); + pr = new pkRunnable(pkUid, pkhead, pkname, isLadders); + mHandler.postDelayed(pr, 4000);//3秒后执行Runnable中的run方法 + } + } else { + if (mLiveRyLinkMicPkPresenter != null && mLiveRoomViewHolder != null) { + mLiveRyLinkMicPkPresenter.onLinkMicPkStart(pkUid, 1); + pr = new pkRunnable(pkUid, pkhead, pkname, isLadders); + mHandler.postDelayed(pr, 4000);//3秒后执行Runnable中的run方法 + } } } @@ -774,6 +805,8 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL mLiveRyLinkMicPkPresenter.onLinkMicPkClose(i); } else if (mLiveLinkMicPkPresenter != null) { mLiveLinkMicPkPresenter.onLinkMicPkClose(i); + } else if (mLiveSwLinkMicPkPresenter != null) { + mLiveSwLinkMicPkPresenter.onLinkMicPkClose(i); } } @@ -812,6 +845,9 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL } else if (mLiveLinkMicPkPresenter != null) { mLiveLinkMicPkPresenter.onLinkMicPkEnd(winUid); mLiveRoomViewHolder.setDelOtherInfo(); + } else if (mLiveSwLinkMicPkPresenter != null) { + mLiveSwLinkMicPkPresenter.onLinkMicPkEnd(winUid); + mLiveRoomViewHolder.setDelOtherInfo(); } } @@ -1336,32 +1372,31 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL if (outRankHideFirst) { //获取隐身的用户的ID - LiveNetManager.get(mContext) - .getNobleRankHideUserList(new com.yunbao.common.http.base.HttpCallback() { - @Override - public void onSuccess(NobleRankHideUserListModel data) { - outRankHide = data.getInRankHide(); - LiveUserMoreDialogFragment fragment = new LiveUserMoreDialogFragment(); - fragment.setLiveGuardInfo(mLiveGuardInfo); - Bundle bundle = new Bundle(); - bundle.putString(Constants.LIVE_UID, mLiveUid); - bundle.putString(Constants.STREAM, mStream); - bundle.putString("By", i + ""); - bundle.putBoolean("only", isOnly); - bundle.putBoolean("noble", noble); - bundle.putString("outRankHide", GsonUtils.toJson(outRankHide)); - bundle.putBoolean("showBuyView", !showBuyView); - fragment.setArguments(bundle); - fragment.show(getSupportFragmentManager(), "LiveUserMoreDialogFragment"); - outRankHideFirst = false; - } + LiveNetManager.get(mContext).getNobleRankHideUserList(new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(NobleRankHideUserListModel data) { + outRankHide = data.getInRankHide(); + LiveUserMoreDialogFragment fragment = new LiveUserMoreDialogFragment(); + fragment.setLiveGuardInfo(mLiveGuardInfo); + Bundle bundle = new Bundle(); + bundle.putString(Constants.LIVE_UID, mLiveUid); + bundle.putString(Constants.STREAM, mStream); + bundle.putString("By", i + ""); + bundle.putBoolean("only", isOnly); + bundle.putBoolean("noble", noble); + bundle.putString("outRankHide", GsonUtils.toJson(outRankHide)); + bundle.putBoolean("showBuyView", !showBuyView); + fragment.setArguments(bundle); + fragment.show(getSupportFragmentManager(), "LiveUserMoreDialogFragment"); + outRankHideFirst = false; + } - @Override - public void onError(String error) { - Log.e("LiveUserMoreDialog", error); - ToastUtil.show(WordUtil.isNewZh() ? "抱歉!出錯了!" : "i \\'m sorry! An error occurred"); - } - }); + @Override + public void onError(String error) { + Log.e("LiveUserMoreDialog", error); + ToastUtil.show(WordUtil.isNewZh() ? "抱歉!出錯了!" : "i \\'m sorry! An error occurred"); + } + }); } else { LiveUserMoreDialogFragment fragment = new LiveUserMoreDialogFragment(); fragment.setLiveGuardInfo(mLiveGuardInfo); @@ -1672,27 +1707,26 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL micListener = fragment.getMicListener(); fragment.setMicQueueList(mMicQueueList); fragment.setAudienceList(mAudienceList); - fragment.show(((LiveRyAnchorActivity) mContext).getSupportFragmentManager(), "LiveMicAnchorDialogFragment"); + fragment.show(((LiveSwAnchorActivity) mContext).getSupportFragmentManager(), "LiveMicAnchorDialogFragment"); } /** * 获取连麦列表 */ public void showMicList(String uid, LiveRoomViewHolder mLiveRoomViewHolder) { - LiveNetManager.get(mContext) - .getDRMicUserList(uid, new com.yunbao.common.http.base.HttpCallback>() { - @Override - public void onSuccess(List data) { - if (mLiveRoomViewHolder != null) { - mLiveRoomViewHolder.updataMicList(data); - } - } + LiveNetManager.get(mContext).getDRMicUserList(uid, new com.yunbao.common.http.base.HttpCallback>() { + @Override + public void onSuccess(List data) { + if (mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.updataMicList(data); + } + } - @Override - public void onError(String error) { - System.out.println("live.getDrLm error = " + error); - } - }); + @Override + public void onError(String error) { + System.out.println("live.getDrLm error = " + error); + } + }); } @Override 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 282a8dac0..e8b571e2c 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveAnchorActivity.java @@ -282,7 +282,7 @@ public class LiveAnchorActivity extends LiveActivity implements LiveFunctionClic + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&anchorUid=" + mLiveUid + "&isZh=" + ((IMLoginManager.get(mContext).getLocaleLanguage() == Locale.SIMPLIFIED_CHINESE) ? "1" : "0"); - ZhuangBanActivity.forward(mContext, url, false,0); + ZhuangBanActivity.forward(mContext, url, false, 0); break; case Constants.LIVE_FUNC_LINK_MIC://连麦 openLinkMicAnchorWindow(); @@ -632,6 +632,9 @@ public class LiveAnchorActivity extends LiveActivity implements LiveFunctionClic // } else { // SocketRyChatUtil.closeLive(mLiveUid, mSocketRyClient); //断开socket + if (mSocketSwClient != null) { + mSocketSwClient.disConnect(); + } if (mSocketRyClient != null) { mSocketRyClient.disConnect(); } diff --git a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java index 6f035614f..5b27c1498 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java @@ -31,7 +31,6 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.blankj.utilcode.util.GsonUtils; import com.facebook.appevents.AppEventsLogger; -import com.google.gson.Gson; import com.lxj.xpopup.XPopup; import com.lxj.xpopup.core.BasePopupView; import com.lxj.xpopup.enums.PopupPosition; @@ -188,6 +187,7 @@ public class LiveAudienceActivity extends LiveActivity { private boolean liveIndex = true; private boolean isPk = false; private boolean isRadPacetModle = false; + public boolean isSw; @Override public T findViewById(@IdRes int id) { @@ -209,6 +209,7 @@ public class LiveAudienceActivity extends LiveActivity { mProcessResultUtil = new ProcessResultUtil(this); Intent intent = getIntent(); mLiveSDK = intent.getIntExtra(Constants.LIVE_SDK, Constants.LIVE_SDK_KSY); + isSw = intent.getBooleanExtra(Constants.LIVE_SDK_IS_SW, false); L.e(TAG, "直播sdk----->" + (mLiveSDK == Constants.LIVE_SDK_KSY ? "金山云" : "腾讯云")); mLiveType = intent.getIntExtra(Constants.LIVE_TYPE, Constants.LIVE_TYPE_NORMAL); mLiveTypeVal = intent.getIntExtra(Constants.LIVE_TYPE_VAL, 0); @@ -300,38 +301,36 @@ public class LiveAudienceActivity extends LiveActivity { Log.e(TAG, "mCurrentItem:" + mCurrentItem); if (mCurrentItem == itemModelList.size() - 1) { if (isRadPacetModle) {//从红包专区进去的走红包专区列表 - MainNetManager.get(mContext) - .getRedPacket(new com.yunbao.common.http.base.HttpCallback>() { - @Override - public void onSuccess(List data) { - if (TextUtils.equals(data.get(0).getUid(), mLiveBean.getUid())) { - data.remove(0); - } - itemModelList.addAll(data); - mPagerAdapter.notifyDataSetChanged(); - } + MainNetManager.get(mContext).getRedPacket(new com.yunbao.common.http.base.HttpCallback>() { + @Override + public void onSuccess(List data) { + if (TextUtils.equals(data.get(0).getUid(), mLiveBean.getUid())) { + data.remove(0); + } + itemModelList.addAll(data); + mPagerAdapter.notifyDataSetChanged(); + } - @Override - public void onError(String error) { + @Override + public void onError(String error) { - } - }); + } + }); } else { - MainNetManager.get(mContext) - .anchorRecommendType("30", new com.yunbao.common.http.base.HttpCallback() { - @Override - public void onSuccess(AnchorRecommendModel data) { - if (TextUtils.equals(data.getList().get(0).getUid(), mLiveBean.getUid())) { - data.getList().remove(0); - } - itemModelList.addAll(data.getList()); - mPagerAdapter.notifyDataSetChanged(); - } + MainNetManager.get(mContext).anchorRecommendType("30", new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(AnchorRecommendModel data) { + if (TextUtils.equals(data.getList().get(0).getUid(), mLiveBean.getUid())) { + data.getList().remove(0); + } + itemModelList.addAll(data.getList()); + mPagerAdapter.notifyDataSetChanged(); + } - @Override - public void onError(String error) { - } - }); + @Override + public void onError(String error) { + } + }); } } } @@ -404,7 +403,7 @@ public class LiveAudienceActivity extends LiveActivity { mHandler.removeCallbacks(pr); pr = null; } - manager.onAdd(mLiveBean, mLiveType, mLiveTypeVal, mLiveSDK); + manager.onAdd(mLiveBean, mLiveType, mLiveTypeVal, mLiveSDK, isSw); //加载完页面后再后台静默下载礼物svga downloadAllGift(); @@ -413,7 +412,7 @@ public class LiveAudienceActivity extends LiveActivity { } else { new LiveRoomCheckLivePresenter(mContext, data.getUid(), data.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk, boolean isSw) { liveIndex = false; try { mLiveSDK = Integer.parseInt(liveSdk); @@ -441,7 +440,7 @@ public class LiveAudienceActivity extends LiveActivity { } mViewGroup.addView(manager.getRootView()); - manager.onAdd(mLiveBean, liveType, mLiveTypeVal, mLiveSDK); + manager.onAdd(mLiveBean, liveType, mLiveTypeVal, mLiveSDK, isSw); //加载完页面后再后台静默下载礼物svga downloadAllGift(); over(); @@ -483,12 +482,7 @@ public class LiveAudienceActivity extends LiveActivity { if (TextUtils.isEmpty(mLiveUid) || TextUtils.isEmpty(mStream)) { return; } - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.GIFT_POPUP) - .setmLiveUid(mLiveUid) - .setmStream(mStream) - .setPk(isPk) - .setLiveGuardInfo(mLiveGuardInfo)); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.GIFT_POPUP).setmLiveUid(mLiveUid).setmStream(mStream).setPk(isPk).setLiveGuardInfo(mLiveGuardInfo)); }); } @@ -496,13 +490,7 @@ public class LiveAudienceActivity extends LiveActivity { if (TextUtils.isEmpty(mLiveUid) || TextUtils.isEmpty(mStream)) { return; } - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.GIFT_POPUP) - .setmLiveUid(mLiveUid) - .setmStream(mStream) - .setPk(isPk) - .setLiveGuardInfo(mLiveGuardInfo) - .setmWishGiftId(giftId)); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.GIFT_POPUP).setmLiveUid(mLiveUid).setmStream(mStream).setPk(isPk).setLiveGuardInfo(mLiveGuardInfo).setmWishGiftId(giftId)); } public void openGiftWindow(String giftId, String for_by) { @@ -511,14 +499,7 @@ public class LiveAudienceActivity extends LiveActivity { } new Handler(Looper.getMainLooper()).post(() -> { - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.GIFT_POPUP) - .setmLiveUid(mLiveUid) - .setmStream(mStream) - .setPk(isPk) - .setLiveGuardInfo(mLiveGuardInfo) - .setmWishGiftId(giftId) - .setUname("1"));//setUname==by + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.GIFT_POPUP).setmLiveUid(mLiveUid).setmStream(mStream).setPk(isPk).setLiveGuardInfo(mLiveGuardInfo).setmWishGiftId(giftId).setUname("1"));//setUname==by }); } @@ -573,7 +554,7 @@ public class LiveAudienceActivity extends LiveActivity { @Override public void onLinkDRMicPkApplyOk(UserBean u) { - L.eSw("onLinkDRMicPkApplyOk:"+u.getId()); + L.eSw("onLinkDRMicPkApplyOk:" + u.getId()); //多人PK 连麦 //manager.getmLivePlayViewHolder().setDrMicInfo(u); } @@ -591,39 +572,33 @@ public class LiveAudienceActivity extends LiveActivity { @Override public void onBackPressed() { if (manager != null && manager.getsudGameMin()) { - new XPopup.Builder(mContext) - .asCustom(new HintCustomPopup(mContext, - mContext.getString(com.yunbao.common.R.string.dialog_tip), - mContext.getString(com.yunbao.common.R.string.the_live_room)) - .setLiveOpenOk(mContext.getString(com.yunbao.common.R.string.confirm)) - .setLiveOpenCancel(mContext.getString(com.yunbao.common.R.string.cancel)) - .setCallBack(new HintCustomPopup.HintCustomCallBack() { - @Override - public void onSure() { - MobclickAgent.onEvent(mContext, "live_room_close", "退出直播间"); - OpenAdManager.getInstance().dismiss(); - try { - manager.onBackPressed(); - if (MicStatusManager.getInstance().getMicStatus() == MicStatusManager.MIC_TYPE_REQUEST) { - manager.micIngTypeOne(mLiveBean, mLiveType, mLiveTypeVal); - } else if (MicStatusManager.getInstance().getMicStatus() == MicStatusManager.MIC_TYPE_OPEN) { - manager.micIngTypeTwo(mLiveBean, mLiveType, mLiveTypeVal); - } else { - manager.onRemove(true); + new XPopup.Builder(mContext).asCustom(new HintCustomPopup(mContext, mContext.getString(com.yunbao.common.R.string.dialog_tip), mContext.getString(com.yunbao.common.R.string.the_live_room)).setLiveOpenOk(mContext.getString(com.yunbao.common.R.string.confirm)).setLiveOpenCancel(mContext.getString(com.yunbao.common.R.string.cancel)).setCallBack(new HintCustomPopup.HintCustomCallBack() { + @Override + public void onSure() { + MobclickAgent.onEvent(mContext, "live_room_close", "退出直播间"); + OpenAdManager.getInstance().dismiss(); + try { + manager.onBackPressed(); + if (MicStatusManager.getInstance().getMicStatus() == MicStatusManager.MIC_TYPE_REQUEST) { + manager.micIngTypeOne(mLiveBean, mLiveType, mLiveTypeVal); + } else if (MicStatusManager.getInstance().getMicStatus() == MicStatusManager.MIC_TYPE_OPEN) { + manager.micIngTypeTwo(mLiveBean, mLiveType, mLiveTypeVal); + } else { + manager.onRemove(true); - } - Bus.get().post(new HideShowEvent().setClose(true)); - } catch (Exception e) { - e.printStackTrace(); - } - } + } + Bus.get().post(new HideShowEvent().setClose(true)); + } catch (Exception e) { + e.printStackTrace(); + } + } - @Override - public void onCancel() { + @Override + public void onCancel() { - } - })).show(); + } + })).show(); } else { MobclickAgent.onEvent(mContext, "live_room_close", "退出直播间"); OpenAdManager.getInstance().dismiss(); @@ -646,8 +621,7 @@ public class LiveAudienceActivity extends LiveActivity { } public void end() { - if (manager != null) - manager.end(); + if (manager != null) manager.end(); } /** @@ -702,24 +676,21 @@ public class LiveAudienceActivity extends LiveActivity { * 计时收费更新主播映票数 */ public void roomChargeUpdateVotes() { - if (manager != null) - manager.sendUpdateVotesMessage(); + if (manager != null) manager.sendUpdateVotesMessage(); } /** * 暂停播放 */ public void pausePlay() { - if (manager != null) - manager.pausePlay(); + if (manager != null) manager.pausePlay(); } /** * 恢复播放 */ public void resumePlay() { - if (manager != null) - manager.resumePlay(); + if (manager != null) manager.resumePlay(); } public CountDownTimer getCountDownTimer() { @@ -730,8 +701,7 @@ public class LiveAudienceActivity extends LiveActivity { * 充值成功 */ public void onChargeSuccess() { - if (manager != null) - manager.onChargeSuccess(); + if (manager != null) manager.onChargeSuccess(); } public void setCoinNotEnough(boolean coinNotEnough) { @@ -835,12 +805,11 @@ public class LiveAudienceActivity extends LiveActivity { mStream = liveBean.getStream(); mAncherName = liveBean.getUserNiceName(); mAncherIcon = liveBean.getAvatar(); - manager.onAdd(liveBean, mLiveType, mLiveTypeVal, mLiveSDK); + //暂时 true + manager.onAdd(liveBean, mLiveType, mLiveTypeVal, mLiveSDK, isSw); } } } - - } @Override @@ -855,14 +824,12 @@ public class LiveAudienceActivity extends LiveActivity { if (mLiveRoomViewHolder != null) { mLiveRoomViewHolder.setFansGroup("0"); } - is_fans = "2"; } } GiftCacheUtil.getInstance().restart(); if (manager.isEnterRoom()) { - new Handler(Looper.getMainLooper()).postDelayed(() -> OpenAdManager.getInstance().show(OpenAdManager.TYPE_LIVE, - LiveGuardInfo.isGuard(mLiveGuardInfo)), 400); + new Handler(Looper.getMainLooper()).postDelayed(() -> OpenAdManager.getInstance().show(OpenAdManager.TYPE_LIVE, LiveGuardInfo.isGuard(mLiveGuardInfo)), 400); } } @@ -874,8 +841,7 @@ public class LiveAudienceActivity extends LiveActivity { private void adjustFullScreen(Configuration config) { final WindowInsetsControllerCompat insetsController = ViewCompat.getWindowInsetsController(getWindow().getDecorView()); - if (insetsController == null) - return; + if (insetsController == null) return; if (config.orientation == Configuration.ORIENTATION_LANDSCAPE) { insetsController.hide(WindowInsetsCompat.Type.systemBars()); } else { @@ -949,7 +915,7 @@ public class LiveAudienceActivity extends LiveActivity { LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class); new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk, boolean isSw) { if (liveBean == null) { return; } @@ -974,18 +940,15 @@ public class LiveAudienceActivity extends LiveActivity { public void informationTransfer(CustomDrawerPopupEvent event) { //跳转贵族 if (TextUtils.equals(event.getRightsInterests(), getString(com.yunbao.common.R.string.noble))) { - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.NOBLE)); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.NOBLE)); //跳转守护 } else if (TextUtils.equals(event.getRightsInterests(), getString(com.yunbao.common.R.string.guard_guard))) { - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.GUARD)); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.GUARD)); manager.onGuardRed(); //跳转粉丝团 } else if (TextUtils.equals(event.getRightsInterests(), getString(com.yunbao.common.R.string.fan_club))) { - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.FAN_CLUB)); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.FAN_CLUB)); } } @@ -1011,69 +974,53 @@ public class LiveAudienceActivity extends LiveActivity { @Override public void evenTheWheat() { - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.LIAN_MAI)); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LIAN_MAI)); } @Override public void effectsSetting() { - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.EFFECTS_SETTINGS)); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.EFFECTS_SETTINGS)); } @Override public void slideSetting() { - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.SLIDE_SETTINGS)); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.SLIDE_SETTINGS)); } @Override public void floatSetting() { - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.FLOAT_SETTING)); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.FLOAT_SETTING)); } @Override public void systemNotice() { - Bus.get().post(new LiveAudienceEvent() - .setBean(mLiveBean) - .setType(LiveAudienceEvent.LiveAudienceType.NOTICE)); + Bus.get().post(new LiveAudienceEvent().setBean(mLiveBean).setType(LiveAudienceEvent.LiveAudienceType.NOTICE)); } @Override public void changeVideo() { - Bus.get().post(new LiveAudienceEvent() - .setBean(mLiveBean) - .setType(LiveAudienceEvent.LiveAudienceType.LIVE_VIDEO)); + Bus.get().post(new LiveAudienceEvent().setBean(mLiveBean).setType(LiveAudienceEvent.LiveAudienceType.LIVE_VIDEO)); } @Override public void online() { - Bus.get().post(new LiveAudienceEvent() - .setBean(mLiveBean) - .setType(LiveAudienceEvent.LiveAudienceType.ONLINE)); + Bus.get().post(new LiveAudienceEvent().setBean(mLiveBean).setType(LiveAudienceEvent.LiveAudienceType.ONLINE)); } @Override public void reportLayout() { - Bus.get().post(new LiveAudienceEvent() - .setBean(mLiveBean) - .setType(LiveAudienceEvent.LiveAudienceType.REPORT)); + Bus.get().post(new LiveAudienceEvent().setBean(mLiveBean).setType(LiveAudienceEvent.LiveAudienceType.REPORT)); } @Override public void share() { - Bus.get().post(new LiveAudienceEvent() - .setBean(mLiveBean) - .setType(LiveAudienceEvent.LiveAudienceType.LIVE_SHARE)); + Bus.get().post(new LiveAudienceEvent().setBean(mLiveBean).setType(LiveAudienceEvent.LiveAudienceType.LIVE_SHARE)); } @Override public void changeFontSize() { - Bus.get().post(new LiveAudienceEvent() - .setBean(mLiveBean) - .setType(LiveAudienceEvent.LiveAudienceType.FONT_SIZE)); + Bus.get().post(new LiveAudienceEvent().setBean(mLiveBean).setType(LiveAudienceEvent.LiveAudienceType.FONT_SIZE)); } @Override @@ -1082,23 +1029,17 @@ public class LiveAudienceActivity extends LiveActivity { ToastUtil.show(WordUtil.isNewZh() ? "您已在游戏房间中" : "You are already in the game room"); } else { //直播间来的 - new XPopup.Builder(mContext) - .enableDrag(false) + new XPopup.Builder(mContext).enableDrag(false) // .dismissOnTouchOutside(false) // .dismissOnBackPressed(false) - .moveUpToKeyboard(false) - .asCustom(new SudGameListPopup(mContext, interactionID, child, mLiveUid)) + .moveUpToKeyboard(false).asCustom(new SudGameListPopup(mContext, interactionID, child, mLiveUid)) .show(); } } }); - new XPopup.Builder(mContext) - .hasShadowBg(false) - .isDestroyOnDismiss(true) - .isLightStatusBar(false) - .popupPosition(PopupPosition.Right)//右边 + new XPopup.Builder(mContext).hasShadowBg(false).isDestroyOnDismiss(true).isLightStatusBar(false).popupPosition(PopupPosition.Right)//右边 .hasStatusBarShadow(true) //启用状态栏阴影 .setPopupCallback(new XPopupCallback() { @Override @@ -1144,9 +1085,7 @@ public class LiveAudienceActivity extends LiveActivity { public void onClickOutside(BasePopupView popupView) { } - }) - .asCustom(customDrawerPopupView) - .show(); + }).asCustom(customDrawerPopupView).show(); } break; @@ -1196,15 +1135,9 @@ public class LiveAudienceActivity extends LiveActivity { //粉絲團粉絲團 //不是粉絲 if (LiveAudienceActivity.is_fans == null || "2".equals(LiveAudienceActivity.is_fans)) { - bundle.putString(Constants.URL, - (CommonAppConfig.HOST + "/h5/live/joinFansClub.html" + - "?uid=" + userInfo.getId() + - "&token=" + userInfo.getToken() + "&anchorUid=" + mLiveUid) + "&isZh=" + (WordUtil.isNewZh() ? "1" : 0)); + bundle.putString(Constants.URL, (CommonAppConfig.HOST + "/h5/live/joinFansClub.html" + "?uid=" + userInfo.getId() + "&token=" + userInfo.getToken() + "&anchorUid=" + mLiveUid) + "&isZh=" + (WordUtil.isNewZh() ? "1" : 0)); } else { - bundle.putString(Constants.URL, - (CommonAppConfig.HOST + "/h5/live/fansClub.html" + - "?uid=" + userInfo.getId() + - "&token=" + userInfo.getToken() + "&anchorUid=" + mLiveUid) + "&isZh=" + (WordUtil.isNewZh() ? "1" : 0)); + bundle.putString(Constants.URL, (CommonAppConfig.HOST + "/h5/live/fansClub.html" + "?uid=" + userInfo.getId() + "&token=" + userInfo.getToken() + "&anchorUid=" + mLiveUid) + "&isZh=" + (WordUtil.isNewZh() ? "1" : 0)); } bundle.putString("liveUid", mLiveUid); bundle.putString("anchorName", mAncherName); @@ -1214,25 +1147,18 @@ public class LiveAudienceActivity extends LiveActivity { break; case GUARD: if (event.getObject() == null) { - openNewGuardListWindow(mContext instanceof LiveRyAnchorActivity); + openNewGuardListWindow(mContext instanceof LiveSwAnchorActivity); } else { openNewBuyGuardWindow(true); } break; case LIVE_WKS://周星榜 - String weeklyStarUrl = CommonAppConfig.HOST + "/h5/activity/weekStar/index.html?&uid=" - + userInfo.getId() + - "&token=" + userInfo.getToken() + "&anchorUid=" + mLiveUid + "&isZh=" + (WordUtil.isNewZh() ? "1" : 0); + String weeklyStarUrl = CommonAppConfig.HOST + "/h5/activity/weekStar/index.html?&uid=" + userInfo.getId() + "&token=" + userInfo.getToken() + "&anchorUid=" + mLiveUid + "&isZh=" + (WordUtil.isNewZh() ? "1" : 0); ZhuangBanActivity.forward(mContext, weeklyStarUrl, false, 1); break; case NOBLE: Constants.isTitle = true; - String nobleUrl = CommonAppConfig.HOST + "/h5/Noble/index.html?nickname=" + userInfo.getUserNicename() - + "&usernobId=" + userInfo.getNobleId() - + "&token=" + userInfo.getToken() - + "&anchorUid=" + mLiveBean.getUid() - + "&ancherName=" + mLiveBean.getUserNiceName() - + "&uid=" + userInfo.getId() + "&isZh=" + (WordUtil.isNewZh() ? "1" : 0); + String nobleUrl = CommonAppConfig.HOST + "/h5/Noble/index.html?nickname=" + userInfo.getUserNicename() + "&usernobId=" + userInfo.getNobleId() + "&token=" + userInfo.getToken() + "&anchorUid=" + mLiveBean.getUid() + "&ancherName=" + mLiveBean.getUserNiceName() + "&uid=" + userInfo.getId() + "&isZh=" + (WordUtil.isNewZh() ? "1" : 0); ZhuangBanActivity.forward(mContext, nobleUrl, false, 1); break; case LIAN_MAI: @@ -1246,25 +1172,23 @@ public class LiveAudienceActivity extends LiveActivity { manager.micIngTypeTwo(event.getBean(), event.getLiveType(), event.getLiveTypeVal()); } else { //获取房间连麦状态 - HttpClient.getInstance().get("live.getDrLm", "live.getDrLm") - .params("uid", mLiveUid, true) - .execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - if (code == 0) { - LiveMicUserDialogFragment fragment = new LiveMicUserDialogFragment(); - Bundle bundle = new Bundle(); - bundle.putString(Constants.LIVE_UID, mLiveUid); - bundle.putString(Constants.STREAM, mStream); - bundle.putString("By", "1"); - fragment.setArguments(bundle); - fragment.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "LiveUserMoreDialogFragment"); - LiveMicUserDialogFragment.activity = ((LiveAudienceActivity) mContext); - } else { - ToastUtil.show(mContext.getString(R.string.no_mic_opn)); - } - } - }); + HttpClient.getInstance().get("live.getDrLm", "live.getDrLm").params("uid", mLiveUid, true).execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (code == 0) { + LiveMicUserDialogFragment fragment = new LiveMicUserDialogFragment(); + Bundle bundle = new Bundle(); + bundle.putString(Constants.LIVE_UID, mLiveUid); + bundle.putString(Constants.STREAM, mStream); + bundle.putString("By", "1"); + fragment.setArguments(bundle); + fragment.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "LiveUserMoreDialogFragment"); + LiveMicUserDialogFragment.activity = ((LiveAudienceActivity) mContext); + } else { + ToastUtil.show(mContext.getString(R.string.no_mic_opn)); + } + } + }); } break; case EFFECTS_SETTINGS: @@ -1285,31 +1209,20 @@ public class LiveAudienceActivity extends LiveActivity { } break; case OPEN_PARAMETERS: - mDanmuPrice = TextUtils.equals(event.getParametersModel().getmDanmuPrice(), mDanmuPrice) ? - mDanmuPrice : event.getParametersModel().getmDanmuPrice(); - mSocketUserType = TextUtils.equals(String.valueOf(mSocketUserType), String.valueOf(event.getParametersModel().getmSocketUserType())) ? - mSocketUserType : event.getParametersModel().getmSocketUserType(); - mChatLevel = TextUtils.equals(String.valueOf(mChatLevel), String.valueOf(event.getParametersModel().getmChatLevel())) ? - mChatLevel : event.getParametersModel().getmChatLevel(); - mDanMuLevel = TextUtils.equals(String.valueOf(mDanMuLevel), String.valueOf(event.getParametersModel().getmDanMuLevel())) ? - mDanMuLevel : event.getParametersModel().getmDanMuLevel(); - mLiveType = TextUtils.equals(String.valueOf(mLiveType), String.valueOf(event.getParametersModel().getmLiveType())) ? - mLiveType : event.getParametersModel().getmLiveType(); - mLiveTypeVal = TextUtils.equals(String.valueOf(mLiveTypeVal), String.valueOf(event.getParametersModel().getmLiveTypeVal())) ? - mLiveTypeVal : event.getParametersModel().getmLiveTypeVal(); - mLiveGuardInfo = event.getParametersModel().getmLiveGuardInfo() == null ? - mLiveGuardInfo : event.getParametersModel().getmLiveGuardInfo(); - liveBg = TextUtils.equals(String.valueOf(liveBg), String.valueOf(event.getParametersModel().getLiveBg())) ? - liveBg : event.getParametersModel().getLiveBg(); - is_fans = TextUtils.equals(String.valueOf(is_fans), String.valueOf(event.getParametersModel().getIs_fans())) ? - is_fans : event.getParametersModel().getIs_fans(); - fansNum = TextUtils.equals(String.valueOf(fansNum), String.valueOf(event.getParametersModel().getFansNum())) ? - fansNum : event.getParametersModel().getFansNum(); + mDanmuPrice = TextUtils.equals(event.getParametersModel().getmDanmuPrice(), mDanmuPrice) ? mDanmuPrice : event.getParametersModel().getmDanmuPrice(); + mSocketUserType = TextUtils.equals(String.valueOf(mSocketUserType), String.valueOf(event.getParametersModel().getmSocketUserType())) ? mSocketUserType : event.getParametersModel().getmSocketUserType(); + mChatLevel = TextUtils.equals(String.valueOf(mChatLevel), String.valueOf(event.getParametersModel().getmChatLevel())) ? mChatLevel : event.getParametersModel().getmChatLevel(); + mDanMuLevel = TextUtils.equals(String.valueOf(mDanMuLevel), String.valueOf(event.getParametersModel().getmDanMuLevel())) ? mDanMuLevel : event.getParametersModel().getmDanMuLevel(); + mLiveType = TextUtils.equals(String.valueOf(mLiveType), String.valueOf(event.getParametersModel().getmLiveType())) ? mLiveType : event.getParametersModel().getmLiveType(); + mLiveTypeVal = TextUtils.equals(String.valueOf(mLiveTypeVal), String.valueOf(event.getParametersModel().getmLiveTypeVal())) ? mLiveTypeVal : event.getParametersModel().getmLiveTypeVal(); + mLiveGuardInfo = event.getParametersModel().getmLiveGuardInfo() == null ? mLiveGuardInfo : event.getParametersModel().getmLiveGuardInfo(); + liveBg = TextUtils.equals(String.valueOf(liveBg), String.valueOf(event.getParametersModel().getLiveBg())) ? liveBg : event.getParametersModel().getLiveBg(); + is_fans = TextUtils.equals(String.valueOf(is_fans), String.valueOf(event.getParametersModel().getIs_fans())) ? is_fans : event.getParametersModel().getIs_fans(); + fansNum = TextUtils.equals(String.valueOf(fansNum), String.valueOf(event.getParametersModel().getFansNum())) ? fansNum : event.getParametersModel().getFansNum(); break; case ACTIVITY_CENTER://活动中心 String url = CommonAppConfig.HOST + "/h5/live/hallOfFame/index.html?g=Appapi&m=Turntable&a=tricky"; - url += "&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" - + CommonAppConfig.getInstance().getToken() + "&anchorUid=" + mLiveUid + "&isZh=" + (WordUtil.isNewZh() ? "1" : 0); + url += "&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&anchorUid=" + mLiveUid + "&isZh=" + (WordUtil.isNewZh() ? "1" : 0); Log.i("tag", url); Intent intent = new Intent(mContext, ZhuangBanActivity.class); intent.putExtra("url", url); @@ -1331,10 +1244,7 @@ public class LiveAudienceActivity extends LiveActivity { break; case POPULAR: url = CommonAppConfig.HOST + "/h5/activity/PopularityTask/index.html"; - url += "?anchorUid=" + mLiveUid - + "&stream=" + mStream - + "&uid=" + CommonAppConfig.getInstance().getUid() - + "&token=" + CommonAppConfig.getInstance().getToken() + "&isZh=" + (WordUtil.isNewZh() ? "1" : 0); + url += "?anchorUid=" + mLiveUid + "&stream=" + mStream + "&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&isZh=" + (WordUtil.isNewZh() ? "1" : 0); LiveHDDialogFragment liveHDDialogFragment = new LiveHDDialogFragment(); bundle.putString("url", url); bundle.putInt("show_type", 0); @@ -1407,16 +1317,13 @@ public class LiveAudienceActivity extends LiveActivity { } 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(); - } - } - ); + 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: @@ -1485,12 +1392,7 @@ public class LiveAudienceActivity extends LiveActivity { showMsgRed(-1); break; case LIVE_SHARE: - new SharePopDialog(mContext) - .setUid(CommonAppConfig.getInstance().getUid()) - .setAnchorId(event.getBean().getUid()) - .setAnchorName(event.getBean().getUserNiceName()) - .setAnchorAvatar(event.getBean().getAvatar()) - .showDialog(); + new SharePopDialog(mContext).setUid(CommonAppConfig.getInstance().getUid()).setAnchorId(event.getBean().getUid()).setAnchorName(event.getBean().getUserNiceName()).setAnchorAvatar(event.getBean().getAvatar()).showDialog(); break; case WISH_LIST_PROGRESS: if (manager != null) { @@ -1631,22 +1533,14 @@ public class LiveAudienceActivity extends LiveActivity { if (type.equals(bean.getType())) { switch (type) { case "1": - startActivity(new Intent(mContext, SystemMessageActivity.class) - .putExtra("type", bean.getType()) - .putExtra("uid", "") - .putExtra("title", bean.getTitle()) - .putExtra("headImg", "")); + startActivity(new Intent(mContext, SystemMessageActivity.class).putExtra("type", bean.getType()).putExtra("uid", "").putExtra("title", bean.getTitle()).putExtra("headImg", "")); break; case "3": AppEventsLogger.newLogger(mContext).logEvent("FB_customer_service"); if (bean.getLink() != null && !"".equals(bean.getLink())) { WebViewActivity.forward(mContext, bean.getLink(), true); } else { - startActivity(new Intent(mContext, SystemMessageActivity.class) - .putExtra("type", bean.getType()) - .putExtra("uid", "") - .putExtra("title", "") - .putExtra("headImg", "")); + startActivity(new Intent(mContext, SystemMessageActivity.class).putExtra("type", bean.getType()).putExtra("uid", "").putExtra("title", "").putExtra("headImg", "")); } break; @@ -1676,23 +1570,22 @@ public class LiveAudienceActivity extends LiveActivity { map.put("num", "9"); map.put("live_recommend", "sidebar"); //推荐位 - MainNetManager.get(mContext) - .anchorRecommend(map, new com.yunbao.common.http.base.HttpCallback() { - @Override - public void onSuccess(AnchorRecommendModel anchorRecommendModel) { - list.clear(); - slideInfoModels.clear(); - List models = anchorRecommendModel.getList(); + MainNetManager.get(mContext).anchorRecommend(map, new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(AnchorRecommendModel anchorRecommendModel) { + list.clear(); + slideInfoModels.clear(); + List models = anchorRecommendModel.getList(); - list.addAll(models); - slideInfoModels = anchorRecommendModel.getSlide(); - } + list.addAll(models); + slideInfoModels = anchorRecommendModel.getSlide(); + } - @Override - public void onError(String error) { - ToastUtil.show(WordUtil.isNewZh() ? "抱歉!出錯了!" : "i \\'m sorry! An error occurred"); - } - }); + @Override + public void onError(String error) { + ToastUtil.show(WordUtil.isNewZh() ? "抱歉!出錯了!" : "i \\'m sorry! An error occurred"); + } + }); } @@ -1765,11 +1658,7 @@ public class LiveAudienceActivity extends LiveActivity { case 0: if (liveSudGamePopupXPopup == null) { liveSudGamePopupXPopup = new LiveSudGamePopup(mContext, event.getCreateSudRoomModel()); - new XPopup.Builder(mContext) - .enableDrag(false) - .dismissOnTouchOutside(false) - .dismissOnBackPressed(false) - .asCustom(liveSudGamePopupXPopup).show(); + new XPopup.Builder(mContext).enableDrag(false).dismissOnTouchOutside(false).dismissOnBackPressed(false).asCustom(liveSudGamePopupXPopup).show(); } else { if (liveSudGamePopupXPopup != null) { liveSudGamePopupXPopup.dialog.show(); @@ -1865,17 +1754,14 @@ public class LiveAudienceActivity extends LiveActivity { if (!TextUtils.isEmpty(event.getRightsInterests())) { //跳转贵族 if (TextUtils.equals(event.getRightsInterests(), getString(com.yunbao.common.R.string.noble))) { - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.NOBLE)); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.NOBLE)); //跳转守护 } else if (TextUtils.equals(event.getRightsInterests(), getString(com.yunbao.common.R.string.guard_guard))) { - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.GUARD)); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.GUARD)); manager.onGuardRed(); //跳转粉丝团 } else if (TextUtils.equals(event.getRightsInterests(), getString(com.yunbao.common.R.string.fan_club))) { - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.FAN_CLUB)); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.FAN_CLUB)); } } //互动游戏 @@ -1885,12 +1771,10 @@ public class LiveAudienceActivity extends LiveActivity { ToastUtil.show(WordUtil.isNewZh() ? "您已在游戏房间中" : "You are already in the game room"); } else { //直播间来的 - new XPopup.Builder(mContext) - .enableDrag(false) + new XPopup.Builder(mContext).enableDrag(false) // .dismissOnTouchOutside(false) // .dismissOnBackPressed(false) - .moveUpToKeyboard(false) - .asCustom(new SudGameListPopup(mContext, event.getInteractionID(), event.getChild(), mLiveUid)) + .moveUpToKeyboard(false).asCustom(new SudGameListPopup(mContext, event.getInteractionID(), event.getChild(), mLiveUid)) .show(); } @@ -1948,9 +1832,7 @@ public class LiveAudienceActivity extends LiveActivity { new Handler().postDelayed(new Runnable() { @Override public void run() { - new XPopup.Builder(mContext) - .asCustom(new DragonExpirePopup(mContext, mLiveUid, maturityDateRemindModel, mStream)) - .show(); + new XPopup.Builder(mContext).asCustom(new DragonExpirePopup(mContext, mLiveUid, maturityDateRemindModel, mStream)).show(); } }, 3000); @@ -1997,34 +1879,33 @@ public class LiveAudienceActivity extends LiveActivity { private void checkMsgRed() { - LiveNetManager.get(mContext) - .getContactMsg(1, new com.yunbao.common.http.base.HttpCallback>() { - @Override - public void onSuccess(List data) { - Log.i(TAG, "onSuccess: " + data.size()); - for (LiveUserMailBoxModel datum : data) { - Log.i(TAG, "for data : " + datum); - } - setData(data); + LiveNetManager.get(mContext).getContactMsg(1, new com.yunbao.common.http.base.HttpCallback>() { + @Override + public void onSuccess(List data) { + Log.i(TAG, "onSuccess: " + data.size()); + for (LiveUserMailBoxModel datum : data) { + Log.i(TAG, "for data : " + datum); + } + setData(data); + } + + @Override + public void onError(String error) { + Log.e(TAG, "onError: " + error); + setData(new ArrayList<>()); + } + + void setData(List data) { + for (LiveUserMailBoxModel model : data) { + if (model.getIsRead() == 0) { + showMsgRed(0); + return; } - - @Override - public void onError(String error) { - Log.e(TAG, "onError: " + error); - setData(new ArrayList<>()); - } - - void setData(List data) { - for (LiveUserMailBoxModel model : data) { - if (model.getIsRead() == 0) { - showMsgRed(0); - return; - } - } + } - showMsgRed(-1); - } - }); + showMsgRed(-1); + } + }); } } diff --git a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java index 76c3fb7ba..f92e9fe4a 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java @@ -3,7 +3,6 @@ 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_LINK_MIC_PK; 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; @@ -71,6 +70,7 @@ 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; @@ -102,11 +102,12 @@ 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.LiveLinkMicPkPresenter; import com.yunbao.live.presenter.LiveLinkMicPresenter; import com.yunbao.live.presenter.LiveRyLinkMicPkPresenter; +import com.yunbao.live.presenter.LiveSwLinkMicPkPresenter; import com.yunbao.live.socket.SocketRyChatUtil; import com.yunbao.live.socket.SocketRyClient; +import com.yunbao.live.socket.SocketSwClient; import com.yunbao.live.socket.SocketSendBean; import com.yunbao.live.views.LiveEndViewHolder; import com.yunbao.live.views.LiveMusicViewHolder; @@ -193,7 +194,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl if (RandomPkManager.getInstance().isRankModel()) { msg1.put("is_ladders", "https://downs.yaoulive.com/rank_top_box.png"); } - linkMicAnchorApply(pkUid, pkUid, true); + linkMicAnchorApply(pkUid, pkUid, msg1.toString()); } @Override @@ -222,6 +223,27 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl 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); @@ -251,13 +273,6 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl RandomPkManager.getInstance().addOnRandomPkTimer(onRandomPkTimer); - manager.setOnMirrorChanged(new FaceManager.OnMirrorChanged() { - @Override - public void onChange(boolean falg) { - mLivePushViewHolder.setEnableBeauty(falg); - } - }); - //添加开播前设置控件 mLiveReadyViewHolder = new LiveNewReadyRyViewHolder(mContext, mContainer, mLiveSDK); mLiveReadyViewHolder.setManager(manager); @@ -294,8 +309,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl private void initFaceManager() { manager = new FaceManager(); manager.initFURender(mContext); - //暂时去掉 - //manager.drawRongFrame(mContext); + manager.drawRongFrame(mContext); } public boolean isStartPreview() { @@ -406,7 +420,6 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl public void onSuccess(int code, String msg, String[] info) { if (code == 0) { - LiveRyLinkMicPkPresenter.mApplyUid = CommonAppConfig.getInstance().getUid(); btn_start_dr_pk.setVisibility(View.VISIBLE); // dr_pk_view.setVisibility(View.VISIBLE); final SocketSendBean msg1 = new SocketSendBean() @@ -419,7 +432,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); Message message = Message.obtain("g" + mLiveUid, conversationType, messageContent); - RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + RongcloudIMManager.sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { @Override public void onAttached(Message message) { @@ -708,6 +721,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl fragment.show(getSupportFragmentManager(), "LiveLinkMicListDialogFragment");*/ FreePkDialogFragment fragment = new FreePkDialogFragment(); fragment.setDrPkNum(pk_nub); + fragment.setLiveUid(mLiveUid); fragment.show(getSupportFragmentManager(), "LiveLinkMicListDialogFragment"); } @@ -725,6 +739,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl public void openRandomPkWindow() { RandomPkDialogFragment fragment = new RandomPkDialogFragment(); Bundle bundle = new Bundle(); + bundle.putBoolean("isSw",false); fragment.setArguments(bundle); fragment.show(getSupportFragmentManager(), "RandomPkDialogFragment"); } @@ -959,7 +974,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl JSONObject obj = JSON.parseObject(info[0]); JSONObject datas = obj.getJSONObject("data"); try { - SocketRyChatUtil.closeLive(datas.getString("votes"), datas.getString("length"), datas.getString("nums"), mLiveUid, mSocketRyClient); + SocketRyChatUtil.closeLive(datas.getString("votes"), datas.getString("length"), datas.getString("nums"), mLiveUid, mSocketSwClient); } catch (Exception e) { e.printStackTrace(); } @@ -1045,8 +1060,8 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl mLivePushViewHolder = null; mLiveLinkMicPresenter = null; //断开socket - if (mSocketRyClient != null) { - mSocketRyClient.disConnect(); + if (mSocketSwClient != null) { + mSocketSwClient.disConnect(); } super.release(); } @@ -1203,7 +1218,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl */ public void linkMicAnchorApply(String pkUid, String stream) { JSONObject msg1 = buildLinkMicJSON(); - linkMicAnchorApply(pkUid, stream, false); + linkMicAnchorApply(pkUid, stream, msg1.toString()); } public JSONObject buildLinkMicJSON() { @@ -1215,7 +1230,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl return msg1; } - public void linkMicAnchorApply(final String pkUid, String stream, boolean extra) { + public void linkMicAnchorApply(final String pkUid, String stream, String extra) { LiveHttpUtil.livePkCheckLive(pkUid, stream, mStream, new HttpCallback() { @Override @@ -1224,46 +1239,38 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl JSONObject obj = JSON.parseObject(info[0]); if (obj != null) { if (obj.getString("ispk").equals("0")) { - final SocketSendBean msg1 = new SocketSendBean() - .param("_method_", SOCKET_LINK_MIC_PK) - .param("action", 1) - .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) - .param("pkuid", pkUid) - .param("uid", CommonAppConfig.getInstance().getUid()) - .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) - .param("uhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) - .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); - //判断是否是随机PK - if(extra){ - msg1.param("random_pk", "1"); - msg1.param("msgtype","11"); - if (RandomPkManager.getInstance().isRankModel()) { - msg1.param("is_ladders", "https://downs.yaoulive.com/rank_top_box.png"); + + + 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); } } - 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" + pkUid, 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("tx", "发送成功"); - } - - @Override - public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { - Log.e("tx", "发送失败" + errorCode.getMessage()); - - } - }); } else { ToastUtil.show("主播正在PK,稍後再試"); if (RandomPkManager.getInstance().isRandomModel()) { @@ -1289,6 +1296,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl if (mLiveAnchorViewHolder != null) { mLiveAnchorViewHolder.setYaoqing(pkUid); } + } /** @@ -1308,39 +1316,34 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl if (obj != null) { if (obj.getString("ispk").equals("0")) { - // TODO: 2024/4/19 邀请主播进行多人连麦 - final SocketSendBean msg1 = new SocketSendBean() - .param("_method_", SOCKET_LIVE_DRPK) - .param("action", 1) - .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) - .param("pkuid", pkUid) - .param("uid", CommonAppConfig.getInstance().getUid()) - .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) - .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); - msg1.create(); - - String targetId = "g" + pkUid; - Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; - TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); - Message message = Message.obtain(targetId, conversationType, messageContent); - - RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + IMRTCManager.getInstance().requestJoinOtherRoom(pkUid, true, extra, new IRCRTCResultCallback() { @Override - public void onAttached(Message message) { - - } - - @Override - public void onSuccess(Message message) { - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(message.toString() + ""); + 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 onError(Message message, RongIMClient.ErrorCode errorCode) { - Log.e("tx", "aaa" + errorCode.toString()); - ToastUtil.show(errorCode.code + ":" + errorCode.msg); + 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 { @@ -1411,7 +1414,6 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl //多人PK接受 @Override public void onLinkDRMicPkApplyOk(UserBean u) { - L.eSw("onLinkDRMicPkApplyOk111111"); if (mLiveRyLinkMicPkPresenter != null) { mLiveRyLinkMicPkPresenter.onLinkDRMicPkApplyOk(u); } @@ -1672,8 +1674,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl break; case DISCONNEXT_PK_TIME: if (mLivePushViewHolder != null) { - //mLivePushViewHolder.changeToBig(); - mLivePushViewHolder.anchorClose(); + mLivePushViewHolder.changeToBig(); mLiveRyLinkMicPkPresenter.leaveDRRoom(); } break; @@ -1721,6 +1722,15 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl 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; } } @@ -1859,6 +1869,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl .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 = @@ -1872,7 +1883,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl TextMessage messageContent = TextMessage.obtain(msg.mResult.toString()); Message message = Message.obtain(targetId, conversationType, messageContent); - RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + RongcloudIMManager.sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { @Override public void onAttached(Message message) { @@ -1880,8 +1891,8 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl @Override public void onSuccess(Message message) { - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketSwClient.mSocketHandler != null) { + SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } } diff --git a/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java new file mode 100644 index 000000000..bad0121c0 --- /dev/null +++ b/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java @@ -0,0 +1,1939 @@ +package com.yunbao.live.activity; + +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_LINK_MIC_PK; +import static com.yunbao.common.Constants.SOCKET_LIVE_DRPK; +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.MicUserManager; +import com.yunbao.common.manager.MicedUserManager; +import com.yunbao.common.manager.RandomPkManager; +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.LiveSwLinkMicPkPresenter; +import com.yunbao.live.socket.SocketRyChatUtil; +import com.yunbao.live.socket.SocketSwClient; +import com.yunbao.live.socket.SocketSendBean; +import com.yunbao.live.views.LiveEndViewHolder; +import com.yunbao.live.views.LiveMusicViewHolder; +import com.yunbao.live.views.LiveNewReadySwViewHolder; +import com.yunbao.live.views.LivePushSwViewHolder; +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.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.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 LiveSwAnchorActivity extends LiveActivity implements LiveFunctionClickListener { + + private static final String TAG = "LiveSwAnchorActivity"; + + public static void forward(Context context, int liveSdk, LiveKsyConfigBean bean) { + Intent intent = new Intent(context, LiveSwAnchorActivity.class); + intent.putExtra(Constants.LIVE_SDK, liveSdk); + intent.putExtra(Constants.LIVE_KSY_CONFIG, bean); + context.startActivity(intent); + } + + private ViewGroup mRoot; + private ViewGroup mContainerWrap; + public LivePushSwViewHolder mLivePushViewHolder; + public LiveNewReadySwViewHolder 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 isDRPK = 0; + public static boolean PKing = false; + 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, true); + } + + @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(); + leave_img = findViewById(R.id.leave_img); + mLiveSDK = intent.getIntExtra(Constants.LIVE_SDK, Constants.LIVE_SDK_KSY); + if(mLiveSDK ==Constants.LIVE_SDK_SW){ + isSw = true; + } + 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 LivePushSwViewHolder(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); + mLiveSwLinkMicPkPresenter = new LiveSwLinkMicPkPresenter(mContext, mLivePushViewHolder, true, mContainer); + + RandomPkManager.getInstance().addOnRandomPkTimer(onRandomPkTimer); + + manager.setOnMirrorChanged(new FaceManager.OnMirrorChanged() { + @Override + public void onChange(boolean falg) { + mLivePushViewHolder.setEnableBeauty(falg); + } + }); + + //添加开播前设置控件 + mLiveReadyViewHolder = new LiveNewReadySwViewHolder(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.setmLiveUid(mLiveUid); + fragment.show(getSupportFragmentManager(), "LivePrankDialogFragment"); + 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) { + LiveSwLinkMicPkPresenter.mApplyUid = CommonAppConfig.getInstance().getUid(); + 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); + + RongIMClient.getInstance().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); + mLiveSwLinkMicPkPresenter.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); + sendSystemMessage(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); + sendSystemMessage(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(LiveSwAnchorActivity.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()); + 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",true); + 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()); + 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")); + } + if (mLiveAnchorViewHolder == null) { + mLiveAnchorViewHolder = new LiveRyAnchorViewHolder(mContext, mContainer); + mLiveAnchorViewHolder.setLiveBean(mLiveBean); + mLiveAnchorViewHolder.addToParent(); + mLiveAnchorViewHolder.startAnchorLiveTime(); + } + mLiveBottomViewHolder = mLiveAnchorViewHolder; + mSocketSwClient = new SocketSwClient(mLiveUid, this, mContext); + mSocketSwClient.setLivePushSwViewHolder(mLivePushViewHolder); + CommonAppContext.Ingroup = 1; + + if (mLiveLinkMicPresenter != null) { + mLiveLinkMicPresenter.setSocketClient(mSocketClient); + } + if (mLiveLinkMicAnchorPresenter != null) { + mLiveLinkMicAnchorPresenter.setSocketClient(mSocketClient); + mLiveLinkMicAnchorPresenter.setPlayUrl(playUrl); + mLiveLinkMicAnchorPresenter.setSelfStream(mStream); + } + if (mLiveSwLinkMicPkPresenter != null) { + mLiveSwLinkMicPkPresenter.setSelfStream(mStream); + } + if (mLiveSwLinkMicPkPresenter != null) { + mLiveSwLinkMicPkPresenter.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(); + } + + /** + * 关闭直播 + */ + 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, mSocketSwClient); + } 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 (mSocketSwClient != null) { + mSocketSwClient.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, false); + } + + 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, boolean 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")) { + final SocketSendBean msg1 = new SocketSendBean() + .param("_method_", SOCKET_LINK_MIC_PK) + .param("action", 1) + .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) + .param("pkuid", pkUid) + .param("uid", CommonAppConfig.getInstance().getUid()) + .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) + .param("uhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) + .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); + //判断是否是随机PK + if(extra){ + msg1.param("random_pk", "1"); + msg1.param("msgtype","11"); + if (RandomPkManager.getInstance().isRankModel()) { + msg1.param("is_ladders", "https://downs.yaoulive.com/rank_top_box.png"); + } + } + 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" + pkUid, 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("tx", "发送成功"); + } + + @Override + public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { + Log.e("tx", "发送失败" + errorCode.getMessage()); + + } + }); + } else { + ToastUtil.show("主播正在PK,稍後再試"); + 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")) { + + // TODO: 2024/4/19 邀请主播进行多人连麦 + final SocketSendBean msg1 = new SocketSendBean() + .param("_method_", SOCKET_LIVE_DRPK) + .param("action", 1) + .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) + .param("pkuid", pkUid) + .param("uid", CommonAppConfig.getInstance().getUid()) + .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) + .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); + msg1.create(); + + String targetId = "g" + pkUid; + Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; + TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); + Message message = Message.obtain(targetId, conversationType, messageContent); + + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(Message message) { + + } + + @Override + public void onSuccess(Message message) { + if (SocketSwClient.mSocketHandler != null) { + SocketSwClient.mSocketHandler.processBroadcast(message.toString() + ""); + } + } + + @Override + public void onError(Message message, RongIMClient.ErrorCode errorCode) { + Log.e("tx", "aaa" + errorCode.toString()); + ToastUtil.show(errorCode.code + ":" + errorCode.msg); + } + }); + } else { + ToastUtil.show("主播正在PK,稍後再試"); + } + } + } + } + }); + + + } + + /** + * 设置连麦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) && mLiveSwLinkMicPkPresenter != null) { + mLiveSwLinkMicPkPresenter.applyLinkMicPk(pkUid, mStream); + } + } + + /** + * 主播与主播PK 主播收到对方主播发过来的PK申请的回调 + * + * @param u 对方主播的信息 + * @param stream 对方主播的stream + */ + @Override + public void onLinkMicPkApply(UserBean u, String stream, int forwhat) { + if (mLiveSwLinkMicPkPresenter != null) { + mLiveSwLinkMicPkPresenter.onLinkMicPkApply(u, stream, 0); + } + } + + //多人PK接受 + @Override + public void onLinkDRMicPkApply(UserBean u) { + if (mLiveSwLinkMicPkPresenter != null) { + mLiveSwLinkMicPkPresenter.onLinkDRMicPkApply(u); + } + } + + @Override + public void onLinkDRMicPKToUser(UserBean u) { + + } + + //多人PK接受 + @Override + public void onLinkDRMicPkApplyOk(UserBean u) { + L.eSw("onLinkDRMicPkApplyOk111111"); + if (mLiveSwLinkMicPkPresenter != null) { + mLiveSwLinkMicPkPresenter.onLinkDRMicPkApplyOk(u); + } + } + + /** + * 主播与主播PK 对方主播拒绝pk的回调 + */ + @Override + public void onLinkMicPkRefuse() { + if (mLiveSwLinkMicPkPresenter != null) { + mLiveSwLinkMicPkPresenter.onLinkMicPkRefuse(); + } + } + + /** + * 主播与主播PK 对方主播正在忙的回调 + */ + @Override + public void onLinkMicPkBusy() { + if (mLiveSwLinkMicPkPresenter != null) { + mLiveSwLinkMicPkPresenter.onLinkMicPkBusy(); + } + } + + /** + * 主播与主播PK 对方主播无响应的回调 + */ + @Override + public void onLinkMicPkNotResponse() { + if (mLiveSwLinkMicPkPresenter != null) { + mLiveSwLinkMicPkPresenter.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); + } + } + + + /** + * 腾讯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 LiveSwAnchorActivity) { + fragment4Audience.show(((LiveSwAnchorActivity) 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 (mLiveSwLinkMicPkPresenter != null) { + mLiveSwLinkMicPkPresenter.leaveDRRoom(); + } + if (mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.seisShowGif(true); + mLiveRoomViewHolder.endDRGif(); + } +// if (mLiveRoomViewHolder != null) { +// mLiveRoomViewHolder.hotAddVisibility(false); +// } + break; + case LEAVE_PK_SCORE: + if (mLiveSwLinkMicPkPresenter != null) { + mLiveSwLinkMicPkPresenter.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(); + mLivePushViewHolder.anchorClose(); + mLiveSwLinkMicPkPresenter.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; + + } + } + + @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") + .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); + + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(Message message) { + + } + + @Override + public void onSuccess(Message message) { + if (SocketSwClient.mSocketHandler != null) { + SocketSwClient.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/LiveTRTCAnchorActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveTRTCAnchorActivity.java index 0db3b6e73..6f99feee7 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveTRTCAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveTRTCAnchorActivity.java @@ -213,7 +213,7 @@ public class LiveTRTCAnchorActivity extends TRTCBaseActivity { return; } String title = mEditTitle.getText().toString().trim(); - LiveHttpUtil.newcreateRoom(title, mLiveClassID, mLiveType, mLiveTypeVal, null,0, new HttpCallback() { + LiveHttpUtil.newcreateRoom(title, mLiveClassID, mLiveType, mLiveTypeVal, null,0,false, new HttpCallback() { @Override public void onSuccess(int code, String msg, final String[] info) { if (code == 0 && info.length > 0) { diff --git a/live/src/main/java/com/yunbao/live/activity/PDLIiveChatActivity.java b/live/src/main/java/com/yunbao/live/activity/PDLIiveChatActivity.java index 42ce00194..a9f9b3138 100644 --- a/live/src/main/java/com/yunbao/live/activity/PDLIiveChatActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/PDLIiveChatActivity.java @@ -197,8 +197,8 @@ public class PDLIiveChatActivity extends FragmentActivity { LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class); new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal),isSw); } @Override diff --git a/live/src/main/java/com/yunbao/live/activity/WebViewActivityMedal.java b/live/src/main/java/com/yunbao/live/activity/WebViewActivityMedal.java index 3a762d003..3d6e6e089 100644 --- a/live/src/main/java/com/yunbao/live/activity/WebViewActivityMedal.java +++ b/live/src/main/java/com/yunbao/live/activity/WebViewActivityMedal.java @@ -172,7 +172,7 @@ public class WebViewActivityMedal extends AbsActivity { LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class); new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { if (liveBean == null) { return; } @@ -180,7 +180,7 @@ public class WebViewActivityMedal extends AbsActivity { MicStatusManager.getInstance().showDownMicDialog(mContext); return; } - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveTypeVal), Integer.parseInt(liveSdk)); + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveTypeVal), Integer.parseInt(liveSdk),isSw); finish(); } diff --git a/live/src/main/java/com/yunbao/live/activity/ZhuangBanActivity.java b/live/src/main/java/com/yunbao/live/activity/ZhuangBanActivity.java index c55118a49..1ce6a9acd 100644 --- a/live/src/main/java/com/yunbao/live/activity/ZhuangBanActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/ZhuangBanActivity.java @@ -409,7 +409,7 @@ public class ZhuangBanActivity extends AbsActivity { LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class); new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { if (liveBean == null) { return; } @@ -426,7 +426,7 @@ public class ZhuangBanActivity extends AbsActivity { EventBus.getDefault().post(new LiveRoomChangeEvent(liveBean, liveType, Integer.parseInt(liveTypeVal))); finish(); } else { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveTypeVal), Integer.parseInt(liveSdk)); + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveTypeVal), Integer.parseInt(liveSdk),isSw); } finish(); } diff --git a/live/src/main/java/com/yunbao/live/adapter/AnchorUserMicInfoAdapter.java b/live/src/main/java/com/yunbao/live/adapter/AnchorUserMicInfoAdapter.java index 05b04fc0d..b5bff9e8b 100644 --- a/live/src/main/java/com/yunbao/live/adapter/AnchorUserMicInfoAdapter.java +++ b/live/src/main/java/com/yunbao/live/adapter/AnchorUserMicInfoAdapter.java @@ -21,7 +21,6 @@ import com.yunbao.common.CommonAppConfig; import com.yunbao.common.Constants; import com.yunbao.common.adapter.RefreshAdapter; import com.yunbao.common.bean.BaseModel; -import com.yunbao.common.bean.LevelBean; import com.yunbao.common.bean.UserBean; import com.yunbao.common.custom.CommonRefreshView; import com.yunbao.common.dialog.AbsDialogFragment; @@ -37,6 +36,7 @@ import com.yunbao.common.utils.WordUtil; import com.yunbao.live.R; import com.yunbao.live.activity.LiveActivity; import com.yunbao.live.socket.SocketSendBean; +import com.yunbao.live.socket.SocketSwClient; import com.yunbao.live.utils.LiveTextRender; import java.net.MalformedURLException; @@ -173,7 +173,7 @@ public class AnchorUserMicInfoAdapter extends RefreshAdapter { /** * 发送IM消息 * - * @param action 4为同意请求,1为邀请,其余见 {@link com.yunbao.live.socket.SocketRyClient} Constants.LIAN_MAI解析 + * @param action 4为同意请求,1为邀请,其余见 {@link SocketSwClient} Constants.LIAN_MAI解析 */ void applyMic(UserBean bean, int action, SocketSendBean msg) { msg.param("action", action); 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 3f2a0cbf6..065f13413 100644 --- a/live/src/main/java/com/yunbao/live/adapter/FreePkRecyclerAdapter.java +++ b/live/src/main/java/com/yunbao/live/adapter/FreePkRecyclerAdapter.java @@ -22,6 +22,7 @@ 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 java.util.Arrays; import java.util.HashMap; @@ -35,6 +36,7 @@ public class FreePkRecyclerAdapter extends RefreshAdapter { private static final int ITEM = 2; private int freePkNum;//PK次数 private int mDrPkNum = -1;//多人PK剩余次数,为-1则认为是单人PK + private String liveUid; public void setFreePkNum(int freePkNum) { this.freePkNum = freePkNum; @@ -48,6 +50,10 @@ public class FreePkRecyclerAdapter extends RefreshAdapter { this.mDrPkNum = mDrPkNum; } + public void setLiveUid(String liveUid) { + this.liveUid = liveUid; + } + @NonNull @Override public HeadViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { @@ -128,8 +134,7 @@ public class FreePkRecyclerAdapter extends RefreshAdapter { ToastUtil.show(mContext.getString(R.string.free_pk_num_null)); // return; } - - LiveHttpUtil.getMicList(LiveRyAnchorActivity.mLiveUid, 0, new com.yunbao.common.http.HttpCallback() { + LiveHttpUtil.getMicList(liveUid, 0, new com.yunbao.common.http.HttpCallback() { @Override public void onSuccess(int code, String msg, String[] info) { System.out.println("code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info)); @@ -142,8 +147,14 @@ public class FreePkRecyclerAdapter extends RefreshAdapter { ToastUtil.show("invite " + bean.getUserNiceName() + " successful"); } mOnItemClickListener.onItemClick(bean, -1); - ((LiveRyAnchorActivity) mContext).linkMicAnchorApply(bean.getId(), bean.getId(), - false); + if(mContext instanceof LiveSwAnchorActivity){ + ((LiveSwAnchorActivity) mContext).linkMicAnchorApply(bean.getId(), bean.getId(), + false); + }else{ + ((LiveRyAnchorActivity) mContext).linkMicAnchorApply(bean.getId(), bean.getId(), + ((LiveRyAnchorActivity) mContext).buildLinkMicJSON().toString() + ); + } return; } if (mDrPkNum <= 0) { @@ -156,7 +167,11 @@ public class FreePkRecyclerAdapter extends RefreshAdapter { } yaoqing.put(bean.getId(), bean.getId()); if (yaoqing.size() < 5) { - ((LiveRyAnchorActivity) mContext).linkDrMicAnchorApply(bean.getId(), bean.getId()); + 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"); } diff --git a/live/src/main/java/com/yunbao/live/adapter/LiveFunctionAdapter.java b/live/src/main/java/com/yunbao/live/adapter/LiveFunctionAdapter.java index 338c84bb9..167dd8a0f 100644 --- a/live/src/main/java/com/yunbao/live/adapter/LiveFunctionAdapter.java +++ b/live/src/main/java/com/yunbao/live/adapter/LiveFunctionAdapter.java @@ -13,7 +13,7 @@ import androidx.recyclerview.widget.RecyclerView; import com.yunbao.common.Constants; import com.yunbao.common.interfaces.OnItemClickListener; import com.yunbao.live.R; -import com.yunbao.live.activity.LiveRyAnchorActivity; +import com.yunbao.live.activity.LiveSwAnchorActivity; import com.yunbao.live.bean.LiveFunctionBean; import java.util.ArrayList; @@ -38,11 +38,10 @@ public class LiveFunctionAdapter extends RecyclerView.Adapter mLiveRoomHandler.postDelayed(() -> ((LiveRyAnchorActivity) (mContext)).mLiveRoomViewHolder.initAnchorSayData(), 1000)).showDialog(); + new LiveAnchorSayPopDialog(mContext).setLiveUid(liveUid).setOnItemClickListener(new OnItemClickListener() { + @Override + public void onItemClick(LiveAnchorSayModel bean, int position) { + mLiveRoomHandler.postDelayed(new Runnable() { + @Override + public void run() { + if (mContext instanceof LiveSwAnchorActivity) { + ((LiveSwAnchorActivity) (mContext)).mLiveRoomViewHolder.initAnchorSayData(); + } else { + ((LiveRyAnchorActivity) (mContext)).mLiveRoomViewHolder.initAnchorSayData(); + } + } + }, 1000); + } + }).showDialog(); } else if (id == R.id.live_tool_qa) { new LiveAnchorCreateQADialog(mContext).setLiveUid(liveUid).showDialog(); } else if (id == R.id.live_tool_game) { - LiveNetManager.get(mContext) - .getCustomSidebarInfo("1", new HttpCallback>() { - @Override - public void onSuccess(List data) { - for (CustomSidebarInfoModel datum : data) { - if (datum.getType().equals("6")) { - //直播间来的 - new XPopup.Builder(mContext) - .enableDrag(false) - .moveUpToKeyboard(false) + LiveNetManager.get(mContext).getCustomSidebarInfo("1", new HttpCallback>() { + @Override + public void onSuccess(List data) { + for (CustomSidebarInfoModel datum : data) { + if (datum.getType().equals("6")) { + //直播间来的 + new XPopup.Builder(mContext).enableDrag(false).moveUpToKeyboard(false) // .dismissOnTouchOutside(false) // .dismissOnBackPressed(false) - .asCustom(new SudGameListPopup(mContext, 0, datum.getChild(), liveUid)) + .asCustom(new SudGameListPopup(mContext, 0, datum.getChild(), liveUid)) - .show(); - return; - } - } + .show(); + return; } + } + } - @Override - public void onError(String error) { + @Override + public void onError(String error) { - } - }); + } + }); dismiss(); } } diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveNewGuardBuyDialogFragment.java b/live/src/main/java/com/yunbao/live/dialog/LiveNewGuardBuyDialogFragment.java index af918e29c..915b38355 100644 --- a/live/src/main/java/com/yunbao/live/dialog/LiveNewGuardBuyDialogFragment.java +++ b/live/src/main/java/com/yunbao/live/dialog/LiveNewGuardBuyDialogFragment.java @@ -42,7 +42,7 @@ 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.activity.LiveSwAnchorActivity; import com.yunbao.live.adapter.GuardRightAdapter; import com.yunbao.live.adapter.LiveNewGuardBuyItemsAdapter; import com.yunbao.live.bean.GuardBuyBean; @@ -305,7 +305,7 @@ public class LiveNewGuardBuyDialogFragment extends AbsDialogFragment implements private void gotoBack() { dismiss(); - ((LiveActivity) mContext).openNewGuardListWindow(mContext instanceof LiveRyAnchorActivity); + ((LiveActivity) mContext).openNewGuardListWindow(mContext instanceof LiveSwAnchorActivity); } /** diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveNewWishListDialogFragment.java b/live/src/main/java/com/yunbao/live/dialog/LiveNewWishListDialogFragment.java index b1a7905d0..6f56ecd5b 100644 --- a/live/src/main/java/com/yunbao/live/dialog/LiveNewWishListDialogFragment.java +++ b/live/src/main/java/com/yunbao/live/dialog/LiveNewWishListDialogFragment.java @@ -25,7 +25,7 @@ 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.LiveNewWishListAdapter; import com.yunbao.live.bean.LiveWishlistBean; import com.yunbao.live.event.LiveAudienceEvent; @@ -119,7 +119,7 @@ public class LiveNewWishListDialogFragment extends AbsDialogFragment implements @Override public void onSuccess(int code, String msg, String[] info) { if (code == 0 && info.length > 0) { - ToastUtil.show(WordUtil.isNewZh()?"修改成功":"Success"); + ToastUtil.show(WordUtil.isNewZh() ? "修改成功" : "Success"); dismiss(); } else { ToastUtil.show("修改失败" + (msg.isEmpty() ? "" : msg)); @@ -178,17 +178,16 @@ public class LiveNewWishListDialogFragment extends AbsDialogFragment implements } - /** * 心愿单打开礼物窗口 */ public void openGiftWindow() { LiveGiftDialogFragment4Wishlist fragment = new LiveGiftDialogFragment4Wishlist(); - Log.e("ry",getTag()); - if(getTag().equals("TX")) { + Log.e("ry", getTag()); + if (mContext instanceof LiveSwAnchorActivity) { + fragment.show(((LiveSwAnchorActivity) mContext).getSupportFragmentManager(), "LiveGiftDialogFragment"); + } else { fragment.show(((LiveAnchorActivity) mContext).getSupportFragmentManager(), "LiveGiftDialogFragment"); - }else{ - fragment.show(((LiveRyAnchorActivity) mContext).getSupportFragmentManager(), "LiveGiftDialogFragment"); } } 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 21f31a484..c2aff85c3 100644 --- a/live/src/main/java/com/yunbao/live/dialog/LiveOldUserDialogFragment.java +++ b/live/src/main/java/com/yunbao/live/dialog/LiveOldUserDialogFragment.java @@ -145,7 +145,7 @@ public class LiveOldUserDialogFragment extends AbsDialogFragment implements View LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class); new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { if (liveBean == null) { return; } diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveUserDialogFragment.java b/live/src/main/java/com/yunbao/live/dialog/LiveUserDialogFragment.java index 79d4166a1..4ab67742a 100644 --- a/live/src/main/java/com/yunbao/live/dialog/LiveUserDialogFragment.java +++ b/live/src/main/java/com/yunbao/live/dialog/LiveUserDialogFragment.java @@ -52,7 +52,7 @@ import com.yunbao.common.views.weight.ViewClicksAntiShake; 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.event.LiveAudienceEvent; import com.yunbao.live.utils.LiveTextRender; @@ -663,7 +663,7 @@ public class LiveUserDialogFragment extends AbsDialogFragment implements View.On LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class); new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { if (liveBean == null) { return; } @@ -722,7 +722,7 @@ public class LiveUserDialogFragment extends AbsDialogFragment implements View.On } else if (i == R.id.btn_guard) { if (TextUtils.equals(mLiveUid, "uid")) return; MobclickAgent.onEvent(mContext, "anchor_avatar_guard", "守护按钮"); - ((LiveActivity) mContext).openNewGuardListWindow(mContext instanceof LiveRyAnchorActivity, mToUid); + ((LiveActivity) mContext).openNewGuardListWindow(mContext instanceof LiveSwAnchorActivity, mToUid); } else if (i == R.id.btn_live) { gotoLive(mToUid); } else if (i == R.id.noble_icon_layout) { diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveUserMoreDialogFragment.java b/live/src/main/java/com/yunbao/live/dialog/LiveUserMoreDialogFragment.java index 5f68adfbb..cc589f42e 100644 --- a/live/src/main/java/com/yunbao/live/dialog/LiveUserMoreDialogFragment.java +++ b/live/src/main/java/com/yunbao/live/dialog/LiveUserMoreDialogFragment.java @@ -36,7 +36,7 @@ import com.yunbao.common.http.HttpCallback; import com.yunbao.common.utils.DpUtil; import com.yunbao.live.R; import com.yunbao.live.activity.LiveActivity; -import com.yunbao.live.activity.LiveRyAnchorActivity; +import com.yunbao.live.activity.LiveSwAnchorActivity; import com.yunbao.live.adapter.UserMoreInfoAdapter; import com.yunbao.live.bean.LiveGuardInfo; import com.yunbao.common.http.LiveHttpUtil; @@ -144,7 +144,7 @@ public class LiveUserMoreDialogFragment extends AbsDialogFragment implements Vie ((LiveActivity) mContext).openLuckGiftTip(); } else if (Tips.equals("2")) { dismiss(); - ((LiveActivity) mContext).openNewGuardListWindow(mContext instanceof LiveRyAnchorActivity); + ((LiveActivity) mContext).openNewGuardListWindow(mContext instanceof LiveSwAnchorActivity); } else if (Tips.equals("3")) { dismiss(); ((LiveActivity) mContext).openFansWindow(); 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 12eb62dd7..616fdd1f0 100644 --- a/live/src/main/java/com/yunbao/live/dialog/LiveWishListDialogFragment.java +++ b/live/src/main/java/com/yunbao/live/dialog/LiveWishListDialogFragment.java @@ -22,6 +22,7 @@ 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; import com.yunbao.common.http.LiveHttpConsts; @@ -192,8 +193,8 @@ public class LiveWishListDialogFragment extends AbsDialogFragment implements OnI public void openGiftWindow() { LiveGiftDialogFragment4Wishlist fragment = new LiveGiftDialogFragment4Wishlist(); Log.e("ry",getTag()); - if(getTag().equals("TX")) { - fragment.show(((LiveAnchorActivity) mContext).getSupportFragmentManager(), "LiveGiftDialogFragment"); + 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 f5c7f0666..5112dd593 100644 --- a/live/src/main/java/com/yunbao/live/dialog/RandomPkDialogFragment.java +++ b/live/src/main/java/com/yunbao/live/dialog/RandomPkDialogFragment.java @@ -23,6 +23,7 @@ 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; import java.util.Arrays; @@ -36,6 +37,7 @@ public class RandomPkDialogFragment extends AbsDialogFragment implements View.On private TextView mPkBtnTitle; private TextView mPkBtnDesc; private ImageView mRandomPkSwitch; + private boolean isSw ; private final RandomPkManager.OnRandomPkTimer randomPkTimer = new RandomPkManager.OnRandomPkTimer() { @@ -124,6 +126,7 @@ public class RandomPkDialogFragment extends AbsDialogFragment implements View.On @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); + isSw = getArguments().getBoolean("isSw"); initView(); initData(); RandomPkManager.debugUid = null; @@ -260,14 +263,13 @@ public class RandomPkDialogFragment extends AbsDialogFragment implements View.On } else { ToastUtil.show("The random PK switch is not enabled"); } - return; } if ((mPkBtn.getTag() != null && (boolean) mPkBtn.getTag()) || RandomPkManager.getInstance().isRequestPk()) { RandomPkManager.getInstance().exitPk(); return; } - LiveHttpUtil.getMicList(LiveRyAnchorActivity.mLiveUid, 0, new HttpCallback() { + LiveHttpUtil.getMicList(isSw?LiveSwAnchorActivity.mLiveUid: LiveRyAnchorActivity.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/event/LiveAudienceEvent.java b/live/src/main/java/com/yunbao/live/event/LiveAudienceEvent.java index 55e5044e4..30de0e49e 100644 --- a/live/src/main/java/com/yunbao/live/event/LiveAudienceEvent.java +++ b/live/src/main/java/com/yunbao/live/event/LiveAudienceEvent.java @@ -489,7 +489,8 @@ public class LiveAudienceEvent extends BaseModel { UPDATE_FANS_TASK_STATUS(74, "更新粉丝任务状态"), SUD_GAME_CREATE_ROOM(75, "主播创建sud游戏"), PK_RANK_START(76, "PK排位赛开始"), - GuardSpecialEffect(77, "PK排位赛开始"); + GuardSpecialEffect(77, "PK排位赛开始"), + LIVE_DIALOG_ANCHOR_TIPS(78, "主播公会赛tips"); private int type; private String name; diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveGiftAnimPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveGiftAnimPresenter.java index b73e45d18..1696e56af 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveGiftAnimPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveGiftAnimPresenter.java @@ -452,7 +452,7 @@ public class LiveGiftAnimPresenter { LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class); new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { if (liveBean == null) { return; } diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java index 8357e9d30..4c4f563ed 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java @@ -29,7 +29,6 @@ import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.PopupWindow; @@ -38,7 +37,6 @@ import android.widget.TextView; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; -import com.google.gson.Gson; import com.tencent.trtc.TRTCCloud; import com.yunbao.common.CommonAppConfig; import com.yunbao.common.bean.LiveInfoModel; @@ -51,10 +49,10 @@ 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; @@ -62,18 +60,14 @@ 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.DrPkbean; import com.yunbao.live.bean.LivePKUserListBean; import com.yunbao.live.custom.ProgressTextView; import com.yunbao.live.event.LiveAudienceEvent; -import com.yunbao.live.event.LiveOpenSuccessEvent; -import com.yunbao.live.event.LivePKRightUserInfoEvent; 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.LivePlayRyViewHolder; import com.yunbao.live.views.LivePushRyViewHolder; import org.greenrobot.eventbus.EventBus; @@ -102,7 +96,6 @@ 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.agora.beautyapi.faceunity.agora.SWManager; import io.rong.imlib.IRongCallback; import io.rong.imlib.RongIMClient; import io.rong.imlib.model.Conversation; @@ -167,8 +160,6 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { public static List inputStreamList1 = new ArrayList<>(); private boolean DRInitiator = false;//是否是duorenPK发起人 - private List drPkbeans = new ArrayList<>(); - public LiveRyLinkMicPkPresenter setDRInitiator(boolean DRInitiator) { this.DRInitiator = DRInitiator; return this; @@ -403,34 +394,50 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { 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]); + 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()); + 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")); + 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) { + 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) { + + } + }); + } + }); - } - }); } - }); - - } - } - }); + } + }); } } @@ -517,44 +524,137 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { /** * 主播与主播PK 主播收到其他主播发过来的多人PK申请同意了的回调 */ + public void onLinkDRMicPkApplyOk(UserBean u) { - L.eSw("onLinkDRMicPkApplyOk(UserBean u) " + u.getUserNiceName()); - int index = 0; - if (livePushRyViewHolder != null) { - livePushRyViewHolder.setAnDrPkRtc(String.valueOf(u.getId()), -1); - } - final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LIVE_DRPK) - .param("action", 3) - .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) - .param("pkuid", CommonAppConfig.getInstance().getUid()) - .param("type", 3) - .param("uid", u.getId()) - .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) - .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); - 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); - - RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + /** + * 加入副房间 + * + * 前提必须已经 通过 {@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 onAttached(io.rong.imlib.model.Message message) { + 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 onSuccess(io.rong.imlib.model.Message message) { - } - - @Override - public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { - Log.e("tx", "aaa" + errorCode.toString()); - ToastUtil.show(errorCode.code + ":" + errorCode.msg); + public void onFailed(RTCErrorCode rtcErrorCode) { + Log.i("ry", "加入其他房间失败 :" + rtcErrorCode.getReason()); } }); - dRjoinOtherRoom(u); + } /** @@ -584,21 +684,129 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { public void onLinkMicToPk(UserBean u) { EventBus.getDefault().post(new AnchorInfoEvent(false, u.getId(), u.getUserNiceName(), u.getAvatar())); Log.e("eve", u.getId() + ""); - L.eSw("主播接受了主播的PK邀請"); + /** + * 加入副房间 + * + * 前提必须已经 通过 {@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; - livePushRyViewHolder.setAnPkRtc(u);//设置对方主播视图 + 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); - 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()); + 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(); - LivePushRyViewHolder.btn_close.setVisibility(View.VISIBLE); - /*Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; + 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); - RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + RongcloudIMManager.sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { @Override public void onAttached(io.rong.imlib.model.Message message) { @@ -614,12 +822,11 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { Log.e("tx", "发送失败" + errorCode.getMessage()); } - });*/ + }); } private void isPK(UserBean bean) { - EventBus.getDefault().post(new AnchorInfoEvent(false, bean.getId(), bean.getUserNiceName(), bean.getAvatar())); ScreenDimenUtil util = ScreenDimenUtil.getInstance(); int mScreenWdith = util.getScreenWdith(); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, mScreenWdith * 720 / 960); @@ -631,56 +838,127 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { LivePushRyViewHolder.btn_close.setVisibility(View.VISIBLE); LiveRyAnchorActivity.isDRPK = 1; - /*---------------------------------------------------------------- */ - final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK) - .param("action", 2) //回复PK申请 2 - .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) - .param("pkuid", bean.getId()) - .param("uid", CommonAppConfig.getInstance().getUid()) - .param("uhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) - .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) - .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); - if (RandomPkManager.getInstance().isRankModel()) { - L.eSw("排位赛"); - msg1.param("is_ladders", "https://downs.yaoulive.com/rank_top_box.png"); + 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()); } - msg1.param("is_ladders", "https://downs.yaoulive.com/rank_top_box.png"); - msg1.create(); System.out.println("PK回执 = " + msg1.toString()); - 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( bean.getId(), conversationType, messageContent); - - RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + IMRTCManager.getInstance().responseJoinOtherRoom(mApplyUid, true, msg1.toString(), new IRCRTCResultCallback() { @Override - public void onAttached(io.rong.imlib.model.Message message) { + 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 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()); - + public void onFailed(RTCErrorCode errorCode) { + ToastUtil.show("接受失败"); } }); - // TODO: 2024/4/12 视图渲染 - livePushRyViewHolder.setAnPkRtc(bean); - 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); - } - }); } //与用户连麦 @@ -772,9 +1050,6 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { isPK(u); } else { if (mPkWaitCount < 0) { - if(rtcRoom==null){ - return; - } rtcRoom.getLocalUser().responseJoinOtherRoom(u.getId(), u.getId(), false, false, "extra", new IRCRTCResultCallback() { @Override @@ -784,7 +1059,9 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { @Override public void onSuccess() { - final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 8); + final SocketSendBean msg1 = new SocketSendBean() + .param("_method_", SOCKET_LINK_MIC_PK) + .param("action", 8); msg1.create(); String targetId = u.getId(); @@ -792,7 +1069,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { 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() { + RongcloudIMManager.sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { @Override public void onAttached(io.rong.imlib.model.Message message) { @@ -864,12 +1141,82 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { public void run() { if (btn_close != null) { btn_close.setVisibility(View.GONE); - livePushRyViewHolder.timeTitle.setVisibility(View.GONE); } } }); - livePushRyViewHolder.exitChannelDrPk(drPkbeans); - leaveHandler.removeCallbacks(leaveRunnable); + + 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()); @@ -877,12 +1224,15 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { @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.dr2_preview.removeAllViews(); livePushRyViewHolder.dr3_preview.removeAllViews(); - livePushRyViewHolder.dr4_preview.removeAllViews(); livePushRyViewHolder.cameraPreview3.removeAllViews(); leaveHandler.removeCallbacks(leaveRunnable); livePushRyViewHolder.timeTitle.setVisibility(View.GONE); @@ -895,70 +1245,82 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { * 随机PK拒绝对话框 */ public 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()); + 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 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(); - } + 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); } - }; - 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 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); - } + @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(); - ((TextView) title).setText("您因拒絕隨機PK,被限制關閉中"); - ((TextView) confirmBtn).setText("确定"); - ((TextView) context).setText("隨機PK可打開時間:" + 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 showClose(Dialog dialog, View title, View context, View confirmBtn, View cancelBtn) { + task.cancel(); + ((TextView) title).setText("您因拒絕隨機PK,被限制關閉中"); + ((TextView) confirmBtn).setText("确定"); + ((TextView) context).setText("隨機PK可打開時間:" + 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() { - isPK(u); - } - }).build().show(); + void apply() { + isPK(u); + } + }) + .build().show(); } private void refusePk(UserBean u) { @@ -971,7 +1333,8 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { @Override public void onSuccess() { - final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK) + final SocketSendBean msg1 = new SocketSendBean() + .param("_method_", SOCKET_LINK_MIC_PK) // .param("randomPk",u.isRandomPk()+"") .param("action", 3); msg1.create(); @@ -981,7 +1344,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { 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() { + RongcloudIMManager.sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { @Override public void onAttached(io.rong.imlib.model.Message message) { @@ -1006,7 +1369,6 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { LiveNetManager.get(mContext).setBanRandomPK(null); } - /** * 显示申请多人PK的弹窗 */ @@ -1030,215 +1392,135 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { } if (mAcceptPk) { - 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; - if (finalAgree) { - HttpClient.getInstance().get("live.joinDRPKroom", "live.joinDRPKroom").params("uid", CommonAppConfig.getInstance().getUid()).params("roomid", u.getId()).execute(new HttpCallback() { + 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) { - L.eSw("多人PK" + "code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info)); - if (info.length == 0) { - return; - } - JSONObject obj = JSONObject.parseObject(info[0]); - drPkbeans = JSONObject.parseArray(obj.getString("userlist"), DrPkbean.class); - SWManager.get().setDimensions(3);//加入成功后,将分别率设置为 VD_320x240 - //将自己从多人pk列表里剔除 - int removeIndex = -1; - for (int i = 0; i < drPkbeans.size(); i++) { - if (CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))) { - removeIndex = i; + 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; } - } - if (removeIndex != -1) { - drPkbeans.remove(removeIndex); - L.eSw("将自己从多人pk列表里剔除" + new Gson().toJson(drPkbeans)); - } + 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() { - HttpClient.getInstance().get("Live.getDRPKroom", "Live.getDRPKroom").params("uid", CommonAppConfig.getInstance().getUid()).params("roomid", mApplyUid).execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - if (info.length > 0) { - JSONObject obj = JSONObject.parseObject(info[0]); - drPkbeans = JSONObject.parseArray(obj.getString("userlist"), DrPkbean.class); - for (int i = 0; i < drPkbeans.size(); i++) { - if (!CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))) { - final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LIVE_DRPK) - .param("action", 2) - .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) - .param("pkuid", CommonAppConfig.getInstance().getUid()) - .param("msgtype", 2) - .param("uid", drPkbeans.get(i).getId()) - .param("uhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) - .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) - .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); - msg1.create(); - L.eSw("uiduiduiduiduiduiduiduid"+drPkbeans.get(i).getId()); - String targetId = String.valueOf(drPkbeans.get(i).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); + @Override + public void onSuccess(int code, String msg, String[] info) { + Log.i("多人PK", "code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info)); - RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { - @Override - public void onAttached(io.rong.imlib.model.Message message) { + 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) { - } + } - @Override - public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { - Log.e("tx", "aaa" + errorCode.toString()); - ToastUtil.show(errorCode.code + ":" + errorCode.msg); - } - }); + @Override + public void onSuccess(io.rong.imlib.model.Message message) { + Log.e("ry", "发送成功"); + if (SocketRyClient.mSocketHandler != null) { + SocketRyClient.mSocketHandler.processBroadcast(msg1.mResult.toString() + ""); + } + } - // - int index = livePushRyViewHolder.setAnDrPkRtc(String.valueOf(drPkbeans.get(i).getId()), -1); + @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"); - L.eSw("onLinkDRMicPkApplyOk(UserBean u)-点击接收 1 " + u.getUserNiceName()); - L.eSw("發送action = 2"); + //添加水印 +// 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() { + } - if (!CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))) { - final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LIVE_DRPK) - .param("action", 3) - .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) - .param("pkuid", CommonAppConfig.getInstance().getUid()) - .param("msgtype", 3) - .param("uid", drPkbeans.get(i).getId()) - .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) - .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); - msg1.create(); - L.eSw("發送給自己直播間"+drPkbeans.get(i).getId()); - 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); + @Override + public void onFailed(RTCErrorCode errorCode) { - 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) { - } - - @Override - public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { - Log.e("tx", "aaa" + errorCode.toString()); - ToastUtil.show(errorCode.code + ":" + errorCode.msg); - } - }); - } - - - if(!mApplyUid.equals(String.valueOf(drPkbeans.get(i).getId()))&&!CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))){ - final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LIVE_DRPK) - .param("action", 3) - .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) - .param("pkuid", CommonAppConfig.getInstance().getUid()) - .param("msgtype", 3) - .param("uid", drPkbeans.get(i).getId()) - .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) - .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); - msg1.create(); - L.eSw("發送給其他主播直播间"+drPkbeans.get(i).getId()); - String targetId = "g" + drPkbeans.get(i).getId(); - 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); - - 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) { - } - - @Override - public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { - Log.e("tx", "aaa" + errorCode.toString()); - ToastUtil.show(errorCode.code + ":" + errorCode.msg); - } - }); - } + } + }); + } + } + } + } + }); } - dRjoinOtherRoom(u); } - } - }); - - /*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) { - - } - }); + @Override + public void onFailed(RTCErrorCode errorCode) { + ToastUtil.show("接受失败"); } - } - }*/ + }); + } else { + ToastUtil.show(msg); + } } + }); - } - } else { - ToastUtil.show(msg); - } + + } - - }); - - - } - } - }); + } + }); } else { @@ -1252,7 +1534,9 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { @Override public void onSuccess() { - final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 8); + final SocketSendBean msg1 = new SocketSendBean() + .param("_method_", SOCKET_LINK_MIC_PK) + .param("action", 8); msg1.create(); String targetId = u.getId(); @@ -1260,7 +1544,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { 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() { + RongcloudIMManager.sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { @Override public void onAttached(io.rong.imlib.model.Message message) { @@ -1292,7 +1576,9 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { @Override public void onSuccess() { - final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 3); + final SocketSendBean msg1 = new SocketSendBean() + .param("_method_", SOCKET_LINK_MIC_PK) + .param("action", 3); msg1.create(); String targetId = u.getId(); @@ -1300,7 +1586,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { 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() { + RongcloudIMManager.sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { @Override public void onAttached(io.rong.imlib.model.Message message) { @@ -1336,134 +1622,190 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { } } - public void setMyDrPkDetailsView() { - if (detailsView1 != null) { - livePushRyViewHolder.dr1_preview.removeView(detailsView1); - } - 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); - textPkName1 = detailsView1.findViewById(R.id.text_pk_name1); - imageGrade1.setTag(String.valueOf(IMLoginManager.get(mContext).getUserInfo().getId())); - livePushRyViewHolder.dr1_preview.addView(detailsView1); - detailsLinearLayout1.setVisibility(View.GONE); - linearGrade1.setVisibility(View.GONE); - } - - - public void setPkUserInfoView(UserBean userBean){ - - } //多人PK接受申请画 加入副房间 - public void dRjoinOtherRoom(UserBean u) { - setMyDrPkDetailsView(); - HttpClient.getInstance().get("Live.getDRPKroom", "Live.getDRPKroom").params("uid", CommonAppConfig.getInstance().getUid()).params("roomid", mApplyUid).execute(new HttpCallback() { + 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(int code, String msg, String[] info) { - if (info.length > 0) { - JSONObject obj = JSONObject.parseObject(info[0]); - drPkbeans = JSONObject.parseArray(obj.getString("userlist"), DrPkbean.class); - int removeIndex = -1; - for (int i = 0; i < drPkbeans.size(); i++) { - if (CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))) { - removeIndex = i; + 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 (removeIndex != -1) { - drPkbeans.remove(removeIndex); - } - setDrPkUserInfoView(drPkbeans); - } + }); + } + + @Override + public void onFailed(RTCErrorCode rtcErrorCode) { + Log.e("ry", mApplyUid + "加入其他房间失败 :" + rtcErrorCode); + Log.i("ry", mApplyUid + "加入其他房间失败 :" + rtcErrorCode); } }); } - private void setDrPkUserInfoView(List drPkbeanList) { - L.eSw("setDrPkUserInfoView" + new Gson().toJson(drPkbeanList)); - mHandler.postDelayed(new Runnable() { - @Override - public void run() { - for (int j = 0; j < drPkbeanList.size(); j++) { - if (j == 0) { - L.eSw("j == 0:" + j); - //设置多人PK数据 - if (detailsView2 != null) { - livePushRyViewHolder.dr2_preview.removeView(detailsView2); - } - 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(drPkbeanList.get(0).getId())); - textPkName2.setText(drPkbeanList.get(0).getUser_nicename()); - livePushRyViewHolder.dr2_preview.addView(detailsView2); - detailsLinearLayout2.setVisibility(View.GONE); - linearGrade2.setVisibility(View.GONE); - } else if (j == 1) { - L.eSw("j == 1:" + j); - if (detailsView4 != null) { - livePushRyViewHolder.dr4_preview.removeView(detailsView4); - } - 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(String.valueOf(drPkbeanList.get(1).getId())); - textPkName4.setText(drPkbeanList.get(1).getUser_nicename()); - livePushRyViewHolder.dr4_preview.addView(detailsView4); - detailsLinearLayout4.setVisibility(View.GONE); - linearGrade4.setVisibility(View.GONE); - } else if (j == 2) { - L.eSw("j == 2:" + j); - - if (detailsView4 != null) { - livePushRyViewHolder.dr4_preview.removeView(detailsView4); - } - 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(String.valueOf(drPkbeanList.get(2).getId())); - textPkName4.setText(drPkbeanList.get(2).getUser_nicename()); - livePushRyViewHolder.dr4_preview.addView(detailsView4); - detailsLinearLayout4.setVisibility(View.GONE); - linearGrade4.setVisibility(View.GONE); - - if (detailsView3 != null) { - livePushRyViewHolder.dr3_preview.removeView(detailsView3); - } - 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(String.valueOf(drPkbeanList.get(1).getId())); - textPkName3.setText(drPkbeanList.get(1).getUser_nicename()); - livePushRyViewHolder.dr3_preview.addView(detailsView3); - detailsLinearLayout3.setVisibility(View.GONE); - linearGrade3.setVisibility(View.GONE); - - - ToastUtil.show(WordUtil.isNewZh() ? "接受成功" : "Success"); - - } - } - } - }, 2000); - L.eSw("dRjoinOtherRoom:size:" + drPkbeanList.size() + " json " + new Gson().toJson(drPkbeanList)); - - } - /** * 多人PK PK主播发过来的已经接受 */ @@ -1479,7 +1821,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { * @group 房间管理 */ - /*RCRTCEngine.getInstance().joinOtherRoom(u, new IRCRTCResultDataCallback() { + RCRTCEngine.getInstance().joinOtherRoom(u, new IRCRTCResultDataCallback() { @Override public void onSuccess(RCRTCOtherRoom rcrtcOtherRoom) { rcrtcOtherRoom.registerOtherRoomEventsListener(otherRoomEventsListener); @@ -1653,7 +1995,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { public void onFailed(RTCErrorCode rtcErrorCode) { Log.i("ry", "加入其他房间失败 :" + rtcErrorCode.getReason()); } - });*/ + }); } @@ -1905,7 +2247,6 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { * 主播与主播PK 所有人收到PK开始的回调 */ public void onLinkMicPkStart(String pkUid, int i) { - L.eSw("onLinkMicPkStart pkUid "+pkUid+" "+i); Log.d("tag", i + "mPkTimeCount2"); mIsPk = true; hideSendPkWait(); @@ -1914,7 +2255,6 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { mPkUid = pkUid; mApplyUid = null; mApplyStream = null; - isDRPK=1; if (mLiveLinkMicPkViewHolder == null) { mLiveLinkMicPkViewHolder = new LiveLinkMicPkViewHolder(mContext, mPkContainer); mLiveLinkMicPkViewHolder.addToParent(); @@ -1922,15 +2262,17 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { 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);//时间倒计时 + nextPkTimeCountDown(2); if (mIsAnchor) { ((LiveRyAnchorActivity) mContext).setPkBtnVisible(false); mPkTimeCount = PK_TIME_MAX; + } else { // mPkTimeCount=mPkTimeFromServer; mPkTimeCount = PK_TIME_MAX; @@ -2004,6 +2346,45 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { } } }); +// 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() { @@ -2118,7 +2499,6 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { * 更新Pk分数 */ public void upDataPkScore(JSONArray pkScores, String uid, int time) { - L.eSw("更新Pk分数 upDataPkScore time:" + time + " " + pkScores); String userID1 = (String) imageGrade1.getTag(); String userID2 = (String) imageGrade2.getTag(); String userID4 = (String) imageGrade4.getTag(); @@ -2131,18 +2511,15 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { String pkTime = StringUtil.getDurationText(time * 1000); livePushRyViewHolder.textTime.setText(String.format(mContext.getString(R.string.pk_time), pkTime)); mPkTimeCount = time; - if (time > 0) { + 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) { - detailsLinearLayout1.setVisibility(View.VISIBLE); - detailsLinearLayout2.setVisibility(View.VISIBLE); - detailsLinearLayout4.setVisibility(View.VISIBLE); - linearGrade1.setVisibility(View.VISIBLE); linearGrade2.setVisibility(View.VISIBLE); linearGrade4.setVisibility(View.VISIBLE); @@ -2218,12 +2595,6 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { } } else { String userID3 = (String) imageGrade3.getTag(); - - detailsLinearLayout1.setVisibility(View.VISIBLE); - detailsLinearLayout2.setVisibility(View.VISIBLE); - detailsLinearLayout3.setVisibility(View.VISIBLE); - detailsLinearLayout4.setVisibility(View.VISIBLE); - linearGrade1.setVisibility(View.VISIBLE); linearGrade2.setVisibility(View.VISIBLE); linearGrade3.setVisibility(View.VISIBLE); @@ -2342,7 +2713,8 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { if (mHandler != null) { mHandler.removeCallbacksAndMessages(null); } - Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.PK_TIME_COUNT)); + 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 new file mode 100644 index 000000000..0eefc39f1 --- /dev/null +++ b/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java @@ -0,0 +1,2324 @@ +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.LiveSwAnchorActivity.PKing; +import static com.yunbao.live.activity.LiveSwAnchorActivity.isDRPK; +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; +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.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.google.gson.Gson; +import com.tencent.trtc.TRTCCloud; +import com.yunbao.common.CommonAppConfig; +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.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; +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.LiveSwAnchorActivity; +import com.yunbao.live.bean.DrPkbean; +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.SocketSwClient; +import com.yunbao.live.socket.SocketSwLinkMicPkUtil; +import com.yunbao.live.socket.SocketSendBean; +import com.yunbao.live.views.LiveLinkMicPkViewHolder; +import com.yunbao.live.views.LivePushSwViewHolder; + +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.RCRTCVideoStreamConfig; +import cn.rongcloud.rtc.base.RCRTCMediaType; +import cn.rongcloud.rtc.base.RCRTCRoomType; +import cn.rongcloud.rtc.base.RTCErrorCode; +import io.agora.beautyapi.faceunity.agora.SWManager; +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 LiveSwLinkMicPkPresenter 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 SocketSwClient mSocketRyClient; + private ViewGroup mPkContainer; + private boolean mIsApplyDialogShow;//是否显示了申请PK的弹窗 + private boolean mAcceptPk;//是否接受连麦 + private boolean mIsPk;//是否已经Pk了 + public static String mApplyUid;//正在申请Pk的主播的uid + private String mApplyUrl;//正在申请Pk的主播的头像 + private String mApplyNmae;//正在申请Pk的主播的名字 + private String mApplyStream;//正在申请Pk的主播的stream + private String mLiveUid;//自己主播的uid + private String mUrl;//主播的头像 + public static String mPkUid;//正在Pk的对方主播的uid + public static String oldmPkUid;//正在Pk的对方主播的uid + 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 mIsPkEnd;//pk是否结束,进入惩罚时间 + 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 LivePushSwViewHolder livePushRyViewHolder; + + public static List inputStreamList = new ArrayList<>(); + public static List inputStreamList1 = new ArrayList<>(); + private boolean DRInitiator = false;//是否是duorenPK发起人 + + private List drPkbeans = new ArrayList<>(); + + public LiveSwLinkMicPkPresenter 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 LiveSwLinkMicPkPresenter(Context context, ILiveLinkMicViewHolder linkMicViewHolder, boolean isAnchor, View root) { + 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 LiveSwLinkMicPkPresenter(Context context, LivePushSwViewHolder linkMicViewHolder, boolean isAnchor, View root) { + 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(SocketSwClient 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) { + ((LiveSwAnchorActivity) 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) { + ((LiveSwAnchorActivity) 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; + SocketSwLinkMicPkUtil.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) { + ((LiveSwAnchorActivity) mContext).setPkBtnVisible(false); + } + } + + /** + * 主播与主播PK 主播收到其他主播发过来的多人PK申请的回调 + */ + public void onLinkDRMicPkApply(UserBean u) { + Log.e("ry", "多人收到"); + showDRApplyDialog(u); + } + + /** + * 主播与主播PK 主播收到其他主播发过来的多人PK申请同意了的回调 + */ + public void onLinkDRMicPkApplyOk(UserBean u) { + L.eSw("onLinkDRMicPkApplyOk(UserBean u) " + u.getUserNiceName()); + int index = 0; + if (livePushRyViewHolder != null) { + livePushRyViewHolder.setAnDrPkRtc(String.valueOf(u.getId()), -1); + } + final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LIVE_DRPK) + .param("action", 3) + .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) + .param("pkuid", CommonAppConfig.getInstance().getUid()) + .param("type", 3) + .param("uid", u.getId()) + .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) + .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); + 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); + + 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) { + } + + @Override + public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { + Log.e("tx", "aaa" + errorCode.toString()); + ToastUtil.show(errorCode.code + ":" + errorCode.msg); + } + }); + dRjoinOtherRoom(u); + } + + /** + * 主播与主播PK 主播收到其他主播发过来的PK申请的回调 + */ + public void onLinkMicPkApply(UserBean u, String stream, int by) { + Log.e("ry", u.getUserNiceName() + "单人收到" + u.getAvatar()); + mApplyUid = u.getId(); + mApplyUrl = u.getAvatar(); + mApplyNmae = u.getUserNiceName(); + if (by != 1) { + if (mIsApplyDialogShow == false) { + if (u.isRandomPk()) { + showPkDialog(u); + } else { + showApplyDialog(u); + } + } + } else { + isPK(u); + } + } + + /** + * 主播与主播PK PK主播发过来的已经接受 + */ + public void onLinkMicToPk(UserBean u) { + EventBus.getDefault().post(new AnchorInfoEvent(false, u.getId(), u.getUserNiceName(), u.getAvatar())); + Log.e("eve", u.getId() + ""); + L.eSw("主播接受了主播的PK邀請"); + RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_START); + LivePushSwViewHolder.btn_close.setVisibility(View.VISIBLE); + LiveSwAnchorActivity.isDRPK = 1; + livePushRyViewHolder.setAnPkRtc(u);//设置对方主播视图 + + 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(); + LivePushSwViewHolder.btn_close.setVisibility(View.VISIBLE); + } + + private void isPK(UserBean bean) { + EventBus.getDefault().post(new AnchorInfoEvent(false, bean.getId(), bean.getUserNiceName(), bean.getAvatar())); + 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); + LivePushSwViewHolder.btn_close.setVisibility(View.VISIBLE); + LiveSwAnchorActivity.isDRPK = 1; + + /*---------------------------------------------------------------- */ + final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK) + .param("action", 2) //回复PK申请 2 + .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) + .param("pkuid", bean.getId()) + .param("uid", CommonAppConfig.getInstance().getUid()) + .param("uhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) + .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) + .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); + if (RandomPkManager.getInstance().isRankModel()) { + L.eSw("排位赛"); + msg1.param("is_ladders", "https://downs.yaoulive.com/rank_top_box.png"); + } + msg1.param("is_ladders", "https://downs.yaoulive.com/rank_top_box.png"); + msg1.create(); + System.out.println("PK回执 = " + msg1.toString()); + 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( bean.getId(), 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("tx", "发送成功"); + } + + @Override + public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { + Log.e("tx", "发送失败" + errorCode.getMessage()); + + } + }); + + // TODO: 2024/4/12 视图渲染 + livePushRyViewHolder.setAnPkRtc(bean); + new Handler(Looper.getMainLooper()).post(new Runnable() { + public void run() { + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.UN_LEAVELIVE)); + LiveSwAnchorActivity.isDRPK = 1; + LivePushSwViewHolder.btn_close.setVisibility(View.VISIBLE); + SocketSwLinkMicPkUtil.linkMicPkAccept(mSocketRyClient, mApplyUid, mApplyUrl, mApplyNmae); + EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.UP_PK_TWO).setObject(mApplyUid)); + onLinkMicPkStart(mApplyUid, 2); + } + }); + } + + //与用户连麦 + 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的弹窗 + */ + private 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) { + isPK(u); + } else { + if (mPkWaitCount < 0) { + if(rtcRoom==null){ + return; + } + 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); + + 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", "发送失敗" + u.getId()); + } + }); + } + }); + + } + 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); + livePushRyViewHolder.timeTitle.setVisibility(View.GONE); + } + } + }); + livePushRyViewHolder.exitChannelDrPk(drPkbeans); + leaveHandler.removeCallbacks(leaveRunnable); + } + + private Handler leaveHandler = new Handler(Looper.getMainLooper()); + private Runnable leaveRunnable = new Runnable() { + @Override + public void run() { + //恢复全屏画面 + livePushRyViewHolder.dr_pk_view.setVisibility(View.GONE); + //删除之前其他主播的画面 + livePushRyViewHolder.dr1_preview.removeAllViews(); + livePushRyViewHolder.dr2_preview.removeAllViews(); + livePushRyViewHolder.dr3_preview.removeAllViews(); + livePushRyViewHolder.dr4_preview.removeAllViews(); + livePushRyViewHolder.cameraPreview3.removeAllViews(); + leaveHandler.removeCallbacks(leaveRunnable); + livePushRyViewHolder.timeTitle.setVisibility(View.GONE); + livePushRyViewHolder.mPreView.removeView(detailsView1); + livePushRyViewHolder.cameraPreview3.setVisibility(View.GONE); + } + }; + + /** + * 随机PK拒绝对话框 + */ + public 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(); + ((TextView) title).setText("您因拒絕隨機PK,被限制關閉中"); + ((TextView) confirmBtn).setText("确定"); + ((TextView) context).setText("隨機PK可打開時間:" + 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() { + isPK(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); + + 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", "发送失敗" + u.getId()); + } + }); + } + }); + + LiveNetManager.get(mContext).setBanRandomPK(null); + } + + + /** + * 显示申请多人PK的弹窗 + */ + private 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) { + + 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; + if (finalAgree) { + 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) { + L.eSw("多人PK" + "code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info)); + if (info.length == 0) { + return; + } + JSONObject obj = JSONObject.parseObject(info[0]); + drPkbeans = JSONObject.parseArray(obj.getString("userlist"), DrPkbean.class); + SWManager.get().setDimensions(3);//加入成功后,将分别率设置为 VD_320x240 + //将自己从多人pk列表里剔除 + int removeIndex = -1; + for (int i = 0; i < drPkbeans.size(); i++) { + if (CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))) { + removeIndex = i; + } + } + if (removeIndex != -1) { + drPkbeans.remove(removeIndex); + L.eSw("将自己从多人pk列表里剔除" + new Gson().toJson(drPkbeans)); + } + + HttpClient.getInstance().get("Live.getDRPKroom", "Live.getDRPKroom").params("uid", CommonAppConfig.getInstance().getUid()).params("roomid", mApplyUid).execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (info.length > 0) { + JSONObject obj = JSONObject.parseObject(info[0]); + drPkbeans = JSONObject.parseArray(obj.getString("userlist"), DrPkbean.class); + for (int i = 0; i < drPkbeans.size(); i++) { + if (!CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))) { + final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LIVE_DRPK) + .param("action", 2) + .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) + .param("pkuid", CommonAppConfig.getInstance().getUid()) + .param("msgtype", 2) + .param("uid", drPkbeans.get(i).getId()) + .param("uhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) + .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) + .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); + msg1.create(); + L.eSw("uiduiduiduiduiduiduiduid"+drPkbeans.get(i).getId()); + String targetId = String.valueOf(drPkbeans.get(i).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) { + } + + @Override + public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { + Log.e("tx", "aaa" + errorCode.toString()); + ToastUtil.show(errorCode.code + ":" + errorCode.msg); + } + }); + + // + int index = livePushRyViewHolder.setAnDrPkRtc(String.valueOf(drPkbeans.get(i).getId()), -1); + + L.eSw("onLinkDRMicPkApplyOk(UserBean u)-点击接收 1 " + u.getUserNiceName()); + L.eSw("發送action = 2"); + + } + + if (!CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))) { + final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LIVE_DRPK) + .param("action", 3) + .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) + .param("pkuid", CommonAppConfig.getInstance().getUid()) + .param("msgtype", 3) + .param("uid", drPkbeans.get(i).getId()) + .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) + .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); + msg1.create(); + L.eSw("發送給自己直播間"+drPkbeans.get(i).getId()); + 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); + + 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) { + } + + @Override + public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { + Log.e("tx", "aaa" + errorCode.toString()); + ToastUtil.show(errorCode.code + ":" + errorCode.msg); + } + }); + } + + + if(!mApplyUid.equals(String.valueOf(drPkbeans.get(i).getId()))&&!CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))){ + final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LIVE_DRPK) + .param("action", 3) + .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) + .param("pkuid", CommonAppConfig.getInstance().getUid()) + .param("msgtype", 3) + .param("uid", drPkbeans.get(i).getId()) + .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) + .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); + msg1.create(); + L.eSw("發送給其他主播直播间"+drPkbeans.get(i).getId()); + String targetId = "g" + drPkbeans.get(i).getId(); + 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); + + 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) { + } + + @Override + public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { + Log.e("tx", "aaa" + errorCode.toString()); + ToastUtil.show(errorCode.code + ":" + errorCode.msg); + } + }); + } + } + dRjoinOtherRoom(u); + } + } + }); + + + /*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) { + + } + }); + } + } + }*/ + } + }); + } + } else { + ToastUtil.show(msg); + } + } + + }); + + + } + } + }); + + + } else { + if (mPkWaitCount < 0) { + 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); + } + }); + } + }); + + } else { + 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", "发送失敗"); + } + }); + } + }); + } + 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 void setMyDrPkDetailsView() { + if (detailsView1 != null) { + livePushRyViewHolder.dr1_preview.removeView(detailsView1); + } + 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); + textPkName1 = detailsView1.findViewById(R.id.text_pk_name1); + imageGrade1.setTag(String.valueOf(IMLoginManager.get(mContext).getUserInfo().getId())); + livePushRyViewHolder.dr1_preview.addView(detailsView1); + detailsLinearLayout1.setVisibility(View.GONE); + linearGrade1.setVisibility(View.GONE); + } + + + public void setPkUserInfoView(UserBean userBean){ + + } + + //多人PK接受申请画 加入副房间 + public void dRjoinOtherRoom(UserBean u) { + setMyDrPkDetailsView(); + HttpClient.getInstance().get("Live.getDRPKroom", "Live.getDRPKroom").params("uid", CommonAppConfig.getInstance().getUid()).params("roomid", mApplyUid).execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (info.length > 0) { + JSONObject obj = JSONObject.parseObject(info[0]); + drPkbeans = JSONObject.parseArray(obj.getString("userlist"), DrPkbean.class); + int removeIndex = -1; + for (int i = 0; i < drPkbeans.size(); i++) { + if (CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))) { + removeIndex = i; + } + } + if (removeIndex != -1) { + drPkbeans.remove(removeIndex); + } + setDrPkUserInfoView(drPkbeans); + } + } + }); + } + + private void setDrPkUserInfoView(List drPkbeanList) { + L.eSw("setDrPkUserInfoView" + new Gson().toJson(drPkbeanList)); + mHandler.postDelayed(new Runnable() { + @Override + public void run() { + for (int j = 0; j < drPkbeanList.size(); j++) { + if (j == 0) { + L.eSw("j == 0:" + j); + //设置多人PK数据 + if (detailsView2 != null) { + livePushRyViewHolder.dr2_preview.removeView(detailsView2); + } + 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(drPkbeanList.get(0).getId())); + textPkName2.setText(drPkbeanList.get(0).getUser_nicename()); + livePushRyViewHolder.dr2_preview.addView(detailsView2); + detailsLinearLayout2.setVisibility(View.GONE); + linearGrade2.setVisibility(View.GONE); + } else if (j == 1) { + L.eSw("j == 1:" + j); + if (detailsView4 != null) { + livePushRyViewHolder.dr4_preview.removeView(detailsView4); + } + 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(String.valueOf(drPkbeanList.get(1).getId())); + textPkName4.setText(drPkbeanList.get(1).getUser_nicename()); + livePushRyViewHolder.dr4_preview.addView(detailsView4); + detailsLinearLayout4.setVisibility(View.GONE); + linearGrade4.setVisibility(View.GONE); + } else if (j == 2) { + L.eSw("j == 2:" + j); + + if (detailsView4 != null) { + livePushRyViewHolder.dr4_preview.removeView(detailsView4); + } + 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(String.valueOf(drPkbeanList.get(2).getId())); + textPkName4.setText(drPkbeanList.get(2).getUser_nicename()); + livePushRyViewHolder.dr4_preview.addView(detailsView4); + detailsLinearLayout4.setVisibility(View.GONE); + linearGrade4.setVisibility(View.GONE); + + if (detailsView3 != null) { + livePushRyViewHolder.dr3_preview.removeView(detailsView3); + } + 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(String.valueOf(drPkbeanList.get(1).getId())); + textPkName3.setText(drPkbeanList.get(1).getUser_nicename()); + livePushRyViewHolder.dr3_preview.addView(detailsView3); + detailsLinearLayout3.setVisibility(View.GONE); + linearGrade3.setVisibility(View.GONE); + + + ToastUtil.show(WordUtil.isNewZh() ? "接受成功" : "Success"); + + } + } + } + }, 2000); + L.eSw("dRjoinOtherRoom:size:" + drPkbeanList.size() + " json " + new Gson().toJson(drPkbeanList)); + + } + + /** + * 多人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) { + L.eSw("onLinkMicPkStart pkUid "+pkUid+" "+i); + Log.d("tag", i + "mPkTimeCount2"); + mIsPk = true; + hideSendPkWait(); + mIsPkEnd = false; + oldmPkUid = pkUid; + mPkUid = pkUid; + mApplyUid = null; + mApplyStream = null; + isDRPK=1; + 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) { + ((LiveSwAnchorActivity) 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) { + ((LiveSwAnchorActivity) 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; + LiveSwAnchorActivity.isDRPK = 0; + +// //恢复播放画面 + if (i == 1) { + runOnUiThread(new Runnable() { + @Override + public void run() { + if (btn_close != null) { + btn_close.setVisibility(View.GONE); + } + } + }); + + 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) { + ((LiveSwAnchorActivity) mContext).setPkBtnVisible(true); + } + ToastUtil.show(mContext.getString(R.string.link_mic_refuse_pk)); + } + + /** + * 主播与主播Pk 对方主播无响应的回调 + */ + public void onLinkMicPkNotResponse() { + hideSendPkWait(); + if (mIsAnchor) { + ((LiveSwAnchorActivity) mContext).setPkBtnVisible(true); + } + ToastUtil.show(mContext.getString(R.string.link_mic_anchor_not_response_2)); + } + + /** + * 主播与主播Pk 对方主播正在忙的回调 + */ + public void onLinkMicPkBusy() { + hideSendPkWait(); + if (mIsAnchor) { + ((LiveSwAnchorActivity) 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) { + L.eSw("更新Pk分数 upDataPkScore time:" + time + " " + pkScores); + 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) { + detailsLinearLayout1.setVisibility(View.VISIBLE); + detailsLinearLayout2.setVisibility(View.VISIBLE); + detailsLinearLayout4.setVisibility(View.VISIBLE); + + 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(); + + detailsLinearLayout1.setVisibility(View.VISIBLE); + detailsLinearLayout2.setVisibility(View.VISIBLE); + detailsLinearLayout3.setVisibility(View.VISIBLE); + detailsLinearLayout4.setVisibility(View.VISIBLE); + + 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/socket/SocketRyChatUtil.java b/live/src/main/java/com/yunbao/live/socket/SocketRyChatUtil.java index 6192c56cc..f451fb908 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketRyChatUtil.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketRyChatUtil.java @@ -34,7 +34,7 @@ import io.rong.message.TextMessage; public class SocketRyChatUtil { //关闭直播 - public static void closeLive(final String votes, final String length, final String nums, final String mLiveUid, SocketRyClient client) { + public static void closeLive(final String votes, final String length, final String nums, final String mLiveUid, SocketSwClient client) { UserBean u = CommonAppConfig.getInstance().getUserBean(); final SocketSendBean msg = new SocketSendBean() .param("_method_", Constants.SOCKET_LIVE_END) @@ -64,8 +64,8 @@ public class SocketRyChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketRyClient.mSocketHandler != null) - SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketSwClient.mSocketHandler != null) + SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } @Override @@ -128,8 +128,8 @@ public class SocketRyChatUtil { @Override public void onSuccess(Message message) { - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketSwClient.mSocketHandler != null) { + SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } LiveNetManager.get(CommonAppContext.sInstance) .addChatCount(LiveActivity.mStream, new com.yunbao.common.http.base.HttpCallback() { @@ -212,11 +212,10 @@ public class SocketRyChatUtil { if (code == 0) { EventBus.getDefault().post("stop_svga_new_user_double1"); } - } }); - if (SocketRyClient.mSocketHandler != null) - SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketSwClient.mSocketHandler != null) + SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } @Override @@ -264,8 +263,8 @@ public class SocketRyChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketSwClient.mSocketHandler != null) { + SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } } @@ -401,8 +400,8 @@ public class SocketRyChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketSwClient.mSocketHandler != null) { + SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } } @@ -471,8 +470,8 @@ public class SocketRyChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketSwClient.mSocketHandler != null) { + SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } } @@ -518,8 +517,8 @@ public class SocketRyChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketSwClient.mSocketHandler != null) { + SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } } @@ -555,8 +554,8 @@ public class SocketRyChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketSwClient.mSocketHandler != null) { + SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } } @@ -598,8 +597,8 @@ public class SocketRyChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketRyClient.mSocketHandler != null) - SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketSwClient.mSocketHandler != null) + SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } @Override @@ -635,8 +634,8 @@ public class SocketRyChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketSwClient.mSocketHandler != null) { + SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } } @@ -675,8 +674,8 @@ public class SocketRyChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketSwClient.mSocketHandler != null) { + SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } } @@ -779,8 +778,8 @@ public class SocketRyChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketSwClient.mSocketHandler != null) { + SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } } diff --git a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java index c5b55e527..57e2d62ae 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java @@ -2,10 +2,7 @@ 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_LINK_MIC_PK; -import static com.yunbao.common.Constants.SOCKET_LIVE_DRPK; import static com.yunbao.common.Constants.SOCKET_LIVE_MSG_TO_USER; -import static com.yunbao.common.Constants.isAnchor; import static com.yunbao.live.activity.LiveRyAnchorActivity.isDRPK; import static com.yunbao.live.views.LiveRoomViewHolder.getIsHot; @@ -22,7 +19,6 @@ 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.Gson; import com.yunbao.common.CommonAppConfig; import com.yunbao.common.CommonAppContext; import com.yunbao.common.Constants; @@ -30,7 +26,6 @@ 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.LiveInfoModel; import com.yunbao.common.bean.LiveUserGiftBean; import com.yunbao.common.bean.MsgModel; import com.yunbao.common.bean.PkRankBean; @@ -51,7 +46,6 @@ 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.http.live.LiveNetManager; import com.yunbao.common.manager.IMRTCManager; import com.yunbao.common.manager.MicUserManager; import com.yunbao.common.manager.MicedUserManager; @@ -59,7 +53,6 @@ import com.yunbao.common.manager.NewLevelManager; import com.yunbao.common.manager.RandomPkManager; import com.yunbao.common.utils.Bus; import com.yunbao.common.utils.L; -import com.yunbao.common.utils.StringUtil; import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.utils.WordUtil; import com.yunbao.live.R; @@ -80,7 +73,7 @@ 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.LivePlaySwViewHolder; import com.yunbao.live.views.LivePushRyViewHolder; import com.yunbao.live.views.LiveRoomViewHolder; @@ -92,26 +85,21 @@ 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.agora.beautyapi.faceunity.agora.SWManager; -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.message.TextMessage; public class SocketRyClient { private final String TAG = "socket"; private String mLiveUid; private String mStream; - public static SocketRyClient.SocketHandler mSocketHandler; + public static SocketHandler mSocketHandler; private Context mContext; public SocketRyClient(String mLiveUid, SocketMessageListener listener, Activity mContext) { this.mContext = mContext; - mSocketHandler = new SocketRyClient.SocketHandler(listener); + mSocketHandler = new SocketHandler(listener); mSocketHandler.setLiveUid(mLiveUid); RongChatRoomClient.getInstance().joinChatRoom("g" + mLiveUid, -1, new IRongCoreCallback.OperationCallback() { @Override @@ -208,7 +196,6 @@ public class SocketRyClient { //用户连麦 case Constants.LIAN_MAI: int actions = map.getIntValue("action"); - L.eSw("用户连麦:actions"+actions); //主播邀请用户连麦消息 if (actions == 1) { EventBus.getDefault().post("inviteMic"); @@ -217,7 +204,10 @@ public class SocketRyClient { 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))); + 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()) { @@ -226,9 +216,10 @@ public class SocketRyClient { 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))); + 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 { @@ -236,16 +227,24 @@ public class SocketRyClient { } EventBus.getDefault().post("endMic"); } else if (actions == 3) { - Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LINK_MIC).setObject(map.toJavaObject(LinkMicUserBean.class))); + 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)); + 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))); + 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")); @@ -264,7 +263,9 @@ public class SocketRyClient { } 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"); + ctTmp = ctTmp.replace("由於", "Due to") + .replace("退出比賽", "withdrawing from the competition") + .replace("獲得勝利", "won"); map.put("ct", ctTmp); } systemChatMessage2(map.getString("ct")); @@ -276,15 +277,15 @@ public class SocketRyClient { if (LivePlayKsyViewHolder.leave != null) { LivePlayKsyViewHolder.leave.setVisibility(View.VISIBLE); } - if (LivePlayRyViewHolder.leave != null) { - LivePlayRyViewHolder.leave.setVisibility(View.VISIBLE); + if (LivePlaySwViewHolder.leave != null) { + LivePlaySwViewHolder.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); + if (LivePlaySwViewHolder.leave != null) { + LivePlaySwViewHolder.leave.setVisibility(View.GONE); } } break; @@ -313,7 +314,6 @@ public class SocketRyClient { // break; case Constants.SOCKET_LIVE_DRPK_RANDOM: case Constants.SOCKET_LIVE_DRPK://多人PK - L.eSw("map"+new Gson().toJson(map)); int action3 = map.getIntValue("action"); //收到多人PK邀请 if (action3 == 1) { @@ -324,65 +324,59 @@ public class SocketRyClient { } //收到对方同意多人PK邀请 else if (action3 == 2) { - if("0".equals(map.getString("msgtype"))){ - return; - } - UserBean u = new UserBean(); -// u.setUserNiceName(map.getString("uname")); - u.setId(map.getString("pkuid")); - L.eSw("action3 == 2:"+u.getId()); - L.eSw("收到对方同意多人PK邀请"); - mListener.onLinkDRMicPkApplyOk(u); - SWManager.get().setDimensions(3);//退出直播间,将分别率设置为 VD_840x480 +// 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"))); + 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)); + 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)); + 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)); + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_END_VIEW) + ); + } - SWManager.get().setDimensions(0);//退出直播间,将分别率设置为 VD_840x480 //創建了多人房間 } else if (action3 == 3) { - L.eSw("創建了多人房間action3 == 3"); /* if (LiveAudienceActivity.getmLivePlayViewHolder() != null) { LiveAudienceActivity.getmLivePlayViewHolder().setPkview(); }*/ - if(livePushRyViewHolder==null){ - if("4".equals(map.getString("msgtype"))){ - return; - } - UserBean u = new UserBean(); -// u.setUserNiceName(map.getString("uname")); - u.setId(map.getString("uid")); - if(StringUtil.isEmpty(u.getId())){ - return; - } - L.eSw("通知用户 action3 == 3:"+u.getId()); - mListener.onLinkDRMicPKToUser(u); - Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_VIEW)); - isDRPK = 1; - } + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_VIEW) + ); + isDRPK = 1; } else if (action3 == 10) { - //显示pk分数 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)); + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_VIEW) + ); } } @@ -395,7 +389,7 @@ public class SocketRyClient { receiveGiftBean.setSendtype(map.getIntValue("action")); receiveGiftBean.setAllServerNotify(true); mListener.onSys(receiveGiftBean); - } else if (action2 == 61) {//赠送礼物 + } else if (action2 == 61) {//赠送礼物 超级头条 sendGiftByNotify(map); } else if (action2 == 62) {//购买守护 // buyGuardByNotify(map); @@ -408,7 +402,7 @@ public class SocketRyClient { buyZuoJiByNotify(map); } else if (action2 == 66) {//购买贵族 buyVipByNotify(map); - } else if (action2 == 88) { + } else if (action2 == 88) {//盲盒 JSONObject mCt = map.getJSONObject("ct"); String boxType = map.getString("box_type"); String boxTypeName = ""; @@ -419,19 +413,39 @@ public class SocketRyClient { } 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")); + 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)); + 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)); + 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); buyGuardInSameRoom(map); - } else if (action2 == 91) { + } else if (action2 == 91) {//通用模板 AllServerNotifyFFGGGDJANEvent notifyFFGGGDJANEvent = GsonUtils.fromJson(map.toString(), AllServerNotifyFFGGGDJANEvent.class); Bus.get().post(notifyFFGGGDJANEvent); } @@ -459,7 +473,12 @@ public class SocketRyClient { 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"))); + 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")); @@ -484,7 +503,7 @@ public class SocketRyClient { case Constants.SOCKET_BUY_GUARD://购买守护 buyGuardInSameRoom(map); break; - case Constants.SOCKET_LINK_MIC://连麦-old + case Constants.SOCKET_LINK_MIC://连麦 processLinkMic(map); break; case Constants.SOCKET_LINK_MIC_ANCHOR://主播连麦 @@ -600,7 +619,9 @@ public class SocketRyClient { 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))); + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.TRUMPET_NOTIFY) + .setMsgModel(msg.get(0))); } break; case Constants.RECOMMEND_CARD_NOTIFY://推荐卡消息通知 @@ -608,7 +629,9 @@ public class SocketRyClient { List recommendCardNotifyMsg = recommendCardNotifyModel.getMsg(); if (recommendCardNotifyMsg.size() > 0) { - Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.RECOMMEND_CARD_NOTIFY).setMsgModel(recommendCardNotifyMsg.get(0))); + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.RECOMMEND_CARD_NOTIFY) + .setMsgModel(recommendCardNotifyMsg.get(0))); } break; case Constants.STAR_CHALLENGE_UPDATE://星级助力 @@ -625,21 +648,29 @@ public class SocketRyClient { 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)); + 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))); + 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))); + 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))); + 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()); @@ -649,68 +680,117 @@ public class SocketRyClient { 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)); + 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)); + 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))); + 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)); + 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")))); + 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)); + 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)); + 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)); + 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)); + 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)); + 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)); + 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)); + 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"))); + 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))); + 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 "); + 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; @@ -725,7 +805,9 @@ public class SocketRyClient { 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)); + EventBus.getDefault().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.PK_RANK_START) + .setObject(pkRankBean)); break; case "guardMaturityDateRemind": GuardMaturityDateRemindModel maturityDateRemindModel = GsonUtils.fromJson(map.toString(), GuardMaturityDateRemindModel.class); @@ -738,6 +820,13 @@ public class SocketRyClient { 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; } } @@ -900,6 +989,7 @@ public class SocketRyClient { 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")); @@ -957,6 +1047,7 @@ public class SocketRyClient { chatBean.setBubble(obj.getString("bubble")); chatBean.setMedal(obj.getString("medal")); chatBean.setMedal_new(obj.getString("medal_new")); + chatBean.setMedal_new_en(map.getString("medal_new_en")); chatBean.setHot_num(obj.getString("hot_num")); UserBean.DressBean dressBean = new UserBean.DressBean(); dressBean.setAvatar_frame(obj.getString("avatar_frame")); @@ -977,7 +1068,8 @@ public class SocketRyClient { FansModel fansMedalBean = new NewLevelManager(mContext).getFansModel(map.getIntValue("medal_level")); u.setFansLevel(obj.getIntValue("medal_level")); u.setFansEnterRoomUrl(obj.getString("medal_backgroup_thumb")); - if (fansMedalBean != null) chatBean.setMedalLevelImageUrl(fansMedalBean.getThumb()); + if (fansMedalBean != null) + chatBean.setMedalLevelImageUrl(fansMedalBean.getThumb()); mListener.onEnterRoom(new LiveEnterRoomBean(u, chatBean)); } } @@ -1009,7 +1101,8 @@ public class SocketRyClient { //增加粉丝徽章信息 chatBean.setMedalNmae(map.getString("medal_name")); FansModel fansMedalBean = new NewLevelManager(mContext).getFansModel(map.getIntValue("medal_level")); - if (fansMedalBean != null) chatBean.setMedalLevelImageUrl(fansMedalBean.getThumb()); + if (fansMedalBean != null) + chatBean.setMedalLevelImageUrl(fansMedalBean.getThumb()); //聊天列表显示 玩家名 送 1 个 礼物名 if (CommonAppContext.lang.equals("chinese")) { @@ -1034,7 +1127,8 @@ public class SocketRyClient { mListener.onSendGift(receiveGiftBean, null); } //同一个直播间时才刷新pk - if (mLiveUid.equals(map.getString("pkuid1")) || mLiveUid.equals(map.getString("pkuid2"))) { + if (mLiveUid.equals(map.getString("pkuid1")) || + mLiveUid.equals(map.getString("pkuid2"))) { mListener.onSendGiftPk(map.getLongValue("pktotal2"), map.getLongValue("pktotal1"), livePKUserListBean); } } @@ -1069,6 +1163,7 @@ public class SocketRyClient { 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"))) { @@ -1116,21 +1211,32 @@ public class SocketRyClient { 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 (WordUtil.isNewZh()) { - chatBean.setContent(mContext.getString(R.string.live_send_gift_1) + receiveGiftBean.getGiftCount() + mContext.getString(R.string.live_send_gift_2) + receiveGiftBean.getGiftName()); + 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 { - chatBean.setContent(mContext.getString(R.string.live_send_gift_1) + " " + +receiveGiftBean.getGiftCount() + " " + mContext.getString(R.string.live_send_gift_2) + receiveGiftBean.getGiftnameen()); + 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()); + if (fansMedalBean != null) + chatBean.setMedalLevelImageUrl(fansMedalBean.getThumb()); receiveGiftBean.setLiveChatBean(chatBean); @@ -1158,7 +1264,11 @@ public class SocketRyClient { } 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)); + 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); } @@ -1284,53 +1394,55 @@ public class SocketRyClient { private void processAnchorLinkMicPk(JSONObject map) { int action = map.getIntValue("action"); Log.i("Socket", "action = " + action + " json = " + map.toString()); - L.eSw("处理主播与主播PK逻辑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")); - u.setRandomPk("11".equals(map.getString("msgtype"))); - mListener.onLinkMicPkApply(u, map.getString("stream"), "11".equals(map.getString("msgtype"))?2:1); + mListener.onLinkMicPkApply(u, map.getString("stream"), 1); break; case 2://收到对方主播PK回调 - L.eSw("收到对方主播PK回调"); RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_START); - mListener.onLinkMicToPk(map.getString("uid"), map.getString("uhead"), map.getString("uhead")); - mListener.onLinkMicPkStart(map.getString("uid"), map.getString("uhead"), map.getString("uname"), map.getString("is_ladders"));// mListener.onLinkMicPkStart(map.getString("uid")); - if (livePushRyViewHolder != null) { - UserBean userBean = new UserBean(); - userBean.setId(map.getString("uid")); - userBean.setAvatar(map.getString("uhead")); - userBean.setUserNiceName(map.getString("uname")); - livePushRyViewHolder.setAnPkRtc(userBean); - } + 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开始址的回调 - L.eSw("所有人收到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)); - //断开连麦 - HttpClient.getInstance().post("livepk.setliveuserout", "livepk.setliveuserout").execute(new HttpCallback() { + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.DISCONNEXT_PK_TIME)); + RCRTCEngine.getInstance().leaveOtherRoom(map.getString("pkuid"), true, new IRCRTCResultCallback() { @Override - public void onSuccess(int code, String msg, String[] info) { + 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) { + + } + }); // } - if (livePushRyViewHolder != null) { - livePushRyViewHolder.onLinkMicAnchorClose(); - } mListener.onLinkMicPkClose(1); if (RandomPkManager.getInstance().isRandomModel()) { RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_DEFAULT); @@ -1344,67 +1456,11 @@ public class SocketRyClient { break; case 9://pk结束的回调 mListener.onLinkMicPkEnd(map.getString("win_uid")); - EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LIVE_PK_END).setObject(map.getString("uid"))); - if (livePushRyViewHolder != null) { - livePushRyViewHolder.onLinkMicAnchorClose(); - } + EventBus.getDefault().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.LIVE_PK_END)); break; case 10://系统发起PK回调 - final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK) - .param("action", 2) - .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) - .param("pkuid", CommonAppConfig.getInstance().getUid()) - .param("msgtype", 2) - .param("uid", CommonAppConfig.getInstance().getUid()) - .param("uhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) - .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) - .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); - msg1.create(); - 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(map.getString("uid"), 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) { - } - - @Override - public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { - Log.e("tx", "aaa" + errorCode.toString()); - ToastUtil.show(errorCode.code + ":" + errorCode.msg); - } - }); - - RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_START); - - LiveNetManager.get(mContext).getLiveInfo(map.getString("uid"), new com.yunbao.common.http.base.HttpCallback() { - @Override - public void onSuccess(LiveInfoModel data) { - mListener.onLinkMicToPk(map.getString("uid"), data.getAvatar(), map.getString("uhead")); - mListener.onLinkMicPkStart(map.getString("uid"), data.getAvatar(), map.getString("uname"), map.getString("is_ladders"));// mListener.onLinkMicPkStart(map.getString("uid")); - if (livePushRyViewHolder != null) { - UserBean userBean = new UserBean(); - userBean.setId(map.getString("uid")); - userBean.setAvatar(data.getAvatar()); - userBean.setUserNiceName(map.getString("uname")); - livePushRyViewHolder.setAnPkRtc(userBean); - } - } - - @Override - public void onError(String error) { - - } - } - ); - - /*JSONObject msg1 = new JSONObject(); + JSONObject msg1 = new JSONObject(); msg1.put("type", "autoLivePK"); msg1.put("uid", CommonAppConfig.getInstance().getUid()); msg1.put("pkuid", CommonAppConfig.getInstance().getUid()); @@ -1442,7 +1498,7 @@ public class SocketRyClient { 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 index a7f947d55..6049239b0 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketRyLinkMicPkUtil.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketRyLinkMicPkUtil.java @@ -7,7 +7,7 @@ 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.live.activity.LiveRyAnchorActivity; +import com.yunbao.common.manager.imrongcloud.RongcloudIMManager; import io.rong.imlib.IRongCallback; import io.rong.imlib.RongIMClient; @@ -73,7 +73,7 @@ public class SocketRyLinkMicPkUtil { TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); Message message1 = Message.obtain("g" + CommonAppConfig.getInstance().getUid(), conversationType, messageContent); - RongIMClient.getInstance().sendMessage(message1, null, null, new IRongCallback.ISendMessageCallback() { + RongcloudIMManager.sendMessage(message1, null, null, new IRongCallback.ISendMessageCallback() { @Override public void onAttached(Message message) { @@ -136,7 +136,7 @@ public class SocketRyLinkMicPkUtil { TextMessage messageContent = TextMessage.obtain(msg.mResult.toString()); Message message = Message.obtain(pkUid, conversationType, messageContent); - RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + RongcloudIMManager.sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { @Override public void onAttached(Message message) { diff --git a/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java b/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java new file mode 100644 index 000000000..aec44def7 --- /dev/null +++ b/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java @@ -0,0 +1,1441 @@ +package com.yunbao.live.socket; + +import static com.yunbao.common.Constants.SOCKET_LINK_MIC_PK; +import static com.yunbao.common.Constants.SOCKET_LIVE_MSG_TO_USER; +import static com.yunbao.live.activity.LiveSwAnchorActivity.isDRPK; +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 com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.blankj.utilcode.util.GsonUtils; +import com.google.gson.Gson; +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.LiveInfoModel; +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.http.live.LiveNetManager; +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.L; +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.LiveSwAnchorActivity; +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.LivePlaySwViewHolder; +import com.yunbao.live.views.LivePushSwViewHolder; +import com.yunbao.live.views.LiveRoomViewHolder; + +import org.greenrobot.eventbus.EventBus; + +import java.lang.ref.WeakReference; +import java.util.List; + +import io.agora.beautyapi.faceunity.agora.SWManager; +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.message.TextMessage; + +public class SocketSwClient { + + private final String TAG = "socket"; + private String mLiveUid; + private String mStream; + public static SocketSwClient.SocketHandler mSocketHandler; + private Context mContext; + + public SocketSwClient(String mLiveUid, SocketMessageListener listener, Activity mContext) { + this.mContext = mContext; + mSocketHandler = new SocketSwClient.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 setLivePushSwViewHolder(LivePushSwViewHolder livePushSwViewHolder) { + if (mSocketHandler != null) { + mSocketHandler.setLivePushSwViewHolder(livePushSwViewHolder); + } + } + + public void disConnect() { +// V2TIMManager.getInstance(). + mLiveUid = null; + mStream = null; + mSocketHandler = null; + } + + public class SocketHandler extends Handler { + + private SocketMessageListener mListener; + private LivePushSwViewHolder livePushSwViewHolder; + private String mLiveUid; + + public SocketHandler(SocketMessageListener listener) { + mListener = new WeakReference<>(listener).get(); + } + + public void setLiveUid(String liveUid) { + mLiveUid = liveUid; + } + + public void setLivePushSwViewHolder(LivePushSwViewHolder livePushSwViewHolder) { + this.livePushSwViewHolder = livePushSwViewHolder; + } + + @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); + + switch (map.getString("_method_")) { + //用户连麦 + case Constants.LIAN_MAI: + int actions = map.getIntValue("action"); + L.eSw("用户连麦:actions"+actions); + //主播邀请用户连麦消息 + 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 (LivePlaySwViewHolder.leave != null) { + LivePlaySwViewHolder.leave.setVisibility(View.VISIBLE); + } + } else if (action21 == 13 && map.getString("ct").contains("回來")) { + if (LivePlayKsyViewHolder.leave != null) { + LivePlayKsyViewHolder.leave.setVisibility(View.GONE); + } + if (LivePlaySwViewHolder.leave != null) { + LivePlaySwViewHolder.leave.setVisibility(View.GONE); + } + } + 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 + L.eSw("map"+new Gson().toJson(map)); + 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) { + if("0".equals(map.getString("msgtype"))){ + return; + } + UserBean u = new UserBean(); +// u.setUserNiceName(map.getString("uname")); + u.setId(map.getString("pkuid")); + L.eSw("action3 == 2:"+u.getId()); + L.eSw("收到对方同意多人PK邀请"); + mListener.onLinkDRMicPkApplyOk(u); + SWManager.get().setDimensions(3);//退出直播间,将分别率设置为 VD_840x480 + } 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 (livePushSwViewHolder == 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 (LiveSwAnchorActivity.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)); + } + SWManager.get().setDimensions(0);//退出直播间,将分别率设置为 VD_840x480 + //創建了多人房間 + } else if (action3 == 3) { + L.eSw("創建了多人房間action3 == 3"); + /* if (LiveAudienceActivity.getmLivePlayViewHolder() != null) { + LiveAudienceActivity.getmLivePlayViewHolder().setPkview(); + }*/ + if(livePushSwViewHolder==null){ + if("4".equals(map.getString("msgtype"))){ + return; + } + UserBean u = new UserBean(); +// u.setUserNiceName(map.getString("uname")); + u.setId(map.getString("uid")); + if(StringUtil.isEmpty(u.getId())){ + return; + } + L.eSw("通知用户 action3 == 3:"+u.getId()); + mListener.onLinkDRMicPKToUser(u); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_VIEW)); + isDRPK = 1; + } + } else if (action3 == 10) { + //显示pk分数 + 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); + 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://连麦-old + 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; + + } + } + + 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.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")); + 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.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")); + 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.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.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.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 (WordUtil.isNewZh()) { + 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()); + } + //增加粉丝徽章信息 + 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("处理主播与主播PK逻辑action = " + action + " json = " + 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")); + u.setRandomPk("11".equals(map.getString("msgtype"))); + mListener.onLinkMicPkApply(u, map.getString("stream"), "11".equals(map.getString("msgtype"))?2:1); + break; + case 2://收到对方主播PK回调 + L.eSw("收到对方主播PK回调"); + RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_START); + mListener.onLinkMicToPk(map.getString("uid"), map.getString("uhead"), map.getString("uhead")); + mListener.onLinkMicPkStart(map.getString("uid"), map.getString("uhead"), map.getString("uname"), map.getString("is_ladders"));// mListener.onLinkMicPkStart(map.getString("uid")); + if (livePushSwViewHolder != null) { + UserBean userBean = new UserBean(); + userBean.setId(map.getString("uid")); + userBean.setAvatar(map.getString("uhead")); + userBean.setUserNiceName(map.getString("uname")); + livePushSwViewHolder.setAnPkRtc(userBean); + } + break; + case 3://对方主播拒绝PK的回调 + RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_REFUSE); + mListener.onLinkMicPkRefuse(); + break; + case 4://所有人收到PK开始址的回调 + L.eSw("所有人收到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)); + //断开连麦 + HttpClient.getInstance().post("livepk.setliveuserout", "livepk.setliveuserout").execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + + } + }); +// } + if (livePushSwViewHolder != null) { + livePushSwViewHolder.onLinkMicAnchorClose(); + } + 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).setObject(map.getString("uid"))); + if (livePushSwViewHolder != null) { + livePushSwViewHolder.onLinkMicAnchorClose(); + } + break; + case 10://系统发起PK回调 + final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK) + .param("action", 2) + .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) + .param("pkuid", CommonAppConfig.getInstance().getUid()) + .param("msgtype", 2) + .param("uid", CommonAppConfig.getInstance().getUid()) + .param("uhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) + .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) + .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); + msg1.create(); + 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(map.getString("uid"), 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) { + } + + @Override + public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { + Log.e("tx", "aaa" + errorCode.toString()); + ToastUtil.show(errorCode.code + ":" + errorCode.msg); + } + }); + + RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_START); + + LiveNetManager.get(mContext).getLiveInfo(map.getString("uid"), new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(LiveInfoModel data) { + mListener.onLinkMicToPk(map.getString("uid"), data.getAvatar(), map.getString("uhead")); + mListener.onLinkMicPkStart(map.getString("uid"), data.getAvatar(), map.getString("uname"), map.getString("is_ladders"));// mListener.onLinkMicPkStart(map.getString("uid")); + if (livePushSwViewHolder != null) { + UserBean userBean = new UserBean(); + userBean.setId(map.getString("uid")); + userBean.setAvatar(data.getAvatar()); + userBean.setUserNiceName(map.getString("uname")); + livePushSwViewHolder.setAnPkRtc(userBean); + } + } + + @Override + public void onError(String error) { + + } + } + ); + + /*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/SocketSwLinkMicPkUtil.java b/live/src/main/java/com/yunbao/live/socket/SocketSwLinkMicPkUtil.java new file mode 100644 index 000000000..9c7281eb9 --- /dev/null +++ b/live/src/main/java/com/yunbao/live/socket/SocketSwLinkMicPkUtil.java @@ -0,0 +1,210 @@ +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 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 SocketSwLinkMicPkUtil { + /** + * 发起PK申请 + * + * @param pkUid 对方主播的uid + * @param stream 自己直播间的stream + */ + public static void linkMicPkApply(SocketSwClient 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(SocketSwClient 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); + + RongIMClient.getInstance().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(SocketSwClient 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); + + RongIMClient.getInstance().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(SocketSwClient 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(SocketSwClient 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/utils/LiveRoomVoteManager.java b/live/src/main/java/com/yunbao/live/utils/LiveRoomVoteManager.java index 8407e8dca..297ce9e17 100644 --- a/live/src/main/java/com/yunbao/live/utils/LiveRoomVoteManager.java +++ b/live/src/main/java/com/yunbao/live/utils/LiveRoomVoteManager.java @@ -19,10 +19,8 @@ import com.yunbao.common.http.live.LiveNetManager; import com.yunbao.common.utils.StringUtil; import com.yunbao.common.utils.ToastUtil; import com.yunbao.live.R; -import com.yunbao.live.activity.LiveRyAnchorActivity; +import com.yunbao.live.activity.LiveSwAnchorActivity; -import java.util.HashMap; -import java.util.Map; import java.util.Timer; import java.util.TimerTask; @@ -60,7 +58,7 @@ public class LiveRoomVoteManager { mAnchorVoteHide.setOnClickListener(v -> hideAnchorVote()); mVoteShow.setOnClickListener(v -> hideAnchorVote()); mClose.setOnClickListener(v -> close()); - if (mContext instanceof LiveRyAnchorActivity) { + if (mContext instanceof LiveSwAnchorActivity) { isAnchor = true; } else { isAnchor = false; diff --git a/live/src/main/java/com/yunbao/live/views/LiveAudienceViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveAudienceViewHolder.java index 0a3d60e56..508d1aeae 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveAudienceViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveAudienceViewHolder.java @@ -104,7 +104,6 @@ public class LiveAudienceViewHolder extends AbsLiveViewHolder { initLittlePanda(); } - @Override protected int getLayoutId() { return R.layout.view_live_audience; 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 727b38003..42336041f 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveEndViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveEndViewHolder.java @@ -37,6 +37,7 @@ 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; import com.yunbao.common.event.LiveRoomChangeEvent; @@ -234,9 +235,10 @@ public class LiveEndViewHolder extends AbsViewHolder implements View.OnClickList ((LiveAnchorActivity) mContext).superBackPressed(); } else if (mContext instanceof LiveAudienceActivity) { ((LiveAudienceActivity) mContext).exitLiveRoom(); - } else if (mContext instanceof LiveRyAnchorActivity) { + } else if (mContext instanceof LiveSwAnchorActivity) { + ((LiveSwAnchorActivity) mContext).superBackPressed(); + }else if(mContext instanceof LiveRyAnchorActivity){ ((LiveRyAnchorActivity) mContext).superBackPressed(); - } Bus.get().post(new CloseEvent()); } @@ -266,9 +268,8 @@ public class LiveEndViewHolder extends AbsViewHolder implements View.OnClickList ((LiveAnchorActivity) mContext).superBackPressed(); } else if (mContext instanceof LiveAudienceActivity) { ((LiveAudienceActivity) mContext).exitLiveRoom(); - } else if (mContext instanceof LiveRyAnchorActivity) { - ((LiveRyAnchorActivity) mContext).superBackPressed(); - + } else if (mContext instanceof LiveSwAnchorActivity) { + ((LiveSwAnchorActivity) mContext).superBackPressed(); } Bus.get().post(new CloseEvent()); } @@ -365,9 +366,10 @@ public class LiveEndViewHolder extends AbsViewHolder implements View.OnClickList ((LiveAnchorActivity) mContext).superBackPressed(); } else if (mContext instanceof LiveAudienceActivity) { ((LiveAudienceActivity) mContext).exitLiveRoom(); - } else if (mContext instanceof LiveRyAnchorActivity) { + } else if (mContext instanceof LiveSwAnchorActivity) { + ((LiveSwAnchorActivity) mContext).superBackPressed(); + }else if(mContext instanceof LiveRyAnchorActivity){ ((LiveRyAnchorActivity) mContext).superBackPressed(); - } Bus.get().post(new CloseEvent()); } @@ -424,7 +426,7 @@ public class LiveEndViewHolder extends AbsViewHolder implements View.OnClickList new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { if (liveBean == null) { return; } @@ -448,7 +450,9 @@ public class LiveEndViewHolder extends AbsViewHolder implements View.OnClickList ((LiveAnchorActivity) mContext).superBackPressed(); } else if (mContext instanceof LiveAudienceActivity) { ((LiveAudienceActivity) mContext).exitLiveRoom(); - } else if (mContext instanceof LiveRyAnchorActivity) { + } 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 index 75e3aaa8b..3d25e452b 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveNewReadyRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveNewReadyRyViewHolder.java @@ -65,7 +65,6 @@ 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.LiveFaceUnityDialogNewFragment; import com.yunbao.live.dialog.LiveNewRoomClassDialogFragment; import com.yunbao.live.dialog.LiveNewRoomTypeDialogFragment; import com.yunbao.live.dialog.LiveTimeDialogFragment; @@ -77,7 +76,10 @@ import org.greenrobot.eventbus.ThreadMode; import java.io.File; import java.util.Locale; -import io.agora.beautyapi.faceunity.agora.SWManager; +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 { @@ -305,6 +307,7 @@ public class LiveNewReadyRyViewHolder extends AbsViewHolder implements View.OnCl } private void setSelectClarity(int selectClarity) { + this.selectClarity = selectClarity; IMLoginManager.get(mContext).setSelectClarity(selectClarity); switch (selectClarity) { @@ -324,7 +327,35 @@ public class LiveNewReadyRyViewHolder extends AbsViewHolder implements View.OnCl if (liveOpenCustomPopup != null) { liveOpenCustomPopup.setSelectClarity(selectClarity); } - SWManager.get().setDimensions(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()); @@ -536,7 +567,8 @@ public class LiveNewReadyRyViewHolder extends AbsViewHolder implements View.OnCl } else if (i == R.id.btn_locaiton) { switchLocation(); } else if (i == R.id.btn_horizontally) { - SWManager.get().setMirrorMode(); + RCRTCCameraOutputStream cameraStream = RCRTCEngine.getInstance().getDefaultVideoStream(); + cameraStream.setPreviewMirror(!cameraStream.isPreviewMirror()); } else if (i == R.id.btn_robot) { new XPopup.Builder(mContext) .asCustom(new LiveRobotSettingCustomPopup(mContext)) @@ -580,20 +612,6 @@ public class LiveNewReadyRyViewHolder extends AbsViewHolder implements View.OnCl } } - public void setFaceUnityNew(boolean init){ - LiveFaceUnityDialogNewFragment fragment = new LiveFaceUnityDialogNewFragment(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(); - } - } - } - - /** * 打开心愿单窗口 */ @@ -923,7 +941,7 @@ public class LiveNewReadyRyViewHolder extends AbsViewHolder implements View.OnCl return; } String title = mEditTitle.getText().toString().trim(); - LiveHttpUtil.newcreateRoom(title, mLiveClassID, mLiveType, mLiveTypeVal, mAvatarFile, IMLoginManager.get(mContext).getSelectClarity() + 1, new HttpCallback() { + 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) { if (code == 0 && info.length > 0) { diff --git a/live/src/main/java/com/yunbao/live/views/LiveNewReadySwViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveNewReadySwViewHolder.java new file mode 100644 index 000000000..ff5bd9ede --- /dev/null +++ b/live/src/main/java/com/yunbao/live/views/LiveNewReadySwViewHolder.java @@ -0,0 +1,963 @@ +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.LiveSwAnchorActivity; +import com.yunbao.live.dialog.LiveAnchorEditCallMeDialog; +import com.yunbao.live.dialog.LiveAnchorSayPopDialog; +import com.yunbao.live.dialog.LiveFaceUnityDialogFragment; +import com.yunbao.live.dialog.LiveFaceUnityDialogNewFragment; +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 io.agora.beautyapi.faceunity.agora.SWManager; + +public class LiveNewReadySwViewHolder 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 LiveNewReadySwViewHolder(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() { + ((LiveSwAnchorActivity) 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); + } + SWManager.get().setDimensions(selectClarity); + 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) { + SWManager.get().setMirrorMode(); + } 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 LiveSwAnchorActivity) { + fragment.show(((LiveSwAnchorActivity) mContext).getSupportFragmentManager(), "FaceUnity"); + mRootView.setVisibility(View.INVISIBLE); + if (init) { + fragment.dismiss(); + } + } + } + + public void setFaceUnityNew(boolean init){ + LiveFaceUnityDialogNewFragment fragment = new LiveFaceUnityDialogNewFragment(mContext); + fragment.setManager(manager); + fragment.setDismissShowUi(mRootView); + if (mContext instanceof LiveSwAnchorActivity) { + fragment.show(((LiveSwAnchorActivity) 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((LiveSwAnchorActivity) 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.getImageByAlumb(); + } 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.getImageByAlumb(); + } + } + }); + } + } + + /** + * 切换镜头 + */ + private void toggleCamera() { + ((LiveSwAnchorActivity) mContext).toggleCamera(); + } + + /** + * 关闭 + */ + private void close() { + ((LiveSwAnchorActivity) 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(((LiveSwAnchorActivity) mContext).getSupportFragmentManager(), "LiveRoomTypeDialogFragment"); + + } + + /** + * 设置美颜 + */ + private void beauty() { + ((LiveSwAnchorActivity) 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(((LiveSwAnchorActivity) 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(((LiveSwAnchorActivity) 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 = ((LiveSwAnchorActivity) 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,true, 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(); + ((LiveSwAnchorActivity) 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/LivePlayKsyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePlayKsyViewHolder.java index a379ef3e7..24614a852 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlayKsyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlayKsyViewHolder.java @@ -11,25 +11,16 @@ import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.RelativeLayout; -import com.alibaba.fastjson.JSONObject; -import com.google.gson.Gson; import com.tencent.live2.V2TXLiveDef; import com.tencent.live2.V2TXLivePlayer; import com.tencent.live2.impl.V2TXLivePlayerImpl; import com.tencent.rtmp.ui.TXCloudVideoView; -import com.yunbao.common.CommonAppConfig; import com.yunbao.common.bean.UserBean; import com.yunbao.common.glide.ImgLoader; -import com.yunbao.common.http.HttpCallback; -import com.yunbao.common.http.HttpClient; import com.yunbao.common.utils.DpUtil; import com.yunbao.common.utils.L; import com.yunbao.common.utils.ScreenDimenUtil; import com.yunbao.live.R; -import com.yunbao.live.bean.DrPkbean; - -import java.util.ArrayList; -import java.util.List; /** * Created by cxf on 2018/10/10. @@ -77,7 +68,7 @@ public class LivePlayKsyViewHolder extends LiveRoomPlayViewHolder { @Override protected int getLayoutId() { - return R.layout.view_live_play_ksy; + return R.layout.view_live_play_sw; } @Override @@ -272,6 +263,36 @@ public class LivePlayKsyViewHolder extends LiveRoomPlayViewHolder { LivePlayKsyViewHolder.landscape =landscape; } + @Override + public void endPk() { + + } + + @Override + public void endpk(String liveUid) { + + } + + @Override + public void initSwEngine(String liveUid) { + + } + + @Override + public void removeDetailView() { + + } + + @Override + public void setPkView(String liveUid) { + + } + + @Override + public void claerDrPkInfoView() { + + } + @Override public ViewGroup getSmallContainer() { diff --git a/live/src/main/java/com/yunbao/live/views/LivePlayListener.java b/live/src/main/java/com/yunbao/live/views/LivePlayListener.java index befa67854..39359037b 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlayListener.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlayListener.java @@ -12,7 +12,7 @@ public interface LivePlayListener extends LiveActivityLifeCallback { * * @param data 房间信息 */ - void onAdd(LiveBean data, int liveType, int liveTypeVal, int liveSdk); + void onAdd(LiveBean data, int liveType, int liveTypeVal, int liveSdk,boolean isSw); /** * 用户滑动移除该页面 diff --git a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java index 37fd85f13..52ba0d341 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java @@ -1,10 +1,8 @@ package com.yunbao.live.views; import static com.lzy.okgo.utils.HttpUtils.runOnUiThread; -import static com.yunbao.common.Constants.SOCKET_LIVE_DRPK; import android.Manifest; -import android.app.Activity; import android.app.Dialog; import android.content.Context; import android.graphics.Color; @@ -15,28 +13,23 @@ import android.os.Looper; 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.view.ViewParent; import android.widget.FrameLayout; import android.widget.ImageView; -import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.TextView; -import com.alibaba.fastjson.JSONObject; 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.google.gson.Gson; 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.CommonAppConfig; import com.yunbao.common.bean.EnterRoomNewModel; import com.yunbao.common.bean.UserBean; import com.yunbao.common.dialog.LiveFontSizeSettingDialog; @@ -57,9 +50,8 @@ 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.bean.DrPkbean; import com.yunbao.live.event.LiveAudienceEvent; -import com.yunbao.live.socket.SocketSendBean; +import com.yunbao.live.utils.LiveExoPlayerManager; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; @@ -78,6 +70,7 @@ 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; @@ -94,11 +87,6 @@ import cn.rongcloud.rtc.base.RCRTCRoomType; import cn.rongcloud.rtc.base.RCRTCStreamType; import cn.rongcloud.rtc.base.RTCErrorCode; import cn.rongcloud.rtc.core.RendererCommon; -import io.agora.beautyapi.faceunity.agora.SWAuManager; -import io.rong.imlib.IRongCallback; -import io.rong.imlib.RongIMClient; -import io.rong.imlib.model.Conversation; -import io.rong.message.TextMessage; public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { @@ -107,12 +95,9 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { private ViewGroup mSmallContainer; private ViewGroup mLeftContainer; private ViewGroup mRightContainer; - private ViewGroup mPkContainer; + private RelativeLayout mPkContainer; public StyledPlayerView mVideoView; - private FrameLayout playFrameLayout; - private FrameLayout playFrameLayout1; - private View mLoading, mLoading2; private ImageView mCover; private boolean mPaused;//是否切后台了 @@ -131,29 +116,13 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { static int vHeight;//视频高 private TextView debugView; - //private LiveExoPlayerManager mPlayer; + private LiveExoPlayerManager mPlayer; private boolean isPk = false; private boolean userJoinLinkMic = false;//用户是否已加入房间 //0未申请1申请中2连麦中 RCRTCRoom rcrtcRoom; String purl, srcUrl; - SWAuManager swAuManager; - String liveUid; - - private LinearLayout dr_pk_view; - private FrameLayout dr1_preview; - private FrameLayout dr2_preview; - private FrameLayout dr3_preview; - private FrameLayout dr4_preview; - - 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 int getLandscape() { return landscape; @@ -164,9 +133,9 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { contexts = context; landscape = landscapes; Log.i("收收收", landscape + ""); - L.eSw("liveUid:" + liveUid); } + @Override protected int getLayoutId() { return R.layout.view_live_play_ksy; @@ -178,12 +147,10 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { EventBus.getDefault().register(this); Bus.getOn(this); mRoot = (ViewGroup) findViewById(R.id.root); - playFrameLayout = (FrameLayout) findViewById(R.id.playView); - playFrameLayout1 = (FrameLayout) findViewById(R.id.playView1); mSmallContainer = (ViewGroup) findViewById(R.id.small_container); mLeftContainer = (ViewGroup) findViewById(R.id.left_container); mRightContainer = (ViewGroup) findViewById(R.id.right_container); - mPkContainer = (FrameLayout) findViewById(R.id.pk_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); @@ -198,269 +165,12 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { params.height = vHeight; mPkContainer.requestLayout(); + mPlayer = new LiveExoPlayerManager(mContext); + mPlayer.setMainView(mVideoView); + mPlayer.setListener(new ExoPlayerListener()); debugView = new TextView(mContext); debugView.setBackgroundColor(Color.WHITE); - dr_pk_view = (LinearLayout) findViewById(R.id.dr_pk_view); - 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); - dr_pk_view.setVisibility(View.GONE); - } - - public void initSwEngine(String liveUid) { - this.liveUid = liveUid; - //初始化声网SDK - swAuManager = SWAuManager.get(); - swAuManager.setAudienceContainer(ry_view); - swAuManager.initRtcEngine((Activity) mContext); - swAuManager.setupRemoteVideo(Integer.parseInt(liveUid)); - //进入主播房间 - swAuManager.joinRoom(CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, SWAuManager.getChannelName(liveUid)); - } - - /** - * 开启单人PK - * - * @param Uid - */ - public void setPkView(String Uid) { - L.eSw("setPkView Uid " + Uid); - mPkContainer.setVisibility(View.VISIBLE); - swAuManager.updateMyChannelView((FrameLayout) mLeftContainer, Integer.parseInt(liveUid)); - ry_view.removeAllViews(); - //加入对方主播房间 - swAuManager.setPkContainer1((FrameLayout) mRightContainer); - swAuManager.joinExRoomEx(Integer.parseInt(Uid), CommonAppConfig.SWToken, SWAuManager.getChannelName(Uid)); - } - - List drMicUserList = new ArrayList<>(); - - boolean isAdd = true; - - @Override - public void setDrMicInfo(UserBean u) { - isAdd = true; - L.eSw("setDrMicInfo:-----------------" + u.getId() + " drMicUserList" + new Gson().toJson(drMicUserList)); - for (int i = 0; i < drMicUserList.size(); i++) { - if (u.getId().equals(drMicUserList.get(i).getId()) || u.getId().equals(liveUid)) { - isAdd = false; - } - } - L.eSw("setDrMicInfo:---------------isAdd--" + isAdd); - //加载多人PK(连麦)主播视图 - if (isAdd) { - dr_pk_view.setVisibility(View.VISIBLE); - drMicUserList.add(u); - if (drMicUserList.size() == 1) { - L.eSw("setDrMicInfo:-----------------drMicUserList.size() == 1"); - ry_view.removeAllViews(); - swAuManager.updateMyChannelView((FrameLayout) dr1_preview, Integer.parseInt(liveUid)); - swAuManager.joinChannelDrEx(dr2_preview, CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, u.getId(), SWAuManager.getChannelName(u.getId())); - dr1_preview.setVisibility(View.VISIBLE); - dr2_preview.setVisibility(View.VISIBLE); - dr3_preview.setVisibility(View.GONE); - dr4_preview.setVisibility(View.GONE); - } else if (drMicUserList.size() == 2) { - L.eSw("setDrMicInfo:-----------------drMicUserList.size() == 2"); - dr4_preview.setVisibility(View.VISIBLE); - swAuManager.joinChannelDrEx(dr4_preview, CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, u.getId(), SWAuManager.getChannelName(u.getId())); - } else if (drMicUserList.size() == 3) { - L.eSw("setDrMicInfo:-----------------drMicUserList.size() == 3"); - dr4_preview.setVisibility(View.VISIBLE); - dr3_preview.setVisibility(View.VISIBLE); - swAuManager.exitChannelToUid(Integer.parseInt(CommonAppConfig.getInstance().getUid()), drMicUserList.get(1).getId()); - swAuManager.joinChannelDrEx(dr3_preview, CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, drMicUserList.get(1).getId(), SWAuManager.getChannelName(drMicUserList.get(1).getId())); - swAuManager.joinChannelDrEx(dr4_preview, CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, drMicUserList.get(2).getId(), SWAuManager.getChannelName(drMicUserList.get(2).getId())); - } - } - - HttpClient.getInstance().get("Live.getDRPKroom", "Live.getDRPKroom").params("uid", CommonAppConfig.getInstance().getUid()).params("roomid", liveUid).execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - if (info.length > 0) { - JSONObject obj = JSONObject.parseObject(info[0]); - List drPkbeans = JSONObject.parseArray(obj.getString("userlist"), DrPkbean.class); - int removeIndex = -1; - for (int i = 0; i < drPkbeans.size(); i++) { - if (liveUid.equals(String.valueOf(drPkbeans.get(i).getId()))) { - removeIndex = i; - } - } - if (removeIndex != -1) { - drPkbeans.remove(removeIndex); - } - setDrPkView(drPkbeans); - } - } - }); - } - - public void claerDrPkInfoView() { - if (detailsView1 != null) { - dr1_preview.removeView(detailsView1); - } - if (detailsView2 != null) { - dr2_preview.removeView(detailsView2); - } - if (detailsView3 != null) { - dr3_preview.removeView(detailsView3); - } - if (detailsView4 != null) { - dr4_preview.removeView(detailsView4); - } - } - - public void setDrPkView(List drPkbeanList) { - if (detailsView1 != null) { - dr1_preview.removeView(detailsView1); - } - - /*new Handler().postDelayed(new Runnable() { - @Override - public void run() { - - 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); - textPkName1 = detailsView1.findViewById(R.id.text_pk_name1); - imageGrade1.setTag(String.valueOf(IMLoginManager.get(mContext).getUserInfo().getId())); - dr1_preview.addView(detailsView1); - detailsLinearLayout1.setVisibility(View.VISIBLE); - linearGrade1.setVisibility(View.GONE); - - for (int j = 0; j < drPkbeanList.size(); j++) { - if (j == 0) { - L.eSw("j == 0:" + j); - //设置多人PK数据 - if (detailsView2 != null) { - dr2_preview.removeView(detailsView2); - } - 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(drPkbeanList.get(0).getId())); - textPkName2.setText(drPkbeanList.get(0).getUser_nicename()); - dr2_preview.addView(detailsView2); - detailsLinearLayout2.setVisibility(View.VISIBLE); - linearGrade2.setVisibility(View.GONE); - } else if (j == 1) { - L.eSw("j == 1:" + j); - if (detailsView4 != null) { - dr4_preview.removeView(detailsView4); - } - 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(String.valueOf(drPkbeanList.get(1).getId())); - textPkName4.setText(drPkbeanList.get(1).getUser_nicename()); - dr4_preview.addView(detailsView4); - detailsLinearLayout4.setVisibility(View.VISIBLE); - linearGrade4.setVisibility(View.GONE); - } else if (j == 2) { - L.eSw("j == 2:" + j); - - if (detailsView4 != null) { - dr4_preview.removeView(detailsView4); - } - 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(String.valueOf(drPkbeanList.get(2).getId())); - textPkName4.setText(drPkbeanList.get(2).getUser_nicename()); - dr4_preview.addView(detailsView4); - detailsLinearLayout4.setVisibility(View.VISIBLE); - linearGrade4.setVisibility(View.GONE); - - if (detailsView3 != null) { - dr3_preview.removeView(detailsView3); - } - 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(String.valueOf(drPkbeanList.get(1).getId())); - textPkName3.setText(drPkbeanList.get(1).getUser_nicename()); - dr3_preview.addView(detailsView3); - detailsLinearLayout3.setVisibility(View.VISIBLE); - linearGrade3.setVisibility(View.GONE); - } - } - } - }, 2000);*/ - } - - - /** - * 退出单人pk - * - * @param pkUid - */ - public void endpk(String pkUid) { - L.eSw("endpk " + pkUid); - mPkContainer.setVisibility(View.GONE); - swAuManager.exitChannelToUid(Integer.parseInt(CommonAppConfig.getInstance().getUid()), SWAuManager.getChannelName(pkUid)); - swAuManager.updateMyChannelView(ry_view, Integer.parseInt(liveUid)); - ry_view.setVisibility(View.VISIBLE); - mLeftContainer.removeAllViews(); - mRightContainer.removeAllViews(); - } - - /** - * 退出所有连麦主播的房間 - */ - public void endPk() { - dr_pk_view.setVisibility(View.GONE); - dr1_preview.setVisibility(View.GONE); - dr2_preview.setVisibility(View.GONE); - dr3_preview.setVisibility(View.GONE); - dr4_preview.setVisibility(View.GONE); - dr1_preview.removeAllViews(); - dr2_preview.removeAllViews(); - dr3_preview.removeAllViews(); - dr4_preview.removeAllViews(); - //退出所有连麦主播的房間 - for (int i = 0; i < drMicUserList.size(); i++) { - swAuManager.exitChannelToUid(Integer.parseInt(CommonAppConfig.getInstance().getUid()), drMicUserList.get(i).getId()); - } - drMicUserList = new ArrayList<>(); - //將當前主播畫面放大 - swAuManager.updateMyChannelView((FrameLayout) ry_view, Integer.parseInt(liveUid)); - } - - /** - * 将用户设置成主播,与主播连麦 - */ - private void joinLiveMic() { - L.eSw("joinLiveMic"); - 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 + "热热热"); - if (code == 0) { - swAuManager.setMicAn(true); - } - } - }); - } - - private void endLiveMic() { - L.eSw("endLiveMic"); - swAuManager.setMicAn(false); } @Override @@ -497,6 +207,10 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { 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(); @@ -505,11 +219,11 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { mVideoView.setLayoutParams(params); mVideoView.requestLayout(); - /* RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); + RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); params1.height = RelativeLayout.LayoutParams.MATCH_PARENT; params1.topMargin = 0; ry_view.setLayoutParams(params1); - ry_view.requestLayout();*/ + ry_view.requestLayout(); RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) mCover.getLayoutParams(); params2.height = RelativeLayout.LayoutParams.MATCH_PARENT; params2.topMargin = 0; @@ -525,12 +239,12 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { mVideoView.setLayoutParams(params); mVideoView.requestLayout(); - /*RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); + 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();*/ + ry_view.requestLayout(); RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) mCover.getLayoutParams(); params2.height = DpUtil.dp2px(270); params2.topMargin = DpUtil.dp2px(120); @@ -561,7 +275,13 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { */ @Override public void resumePlay() { - + if (!mPlayer.isPlaying()) { + new Handler(Looper.getMainLooper()) + .postDelayed(() -> { + mPlayer.replay(); + // ToastUtil.show("强制播放" + val); + }, 100); + } } /** @@ -575,6 +295,30 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { 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(); } @@ -585,12 +329,14 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { 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); @@ -602,6 +348,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { if (TextUtils.isEmpty(url) || mVideoView == null) { return; } + mPlayer.switchUrl(url); purl = url; } @@ -614,6 +361,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { 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"); @@ -623,6 +371,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { if (!tmpPk) { waitNextUrl = url; } + mPlayer.switchUrl(srcUrl); tmpPk = true; } else if (!isPk) { tmpPk = false; @@ -633,12 +382,14 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { } 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); @@ -646,12 +397,12 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { mVideoView.setLayoutParams(params); mVideoView.requestLayout(); - /* RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); + 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();*/ + ry_view.requestLayout(); RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) mCover.getLayoutParams(); params2.height = DpUtil.dp2px(270); params2.topMargin = DpUtil.dp2px(120); @@ -659,13 +410,31 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { mCover.requestLayout(); } + @Override + public void endPk() { + + } + + @Override + public void endpk(String liveUid) { + + } + + @Override + public void initSwEngine(String liveUid) { + + } + @Override public void release() { mEnd = true; mStarted = false; + if (mPlayer != null) { + mPlayer.stop(); + mPlayer.release(); + } Bus.getOff(this); EventBus.getDefault().unregister(this); - //swAuManager.exitChannelAll(); L.e(TAG, "release------->"); } @@ -678,6 +447,9 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { mCover.setVisibility(View.VISIBLE); } } + if (mPlayer != null) { + mPlayer.stop(); + } stopPlay2(); } @@ -690,14 +462,22 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { 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(); + 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();*/ + ry_view.requestLayout(); isPk = true; + if (mPlayer.getUrl().contains("848_24.flv") || mPlayer.getUrl().contains("1280_24.flv")) { + tmpPk = false; + switchStreamPk(true); + } } /** @@ -714,6 +494,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { } 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(); @@ -723,11 +504,11 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { mVideoView.setLayoutParams(params); mVideoView.requestLayout(); - /*RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); + RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); params1.height = height; params1.topMargin = 0; ry_view.setLayoutParams(params1); - ry_view.requestLayout();*/ + ry_view.requestLayout(); RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) mCover.getLayoutParams(); params2.height = height; params2.topMargin = 0; @@ -745,7 +526,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { mVideoView.setLayoutParams(params); mVideoView.requestLayout(); - /*RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); + RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); params1.height = height; params1.topMargin = 0; params1.addRule(RelativeLayout.ALIGN_TOP); @@ -753,7 +534,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { params1.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); } ry_view.setLayoutParams(params1); - ry_view.requestLayout();*/ + ry_view.requestLayout(); RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) mCover.getLayoutParams(); params2.height = height; params2.topMargin = DpUtil.dp2px(120); @@ -802,6 +583,10 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { // } } + @Override + public void setDrMicInfo(UserBean u) { + + } public void removeDetailView() { // if (detailsView != null) { @@ -810,6 +595,16 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { // } } + @Override + public void setPkView(String liveUid) { + + } + + @Override + public void claerDrPkInfoView() { + + } + @Override public ViewGroup getSmallContainer() { return mSmallContainer; @@ -918,26 +713,15 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { mVideoView.requestLayout(); } - boolean isShow = false; @Subscribe(threadMode = ThreadMode.MAIN) public void onUpdata(String str) { if ("UsertoRY".equals(str)) { - //todo 新增dis监听 - if (isShow) { - return; - } - isShow = true; - DialogUitl.showSimpleDialog(mContext, mContext.getString(R.string.mic_tag), new DialogUitl.SimpleCallback2() { - @Override - public void onCancelClick() { - isShow = false; - } - + DialogUitl.showSimpleDialog(mContext, mContext.getString(R.string.mic_tag), new DialogUitl.SimpleCallback() { @Override public void onConfirmClick(Dialog dialog, String content) { UsertoRY(); - isShow = false; + dialog = null; } }); @@ -950,39 +734,126 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { 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() { + 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 run() { - // UsertoRY(); - //将自己设置成给主播,和主播连麦 - L.eSw("将自己设置成给主播,和主播连麦"); - joinLiveMic(); + 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)) { - L.eSw("endMic.equals(str))" + str); - // 开始切换为观众身份 - //声网-将用户身份切换只观众 - endLiveMic(); + 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(); + EasyFloat.with(mContext) + .setDragEnable(true) + .setTag("Debug") + .setLayout(debugView) + .show(); } } @@ -1000,71 +871,79 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { 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) { + 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 beforeShow(BasePopupView popupView) { - } + } - @Override - public void onShow(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(); - } + @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); - } - } + 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 void beforeDismiss(BasePopupView popupView) { - } + } - @Override - public boolean onBackPressed(BasePopupView popupView) { - return false; - } + @Override + public boolean onBackPressed(BasePopupView popupView) { + return false; + } - @Override - public void onKeyBoardStateChanged(BasePopupView popupView, int height) { + @Override + public void onKeyBoardStateChanged(BasePopupView popupView, int height) { - } + } - @Override - public void onDrag(BasePopupView popupView, int value, float percent, boolean upOrLeft) { + @Override + public void onDrag(BasePopupView popupView, int value, float percent, boolean upOrLeft) { - } + } - @Override - public void onClickOutside(BasePopupView popupView) { + @Override + public void onClickOutside(BasePopupView popupView) { - } - }).asCustom(liveClarityCustomPopup).show(); + } + }) + .asCustom(liveClarityCustomPopup) + .show(); } else if (event.getType() == LiveAudienceEvent.LiveAudienceType.FONT_SIZE) { int fount = 0; try { @@ -1075,17 +954,11 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { 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)); + EventBus.getDefault().post(new LiveAudienceEvent() + .setNums(bean) + .setType(LiveAudienceEvent.LiveAudienceType.LIVE_FONT_SIZE)); } }).showDialog(); - } else if (event.getType() == LiveAudienceEvent.LiveAudienceType.PK_TWO_START) { - //将当前主播画面换个画布展示 - String pkUid = (String) event.getObject(); - setPkView(pkUid); - - } else if (event.getType() == LiveAudienceEvent.LiveAudienceType.LIVE_PK_END) { - String pkUid = (String) event.getObject(); - //endpk(pkUid); } } @@ -1094,17 +967,19 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { */ public List userinputStreamList = new ArrayList<>(); + public void UsertoRY() { userinputStreamList.clear(); Log.e("ry", "主播同意了UsertoRY"); if (userJoinLinkMic) {//已经在房间内,不再joinRoom直接去连麦 - //subscribeMic(rcrtcRoom); - joinLiveMic(); + subscribeMic(rcrtcRoom); return; } - /*RCRTCRoomConfig roomConfig = RCRTCRoomConfig.Builder.create() + RCRTCRoomConfig roomConfig = RCRTCRoomConfig.Builder.create() // 根据实际场景,选择音视频直播:LIVE_AUDIO_VIDEO 或音频直播:LIVE_AUDIO - .setRoomType(RCRTCRoomType.LIVE_AUDIO_VIDEO).setLiveRole(RCRTCLiveRole.AUDIENCE).build(); + .setRoomType(RCRTCRoomType.LIVE_AUDIO_VIDEO) + .setLiveRole(RCRTCLiveRole.AUDIENCE) + .build(); RCRTCEngine.getInstance().joinRoom(LiveActivity.mLiveUid, roomConfig, new IRCRTCResultDataCallback() { @@ -1113,6 +988,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { userJoinLinkMic = true; rcrtcRoom = data; subscribeMic(data); + } @Override @@ -1137,7 +1013,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { } } - });*/ + }); } @@ -1153,7 +1029,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { Log.i(TAG, "资源流 type: " + stream.getMediaType()); if (stream.getMediaType() == RCRTCMediaType.VIDEO) { //暂停播放 - + mPlayer.stop(); //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 @@ -1285,7 +1161,8 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { break; } // 示例代码使用480x640分辨率演示 - RCRTCVideoStreamConfig config = RCRTCVideoStreamConfig.Builder.create() + RCRTCVideoStreamConfig config = RCRTCVideoStreamConfig + .Builder.create() //设置分辨率 .setVideoResolution(rcrtcVideoResolution) //设置帧率 @@ -1293,7 +1170,8 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { //设置最小码率,480P下推荐200 .setMinRate(minRate) //设置最大码率,480P下推荐900 - .setMaxRate(maxRate).build(); + .setMaxRate(maxRate) + .build(); RCRTCEngine.getInstance().getDefaultVideoStream().setVideoConfig(config); // 创建视图渲染视图 // RCRTCVideoView videoView = new RCRTCVideoView(contexts); @@ -1351,7 +1229,11 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { ((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"; + 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); @@ -1381,12 +1263,14 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { 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 + "热热热"); - } - }); + 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 @@ -1421,12 +1305,16 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { 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(); + 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) { @@ -1434,6 +1322,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { } 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 { @@ -1483,6 +1372,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { loadingListener.onPlayer(); } if (waitNextUrl != null) { + mPlayer.switchUrl(waitNextUrl); waitNextUrl = null; } } diff --git a/live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java new file mode 100644 index 000000000..2dbe65889 --- /dev/null +++ b/live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java @@ -0,0 +1,1504 @@ +package com.yunbao.live.views; + +import static com.lzy.okgo.utils.HttpUtils.runOnUiThread; + +import android.Manifest; +import android.app.Activity; +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.LinearLayout; +import android.widget.RelativeLayout; +import android.widget.TextView; + +import com.alibaba.fastjson.JSONObject; +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.google.gson.Gson; +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.CommonAppConfig; +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.bean.DrPkbean; +import com.yunbao.live.event.LiveAudienceEvent; + +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.callback.IRCRTCResultCallback; +import cn.rongcloud.rtc.api.callback.IRCRTCRoomEventsListener; +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.RCRTCMediaType; +import cn.rongcloud.rtc.base.RCRTCParamsType; +import cn.rongcloud.rtc.base.RCRTCRemoteVideoFrame; +import cn.rongcloud.rtc.base.RCRTCStreamType; +import cn.rongcloud.rtc.base.RTCErrorCode; +import cn.rongcloud.rtc.core.RendererCommon; +import io.agora.beautyapi.faceunity.agora.SWAuManager; + +public class LivePlaySwViewHolder extends LiveRoomPlayViewHolder { + + private static final String TAG = "LivePlayViewHolder"; + private ViewGroup mRoot; + private ViewGroup mSmallContainer; + private ViewGroup mLeftContainer; + private ViewGroup mRightContainer; + private ViewGroup mPkContainer; + public StyledPlayerView mVideoView; + + private FrameLayout playFrameLayout; + private FrameLayout playFrameLayout1; + + 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; + SWAuManager swAuManager; + String liveUid; + + private LinearLayout dr_pk_view; + private FrameLayout dr1_preview; + private FrameLayout dr2_preview; + private FrameLayout dr3_preview; + private FrameLayout dr4_preview; + + 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 int getLandscape() { + return landscape; + } + + public LivePlaySwViewHolder(Context context, ViewGroup parentView, int landscapes) { + super(context, parentView); + contexts = context; + landscape = landscapes; + Log.i("收收收", landscape + ""); + L.eSw("liveUid:" + liveUid); + } + + @Override + protected int getLayoutId() { + return R.layout.view_live_play_sw; + } + + @Override + public void init() { + Log.i(TAG, "init: 初始化播放器ViewHolder"); + EventBus.getDefault().register(this); + Bus.getOn(this); + mRoot = (ViewGroup) findViewById(R.id.root); + playFrameLayout = (FrameLayout) findViewById(R.id.playView); + playFrameLayout1 = (FrameLayout) findViewById(R.id.playView1); + mSmallContainer = (ViewGroup) findViewById(R.id.small_container); + mLeftContainer = (ViewGroup) findViewById(R.id.left_container); + mRightContainer = (ViewGroup) findViewById(R.id.right_container); + mPkContainer = (FrameLayout) 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(); + + debugView = new TextView(mContext); + debugView.setBackgroundColor(Color.WHITE); + + dr_pk_view = (LinearLayout) findViewById(R.id.dr_pk_view); + 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); + dr_pk_view.setVisibility(View.GONE); + } + + public void initSwEngine(String liveUid) { + this.liveUid = liveUid; + //初始化声网SDK + swAuManager = SWAuManager.get(); + swAuManager.setAudienceContainer(ry_view); + swAuManager.initRtcEngine((Activity) mContext); + swAuManager.setupRemoteVideo(Integer.parseInt(liveUid)); + //进入主播房间 + swAuManager.joinRoom(CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, SWAuManager.getChannelName(liveUid)); + } + + /** + * 开启单人PK + * + * @param Uid + */ + public void setPkView(String Uid) { + L.eSw("setPkView Uid " + Uid); + mPkContainer.setVisibility(View.VISIBLE); + swAuManager.updateMyChannelView((FrameLayout) mLeftContainer, Integer.parseInt(liveUid)); + ry_view.removeAllViews(); + //加入对方主播房间 + swAuManager.setPkContainer1((FrameLayout) mRightContainer); + swAuManager.joinExRoomEx(Integer.parseInt(Uid), CommonAppConfig.SWToken, SWAuManager.getChannelName(Uid)); + } + + List drMicUserList = new ArrayList<>(); + + boolean isAdd = true; + + @Override + public void setDrMicInfo(UserBean u) { + isAdd = true; + L.eSw("setDrMicInfo:-----------------" + u.getId() + " drMicUserList" + new Gson().toJson(drMicUserList)); + for (int i = 0; i < drMicUserList.size(); i++) { + if (u.getId().equals(drMicUserList.get(i).getId()) || u.getId().equals(liveUid)) { + isAdd = false; + } + } + L.eSw("setDrMicInfo:---------------isAdd--" + isAdd); + //加载多人PK(连麦)主播视图 + if (isAdd) { + dr_pk_view.setVisibility(View.VISIBLE); + drMicUserList.add(u); + if (drMicUserList.size() == 1) { + L.eSw("setDrMicInfo:-----------------drMicUserList.size() == 1"); + ry_view.removeAllViews(); + swAuManager.updateMyChannelView((FrameLayout) dr1_preview, Integer.parseInt(liveUid)); + swAuManager.joinChannelDrEx(dr2_preview, CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, u.getId(), SWAuManager.getChannelName(u.getId())); + dr1_preview.setVisibility(View.VISIBLE); + dr2_preview.setVisibility(View.VISIBLE); + dr3_preview.setVisibility(View.GONE); + dr4_preview.setVisibility(View.GONE); + } else if (drMicUserList.size() == 2) { + L.eSw("setDrMicInfo:-----------------drMicUserList.size() == 2"); + dr4_preview.setVisibility(View.VISIBLE); + swAuManager.joinChannelDrEx(dr4_preview, CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, u.getId(), SWAuManager.getChannelName(u.getId())); + } else if (drMicUserList.size() == 3) { + L.eSw("setDrMicInfo:-----------------drMicUserList.size() == 3"); + dr4_preview.setVisibility(View.VISIBLE); + dr3_preview.setVisibility(View.VISIBLE); + swAuManager.exitChannelToUid(Integer.parseInt(CommonAppConfig.getInstance().getUid()), drMicUserList.get(1).getId()); + swAuManager.joinChannelDrEx(dr3_preview, CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, drMicUserList.get(1).getId(), SWAuManager.getChannelName(drMicUserList.get(1).getId())); + swAuManager.joinChannelDrEx(dr4_preview, CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, drMicUserList.get(2).getId(), SWAuManager.getChannelName(drMicUserList.get(2).getId())); + } + } + + HttpClient.getInstance().get("Live.getDRPKroom", "Live.getDRPKroom").params("uid", CommonAppConfig.getInstance().getUid()).params("roomid", liveUid).execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (info.length > 0) { + JSONObject obj = JSONObject.parseObject(info[0]); + List drPkbeans = JSONObject.parseArray(obj.getString("userlist"), DrPkbean.class); + int removeIndex = -1; + for (int i = 0; i < drPkbeans.size(); i++) { + if (liveUid.equals(String.valueOf(drPkbeans.get(i).getId()))) { + removeIndex = i; + } + } + if (removeIndex != -1) { + drPkbeans.remove(removeIndex); + } + setDrPkView(drPkbeans); + } + } + }); + } + + public void claerDrPkInfoView() { + if (detailsView1 != null) { + dr1_preview.removeView(detailsView1); + } + if (detailsView2 != null) { + dr2_preview.removeView(detailsView2); + } + if (detailsView3 != null) { + dr3_preview.removeView(detailsView3); + } + if (detailsView4 != null) { + dr4_preview.removeView(detailsView4); + } + } + + public void setDrPkView(List drPkbeanList) { + if (detailsView1 != null) { + dr1_preview.removeView(detailsView1); + } + + /*new Handler().postDelayed(new Runnable() { + @Override + public void run() { + + 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); + textPkName1 = detailsView1.findViewById(R.id.text_pk_name1); + imageGrade1.setTag(String.valueOf(IMLoginManager.get(mContext).getUserInfo().getId())); + dr1_preview.addView(detailsView1); + detailsLinearLayout1.setVisibility(View.VISIBLE); + linearGrade1.setVisibility(View.GONE); + + for (int j = 0; j < drPkbeanList.size(); j++) { + if (j == 0) { + L.eSw("j == 0:" + j); + //设置多人PK数据 + if (detailsView2 != null) { + dr2_preview.removeView(detailsView2); + } + 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(drPkbeanList.get(0).getId())); + textPkName2.setText(drPkbeanList.get(0).getUser_nicename()); + dr2_preview.addView(detailsView2); + detailsLinearLayout2.setVisibility(View.VISIBLE); + linearGrade2.setVisibility(View.GONE); + } else if (j == 1) { + L.eSw("j == 1:" + j); + if (detailsView4 != null) { + dr4_preview.removeView(detailsView4); + } + 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(String.valueOf(drPkbeanList.get(1).getId())); + textPkName4.setText(drPkbeanList.get(1).getUser_nicename()); + dr4_preview.addView(detailsView4); + detailsLinearLayout4.setVisibility(View.VISIBLE); + linearGrade4.setVisibility(View.GONE); + } else if (j == 2) { + L.eSw("j == 2:" + j); + + if (detailsView4 != null) { + dr4_preview.removeView(detailsView4); + } + 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(String.valueOf(drPkbeanList.get(2).getId())); + textPkName4.setText(drPkbeanList.get(2).getUser_nicename()); + dr4_preview.addView(detailsView4); + detailsLinearLayout4.setVisibility(View.VISIBLE); + linearGrade4.setVisibility(View.GONE); + + if (detailsView3 != null) { + dr3_preview.removeView(detailsView3); + } + 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(String.valueOf(drPkbeanList.get(1).getId())); + textPkName3.setText(drPkbeanList.get(1).getUser_nicename()); + dr3_preview.addView(detailsView3); + detailsLinearLayout3.setVisibility(View.VISIBLE); + linearGrade3.setVisibility(View.GONE); + } + } + } + }, 2000);*/ + } + + + /** + * 退出单人pk + * + * @param pkUid + */ + public void endpk(String pkUid) { + L.eSw("endpk " + pkUid); + mPkContainer.setVisibility(View.GONE); + swAuManager.exitChannelToUid(Integer.parseInt(CommonAppConfig.getInstance().getUid()), SWAuManager.getChannelName(pkUid)); + swAuManager.updateMyChannelView(ry_view, Integer.parseInt(liveUid)); + ry_view.setVisibility(View.VISIBLE); + mLeftContainer.removeAllViews(); + mRightContainer.removeAllViews(); + } + + /** + * 退出所有连麦主播的房間 + */ + public void endPk() { + dr_pk_view.setVisibility(View.GONE); + dr1_preview.setVisibility(View.GONE); + dr2_preview.setVisibility(View.GONE); + dr3_preview.setVisibility(View.GONE); + dr4_preview.setVisibility(View.GONE); + dr1_preview.removeAllViews(); + dr2_preview.removeAllViews(); + dr3_preview.removeAllViews(); + dr4_preview.removeAllViews(); + //退出所有连麦主播的房間 + for (int i = 0; i < drMicUserList.size(); i++) { + swAuManager.exitChannelToUid(Integer.parseInt(CommonAppConfig.getInstance().getUid()), drMicUserList.get(i).getId()); + } + drMicUserList = new ArrayList<>(); + //將當前主播畫面放大 + swAuManager.updateMyChannelView((FrameLayout) ry_view, Integer.parseInt(liveUid)); + } + + /** + * 将用户设置成主播,与主播连麦 + */ + private void joinLiveMic() { + L.eSw("joinLiveMic"); + 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 + "热热热"); + if (code == 0) { + swAuManager.setMicAn(true); + } + } + }); + } + + private void endLiveMic() { + L.eSw("endLiveMic"); + swAuManager.setMicAn(false); + } + + @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 (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() { + + } + + /** + * 开始播放 + * + * @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); + 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")) { + 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")) { + } + Log.e("purl121", url); + + if (TextUtils.isEmpty(url) || mVideoView == null) { + return; + } + + + if (TextUtils.isEmpty(url) || mVideoView == null) { + return; + } + 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) { + 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; + } + 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; + } + } + } + + @Override + public void clearFrame() { + super.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 release() { + mEnd = true; + mStarted = false; + Bus.getOff(this); + EventBus.getDefault().unregister(this); + //swAuManager.exitChannelAll(); + 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); + } + } + stopPlay2(); + } + + @Override + public void stopPlay2() { + + } + + @Override + public void setViewUP(int i) { + if (mVideoView == null) return; + Log.e("PK状态", "" + i); + + + /*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; + } + + /** + * 播放开始 + */ + public void onPrepared() { + if (mEnd) { + release(); + return; + } + int height; + if (videoLandscape == VIDEO_VERTICAL) { + height = ViewGroup.LayoutParams.MATCH_PARENT; + } else { + height = ViewGroup.LayoutParams.WRAP_CONTENT; + } + 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; +// } + } + + + public void removeDetailView() { +// if (detailsView != null) { +// mVideoView.removeView(detailsView); +// detailsView = null; +// } + } + + @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); + 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(); + } + + boolean isShow = false; + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onUpdata(String str) { + if ("UsertoRY".equals(str)) { + //todo 新增dis监听 + if (isShow) { + return; + } + isShow = true; + DialogUitl.showSimpleDialog(mContext, mContext.getString(R.string.mic_tag), new DialogUitl.SimpleCallback2() { + @Override + public void onCancelClick() { + isShow = false; + } + + @Override + public void onConfirmClick(Dialog dialog, String content) { + UsertoRY(); + isShow = false; + } + }); + + } 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(); + //将自己设置成给主播,和主播连麦 + L.eSw("将自己设置成给主播,和主播连麦"); + joinLiveMic(); + } + }); + } + }); + builder.build().show(); + + } else if ("endMic".equals(str)) { + L.eSw("endMic.equals(str))" + str); + // 开始切换为观众身份 + //声网-将用户身份切换只观众 + endLiveMic(); + } 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(); + } else if (event.getType() == LiveAudienceEvent.LiveAudienceType.PK_TWO_START) { + //将当前主播画面换个画布展示 + String pkUid = (String) event.getObject(); + setPkView(pkUid); + + } else if (event.getType() == LiveAudienceEvent.LiveAudienceType.LIVE_PK_END) { + String pkUid = (String) event.getObject(); + //endpk(pkUid); + } + } + + /** + * 把观众转换成主播 + */ + public List userinputStreamList = new ArrayList<>(); + + public void UsertoRY() { + userinputStreamList.clear(); + Log.e("ry", "主播同意了UsertoRY"); + if (userJoinLinkMic) {//已经在房间内,不再joinRoom直接去连麦 + //subscribeMic(rcrtcRoom); + joinLiveMic(); + 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) { + //暂停播放 + + //如果远端用户发布的是视频流,创建显示视图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"); + } + } + + 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) { + 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/LivePlayTxViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePlayTxViewHolder.java index 60e7155ec..73bb5b84f 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlayTxViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlayTxViewHolder.java @@ -79,6 +79,36 @@ public class LivePlayTxViewHolder extends LiveRoomPlayViewHolder implements ITXL public void setLiveBeanLandscape(int landscape) { } + @Override + public void endPk() { + + } + + @Override + public void endpk(String liveUid) { + + } + + @Override + public void initSwEngine(String liveUid) { + + } + + @Override + public void removeDetailView() { + + } + + @Override + public void setPkView(String liveUid) { + + } + + @Override + public void claerDrPkInfoView() { + + } + @Override protected int getLayoutId() { return R.layout.view_live_play_tx; diff --git a/live/src/main/java/com/yunbao/live/views/LivePlayTxViewHolder_backup.java b/live/src/main/java/com/yunbao/live/views/LivePlayTxViewHolder_backup.java deleted file mode 100644 index d413b7013..000000000 --- a/live/src/main/java/com/yunbao/live/views/LivePlayTxViewHolder_backup.java +++ /dev/null @@ -1,476 +0,0 @@ -package com.yunbao.live.views; - -import android.content.Context; -import android.os.Bundle; -import android.os.Handler; -import android.text.TextUtils; -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 com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; -import com.tencent.rtmp.ITXLivePlayListener; -import com.tencent.rtmp.TXLiveConstants; -import com.tencent.rtmp.TXLivePlayConfig; -import com.tencent.rtmp.TXLivePlayer; -import com.tencent.rtmp.ui.TXCloudVideoView; -import com.yunbao.common.bean.UserBean; -import com.yunbao.common.glide.ImgLoader; -import com.yunbao.common.http.HttpCallback; -import com.yunbao.common.utils.DpUtil; -import com.yunbao.common.utils.L; -import com.yunbao.common.utils.ToastUtil; -import com.yunbao.live.R; -import com.yunbao.common.http.LiveHttpConsts; -import com.yunbao.common.http.LiveHttpUtil; - -/** - * Created by cxf on 2018/10/10. - * 直播间播放器 腾讯播放器 - */ - -public class LivePlayTxViewHolder_backup extends LiveRoomPlayViewHolder implements ITXLivePlayListener { - - private static final String TAG = "LiveTxPlayViewHolder"; - private ViewGroup mRoot; - private ViewGroup mSmallContainer; - private ViewGroup mLeftContainer; - private ViewGroup mRightContainer; - private ViewGroup mPkContainer; - private TXCloudVideoView mVideoView; - private View mLoading; - private ImageView mCover; - private TXLivePlayer mPlayer; - private boolean mPaused;//是否切后台了 - private boolean mStarted;//是否开始了播放 - private boolean mEnd;//是否结束了播放 - private boolean mPausedPlay;//是否被动暂停了播放 - private boolean mChangeToLeft; - private boolean mChangeToAnchorLinkMic; - private String mUrl; - private int mPlayType; - private HttpCallback mGetTxLinkMicAccUrlCallback; - private Handler mHandler; - private int mVideoLastProgress; - - @Override - public void setPkview() { - - } - - @Override - public void setPkEndview() { - - } - - @Override - public void setDrMicInfo(UserBean u) { - - } - - @Override - public void setLiveBeanLandscape(int landscape) { - - } - - public LivePlayTxViewHolder_backup(Context context, ViewGroup parentView) { - super(context, parentView); - } - - @Override - protected int getLayoutId() { - return R.layout.view_live_play_tx; - } - - @Override - public void init() { - 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 = (ViewGroup) findViewById(R.id.pk_container); - mLoading = findViewById(R.id.loading); - mCover = (ImageView) findViewById(R.id.cover); - mVideoView = (TXCloudVideoView) findViewById(R.id.video_view); - - mPlayer = new TXLivePlayer(mContext); - mPlayer.setPlayListener(this); - mPlayer.setPlayerView(mVideoView); - mPlayer.enableHardwareDecode(false); - mPlayer.setRenderRotation(TXLiveConstants.RENDER_ROTATION_PORTRAIT); - mPlayer.setRenderMode(TXLiveConstants.RENDER_MODE_FULL_FILL_SCREEN); - TXLivePlayConfig playConfig = new TXLivePlayConfig(); - playConfig.setAutoAdjustCacheTime(true); - playConfig.setMaxAutoAdjustCacheTime(5.0f); - playConfig.setMinAutoAdjustCacheTime(1.0f); - mPlayer.setConfig(playConfig); - - } - - - @Override - public void onPlayEvent(int e, Bundle bundle) { - if (mEnd) { - return; - } - switch (e) { - case TXLiveConstants.PLAY_EVT_PLAY_BEGIN://播放开始 - if (mLoading != null && mLoading.getVisibility() == View.VISIBLE) { - mLoading.setVisibility(View.INVISIBLE); - } - break; - case TXLiveConstants.PLAY_EVT_PLAY_LOADING: - if (mLoading != null && mLoading.getVisibility() != View.VISIBLE) { - mLoading.setVisibility(View.VISIBLE); - } - break; - case TXLiveConstants.PLAY_EVT_RCV_FIRST_I_FRAME://第一帧 - hideCover(); - break; - case TXLiveConstants.PLAY_EVT_PLAY_END://播放结束 - replay(); - break; - case TXLiveConstants.PLAY_EVT_CHANGE_RESOLUTION://获取视频宽高 - if (mChangeToLeft || mChangeToAnchorLinkMic) { - return; - } - float width = bundle.getInt("EVT_PARAM1", 0); - float height = bundle.getInt("EVT_PARAM2", 0); - L.e(TAG, "流---width----->" + width); - L.e(TAG, "流---height----->" + height); - FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mVideoView.getLayoutParams(); - int targetH = 0; - if (width >= height) {//横屏 9:16=0.5625 - targetH = (int) (mVideoView.getWidth() / width * height); - } else { - targetH = ViewGroup.LayoutParams.MATCH_PARENT; - } - if (targetH != params.height) { - params.height = targetH; - params.gravity = Gravity.CENTER; - mVideoView.requestLayout(); - } - - break; - case TXLiveConstants.PLAY_ERR_NET_DISCONNECT://播放失败 - case TXLiveConstants.PLAY_ERR_FILE_NOT_FOUND: - ToastUtil.show(mContext.getString(R.string.live_play_error)); - break; - case TXLiveConstants.PLAY_EVT_PLAY_PROGRESS: - int progress = bundle.getInt("EVT_PLAY_PROGRESS_MS"); - if (mVideoLastProgress == progress) { - replay(); - } else { - mVideoLastProgress = progress; - } - break; - default:break; - } - } - - @Override - public void onNetStatus(Bundle bundle) { - - } - - - @Override - public void hideCover() { - if (mCover != null) { - mCover.animate().alpha(0).setDuration(500).start(); - } - } - - @Override - public void setCover(String coverUrl) { - if (mCover != null) { - ImgLoader.displayBlur(mContext, coverUrl, mCover); - } - } - - @Override - public void fullScreen() { - - } - - @Override - public void smallScreen() { - - } - - /** - * 循环播放 - */ - private void replay() { - if (mStarted && mPlayer != null) { - mPlayer.seek(0); - mPlayer.resume(); - } - } - - - /** - * 暂停播放 - */ - @Override - public void pausePlay() { - if (!mPausedPlay) { - mPausedPlay = true; - if (!mPaused) { - if (mPlayer != null) { - mPlayer.pause(); - } - } - if (mCover != null) { - mCover.setAlpha(1f); - if (mCover.getVisibility() != View.VISIBLE) { - mCover.setVisibility(View.VISIBLE); - } - } - } - } - - /** - * 暂停播放后恢复 - */ - @Override - public void resumePlay() { - if (mPausedPlay) { - mPausedPlay = false; - if (!mPaused) { - if (mPlayer != null) { - mPlayer.resume(); - } - } - hideCover(); - } - } - - /** - * 开始播放 - * - * @param url 流地址 - */ - @Override - public void play(String url,int playModel) { - if (TextUtils.isEmpty(url)) { - return; - } - int playType = -1; - if (url.startsWith("rtmp://")) { - playType = TXLivePlayer.PLAY_TYPE_LIVE_RTMP; - } else if (url.endsWith(".flv")) { - playType = TXLivePlayer.PLAY_TYPE_LIVE_FLV; - } else if (url.endsWith(".m3u8")) { - playType = TXLivePlayer.PLAY_TYPE_VOD_HLS; - } else if (url.endsWith(".mp4")) { - playType = TXLivePlayer.PLAY_TYPE_VOD_MP4; - } - if (playType == -1) { - ToastUtil.show(mContext.getString(R.string.live_play_error_2)); - return; - } - if (mPlayer != null) { - int result = mPlayer.startPlay(url, playType); - if (result == 0) { - mStarted = true; - mUrl = url; - mPlayType = playType; - } - } - L.e(TAG, "play----url--->" + url); - } - - @Override - public void switchStream(String url, int playModel) { - - } - - @Override - public void stopPlay() { - mChangeToLeft = false; - mChangeToAnchorLinkMic = false; - if (mHandler != null) { - mHandler.removeCallbacksAndMessages(null); - } - if (mCover != null) { - mCover.setAlpha(1f); - if (mCover.getVisibility() != View.VISIBLE) { - mCover.setVisibility(View.VISIBLE); - } - } - stopPlay2(); - } - - @Override - public void stopPlay2() { - if (mPlayer != null) { - mPlayer.stopPlay(false); - } - } - - @Override - public void release() { - mEnd = true; - if (mHandler != null) { - mHandler.removeCallbacksAndMessages(null); - } - mHandler = null; - LiveHttpUtil.cancel(LiveHttpConsts.GET_TX_LINK_MIC_ACC_URL); - if (mPlayer != null) { - mPlayer.stopPlay(false); - mPlayer.setPlayListener(null); - } - mPlayer = null; - L.e(TAG, "release------->"); - } - - - @Override - public ViewGroup getSmallContainer() { - return mSmallContainer; - } - - - @Override - public ViewGroup getRightContainer() { - return mRightContainer; - } - - @Override - public ViewGroup getPkContainer() { - return mPkContainer; - } - - @Override - public void changeToLeft() { - mChangeToLeft = true; - if (mVideoView != null) { - FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mVideoView.getLayoutParams(); - params.width = mVideoView.getWidth() / 2; - params.height = DpUtil.dp2px(250); - params.topMargin = DpUtil.dp2px(130); - mVideoView.setLayoutParams(params); - } - 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() { - mChangeToLeft = false; - if (mVideoView != null) { - FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mVideoView.getLayoutParams(); - params.width = ViewGroup.LayoutParams.MATCH_PARENT; - params.height = ViewGroup.LayoutParams.MATCH_PARENT; - params.topMargin = 0; - mVideoView.setLayoutParams(params); - } - if (mLoading != null && mRoot != 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); - mRoot.addView(mLoading); - } - } - - @Override - public void onResume() { - if (!mPausedPlay && mPaused && mPlayer != null) { - mPlayer.resume(); - } - mPaused = false; - } - - @Override - public void onPause() { - if (!mPausedPlay && mPlayer != null) { - mPlayer.pause(); - } - mPaused = true; - } - - @Override - public void onDestroy() { - release(); - } - - /** - * 腾讯sdk连麦时候切换低延时流 - */ - public void onLinkMicTxAccEvent(boolean linkMic) { - if (mStarted && mPlayer != null && !TextUtils.isEmpty(mUrl)) { - mPlayer.stopPlay(false); - if (linkMic) { - if (mGetTxLinkMicAccUrlCallback == null) { - mGetTxLinkMicAccUrlCallback = 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) { - String accUrl = obj.getString("streamUrlWithSignature"); - if (!TextUtils.isEmpty(accUrl) && mPlayer != null) { - L.e(TAG, "低延时流----->" + accUrl); - mPlayer.startPlay(accUrl, TXLivePlayer.PLAY_TYPE_LIVE_RTMP_ACC); - } - } - } - } - }; - } - LiveHttpUtil.getTxLinkMicAccUrl(mUrl, mGetTxLinkMicAccUrlCallback); - } else { - mPlayer.startPlay(mUrl, mPlayType); - } - } - } - - /** - * 设置主播连麦模式 - * - * @param anchorLinkMic - */ - public void setAnchorLinkMic(final boolean anchorLinkMic, int delayTime) { - if (mVideoView == null) { - return; - } - if (mHandler == null) { - mHandler = new Handler(); - } - mHandler.postDelayed(new Runnable() { - @Override - public void run() { - mChangeToAnchorLinkMic = anchorLinkMic; - FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mVideoView.getLayoutParams(); - if (anchorLinkMic) { - params.height = DpUtil.dp2px(250); - params.topMargin = DpUtil.dp2px(130); - params.gravity = Gravity.TOP; - } else { - params.height = ViewGroup.LayoutParams.MATCH_PARENT; - params.topMargin = 0; - params.gravity = Gravity.CENTER; - } - mVideoView.setLayoutParams(params); - } - }, delayTime); - - } -} diff --git a/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java index 373a64543..169b32dce 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java @@ -9,8 +9,8 @@ import static com.yunbao.live.event.LiveAudienceEvent.LiveAudienceType.LIVE_PK_I 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.Activity; import android.app.Dialog; import android.content.Context; import android.content.res.Resources; @@ -46,17 +46,16 @@ 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.StringUtil; 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.bean.DrPkbean; import com.yunbao.live.event.LiveAudienceEvent; import com.yunbao.common.http.LiveHttpConsts; import com.yunbao.common.http.LiveHttpUtil; @@ -72,23 +71,29 @@ 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 io.agora.beautyapi.faceunity.agora.SWAuManager; -import io.agora.beautyapi.faceunity.agora.SWManager; +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.imlib.model.Message; import io.rong.message.TextMessage; /** @@ -97,11 +102,13 @@ import io.rong.message.TextMessage; */ 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; @@ -111,6 +118,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX public LinearLayout dr_pk_view; public static RCRTCRoom rtcRoom; public static RCRTCLiveInfo rcrtcLiveInfo; + private ViewGroup liveActivityContainer; public FrameLayout timeTitle; public TextView textTime; @@ -119,8 +127,6 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX private LinearLayout goto_room_view; private boolean isPk = false; private boolean isNeedOpenCamera = false; - private SWManager swManager; - private String pkUid1; //修改上面主播的头像 @Subscribe(threadMode = ThreadMode.MAIN) @@ -134,6 +140,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX goto_room_view.setVisibility(View.VISIBLE); } else { goto_room_view.setVisibility(View.GONE); + } } } @@ -231,7 +238,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX UserBean userBean = new UserBean(); userBean.setId(inviterRoomId); //收到邀请这个时候正在PK或连麦中 自动拒绝对方 - if (isPking()) { + if (isPking() == true) { rtcRoom.getLocalUser().responseJoinOtherRoom(userBean.getId(), userBean.getId(), false, false, "extra", new IRCRTCResultCallback() { @@ -242,7 +249,9 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX @Override public void onSuccess() { - final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 8); + final SocketSendBean msg1 = new SocketSendBean() + .param("_method_", SOCKET_LINK_MIC_PK) + .param("action", 8); msg1.create(); String targetId = userBean.getId(); @@ -250,7 +259,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX 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() { + RongcloudIMManager.sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { @Override public void onAttached(io.rong.imlib.model.Message message) { @@ -286,7 +295,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX rtcRoom.getLocalUser().responseJoinOtherRoom(userBean.getId(), userBean.getId(), true, true, "LiveDRPK1", new IRCRTCResultCallback() { @Override public void onSuccess() { - //mLiveRyLinkMicPkPresenter.dRjoinOtherRoom(userBean.getId(), 2); + mLiveRyLinkMicPkPresenter.dRjoinOtherRoom(userBean.getId(), 2); } @Override @@ -301,7 +310,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX JSONObject map = JSONObject.parseObject(extra); userBean1.setId(map.getString("uid")); userBean1.setUserNiceName(map.getString("pkname")); - userBean1.setAvatar(map.getString("uhead")); + userBean1.setAvatar(map.getString("pkhead")); } else { userBean1.setId(inviterRoomId); userBean1.setUserNiceName("null"); @@ -382,7 +391,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX } else if (agree == true && extra.equals(SOCKET_LIVE_DRPK)) { mLiveRyLinkMicPkPresenter.onDRLinkMicToPk(inviteeRoomId); } else if (extra.equals("LiveDRPK1")) { - //mLiveRyLinkMicPkPresenter.dRjoinOtherRoom(inviteeRoomId, 3); + mLiveRyLinkMicPkPresenter.dRjoinOtherRoom(inviteeRoomId, 3); } else { Log.e("ry", extra); UserBean userBean1 = new UserBean(); @@ -406,7 +415,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX @Override public void onError(String error) { - ToastUtil.show(WordUtil.isNewZh() ? "抱歉!出錯了!" : "i \\'m sorry! An error occurred"); + ToastUtil.show(WordUtil.isNewZh()?"抱歉!出錯了!":"i \\'m sorry! An error occurred"); } }); @@ -462,6 +471,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX } }; + @Override public void init() { super.init(); @@ -496,231 +506,283 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX 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().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"); - //退出副房间 - // TODO: 2024/4/13 退出对方主播直播间 - SWManager.get().exitChannelToUid(Integer.parseInt(CommonAppConfig.getInstance().getUid()), pkUid1); - SWManager.get().updateMyChannelView((FrameLayout) mBigContainer); - btn_close.setVisibility(View.GONE);//隐藏连麦按钮 - EventBus.getDefault().post(new AnchorInfoEvent(true, "", "", "")); - closeButtonGone(); - - 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() { + 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(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) { - - } - }); + 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) { + + } + }); + } + }); + } + }); + } + }); + } - }); - } - - } - }); + } + }); } }); } }); - initRtcEngine(); - } - /** - * 初始化声网SDK - */ - private void initRtcEngine() { - swManager = SWManager.get(); - swManager.setAnchorContainer((FrameLayout) mBigContainer); - swManager.initRtcEngine((Activity) mContext, CommonAppConfig.getInstance().getUid()); - swManager.setOnRtcEngineListener(new SWManager.onRtcEngineListener() { + // 构建 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 onOpenSuccess(String channel, int uid) { - //开播成功 - L.eSw("开播成功"); + public void onFailed(RTCErrorCode errorCode) { + ToastUtil.show("开播失败" + errorCode); } - }); - } - public void exitChannelDrPk(List drPkbeanList){ - for (int i = 0; i () { + @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); + } + }); } + }); - mLiveRyLinkMicPkPresenter.setPkUserInfoView(u); - } - private int currentPosition = 0; - private String drpkUid3 = ""; - public int setAnDrPkRtc(String uid, int position) { - L.eSw("setAnDrPkRtc uid:"+uid+" position"+position); - int temp= -1; - if (swManager != null && !StringUtil.isEmpty(uid)) { - L.eSw("设置对方主播的视图 setAnDrPkRtc" + uid + "position:" + position); - if(currentPosition==0){ - position = 2; } - if(position==-1){ - temp = currentPosition+1; - }else{ - temp = position; - } - switch (temp) { - case 2: - swManager.joinChannelDrEx(dr2_preview,CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, uid, SWAuManager.getChannelName(uid)); - swManager.updateMyChannelView(dr1_preview); - mBigContainer.removeAllViews(); - - dr3_preview.setVisibility(View.GONE); - dr4_preview.setVisibility(View.GONE); - break; - case 3: - drpkUid3 = uid; - swManager.joinChannelDrEx(dr4_preview,CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, uid, SWAuManager.getChannelName(uid)); - dr3_preview.setVisibility(View.GONE); - dr4_preview.setVisibility(View.VISIBLE); - break; - case 4: - dr3_preview.setVisibility(View.VISIBLE); - //先退出这个主播的直播间,在进入该直播间,(视图问题暂时這樣處理) - swManager.exitChannelToUid(Integer.parseInt(CommonAppConfig.getInstance().getUid()),drpkUid3); - swManager.joinChannelDrEx(dr3_preview,CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, drpkUid3, SWAuManager.getChannelName(drpkUid3)); - - swManager.joinChannelDrEx(dr4_preview,CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, uid, SWAuManager.getChannelName(uid)); - break; - } - dr_pk_view.setVisibility(View.VISIBLE); - currentPosition = temp; - } - return currentPosition; - } - - public void anchorClose(){ - swManager.updateMyChannelView((FrameLayout) mBigContainer); //用户主动断开连麦再退出画面 - } - - public void onLinkMicAnchorClose() { - //swManager.updateMyChannelView((FrameLayout) mBigContainer); 用户主动断开连麦再退出画面 - //LivePushRyViewHolder.btn_close.setVisibility(View.GONE); - } - - - - public void onLinkDRMicPkApply(UserBean userBean) { - if (mLiveRyLinkMicPkPresenter != null) { - mLiveRyLinkMicPkPresenter.onLinkDRMicPkApply(userBean); - } + }); } @Override public void changeToLeft() { if (mPreView != null) { - LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) mPreView.getLayoutParams(); + FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mPreView.getLayoutParams(); params.width = mPreView.getWidth() / 2; - params.height = DpUtil.dp2px(mPreView.getHeight()); + params.height = DpUtil.dp2px(250); params.topMargin = DpUtil.dp2px(130); camera.setLayoutParams(params); } @@ -754,7 +816,17 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX } else { mCameraFront = true; } - swManager.switchCamera(); + RCRTCEngine.getInstance().getDefaultVideoStream().switchCamera(new CameraVideoCapturer.CameraSwitchHandler() { + @Override + public void onCameraSwitchDone(boolean isFrontCamera) { + + } + + @Override + public void onCameraSwitchError(String errorDescription) { + + } + }); } /** @@ -766,6 +838,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX ToastUtil.show(mContext.getString(R.string.live_open_flash)); return; } + } /** @@ -775,10 +848,6 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX */ @Override public void startPush(String pushUrl) { - //开播成功,创建频道 - if (swManager != null) { - swManager.createChannel(CommonAppConfig.SWToken, CommonAppConfig.getChannelName()); - } if (rcrtcLiveInfo != null) { rcrtcLiveInfo.addPublishStreamUrl(pushUrl, new IRCRTCResultDataCallback() { @Override @@ -878,7 +947,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX public void onResume() { mPaused = false; Log.i("摄像头", "onResume: " + isNeedOpenCamera); - if (isNeedOpenCamera) { + if(isNeedOpenCamera){ RCRTCEngine.getInstance().getDefaultVideoStream().startCamera(new IRCRTCResultDataCallback() { @Override public void onSuccess(Boolean data) { @@ -901,6 +970,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX public void startBgm(String path) { mBgmPath = path; + } @Override @@ -968,20 +1038,30 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX } String ct = "由於 " + uname + " 退出比賽," + pkname + " 獲得勝利"; - SocketSendBean seed_msg = new SocketSendBean().param("_method_", Constants.SOCKET_SYSTEM).param("action", 1).param("ct", ct); + 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() { + + 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) { @@ -1016,12 +1096,6 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX }); } - public void setEnableBeauty(boolean flag) { - if (swManager != null) { - swManager.setEnableBeauty(flag); - } - } - @Subscribe(threadMode = ThreadMode.MAIN) public void updateSub(LiveAudienceEvent event) { if (event.getType() == LIVE_PK_END) { @@ -1031,12 +1105,4 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX } Log.i("PK----->", "updateSub: " + isPk + "|" + event.getType()); } - - @Override - public void onDestroy() { - super.onDestroy(); - if (swManager != null) { - swManager.exitChannelAll(); - } - } } diff --git a/live/src/main/java/com/yunbao/live/views/LivePushSwViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePushSwViewHolder.java new file mode 100644 index 000000000..d5a2402c8 --- /dev/null +++ b/live/src/main/java/com/yunbao/live/views/LivePushSwViewHolder.java @@ -0,0 +1,731 @@ +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; +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.rtmp.ITXLivePushListener; +import com.tencent.rtmp.TXLiveConstants; +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.event.LivePushRyEvent; +import com.yunbao.common.glide.ImgLoader; +import com.yunbao.common.http.HttpCallback; +import com.yunbao.common.http.HttpClient; +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.StringUtil; +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.LiveSwAnchorActivity; +import com.yunbao.live.bean.DrPkbean; +import com.yunbao.live.event.LiveAudienceEvent; +import com.yunbao.common.http.LiveHttpConsts; +import com.yunbao.common.http.LiveHttpUtil; +import com.yunbao.live.presenter.LiveSwLinkMicPkPresenter; +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.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; +import io.rong.imlib.RongIMClient; +import io.rong.imlib.model.Conversation; +import io.rong.imlib.model.Message; +import io.rong.message.TextMessage; + +/** + * Created by cxf on 2018/10/7. + * 腾讯云直播推流 + */ + +public class LivePushSwViewHolder extends AbsRyLivePushViewHolder implements ITXLivePushListener { + private int mMeiBaiVal;//基础美颜 美白 + private int mMoPiVal;//基础美颜 磨皮 + private int mHongRunVal;//基础美颜 红润 + private String mBgmPath;//背景音乐路径 + private Bitmap mFilterBmp; + private Handler mMainHandler; + 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; + private SWManager swManager; + private String pkUid1; + + //修改上面主播的头像 + @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 LivePushSwViewHolder(Context context, ViewGroup parentView) { + super(context, parentView); + this.contexts = context; + EventBus.getDefault().register(this); + } + + @Override + protected int getLayoutId() { + return R.layout.view_live_push_sw; + } + + public void setLiveActivityContainer(ViewGroup liveActivityContainer) { + this.liveActivityContainer = liveActivityContainer; + } + + @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()); + //断开连麦 + LiveSwAnchorActivity.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"); + + //退出副房间 + // TODO: 2024/4/13 退出对方主播直播间 + SWManager.get().exitChannelToUid(Integer.parseInt(CommonAppConfig.getInstance().getUid()), pkUid1); + SWManager.get().updateMyChannelView((FrameLayout) mBigContainer); + btn_close.setVisibility(View.GONE);//隐藏连麦按钮 + EventBus.getDefault().post(new AnchorInfoEvent(true, "", "", "")); + closeButtonGone(); + + 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", LiveSwLinkMicPkPresenter.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" + LiveSwLinkMicPkPresenter.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) { + + } + }); + } + }); + } + }); + } + }); + + } + + } + }); + + + } + }); + } + }); + initRtcEngine(); + } + + /** + * 初始化声网SDK + */ + private void initRtcEngine() { + swManager = SWManager.get(); + swManager.setAnchorContainer((FrameLayout) mBigContainer); + swManager.initRtcEngine((Activity) mContext, CommonAppConfig.getInstance().getUid()); + swManager.setOnRtcEngineListener(new SWManager.onRtcEngineListener() { + @Override + public void onOpenSuccess(String channel, int uid) { + //开播成功 + L.eSw("开播成功"); + } + }); + } + + public void exitChannelDrPk(List drPkbeanList){ + for (int i = 0; i () { + @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); + } + }); + } + + public void setEnableBeauty(boolean flag) { + if (swManager != null) { + swManager.setEnableBeauty(flag); + } + } + + @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()); + } + + @Override + public void onDestroy() { + super.onDestroy(); + if (swManager != null) { + swManager.exitChannelAll(); + } + } +} diff --git a/live/src/main/java/com/yunbao/live/views/LiveReadyRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveReadyRyViewHolder.java index e329329eb..79ea38d0f 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveReadyRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveReadyRyViewHolder.java @@ -34,7 +34,7 @@ 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.activity.LiveSwAnchorActivity; import com.yunbao.live.adapter.LiveReadyShareAdapter; import com.yunbao.common.bean.LiveRoomTypeBean; import com.yunbao.live.dialog.LiveRoomTypeDialogFragment; @@ -123,7 +123,7 @@ public class LiveReadyRyViewHolder extends AbsViewHolder implements View.OnClick @Override public void beforeCamera() { - ((LiveRyAnchorActivity) mContext).beforeCamera(); + ((LiveSwAnchorActivity) mContext).beforeCamera(); } @Override @@ -218,8 +218,8 @@ public class LiveReadyRyViewHolder extends AbsViewHolder implements View.OnClick public void openWishListWindow() { LiveWishListDialogFragment fragment = new LiveWishListDialogFragment(); - if (mContext instanceof LiveRyAnchorActivity){ - fragment.show(((LiveRyAnchorActivity) mContext).getSupportFragmentManager(), "RY"); + if (mContext instanceof LiveSwAnchorActivity){ + fragment.show(((LiveSwAnchorActivity) mContext).getSupportFragmentManager(), "RY"); } } @@ -281,14 +281,14 @@ public class LiveReadyRyViewHolder extends AbsViewHolder implements View.OnClick * 切换镜头 */ private void toggleCamera() { - ((LiveRyAnchorActivity) mContext).toggleCamera(); + ((LiveSwAnchorActivity) mContext).toggleCamera(); } /** * 关闭 */ private void close() { - ((LiveRyAnchorActivity) mContext).endLives(); + ((LiveSwAnchorActivity) mContext).endLives(); } /** @@ -309,7 +309,7 @@ public class LiveReadyRyViewHolder extends AbsViewHolder implements View.OnClick * 设置美颜 */ private void beauty() { - ((LiveRyAnchorActivity) mContext).beauty(); + ((LiveSwAnchorActivity) mContext).beauty(); // Intent intent = new Intent(mContext, Beauty360Activity3.class); // mContext.startActivity(intent); @@ -324,7 +324,7 @@ public class LiveReadyRyViewHolder extends AbsViewHolder implements View.OnClick LiveRoomTypeDialogFragment fragment = new LiveRoomTypeDialogFragment(); fragment.setArguments(bundle); fragment.setCallback(mLiveTypeCallback); - fragment.show(((LiveRyAnchorActivity) mContext).getSupportFragmentManager(), "LiveRoomTypeDialogFragment"); + fragment.show(((LiveSwAnchorActivity) mContext).getSupportFragmentManager(), "LiveRoomTypeDialogFragment"); } /** @@ -398,7 +398,7 @@ public class LiveReadyRyViewHolder extends AbsViewHolder implements View.OnClick mLiveTimeCoin = coin; } }); - fragment.show(((LiveRyAnchorActivity) mContext).getSupportFragmentManager(), "LiveTimeDialogFragment"); + fragment.show(((LiveSwAnchorActivity) mContext).getSupportFragmentManager(), "LiveTimeDialogFragment"); } public void hide() { @@ -418,7 +418,7 @@ public class LiveReadyRyViewHolder extends AbsViewHolder implements View.OnClick * 点击开始直播按钮 */ private void startLive() { - boolean startPreview = ((LiveRyAnchorActivity) mContext).isStartPreview(); + boolean startPreview = ((LiveSwAnchorActivity) mContext).isStartPreview(); // if (!startPreview) { // ToastUtil.show(R.string.please_wait); // return; @@ -471,7 +471,7 @@ public class LiveReadyRyViewHolder extends AbsViewHolder implements View.OnClick return; } String title = mEditTitle.getText().toString().trim(); - LiveHttpUtil.newcreateRoom(title, mLiveClassID, mLiveType, mLiveTypeVal, mAvatarFile,0, new HttpCallback() { + 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) { @@ -480,7 +480,7 @@ public class LiveReadyRyViewHolder extends AbsViewHolder implements View.OnClick final CommonAppConfig appConfig = CommonAppConfig.getInstance(); UserBean u = appConfig.getUserBean(); - ((LiveRyAnchorActivity) mContext).startLiveSuccess(info[0], mLiveType, mLiveTypeVal); + ((LiveSwAnchorActivity) mContext).startLiveSuccess(info[0], mLiveType, mLiveTypeVal); // // RongChatRoomClient.getInstance().joinChatRoom("g" + appConfig.getUid(), -1, new IRongCoreCallback.OperationCallback() { // @Override diff --git a/live/src/main/java/com/yunbao/live/views/LiveReadyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveReadyViewHolder.java index abf89e1fb..a19123a46 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveReadyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveReadyViewHolder.java @@ -492,7 +492,7 @@ public class LiveReadyViewHolder extends AbsViewHolder implements View.OnClickLi return; } String title = mEditTitle.getText().toString().trim(); - LiveHttpUtil.newcreateRoom(title, mLiveClassID, mLiveType, mLiveTypeVal, mAvatarFile, 0, new HttpCallback() { + 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) { diff --git a/live/src/main/java/com/yunbao/live/views/LiveRoomPlayViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveRoomPlayViewHolder.java index 0cbe9709e..7fb4954ca 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRoomPlayViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRoomPlayViewHolder.java @@ -90,6 +90,7 @@ public abstract class LiveRoomPlayViewHolder extends AbsViewHolder implements IL public void setViewDrMic() { } + public void setViewDrPk() { } @@ -115,6 +116,17 @@ public abstract class LiveRoomPlayViewHolder extends AbsViewHolder implements IL public void clearFrame() { } + public abstract void endPk(); + + public abstract void endpk(String liveUid); + + public abstract void initSwEngine(String liveUid); + + public abstract void removeDetailView(); + + public abstract void setPkView(String liveUid); + + public abstract void claerDrPkInfoView(); public interface OnMicCallback { 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 cbe457cc0..2be05e28d 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java @@ -148,7 +148,7 @@ 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.LiveChatAdapter; import com.yunbao.live.adapter.LiveRoomFastMessageRecyclerViewAdapter; @@ -1263,7 +1263,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 || LivePushRyViewHolder.rtcRoom != null) { + if (LivePushTxViewHolder.mTRTCCloud != null || LivePushSwViewHolder.rtcRoom != null) { fans_btn.setVisibility(View.GONE); } mPkRankTopIcon.setVisibility(View.GONE); @@ -1579,7 +1579,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis } // fastMsgRecyclerView.setItemAnimator(new DefaultItemAnimator()); //主播页面隐藏头部 - if (mContext instanceof LiveRyAnchorActivity) { + 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); @@ -1739,7 +1739,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 LiveRyAnchorActivity) { + if (IMLoginManager.get(mContext).getUserInfo().anchorUserType() && mContext instanceof LiveSwAnchorActivity) { anchorTimeHandler.removeCallbacks(anchorTimeRunnable); anchorTimeHandler.post(anchorTimeRunnable); } @@ -1751,7 +1751,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis @Override public void onViewClicks() { - if (!(mContext instanceof LiveRyAnchorActivity)) { + if (!(mContext instanceof LiveSwAnchorActivity)) { LiveNetManager.get(mContext) .redPacketInfo(mLiveUid, redPacketModel.getRedPacketId(), new com.yunbao.common.http.base.HttpCallback() { @Override @@ -1885,7 +1885,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis if (d_pk_view != null) { d_pk_view.setVisibility(View.GONE); } - if (LivePushTxViewHolder.mTRTCCloud != null || LivePushRyViewHolder.rtcRoom != null) { + if (LivePushTxViewHolder.mTRTCCloud != null || LivePushSwViewHolder.rtcRoom != null) { fans_btn.setVisibility(View.GONE); } mRedVal.setVisibility(View.GONE); @@ -3029,7 +3029,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 LiveRyAnchorActivity)); + bundle.putBoolean("SBW", !(mContext instanceof LiveSwAnchorActivity)); giftWallDialog.setArguments(bundle); giftWallDialog.show(((AbsActivity) mContext).getSupportFragmentManager(), "GiftWallDialog"); @@ -3387,7 +3387,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis //直播间 粉丝排行榜 openMedalRankWindow(); } else if (i == R.id.btn_guard) { - ((LiveActivity) mContext).openNewGuardListWindow(mContext instanceof LiveRyAnchorActivity); + ((LiveActivity) mContext).openNewGuardListWindow(mContext instanceof LiveSwAnchorActivity); } else if (i == R.id.btn_red_pack) { ((LiveActivity) mContext).openRedPackListWindow(); @@ -3395,13 +3395,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 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 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 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) @@ -3434,7 +3434,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 LiveRyAnchorActivity); + ((LiveActivity) mContext).openNewGuardListWindow(mContext instanceof LiveSwAnchorActivity); } if (i == R.id.lt_trickery) { showTrickeryDialog(); @@ -3459,7 +3459,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis * @param in 展示的view */ private void changeMsgView(View out, View in) { - if (mContext instanceof LiveRyAnchorActivity) { + if (mContext instanceof LiveSwAnchorActivity) { return; } if (in.getVisibility() == View.VISIBLE) { @@ -3669,23 +3669,23 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis ((LiveAudienceActivity) mContext).setBackIndex(1); ((LiveAnchorActivity) mContext).onBackPressed(); } - } else if (mContext instanceof LiveRyAnchorActivity) { + } else if (mContext instanceof LiveSwAnchorActivity) { if (forAct == 1) { //是否关注0==没关注 if (isAttention == 0) { if (isStayRoomfive) { showFollowDialog(mNameText, mAvatarUrl, mContext); } else { - LiveRyAnchorActivity.backIndex = 1; - ((LiveRyAnchorActivity) mContext).onBackPressed(); + LiveSwAnchorActivity.backIndex = 1; + ((LiveSwAnchorActivity) mContext).onBackPressed(); } } else { - LiveRyAnchorActivity.backIndex = 1; - ((LiveRyAnchorActivity) mContext).onBackPressed(); + LiveSwAnchorActivity.backIndex = 1; + ((LiveSwAnchorActivity) mContext).onBackPressed(); } } else { - LiveRyAnchorActivity.backIndex = 1; - ((LiveRyAnchorActivity) mContext).onBackPressed(); + LiveSwAnchorActivity.backIndex = 1; + ((LiveSwAnchorActivity) mContext).onBackPressed(); } } } @@ -4840,7 +4840,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 LiveRyAnchorActivity) { + if (mContext instanceof LiveSwAnchorActivity) { dialog.dismiss(); return; } @@ -4883,7 +4883,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class); new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { if (liveBean == null) { 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 828916dd6..b57c75d7a 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRyAnchorViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRyAnchorViewHolder.java @@ -1,8 +1,8 @@ package com.yunbao.live.views; import static com.yunbao.live.activity.LiveActivity.mLiveUid; -import static com.yunbao.live.activity.LiveRyAnchorActivity.PKing; -import static com.yunbao.live.activity.LiveRyAnchorActivity.pk_nub; +import static com.yunbao.live.activity.LiveSwAnchorActivity.PKing; +import static com.yunbao.live.activity.LiveSwAnchorActivity.pk_nub; import static com.yunbao.live.event.LiveAudienceEvent.LiveAudienceType.START_MESSAGE; import static com.yunbao.live.event.LiveAudienceEvent.LiveAudienceType.WISH_LIST_UPDATE; @@ -44,6 +44,7 @@ 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; import com.yunbao.live.dialog.LiveHDDialogFragment; @@ -173,7 +174,7 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { if (yaoqing.size() < 3) { if (PKing == false) { - ((LiveRyAnchorActivity) mContext).openLinkMicAnchorWindow(true); + ((LiveSwAnchorActivity) mContext).openLinkMicAnchorWindow(true); } else { ToastUtil.show(WordUtil.isNewZh() ? "您已在PK中" : "You are already in the PK"); } @@ -241,7 +242,7 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { * 关闭直播 */ private void close() { - ((LiveRyAnchorActivity) mContext).closeLive(); + ((LiveSwAnchorActivity) mContext).closeLive(); } @Override @@ -257,7 +258,11 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { if (mBtnFunction != null) { mBtnFunction.setImageDrawable(mDrawable1); } - ((LiveRyAnchorActivity) mContext).showFunctionDialog(); + if(mContext instanceof LiveSwAnchorActivity){ + ((LiveSwAnchorActivity) mContext).showFunctionDialog(); + }else{ + ((LiveRyAnchorActivity) mContext).showFunctionDialog(); + } } /** @@ -290,7 +295,7 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { * 发起主播连麦pk */ private void applyLinkMicPk() { - ((LiveRyAnchorActivity) mContext).applyLinkMicPk(); + ((LiveSwAnchorActivity) mContext).applyLinkMicPk(); } public void setLinkMicEnable(boolean linkMicEnable) { @@ -516,7 +521,7 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { bundle.putString("url", htmlUrl.toString()); LiveHDDialogFragment fragment = new LiveHDDialogFragment(); fragment.setArguments(bundle); - fragment.show(((LiveRyAnchorActivity) mContext).getSupportFragmentManager(), "LiveHDDialogFragment"); + fragment.show(((LiveSwAnchorActivity) mContext).getSupportFragmentManager(), "LiveHDDialogFragment"); } } } @@ -577,7 +582,7 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { bundle.putString("url", htmlUrl.toString()); LiveHDDialogFragment fragment = new LiveHDDialogFragment(); fragment.setArguments(bundle); - fragment.show(((LiveRyAnchorActivity) mContext).getSupportFragmentManager(), "LiveHDDialogFragment"); + fragment.show(((LiveSwAnchorActivity) mContext).getSupportFragmentManager(), "LiveHDDialogFragment"); } } } 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 1ac6894bc..a7605dbca 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -105,10 +105,12 @@ 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.SocketSwClient; import com.yunbao.live.socket.SocketSendBean; import com.yunbao.live.utils.LiveImDeletUtil; @@ -155,7 +157,8 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe //侧滑布局 // private DrawerLayout drawerLayout; //直播间拆分布局 - public LivePlayRyViewHolder mLivePlayViewHolder; + public LiveRoomPlayViewHolder mLivePlayViewHolder; + //头部布局 public LiveRoomViewHolder mLiveRoomViewHolder; //底部布局 @@ -169,14 +172,20 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe //主播与主播连麦逻辑 private LiveLinkMicAnchorPresenter mLiveLinkMicAnchorPresenter; //主播与主播PK逻辑 + private LiveSwLinkMicPkPresenter mLiveSwLinkMicPkPresenter; + private LiveRyLinkMicPkPresenter mLiveRyLinkMicPkPresenter; + + //直播间的类型 普通 密码 门票 计时等 private int mLiveType; //收费价格,计时收费每次扣费的值 private int mLiveTypeVal; //直播结束页面 private LiveEndViewHolder mLiveEndViewHolder; + private SocketSwClient mSocketSwClient; private SocketRyClient mSocketRyClient; + private SocketClient mSocketClient; private String mDanmuPrice;//弹幕价格 private int mSocketUserType;//socket用户类型 30 普通用户 40 管理员 50 主播 60超管 @@ -215,6 +224,8 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe public static PortraitLiveManager portraitLiveManager; private static int waitShowTopBannerTime = 6000; + private boolean isSw; + public PortraitLiveManager setQuitF(boolean quitF) { isQuitF = quitF; return this; @@ -265,6 +276,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe public PortraitLiveManager(Activity context, Intent intent) { this.mContext = context; this.mIntent = intent; + isSw = intent.getBooleanExtra("isSw", false); liveImDeletUtil = new LiveImDeletUtil(); portraitLiveManager = this; ininView(); @@ -333,7 +345,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe @Override - public synchronized void onAdd(LiveBean data, int liveType, int liveTypeVal, int liveSdk) { + public synchronized void onAdd(LiveBean data, int liveType, int liveTypeVal, int liveSdk, boolean isSw) { isEnterRoom = false; MobclickAgent.onEvent(mContext, "live_room_chat_list", "滑动直播间聊天列表"); openParametersModel = new OpenParametersModel(); @@ -351,6 +363,12 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mLiveRyLinkMicPkPresenter.release(); mLiveRyLinkMicPkPresenter = null; } + + if (mLiveSwLinkMicPkPresenter != null) { + mLiveSwLinkMicPkPresenter.clearData(); + mLiveSwLinkMicPkPresenter.release(); + mLiveSwLinkMicPkPresenter = null; + } OpenAdManager.getInstance().dismiss(); mLiveBean = data; mLiveSDK = liveSdk; @@ -369,13 +387,23 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe liveHandler.removeCallbacks(loadRunnableGone); liveHandler.removeCallbacks(loadTimeoutRunnableGone); if (mLivePlayViewHolder == null) { - mLivePlayViewHolder = new LivePlayRyViewHolder(mContext, playContainer, 1); + if (isSw) { + mLivePlayViewHolder = new LivePlaySwViewHolder(mContext, playContainer, 1); + } else { + mLivePlayViewHolder = new LivePlayRyViewHolder(mContext, playContainer, 1); + } mLivePlayViewHolder.initSwEngine(mLiveBean.getUid()); mLiveRoomViewHolder = new LiveRoomViewHolder(false, 1, mContext, mContainer, mSecondPage.findViewById(R.id.gift_gif), mSecondPage.findViewById(R.id.gift_svga), mContainerWrap, mContext.getWindowManager()); mLiveAudienceViewHolder = new LiveAudienceViewHolder(mContext, mContainer); mLiveLinkMicPresenter = new LiveLinkMicPresenter(mContext, mLivePlayViewHolder, false, mLiveSDK, mLiveAudienceViewHolder.getContentView()); mLiveLinkMicAnchorPresenter = new LiveLinkMicAnchorPresenter(mContext, mLivePlayViewHolder, false, mLiveSDK, null); - mLiveRyLinkMicPkPresenter = new LiveRyLinkMicPkPresenter(mContext, mLivePlayViewHolder, false, null); + if (isSw) { + mLiveSwLinkMicPkPresenter = new LiveSwLinkMicPkPresenter(mContext, mLivePlayViewHolder, false, null); + } else { + mLiveRyLinkMicPkPresenter = new LiveRyLinkMicPkPresenter(mContext, mLivePlayViewHolder, false, null); + } + + mLivePlayViewHolder.addToParent(); mLivePlayViewHolder.subscribeActivityLifeCycle(); mLivePlayViewHolder.setLoadViewListener(new LiveRoomPlayViewHolder.LoadingListener() { @@ -394,16 +422,22 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mLiveLinkMicPresenter.setLiveSdk(mLiveSDK); mLiveLinkMicAnchorPresenter.setLiveSdk(mLiveSDK); } - - if (mLiveRyLinkMicPkPresenter == null) { - mLiveRyLinkMicPkPresenter = new LiveRyLinkMicPkPresenter(mContext, mLivePlayViewHolder, false, null); + if (isSw) { + if (mLiveSwLinkMicPkPresenter == null) { + mLiveSwLinkMicPkPresenter = new LiveSwLinkMicPkPresenter(mContext, mLivePlayViewHolder, false, null); + } + } else { + if (mLiveRyLinkMicPkPresenter == null) { + mLiveRyLinkMicPkPresenter = new LiveRyLinkMicPkPresenter(mContext, mLivePlayViewHolder, false, null); + } } + //去除主播离开画面 if (LivePlayKsyViewHolder.leave != null) { LivePlayKsyViewHolder.leave.setVisibility(View.GONE); } - if (LivePlayRyViewHolder.leave != null) { - LivePlayRyViewHolder.leave.setVisibility(View.GONE); + if (LivePlaySwViewHolder.leave != null) { + LivePlaySwViewHolder.leave.setVisibility(View.GONE); } //直播间背景 @@ -438,8 +472,17 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mLiveRoomViewHolder.clearGuardIcon(); mLiveRoomViewHolder.clearChat(); mLiveRoomViewHolder.releaseGift(); - mLiveRyLinkMicPkPresenter.setLiveUid(data.getUid(), ""); - mSocketRyClient = new SocketRyClient(mLiveBean.getUid(), PortraitLiveManager.this, mContext); + if (isSw) { + mLiveSwLinkMicPkPresenter.setLiveUid(data.getUid(), ""); + } else { + mLiveRyLinkMicPkPresenter.setLiveUid(data.getUid(), ""); + } + + if (isSw) { + mSocketSwClient = new SocketSwClient(mLiveBean.getUid(), PortraitLiveManager.this, mContext); + } else { + mSocketRyClient = new SocketRyClient(mLiveBean.getUid(), PortraitLiveManager.this, mContext); + } if (mLiveLinkMicPresenter != null) { mLiveLinkMicPresenter.setSocketClient(mSocketClient); } @@ -616,8 +659,8 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe } if (leave == 1) { - if (LivePlayRyViewHolder.leave != null) { - LivePlayRyViewHolder.leave.setVisibility(View.VISIBLE); + if (LivePlaySwViewHolder.leave != null) { + LivePlaySwViewHolder.leave.setVisibility(View.VISIBLE); } } //判断是否有连麦,要显示连麦窗口 @@ -644,17 +687,17 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe } } } - if(mLivePlayViewHolder != null && data.getEnterRoomInfo().getIsconnection() != null && data.getEnterRoomInfo().getIsconnection().equals("1")){ - JSONArray array = pkInfo.getJSONArray("userlist"); + if (mLivePlayViewHolder != null && data.getEnterRoomInfo().getIsconnection() != null && data.getEnterRoomInfo().getIsconnection().equals("1")) { + JSONArray array = pkInfo.getJSONArray("userlist"); //判断是否是多人连麦 - if(array.size()>0){//多人連麥 + if (array.size() > 0) {//多人連麥 if (mLivePlayViewHolder != null) { List drPkbeans = new ArrayList<>(); for (int j = 0; j < array.size(); j++) { UserBean drPkbean = new UserBean(); DrPkbean drPkbean1 = new DrPkbean(); JSONObject da = array.getJSONObject(j); - if(!String.valueOf(da.getIntValue("id")).equals(String.valueOf(data.getLiveInfo().getUid()))){ + if (!String.valueOf(da.getIntValue("id")).equals(String.valueOf(data.getLiveInfo().getUid()))) { drPkbean.setId(String.valueOf(da.getIntValue("id"))); drPkbean1.setId(da.getIntValue("id")); drPkbean1.setUser_nicename(da.getString("user_nicename")); @@ -664,9 +707,9 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe } //mLivePlayViewHolder.setDrPkView(drPkbeans); } - }else{//单人连麦 - LivePkMicModel connection_info = data.getEnterRoomInfo().getConnectionInfo(); - if(!StringUtil.isEmpty(connection_info.getPkuid())){ + } else {//单人连麦 + LivePkMicModel connection_info = data.getEnterRoomInfo().getConnectionInfo(); + if (!StringUtil.isEmpty(connection_info.getPkuid())) { mPkUid = connection_info.getPkuid(); mLivePlayViewHolder.setPkView(connection_info.getPkuid()); } @@ -692,9 +735,12 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe } }; linkMicPkStartHandler.postDelayed(linkMicPkStartRunnable, 4000); - } - mLiveRyLinkMicPkPresenter.onEnterRoomPkStart(pkUid, pkInfo.getLongValue("pk_gift_liveuid"), pkInfo.getLongValue("pk_gift_pkuid"), pkInfo.getIntValue("pk_time"), livePKUserListBean); + 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); + } } else if (!pkInfo.getString("end_pk_time").equals("0")) { if (mLiveRoomViewHolder != null) { mLiveRoomViewHolder.pkHandler = true; @@ -708,7 +754,11 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe //pk排名数据 LivePKUserListBean livePKUserListBean = JSON.parseObject(pkInfo.getString("pk_top_users"), LivePKUserListBean.class); - mLiveRyLinkMicPkPresenter.onEnterRoomCFStart(pkUid, pkInfo.getLongValue("pk_gift_liveuid"), pkInfo.getLongValue("pk_gift_pkuid"), pkInfo.getIntValue("end_pk_time"), livePKUserListBean); + 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); + } } else { if (mLiveRoomViewHolder != null) { mLiveRoomViewHolder.initPkRank(null); @@ -720,13 +770,13 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mLiveRoomViewHolder.initPkRank(null); } if (mLivePlayViewHolder != null) { - JSONArray array = pkInfo.getJSONArray("userlist"); - List drPkbeans = new ArrayList<>(); + JSONArray array = pkInfo.getJSONArray("userlist"); + List drPkbeans = new ArrayList<>(); for (int j = 0; j < array.size(); j++) { UserBean userBean = new UserBean(); DrPkbean drPkbean = new DrPkbean(); JSONObject da = array.getJSONObject(j); - if(!String.valueOf(da.getIntValue("id")).equals(String.valueOf(data.getLiveInfo().getUid()))){ + if (!String.valueOf(da.getIntValue("id")).equals(String.valueOf(data.getLiveInfo().getUid()))) { userBean.setId(String.valueOf(da.getIntValue("id"))); drPkbean.setId(da.getIntValue("id")); drPkbean.setUser_nicename(da.getString("user_nicename")); @@ -837,10 +887,8 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe } } - - - public void loadTimeoutRunnableGone(){ - if(liveHandler!=null){ + public void loadTimeoutRunnableGone() { + if (liveHandler != null) { liveHandler.postDelayed(loadTimeoutRunnableGone, 1_000); } } @@ -871,11 +919,17 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mLiveRyLinkMicPkPresenter.clearData(); mLiveRyLinkMicPkPresenter.release(); } + if (mLiveSwLinkMicPkPresenter != null) { + mLiveSwLinkMicPkPresenter.clearData(); + mLiveSwLinkMicPkPresenter.release(); + } + mLiveAudienceViewHolder = null; mLiveRoomViewHolder = null; mLiveLinkMicPresenter = null; mLiveLinkMicAnchorPresenter = null; mLiveRyLinkMicPkPresenter = null; + mLiveSwLinkMicPkPresenter = null; mLivePlayViewHolder = null; } @@ -902,6 +956,10 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mSocketRyClient.disConnect(); mSocketRyClient = null; } + if (mSocketSwClient != null) { + mSocketSwClient.disConnect(); + mSocketSwClient = null; + } if (mSocketClient != null) { mSocketClient.disConnect(); mSocketClient = null; @@ -1360,7 +1418,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe public void showAllServerNotifyFFGGGD(AllServerNotifyFFGGGDJANEvent notifyFFGGGDJANEvent) { if (mLiveRoomViewHolder != null) { - mLiveRoomViewHolder.showAllServerNotifyFFGGGD(notifyFFGGGDJANEvent,true); + mLiveRoomViewHolder.showAllServerNotifyFFGGGD(notifyFFGGGDJANEvent, true); } } @@ -1392,20 +1450,34 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe @Override public void onSendGiftPk(long leftGift, long rightGift, LivePKUserListBean bean) { - - if (mLiveRyLinkMicPkPresenter != null) { - mLiveRyLinkMicPkPresenter.onPkProgressChanged(leftGift, rightGift, bean); - + if (isSw) { + if (mLiveSwLinkMicPkPresenter != null) { + mLiveSwLinkMicPkPresenter.onPkProgressChanged(leftGift, rightGift, bean); + } + } else { + if (mLiveRyLinkMicPkPresenter != null) { + mLiveRyLinkMicPkPresenter.onPkProgressChanged(leftGift, rightGift, bean); + } } } @Override public void onEndPk(long leftUid, long rightUid, long left, long right, LivePKUserListBean bean) { - if (mLiveRyLinkMicPkPresenter != null) { - if (mLiveUid.equals(leftUid + "")) { - mLiveRyLinkMicPkPresenter.onPkProgressEnd(left, right, bean); - } else { - mLiveRyLinkMicPkPresenter.onPkProgressEnd(right, left, bean); + if (isSw) { + if (mLiveSwLinkMicPkPresenter != null) { + if (mLiveUid.equals(leftUid + "")) { + mLiveSwLinkMicPkPresenter.onPkProgressEnd(left, right, bean); + } else { + mLiveSwLinkMicPkPresenter.onPkProgressEnd(right, left, bean); + } + } + } else { + if (mLiveRyLinkMicPkPresenter != null) { + if (mLiveUid.equals(leftUid + "")) { + mLiveRyLinkMicPkPresenter.onPkProgressEnd(left, right, bean); + } else { + mLiveRyLinkMicPkPresenter.onPkProgressEnd(right, left, bean); + } } } } @@ -1610,7 +1682,6 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe public void onLinkDRMicPKToUser(UserBean u) { L.eSw("onLinkDRMicPKToUser(UserBean u)PortraitLiveManager"); mLivePlayViewHolder.setDrMicInfo(u); - } @Override @@ -1619,7 +1690,6 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe //mLivePlayViewHolder.setDrMicInfo(u); } - /** * 主播与主播PK 所有人收到PK开始的回调 */ @@ -1645,12 +1715,20 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe } } }; - - if (mLiveRyLinkMicPkPresenter != null && mLiveRoomViewHolder != null) { - mLiveRoomViewHolder.pkHandler = true; - mLiveRyLinkMicPkPresenter.onLinkMicPkStart(pkUid, 1); - linkMicPkStartHandler.postDelayed(linkMicPkStartRunnable, 4000);//3秒后执行Runnable中的run方法 + if (isSw) { + if (mLiveSwLinkMicPkPresenter != null && mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.pkHandler = true; + mLiveSwLinkMicPkPresenter.onLinkMicPkStart(pkUid, 1); + linkMicPkStartHandler.postDelayed(linkMicPkStartRunnable, 4000);//3秒后执行Runnable中的run方法 + } + } else { + if (mLiveRyLinkMicPkPresenter != null && mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.pkHandler = true; + mLiveRyLinkMicPkPresenter.onLinkMicPkStart(pkUid, 1); + linkMicPkStartHandler.postDelayed(linkMicPkStartRunnable, 4000);//3秒后执行Runnable中的run方法 + } } + if (mLivePlayViewHolder != null) { mLivePlayViewHolder.setLiveBeanLandscape(1); } @@ -1673,11 +1751,19 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe @Override public void onLinkMicPkClose(int i) { - - if (mLiveRyLinkMicPkPresenter != null) { - mLiveRyLinkMicPkPresenter.onLinkMicPkClose(i); - if (mLiveRoomViewHolder != null) { - mLiveRoomViewHolder.resetViewGone(); + if (isSw) { + if (mLiveSwLinkMicPkPresenter != null) { + mLiveSwLinkMicPkPresenter.onLinkMicPkClose(i); + if (mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.resetViewGone(); + } + } + } else { + if (mLiveRyLinkMicPkPresenter != null) { + mLiveRyLinkMicPkPresenter.onLinkMicPkClose(i); + if (mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.resetViewGone(); + } } } if (mLiveRoomViewHolder != null) { @@ -1706,9 +1792,16 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe @Override public void onLinkMicPkEnd(String winUid) { - if (mLiveRyLinkMicPkPresenter != null) { - mLiveRyLinkMicPkPresenter.onLinkMicPkEnd(winUid); - //mLiveRoomViewHolder.setDelOtherInfo(); + if (isSw) { + if (mLiveSwLinkMicPkPresenter != null) { + mLiveSwLinkMicPkPresenter.onLinkMicPkEnd(winUid); + //mLiveRoomViewHolder.setDelOtherInfo(); + } + } else { + if (mLiveRyLinkMicPkPresenter != null) { + mLiveRyLinkMicPkPresenter.onLinkMicPkEnd(winUid); + //mLiveRoomViewHolder.setDelOtherInfo(); + } } } @@ -1900,9 +1993,13 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe if (mSocketRyClient != null) { mSocketRyClient.disConnect(); + mSocketRyClient = null; } - mSocketRyClient = null; + if (mSocketSwClient != null) { + mSocketSwClient.disConnect(); + mSocketSwClient = null; + } //结束播放 if (mLivePlayViewHolder != null) { @@ -2210,7 +2307,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe * @param time */ public void upDataPkScore(JSONArray pkScores, int time) { - L.eSw("upDataPkScore"+time); + L.eSw("upDataPkScore" + time); if (mLiveRoomViewHolder != null) { String liveId = mLiveBean.getUid(); JSONObject liveModel = null; diff --git a/live/src/main/java/com/yunbao/live/views/SidebarViewHoler.java b/live/src/main/java/com/yunbao/live/views/SidebarViewHoler.java index 78561638b..4e3a49980 100644 --- a/live/src/main/java/com/yunbao/live/views/SidebarViewHoler.java +++ b/live/src/main/java/com/yunbao/live/views/SidebarViewHoler.java @@ -102,8 +102,8 @@ public class SidebarViewHoler extends RecyclerView.ViewHolder { } new LiveRoomCheckLivePresenter(itemView.getContext(), liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal),isSw); } @Override diff --git a/live/src/main/res/layout/view_live_play_ksy.xml b/live/src/main/res/layout/view_live_play_ksy.xml index f7c596dc0..91b5d0346 100644 --- a/live/src/main/res/layout/view_live_play_ksy.xml +++ b/live/src/main/res/layout/view_live_play_ksy.xml @@ -1,41 +1,18 @@ + android:layout_height="match_parent"> - - - - - - - - - + app:use_controller="false" + android:layout_height="match_parent" /> - + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="@dimen/live_top"> - - + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/layout/view_live_push_ry.xml b/live/src/main/res/layout/view_live_push_ry.xml index bb814174d..1931cc742 100644 --- a/live/src/main/res/layout/view_live_push_ry.xml +++ b/live/src/main/res/layout/view_live_push_ry.xml @@ -1,10 +1,10 @@ + + + android:orientation="horizontal"> + android:background="@mipmap/live_icon_vacancy" /> + android:orientation="horizontal"> + android:background="@mipmap/live_icon_vacancy" /> @@ -93,12 +91,16 @@ + + android:layout_height="match_parent"> + + + - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/main/src/main/java/com/yunbao/main/activity/EntryActivity.java b/main/src/main/java/com/yunbao/main/activity/EntryActivity.java index eca8ddae0..e21d251eb 100644 --- a/main/src/main/java/com/yunbao/main/activity/EntryActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/EntryActivity.java @@ -671,8 +671,8 @@ public class EntryActivity extends AppCompatActivity { } new LiveRoomCheckLivePresenter(activity, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal),isSw); } @Override diff --git a/main/src/main/java/com/yunbao/main/activity/LiveClassActivity.java b/main/src/main/java/com/yunbao/main/activity/LiveClassActivity.java index 58ec570ab..1a7d0bfad 100644 --- a/main/src/main/java/com/yunbao/main/activity/LiveClassActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/LiveClassActivity.java @@ -118,8 +118,8 @@ public class LiveClassActivity extends AbsActivity implements OnItemClickListene public void watchLive(LiveBean liveBean, int position) { new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal),isSw); } @Override diff --git a/main/src/main/java/com/yunbao/main/activity/LoginActivity.java b/main/src/main/java/com/yunbao/main/activity/LoginActivity.java index dbefee6f7..1ad1c7c07 100644 --- a/main/src/main/java/com/yunbao/main/activity/LoginActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/LoginActivity.java @@ -257,8 +257,8 @@ public class LoginActivity extends AbsActivity { } new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal),isSw); } @Override 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 eb8874263..c035f6c70 100644 --- a/main/src/main/java/com/yunbao/main/activity/MainActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/MainActivity.java @@ -271,8 +271,8 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class); new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal),isSw); } @Override @@ -485,8 +485,8 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class); new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal),isSw); } @Override @@ -1069,9 +1069,9 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene public void watchLive(LiveBean liveBean, String key, int position) { new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { MobclickAgent.onEvent(mContext, "home_page_enter_room", "首页点击直播间"); - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal),isSw); } @Override diff --git a/main/src/main/java/com/yunbao/main/activity/MyWebViewActivity.java b/main/src/main/java/com/yunbao/main/activity/MyWebViewActivity.java index 751ae514d..729e0323d 100644 --- a/main/src/main/java/com/yunbao/main/activity/MyWebViewActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/MyWebViewActivity.java @@ -261,7 +261,7 @@ public class MyWebViewActivity extends AbsActivity { } new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { if (LiveRoomViewHolder.mHandler != null) { LiveRoomViewHolder.mHandler.removeCallbacksAndMessages(null); @@ -274,7 +274,7 @@ public class MyWebViewActivity extends AbsActivity { } EventBus.getDefault().post(new LiveRoomChangeEvent(liveBean, liveType, Integer.parseInt(liveTypeVal)).setLiveEnd(true)); } else { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveTypeVal), Integer.parseInt(liveSdk)); + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveTypeVal), Integer.parseInt(liveSdk),isSw); } } diff --git a/main/src/main/java/com/yunbao/main/activity/MyWebViewActivity2.java b/main/src/main/java/com/yunbao/main/activity/MyWebViewActivity2.java index 07b6ddd1c..c5f3c15d1 100644 --- a/main/src/main/java/com/yunbao/main/activity/MyWebViewActivity2.java +++ b/main/src/main/java/com/yunbao/main/activity/MyWebViewActivity2.java @@ -230,7 +230,7 @@ public class MyWebViewActivity2 extends AbsActivity { } new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { if (LiveRoomViewHolder.mHandler != null) { LiveRoomViewHolder.mHandler.removeCallbacksAndMessages(null); @@ -243,7 +243,7 @@ public class MyWebViewActivity2 extends AbsActivity { } EventBus.getDefault().post(new LiveRoomChangeEvent(liveBean, liveType, Integer.parseInt(liveTypeVal))); } else { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveTypeVal), Integer.parseInt(liveSdk)); + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveTypeVal), Integer.parseInt(liveSdk),isSw); } } diff --git a/main/src/main/java/com/yunbao/main/activity/RegisterActivity.java b/main/src/main/java/com/yunbao/main/activity/RegisterActivity.java index 11491f72a..82fcf0718 100644 --- a/main/src/main/java/com/yunbao/main/activity/RegisterActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/RegisterActivity.java @@ -528,8 +528,8 @@ public class RegisterActivity extends AbsActivity { } new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal),isSw); NoviceInstructorManager.get(mContext).setFrist(false); } diff --git a/main/src/main/java/com/yunbao/main/activity/SearchActivity.java b/main/src/main/java/com/yunbao/main/activity/SearchActivity.java index 1ef37dbfe..6a02c7f26 100644 --- a/main/src/main/java/com/yunbao/main/activity/SearchActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/SearchActivity.java @@ -176,8 +176,8 @@ public class SearchActivity extends AbsActivity { LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class); new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal),isSw); } @Override diff --git a/main/src/main/java/com/yunbao/main/activity/WeekWebViewActivity.java b/main/src/main/java/com/yunbao/main/activity/WeekWebViewActivity.java index cd1fb5682..f0096f634 100644 --- a/main/src/main/java/com/yunbao/main/activity/WeekWebViewActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/WeekWebViewActivity.java @@ -154,8 +154,8 @@ public class WeekWebViewActivity extends AbsActivity { } new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal),isSw); } @Override diff --git a/main/src/main/java/com/yunbao/main/activity/ZhuangBanActivity.java b/main/src/main/java/com/yunbao/main/activity/ZhuangBanActivity.java index bf2ac850f..927b5b02c 100644 --- a/main/src/main/java/com/yunbao/main/activity/ZhuangBanActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/ZhuangBanActivity.java @@ -391,7 +391,7 @@ public class ZhuangBanActivity extends AbsActivity { LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class); new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { if (liveBean == null) { return; } @@ -400,7 +400,7 @@ public class ZhuangBanActivity extends AbsActivity { return; } - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveTypeVal), Integer.parseInt(liveSdk)); + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveTypeVal), Integer.parseInt(liveSdk),isSw); finish(); } diff --git a/main/src/main/java/com/yunbao/main/adapter/SearchAdapter.java b/main/src/main/java/com/yunbao/main/adapter/SearchAdapter.java index d3ff13be0..a371e3f93 100644 --- a/main/src/main/java/com/yunbao/main/adapter/SearchAdapter.java +++ b/main/src/main/java/com/yunbao/main/adapter/SearchAdapter.java @@ -203,8 +203,8 @@ public class SearchAdapter extends RefreshAdapter { } new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal),isSw); } @Override diff --git a/main/src/main/java/com/yunbao/main/dialog/AnchorStartLiveNotifyDialog.java b/main/src/main/java/com/yunbao/main/dialog/AnchorStartLiveNotifyDialog.java index a1237951c..c0177c0cb 100644 --- a/main/src/main/java/com/yunbao/main/dialog/AnchorStartLiveNotifyDialog.java +++ b/main/src/main/java/com/yunbao/main/dialog/AnchorStartLiveNotifyDialog.java @@ -77,8 +77,8 @@ public class AnchorStartLiveNotifyDialog extends AbsDialogPositionPopupWindow { LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class); new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveTypeVal), Integer.parseInt(liveSdk)); + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveTypeVal), Integer.parseInt(liveSdk),isSw); } @Override 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 f099229a7..4a19c2e2c 100644 --- a/main/src/main/java/com/yunbao/main/dialog/MainStartDialogFragment.java +++ b/main/src/main/java/com/yunbao/main/dialog/MainStartDialogFragment.java @@ -39,6 +39,7 @@ 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; import com.yunbao.main.activity.MyWebViewActivity; @@ -227,13 +228,23 @@ public class MainStartDialogFragment extends AbsDialogFragment implements View.O @Override public void onSuccess(int code, String msg, String[] info1) { try { - JSONObject obj = JSON.parseObject(info[0]); - JSONObject obj1 = JSON.parseObject(info1[0]); - if (obj1.getString("is_rong").equals("1")) { - LiveRyAnchorActivity.forward(mContext, obj.getIntValue("live_sdk"), JSON.parseObject(obj.getString("android"), LiveKsyConfigBean.class)); - } else { - LiveAnchorActivity.forward(mContext, obj.getIntValue("live_sdk"), JSON.parseObject(obj.getString("android"), LiveKsyConfigBean.class)); - } + LiveHttpUtil.getIsSw(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] infos) { + JSONObject obj = JSON.parseObject(info[0]); + JSONObject obj1 = JSON.parseObject(info1[0]); + try { + code = 200; + 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) { + + } + } + }); } catch (Exception e) { } diff --git a/main/src/main/java/com/yunbao/main/dialog/OneLoginDialog.java b/main/src/main/java/com/yunbao/main/dialog/OneLoginDialog.java index 46bd068f6..fc6406056 100644 --- a/main/src/main/java/com/yunbao/main/dialog/OneLoginDialog.java +++ b/main/src/main/java/com/yunbao/main/dialog/OneLoginDialog.java @@ -150,11 +150,11 @@ public class OneLoginDialog extends AbsDialogFragment { new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal),isSw); NoviceInstructorManager.get(mContext).setFrist(false); } diff --git a/main/src/main/java/com/yunbao/main/fragment/MainHomeCommunityFragment.java b/main/src/main/java/com/yunbao/main/fragment/MainHomeCommunityFragment.java index ae5f07953..cd8d7f804 100644 --- a/main/src/main/java/com/yunbao/main/fragment/MainHomeCommunityFragment.java +++ b/main/src/main/java/com/yunbao/main/fragment/MainHomeCommunityFragment.java @@ -262,8 +262,8 @@ public class MainHomeCommunityFragment extends BaseFragment { new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal),isSw); } @Override diff --git a/main/src/main/java/com/yunbao/main/views/AbsMainListChildViewHolder.java b/main/src/main/java/com/yunbao/main/views/AbsMainListChildViewHolder.java index 410000ee8..6b8d7226b 100644 --- a/main/src/main/java/com/yunbao/main/views/AbsMainListChildViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/AbsMainListChildViewHolder.java @@ -170,8 +170,8 @@ public abstract class AbsMainListChildViewHolder extends AbsMainViewHolder imple LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class); new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal),isSw); } @Override @@ -406,8 +406,8 @@ public abstract class AbsMainListChildViewHolder extends AbsMainViewHolder imple new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal),isSw); } @Override diff --git a/main/src/main/java/com/yunbao/main/views/MainHomeLiveViewHolder.java b/main/src/main/java/com/yunbao/main/views/MainHomeLiveViewHolder.java index 48c711896..81fe8df52 100644 --- a/main/src/main/java/com/yunbao/main/views/MainHomeLiveViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/MainHomeLiveViewHolder.java @@ -402,8 +402,8 @@ public class MainHomeLiveViewHolder extends AbsMainHomeChildViewHolder implement liveBean.setParams(gotoRoomKey); new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal),isSw); } @Override @@ -497,7 +497,7 @@ public class MainHomeLiveViewHolder extends AbsMainHomeChildViewHolder implement } new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { if (LiveRoomViewHolder.mHandler != null) { LiveRoomViewHolder.mHandler.removeCallbacksAndMessages(null); @@ -509,7 +509,7 @@ public class MainHomeLiveViewHolder extends AbsMainHomeChildViewHolder implement } EventBus.getDefault().post(new LiveRoomChangeEvent(liveBean, liveType, Integer.parseInt(liveTypeVal))); } else { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveTypeVal), Integer.parseInt(liveSdk)); + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveTypeVal), Integer.parseInt(liveSdk),isSw); } } diff --git a/main/src/main/java/com/yunbao/main/views/MainMessageViewHolder.java b/main/src/main/java/com/yunbao/main/views/MainMessageViewHolder.java index f71385345..f8a17638a 100644 --- a/main/src/main/java/com/yunbao/main/views/MainMessageViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/MainMessageViewHolder.java @@ -515,8 +515,8 @@ public class MainMessageViewHolder extends AbsMainViewHolder { LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class); new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal),isSw); } @Override diff --git a/main/src/main/java/com/yunbao/main/views/UserHomeViewHolder2.java b/main/src/main/java/com/yunbao/main/views/UserHomeViewHolder2.java index 7f691cf41..e4a566c88 100644 --- a/main/src/main/java/com/yunbao/main/views/UserHomeViewHolder2.java +++ b/main/src/main/java/com/yunbao/main/views/UserHomeViewHolder2.java @@ -794,7 +794,7 @@ public class UserHomeViewHolder2 extends AbsLivePageViewHolder implements LiveSh } new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { if (mFromLiveRoom) { if (MicStatusManager.getInstance().isMic(liveUid)) { @@ -804,7 +804,7 @@ public class UserHomeViewHolder2 extends AbsLivePageViewHolder implements LiveSh ((UserHomeActivity) mContext).onBackPressed(); EventBus.getDefault().post(new LiveRoomChangeEvent(liveBean, liveType, Integer.parseInt(liveTypeVal))); } else { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveTypeVal), Integer.parseInt(liveSdk)); + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveTypeVal), Integer.parseInt(liveSdk),isSw); } }