From 86a0a19feca314f3e1210954c1bed2837a6b4927 Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Thu, 24 Nov 2022 16:27:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=80=E5=A4=84=E9=97=AA?= =?UTF-8?q?=E9=80=80=E9=97=AE=E9=A2=98=20=E6=96=B0=E5=A2=9E=E7=BB=9F?= =?UTF-8?q?=E4=B8=80=E8=BF=9E=E9=BA=A6=E7=8A=B6=E6=80=81=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E7=B1=BB=20=E4=BF=AE=E5=A4=8D=E8=BF=9E=E9=BA=A6=E8=BF=87?= =?UTF-8?q?=E7=A8=8B=E4=B8=AD=E5=8F=AF=E4=BB=A5=E9=80=9A=E8=BF=87=E5=9B=9E?= =?UTF-8?q?=E5=88=B0=E6=A1=8C=E9=9D=A2-=E9=87=8D=E8=BF=9BAPP=EF=BC=8C?= =?UTF-8?q?=E4=BB=8E=E8=80=8C=E5=8F=AF=E4=BB=A5=E8=BF=9B=E5=85=A5=E5=85=B6?= =?UTF-8?q?=E4=BB=96=E7=9B=B4=E6=92=AD=E9=97=B4=E9=97=AE=E9=A2=98=EF=BC=88?= =?UTF-8?q?=E6=96=B9=E6=A1=88=EF=BC=9A=E8=BF=9E=E9=BA=A6=E4=B8=AD=E7=82=B9?= =?UTF-8?q?=E5=87=BB=E5=85=B6=E4=BB=96=E7=9B=B4=E6=92=AD=E9=97=B4=E5=85=88?= =?UTF-8?q?=E8=AF=A2=E9=97=AE=E6=98=AF=E5=90=A6=E9=80=80=E5=87=BA=E8=BF=9E?= =?UTF-8?q?=E9=BA=A6=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../live/activity/LiveAudienceActivity.java | 23 ++++-- .../dialog/LiveMicAnchorDialogFragment.java | 5 +- .../dialog/LiveMicUserDialogFragment.java | 28 +++---- .../live/dialog/SidebarLiveAudience.java | 5 +- .../yunbao/live/utils/MicStatusManager.java | 75 +++++++++++++++++++ .../live/views/LivePlayRyViewHolder.java | 8 +- .../yunbao/live/views/LiveRoomViewHolder.java | 5 +- .../live/views/PortraitLiveManager.java | 6 +- 8 files changed, 121 insertions(+), 34 deletions(-) create mode 100644 live/src/main/java/com/yunbao/live/utils/MicStatusManager.java 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 dbd79875c..3dc90b8e2 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java @@ -1,8 +1,7 @@ package com.yunbao.live.activity; -import static com.yunbao.live.views.LivePlayRyViewHolder.Micing; - import android.annotation.SuppressLint; +import android.app.Dialog; import android.content.Context; import android.content.Intent; import android.content.res.Configuration; @@ -93,6 +92,7 @@ import com.yunbao.live.http.ImHttpUtil; import com.yunbao.live.http.LiveHttpConsts; import com.yunbao.live.http.LiveHttpUtil; import com.yunbao.live.presenter.LiveRoomCheckLivePresenter; +import com.yunbao.live.utils.MicStatusManager; import com.yunbao.live.views.LiveRoomPlayViewHolder; import com.yunbao.live.views.PortraitLiveManager; @@ -222,11 +222,11 @@ public class LiveAudienceActivity extends LiveActivity { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { - if (Micing == 1) { + if (MicStatusManager.getInstance().getMicStatus() == MicStatusManager.MIC_TYPE_REQUEST) { manager.micIngTypeOne(mLiveBean, mLiveType, mLiveTypeVal); verticalViewPager.setEnableScroll(false); - } else if (Micing == 2) { + } else if (MicStatusManager.getInstance().getMicStatus() == MicStatusManager.MIC_TYPE_OPEN) { verticalViewPager.setEnableScroll(false); manager.micIngTypeTwo(mLiveBean, mLiveType, mLiveTypeVal); @@ -490,9 +490,9 @@ public class LiveAudienceActivity extends LiveActivity { public void onBackPressed() { try { manager.onBackPressed(); - if (Micing == 1) { + if (MicStatusManager.getInstance().getMicStatus() == MicStatusManager.MIC_TYPE_REQUEST) { manager.micIngTypeOne(mLiveBean, mLiveType, mLiveTypeVal); - } else if (Micing == 2) { + } else if (MicStatusManager.getInstance().getMicStatus() == MicStatusManager.MIC_TYPE_OPEN) { manager.micIngTypeTwo(mLiveBean, mLiveType, mLiveTypeVal); } else { manager.onRemove(true); @@ -1165,6 +1165,17 @@ public class LiveAudienceActivity extends LiveActivity { public static void forward(Context context, LiveBean liveBean, int liveType, int liveTypeVal, String key, Map map, int position, int liveSdk) { + if (MicStatusManager.getInstance().getMicStatus() != MicStatusManager.MIC_TYPE_DEFAULT && + !MicStatusManager.getInstance().getMicLiveId().equals(liveBean.getUid())) { + Log.i("连麦",MicStatusManager.getInstance().toString()+" | "+liveBean.getUid()); + DialogUitl.showSimpleDialog(context, "當前正在連麥中,是否退出連麥", new DialogUitl.SimpleCallback() { + @Override + public void onConfirmClick(Dialog dialog, String content) { + MicStatusManager.getInstance().downMic(); + } + }); + return; + } Intent intent = new Intent(context, LiveAudienceActivity.class); intent.putExtra(Constants.LIVE_BEAN, liveBean); intent.putExtra(Constants.LIVE_TYPE, liveType); diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveMicAnchorDialogFragment.java b/live/src/main/java/com/yunbao/live/dialog/LiveMicAnchorDialogFragment.java index 5464325d2..76a43e668 100644 --- a/live/src/main/java/com/yunbao/live/dialog/LiveMicAnchorDialogFragment.java +++ b/live/src/main/java/com/yunbao/live/dialog/LiveMicAnchorDialogFragment.java @@ -1,7 +1,5 @@ package com.yunbao.live.dialog; -import static com.yunbao.live.views.LivePlayRyViewHolder.Micing; - import android.app.ActionBar; import android.app.Dialog; import android.graphics.Color; @@ -37,6 +35,7 @@ import com.yunbao.live.bean.LiveUserGiftBean; import com.yunbao.live.bean.MicUserBean; import com.yunbao.live.http.LiveHttpUtil; import com.yunbao.live.utils.LiveImDeletUtil; +import com.yunbao.live.utils.MicStatusManager; import java.util.ArrayList; import java.util.Arrays; @@ -238,7 +237,7 @@ public class LiveMicAnchorDialogFragment extends AbsDialogFragment implements Vi @Override public List processData(String[] info) { - Log.e("tag222", Tips + "ssss" + Micing); + Log.e("tag222", Tips + "ssss" + MicStatusManager.getInstance().toString()); JSONObject obj = JSON.parseObject(info[0]); List data = new ArrayList<>(); diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveMicUserDialogFragment.java b/live/src/main/java/com/yunbao/live/dialog/LiveMicUserDialogFragment.java index 0acd3643e..3acc094c5 100644 --- a/live/src/main/java/com/yunbao/live/dialog/LiveMicUserDialogFragment.java +++ b/live/src/main/java/com/yunbao/live/dialog/LiveMicUserDialogFragment.java @@ -1,7 +1,5 @@ package com.yunbao.live.dialog; -import static com.yunbao.live.views.LivePlayRyViewHolder.Micing; - import android.Manifest; import android.app.ActionBar; import android.app.Dialog; @@ -38,13 +36,13 @@ import com.yunbao.live.bean.MicUserBean; import com.yunbao.live.http.LiveHttpUtil; import com.yunbao.live.socket.SocketSendBean; import com.yunbao.live.utils.LiveImDeletUtil; +import com.yunbao.live.utils.MicStatusManager; import org.greenrobot.eventbus.EventBus; import java.util.ArrayList; import java.util.List; -import io.rong.imkit.IMCenter; import io.rong.imlib.IRongCallback; import io.rong.imlib.RongIMClient; import io.rong.imlib.model.Conversation; @@ -149,20 +147,20 @@ public class LiveMicUserDialogFragment extends AbsDialogFragment implements View mRefreshView = mRootView.findViewById(R.id.refreshView); view_no = mRootView.findViewById(R.id.view_no); apply_btn = mRootView.findViewById(R.id.apply_btn); - if (Micing == 0) { + if (MicStatusManager.getInstance().getMicStatus() == MicStatusManager.MIC_TYPE_DEFAULT) { apply_btn.setBackgroundResource(R.drawable.background_0fdab8); apply_btn.setText(R.string.apply_for_lianmai); - } else if (Micing == 1) { + } else if (MicStatusManager.getInstance().getMicStatus() == MicStatusManager.MIC_TYPE_REQUEST) { apply_btn.setBackgroundResource(R.drawable.background_00a0e9); apply_btn.setText(R.string.cancel_application); - } else if (Micing == 2) { + } else if (MicStatusManager.getInstance().getMicStatus() == MicStatusManager.MIC_TYPE_OPEN) { apply_btn.setBackgroundResource(R.drawable.background_eb6877); apply_btn.setText(R.string.quit_mic); } apply_btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if (Micing == 0) { + if (MicStatusManager.getInstance().getMicStatus() == MicStatusManager.MIC_TYPE_DEFAULT) { LiveAudienceActivity.mProcessResultUtil.requestPermissions(new String[]{ Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE, @@ -207,7 +205,7 @@ public class LiveMicUserDialogFragment extends AbsDialogFragment implements View ToastUtil.show(""); apply_btn.setBackgroundResource(R.drawable.background_00a0e9); apply_btn.setText(R.string.cancel_application); - Micing = 1; + MicStatusManager.getInstance().setMicData(MicStatusManager.MIC_TYPE_REQUEST,mLiveUid); dismiss(); io.rong.imlib.model.Message ids[] = {message}; RongIMClient.getInstance().deleteRemoteMessages(conversationType,message.getTargetId(),ids, null); @@ -227,7 +225,7 @@ public class LiveMicUserDialogFragment extends AbsDialogFragment implements View }); } }); - } else if (Micing == 1) { + } else if (MicStatusManager.getInstance().getMicStatus() == MicStatusManager.MIC_TYPE_REQUEST) { //取消申請 dismiss(); //用户申请联麦 @@ -253,7 +251,7 @@ public class LiveMicUserDialogFragment extends AbsDialogFragment implements View @Override public void onSuccess(io.rong.imlib.model.Message message) { Log.e("ry", "发送成功"); - Micing = 0; + MicStatusManager.getInstance().clear(); dismiss(); io.rong.imlib.model.Message ids[] = {message}; RongIMClient.getInstance().deleteRemoteMessages(conversationType,message.getTargetId(),ids, null); @@ -268,7 +266,7 @@ public class LiveMicUserDialogFragment extends AbsDialogFragment implements View } }); - } else if (Micing == 2) { + } else if (MicStatusManager.getInstance().getMicStatus() == MicStatusManager.MIC_TYPE_OPEN) { //退出连麦 DialogUitl.showSimpleDialog(mContext, "連麥中,退出將斷開語音連麥!", new DialogUitl.SimpleCallback() { @Override @@ -319,11 +317,11 @@ public class LiveMicUserDialogFragment extends AbsDialogFragment implements View @Override public List processData(String[] info) { - Log.e("tag222", Tips + "ssss" + Micing); + Log.e("tag222", Tips + "ssss" + MicStatusManager.getInstance().toString()); JSONObject obj = JSON.parseObject(info[0]); List data = new ArrayList<>(); if (Tips.equals("2")) { - if (Micing == 1) { + if (MicStatusManager.getInstance().getMicStatus() == MicStatusManager.MIC_TYPE_REQUEST) { MicUserBean micuser = new MicUserBean(); micuser.setAvatar(CommonAppConfig.getInstance().getUserBean().getAvatar()); micuser.setUserNiceName(CommonAppConfig.getInstance().getUserBean().getUserNiceName()); @@ -335,7 +333,9 @@ public class LiveMicUserDialogFragment extends AbsDialogFragment implements View } } else { data = JSON.parseArray(obj.getString("userlist"), MicUserBean.class); - data.remove(0); + if(data.size()!=0) { + data.remove(0); + } } if (data.size() > 0 && pg == 1) { nums = 0; diff --git a/live/src/main/java/com/yunbao/live/dialog/SidebarLiveAudience.java b/live/src/main/java/com/yunbao/live/dialog/SidebarLiveAudience.java index 89e28ad83..a9fcb02f9 100644 --- a/live/src/main/java/com/yunbao/live/dialog/SidebarLiveAudience.java +++ b/live/src/main/java/com/yunbao/live/dialog/SidebarLiveAudience.java @@ -20,6 +20,7 @@ import com.yunbao.live.event.LiveAudienceEvent; import com.yunbao.live.event.LiveRoomChangeEvent; import com.yunbao.live.http.LiveHttpUtil; import com.yunbao.live.presenter.LiveRoomCheckLivePresenter; +import com.yunbao.live.utils.MicStatusManager; import com.yunbao.live.views.LivePlayRyViewHolder; import org.greenrobot.eventbus.EventBus; @@ -87,12 +88,12 @@ public class SidebarLiveAudience extends AbsDialogFragment { if (liveBean1 == null) { return; } - if (LivePlayRyViewHolder.Micing == 1) { + if (MicStatusManager.getInstance().getMicStatus() == MicStatusManager.MIC_TYPE_REQUEST) { Bus.get().post(new LiveAudienceEvent() .setType(LiveAudienceEvent.LiveAudienceType.LIAN_MAI) .setMicIng(1) .setBean(liveBean).setLiveType(liveType).setLiveTypeVal(liveTypeVal)); - } else if (LivePlayRyViewHolder.Micing == 2) { + } else if (MicStatusManager.getInstance().getMicStatus() == MicStatusManager.MIC_TYPE_OPEN) { Bus.get().post(new LiveAudienceEvent() .setType(LiveAudienceEvent.LiveAudienceType.LIAN_MAI) .setMicIng(2) diff --git a/live/src/main/java/com/yunbao/live/utils/MicStatusManager.java b/live/src/main/java/com/yunbao/live/utils/MicStatusManager.java new file mode 100644 index 000000000..e354a2765 --- /dev/null +++ b/live/src/main/java/com/yunbao/live/utils/MicStatusManager.java @@ -0,0 +1,75 @@ +package com.yunbao.live.utils; + +import android.util.Log; + +import com.yunbao.common.CommonAppConfig; +import com.yunbao.common.http.HttpCallback; +import com.yunbao.common.http.HttpClient; +import com.yunbao.live.activity.LiveActivity; + +import org.greenrobot.eventbus.EventBus; + +/** + * 统一管理连麦状态 + */ +public class MicStatusManager { + public static final int MIC_TYPE_DEFAULT = 0;//默认状态,未连麦 + public static final int MIC_TYPE_REQUEST = 1;//请求连麦中 + public static final int MIC_TYPE_OPEN = 2;//连麦中 + private static MicStatusManager manager; + private int micStatus;//连麦状态 + private String micLiveId;//主播uid + + public static MicStatusManager getInstance() { + if (manager == null) { + manager = new MicStatusManager(); + } + return manager; + } + + private MicStatusManager() { + } + + public void setMicData(int micStatus, String micLiveId) { + this.micLiveId = micLiveId; + this.micStatus = micStatus; + } + + public void clear() { + micStatus = 0; + micLiveId = ""; + } + + public int getMicStatus() { + return micStatus; + } + + public String getMicLiveId() { + return micLiveId; + } + + @Override + public String toString() { + return "MicStatusManager{" + + "micStatus=" + micStatus + + ", micLiveId='" + micLiveId + '\'' + + '}'; + } + + /** + * 断开连麦 + */ + public void downMic() { + HttpClient.getInstance().get("live.leaveDrLm", "live.leaveDrLm") + .params("roomid", micLiveId) + .params("uid", CommonAppConfig.getInstance().getUid()) + .execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + Log.e("ry", code + "退出多人"); + clear(); + } + }); + EventBus.getDefault().post("endMic"); + } +} 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 13477491f..2d8bca680 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java @@ -37,6 +37,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.utils.MicStatusManager; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; @@ -101,7 +102,6 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { //0未申请1申请中2连麦中 - public static int Micing = 0; RCRTCRoom rcrtcRoom; String purl; @@ -166,7 +166,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { @Override public void setLiveBeanLandscape(int landscape) { - LivePlayRyViewHolder.landscape =landscape; + LivePlayRyViewHolder.landscape = landscape; } /** @@ -579,7 +579,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { ry_view.removeAllViews(); onPrepared(); rcrtcRoom = null; - Micing = 0; + MicStatusManager.getInstance().clear(); ToastUtil.show("已成功退出語音連麥"); } }); @@ -818,7 +818,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { @Override public void onSuccess() { Log.e("ry", "订阅资源成功"); - Micing = 2; + 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); 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 47000f5df..60f516f41 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java @@ -133,6 +133,7 @@ import com.yunbao.live.presenter.LiveEnterRoomAnimPresenter; import com.yunbao.live.presenter.LiveGiftAnimPresenter; import com.yunbao.live.presenter.LiveLightAnimPresenter; import com.yunbao.live.presenter.LiveRoomCheckLivePresenter; +import com.yunbao.live.utils.MicStatusManager; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; @@ -3489,12 +3490,12 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis if (liveBean1 == null) { return; } - if (LivePlayRyViewHolder.Micing == 1) { + if (MicStatusManager.getInstance().getMicStatus() == MicStatusManager.MIC_TYPE_REQUEST) { Bus.get().post(new LiveAudienceEvent() .setType(LiveAudienceEvent.LiveAudienceType.LIAN_MAI) .setMicIng(1) .setBean(liveBean).setLiveType(liveType).setLiveTypeVal(liveTypeVal)); - } else if (LivePlayRyViewHolder.Micing == 2) { + } else if (MicStatusManager.getInstance().getMicStatus() == MicStatusManager.MIC_TYPE_OPEN) { Bus.get().post(new LiveAudienceEvent() .setType(LiveAudienceEvent.LiveAudienceType.LIAN_MAI) .setMicIng(2) 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 efa2a967f..995fdaca3 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -1,6 +1,5 @@ package com.yunbao.live.views; -import static com.yunbao.live.views.LivePlayRyViewHolder.Micing; import static com.yunbao.live.views.LiveRoomViewHolder.isStayRoomfive; import android.app.Activity; @@ -87,6 +86,7 @@ import com.yunbao.live.socket.SocketRyChatUtil; import com.yunbao.live.socket.SocketRyClient; import com.yunbao.live.socket.SocketSendBean; import com.yunbao.live.utils.LiveImDeletUtil; +import com.yunbao.live.utils.MicStatusManager; import org.greenrobot.eventbus.EventBus; @@ -497,7 +497,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe DialogUitl.showSimpleDialog(mContext, null, "您已申請,退出將取消語音連麥申請!", false, new DialogUitl.SimpleCallback3() { @Override public void onConfirmClick(Dialog dialog) { - Micing = 0; + MicStatusManager.getInstance().clear(); //用户申请联麦 final SocketSendBean msg = new SocketSendBean() .param("_method_", Constants.LIAN_MAI) @@ -590,7 +590,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe Log.e("ry", "退出多人房间成功"); if (isBackPressed) { - Micing = 0; + MicStatusManager.getInstance().clear(); ((LiveAudienceActivity) mContext).closeRoom(); } else { EventBus.getDefault().post(new LiveRoomChangeEvent(bean, liveType, liveTypeVal));