diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java index 4869923a3..93eca2957 100644 --- a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java @@ -192,7 +192,7 @@ public class SWAuManager extends BaseCacheManager { // 创建 ChannelMediaOptions 对象,并进行配置 ChannelMediaOptions options = new ChannelMediaOptions(); // 根据场景将用户角色设置为 AUDIENCE (观众) - options.clientRoleType = Constants.CLIENT_ROLE_BROADCASTER; + options.clientRoleType = Constants.CLIENT_ROLE_AUDIENCE; options.autoSubscribeVideo = true; options.autoSubscribeAudio = true; options.publishMicrophoneTrack = false; @@ -213,7 +213,7 @@ public class SWAuManager extends BaseCacheManager { SurfaceView surfaceView = new SurfaceView(mContext); surfaceView.setZOrderMediaOverlay(true); frameLayout.addView(surfaceView); - VideoCanvas videoCanvas = new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_FIT,Integer.parseInt(toUid)); + VideoCanvas videoCanvas = new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_HIDDEN,Integer.parseInt(toUid)); mRtcEngine.setupRemoteVideoEx(videoCanvas, rtcConnection); } }); @@ -244,6 +244,13 @@ public class SWAuManager extends BaseCacheManager { mRtcEngine.leaveChannelEx(rtcConnection); } + /** + * 退出所有的直播间 + */ + public void exitChannelAll(){ + mRtcEngine.leaveChannel(); + } + public static String getChannelName(String liveUid) { if(liveUid.contains("g")){ return liveUid; diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java index 7a780c229..76d06f7fa 100644 --- a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java @@ -300,7 +300,7 @@ public class SWManager extends BaseCacheManager { // 创建 ChannelMediaOptions 对象,并进行配置 ChannelMediaOptions options = new ChannelMediaOptions(); // 根据场景将用户角色设置为 AUDIENCE (观众) - options.clientRoleType = Constants.CLIENT_ROLE_BROADCASTER; + options.clientRoleType = Constants.CLIENT_ROLE_AUDIENCE; options.autoSubscribeVideo = true; options.autoSubscribeAudio = true; options.publishMicrophoneTrack = false; 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 48a769c5f..0f979153b 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveAnchorActivity.java @@ -997,6 +997,11 @@ public class LiveAnchorActivity extends LiveActivity implements LiveFunctionClic } } + @Override + public void onLinkDRMicPKToUser(UserBean u) { + + } + //多人PK接受 @Override public void onLinkDRMicPkApplyOk(UserBean u) { 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 e52c6e360..0c4cc52a1 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java @@ -565,11 +565,16 @@ public class LiveAudienceActivity extends LiveActivity { } + @Override + public void onLinkDRMicPKToUser(UserBean u) { + //manager.getmLivePlayViewHolder().setDrMicInfo(u); + } + @Override public void onLinkDRMicPkApplyOk(UserBean u) { L.eSw("onLinkDRMicPkApplyOk:"+u.getId()); //多人PK 连麦 - manager.getmLivePlayViewHolder().setDrMicInfo(u); + //manager.getmLivePlayViewHolder().setDrMicInfo(u); } @Override 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 c35ee493d..6a8d9bd51 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java @@ -1429,6 +1429,11 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl } } + @Override + public void onLinkDRMicPKToUser(UserBean u) { + + } + //多人PK接受 @Override public void onLinkDRMicPkApplyOk(UserBean u) { 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 03204fba6..32be6313e 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java @@ -512,7 +512,6 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { showDRApplyDialog(u); } - /** * 主播与主播PK 主播收到其他主播发过来的多人PK申请同意了的回调 */ @@ -522,6 +521,37 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { 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); } @@ -600,7 +630,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { /*---------------------------------------------------------------- */ final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 2) //回复PK申请 2 - .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()).param("pkuid", CommonAppConfig.getInstance().getUid()).param("uid", CommonAppConfig.getInstance().getUid()).param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()).param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); + .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()).param("pkuid", bean.getId()).param("uid", CommonAppConfig.getInstance().getUid()).param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()).param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); msg1.create(); System.out.println("PK回执 = " + msg1.toString()); Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; @@ -817,6 +847,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { public void run() { if (btn_close != null) { btn_close.setVisibility(View.GONE); + livePushRyViewHolder.timeTitle.setVisibility(View.GONE); } } }); @@ -1029,28 +1060,20 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { 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); - } - for (int i = 0; i drPkbeanList) { - L.eSw("setDrPkUserInfoView"+new Gson().toJson(drPkbeanList)); + L.eSw("setDrPkUserInfoView" + new Gson().toJson(drPkbeanList)); mHandler.postDelayed(new Runnable() { @Override public void run() { - for (int j = 0; j 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); + } + 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); + new Handler().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) { + 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)); @@ -290,6 +428,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { 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)); } @@ -517,6 +656,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { mStarted = false; Bus.getOff(this); EventBus.getDefault().unregister(this); + swAuManager.exitChannelAll(); L.e(TAG, "release------->"); } @@ -1276,7 +1416,6 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { url = url.replace(".flv", videoRatioHorizontal[PLAY_MODEL_480] + videoFps[0] + ".flv"); } } - private class ExoPlayerListener implements Player.Listener { String TAG = "播放流"; 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 79cc87cb3..a54f2f6b4 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java @@ -589,7 +589,10 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX public void setAnPkRtc(UserBean u) { if (swManager != null && u != null) { + //将多人pk画面屏蔽 + dr_pk_view.setVisibility(View.GONE); L.eSw("设置对方主播的视图setAnPkRtc" + u); + pkUid1 = u.getId(); mPkContainer.setVisibility(View.VISIBLE); //将自己的渲染视图设置到 leftContainer swManager.updateMyChannelView((FrameLayout) mLeftContainer); @@ -608,7 +611,6 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX private String drpkUid3 = ""; public int setAnDrPkRtc(String uid, int position) { L.eSw("setAnDrPkRtc uid:"+uid+" position"+position); - FrameLayout frameLayout = null; int temp= -1; if (swManager != null && !StringUtil.isEmpty(uid)) { L.eSw("设置对方主播的视图 setAnDrPkRtc" + uid + "position:" + position); @@ -622,13 +624,17 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX } switch (temp) { case 2: - frameLayout = dr2_preview; + 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; - frameLayout = dr4_preview; + 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: @@ -637,15 +643,9 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX swManager.exitChannelToUid(Integer.parseInt(CommonAppConfig.getInstance().getUid()),drpkUid3); swManager.joinChannelDrEx(dr3_preview,CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, drpkUid3, SWAuManager.getChannelName(drpkUid3)); - frameLayout = dr4_preview; + swManager.joinChannelDrEx(dr4_preview,CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, uid, SWAuManager.getChannelName(uid)); break; } - - if (temp == 2) { - swManager.updateMyChannelView(dr1_preview); - mBigContainer.removeAllViews(); - } - swManager.joinChannelDrEx(frameLayout,CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, uid, SWAuManager.getChannelName(uid)); dr_pk_view.setVisibility(View.VISIBLE); currentPosition = temp; } 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 0c6667b0c..7c5d090bf 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -647,14 +647,20 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe //判断是否是多人连麦 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()))){ drPkbean.setId(String.valueOf(da.getIntValue("id"))); + drPkbean1.setId(da.getIntValue("id")); + drPkbean1.setUser_nicename(da.getString("user_nicename")); + drPkbeans.add(drPkbean1); mLivePlayViewHolder.setDrMicInfo(drPkbean); } } + mLivePlayViewHolder.setDrPkView(drPkbeans); } }else{//单人连麦 LivePkMicModel connection_info = data.getEnterRoomInfo().getConnectionInfo(); @@ -712,14 +718,20 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe } if (mLivePlayViewHolder != null) { JSONArray array = pkInfo.getJSONArray("userlist"); + List drPkbeans = new ArrayList<>(); for (int j = 0; j < array.size(); j++) { - UserBean drPkbean = new UserBean(); + UserBean userBean = new UserBean(); + DrPkbean drPkbean = new DrPkbean(); JSONObject da = array.getJSONObject(j); if(!String.valueOf(da.getIntValue("id")).equals(data.getLiveInfo().getUid())){ - drPkbean.setId(String.valueOf(da.getIntValue("id"))); - mLivePlayViewHolder.setDrMicInfo(drPkbean); + userBean.setId(String.valueOf(da.getIntValue("id"))); + drPkbean.setId(da.getIntValue("id")); + drPkbean.setUser_nicename(da.getString("user_nicename")); + drPkbeans.add(drPkbean); + mLivePlayViewHolder.setDrMicInfo(userBean); } } + mLivePlayViewHolder.setDrPkView(drPkbeans); } upDataPkScore(pkInfo.getJSONArray("userlist"), pkInfo.getIntValue("drpk_time")); @@ -1585,10 +1597,17 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe } + @Override + public void onLinkDRMicPKToUser(UserBean u) { + L.eSw("onLinkDRMicPKToUser(UserBean u)PortraitLiveManager"); + mLivePlayViewHolder.setDrMicInfo(u); + + } + @Override public void onLinkDRMicPkApplyOk(UserBean u) { L.eSw("onLinkDRMicPkApplyOk(UserBean u)PortraitLiveManager"); - mLivePlayViewHolder.setDrMicInfo(u); + //mLivePlayViewHolder.setDrMicInfo(u); } @@ -2197,6 +2216,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe pkScores.remove(index); pkScores.add(0, liveModel); mLiveRoomViewHolder.upDataPkScore(pkScores, time); + mLivePlayViewHolder.claerDrPkInfoView(); setPkStatus(true); } //通知心愿单位置换地方 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 cdcd20495..03fe704b1 100644 --- a/live/src/main/res/layout/view_live_play_ksy.xml +++ b/live/src/main/res/layout/view_live_play_ksy.xml @@ -69,7 +69,7 @@