优化主播下播时也同步关掉连麦房

This commit is contained in:
zlzw 2022-11-25 15:31:14 +08:00
parent 6bd29ec63e
commit eb65c0e101
3 changed files with 54 additions and 35 deletions

View File

@ -85,6 +85,7 @@ import com.yunbao.live.presenter.LiveRyLinkMicPkPresenter;
import com.yunbao.live.socket.SocketRyChatUtil;
import com.yunbao.live.socket.SocketRyClient;
import com.yunbao.live.socket.SocketSendBean;
import com.yunbao.live.utils.MicStatusManager;
import com.yunbao.live.views.LiveEndViewHolder;
import com.yunbao.live.views.LiveMusicViewHolder;
import com.yunbao.live.views.LiveNewReadyRyViewHolder;
@ -909,6 +910,9 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl
mLivePushViewHolder = null;
mLiveReadyViewHolder = null;
mLiveAnchorViewHolder = null;
if(MicStatusManager.getInstance().isAnchorOpenRoom()){
MicStatusManager.getInstance().closeMic(mContext);
}
L.e("LiveAnchorActivity-------onDestroy------->");
Bus.getOff(this);
}

View File

@ -153,7 +153,7 @@ public class LiveMicAnchorDialogFragment extends AbsDialogFragment implements Vi
Tips = bundle.getString("By");
listMicbtn.setOnClickListener(view -> {
if (!isOpenRoom()) {
if (!MicStatusManager.getInstance().isAnchorOpenRoom()) {
return;
}
Tips = "1";
@ -163,7 +163,7 @@ public class LiveMicAnchorDialogFragment extends AbsDialogFragment implements Vi
});
requestMicBtn = mRootView.findViewById(R.id.guard_btn);
requestMicBtn.setOnClickListener(view -> {
if (!isOpenRoom()) {
if (!MicStatusManager.getInstance().isAnchorOpenRoom()) {
return;
}
Tips = "2";
@ -174,7 +174,7 @@ public class LiveMicAnchorDialogFragment extends AbsDialogFragment implements Vi
inviteMicBtn = mRootView.findViewById(R.id.fans_btn);
inviteMicBtn.setVisibility(View.VISIBLE);
inviteMicBtn.setOnClickListener(view -> {
if (!isOpenRoom()) {
if (!MicStatusManager.getInstance().isAnchorOpenRoom()) {
return;
}
Tips = "3";
@ -193,7 +193,7 @@ public class LiveMicAnchorDialogFragment extends AbsDialogFragment implements Vi
mOpenMicLayout.setVisibility(View.GONE);
mRefreshView.setVisibility(View.VISIBLE);
mDisconnectMic.setVisibility(View.VISIBLE);
isOpenRoom = true;
MicStatusManager.getInstance().setAnchorOpenRoom(true);
mRefreshView.initData();
}
}, Throwable::printStackTrace)
@ -208,8 +208,13 @@ public class LiveMicAnchorDialogFragment extends AbsDialogFragment implements Vi
mDisconnectMic.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
closeMic();
DialogUitl.showSimpleDialog(mContext, "是否確認關閉語音連麥", new DialogUitl.SimpleCallback() {
@Override
public void onConfirmClick(Dialog dialog, String content) {
MicStatusManager.getInstance().closeMic(mContext);
LiveMicAnchorDialogFragment.this.dismiss();
}
});
}
});
userMicInfoAdapter = new AnchorUserMicInfoAdapter(mContext, LiveMicAnchorDialogFragment.this);
@ -345,7 +350,6 @@ public class LiveMicAnchorDialogFragment extends AbsDialogFragment implements Vi
}
}
private boolean isOpenRoom = false;
private void initData() {
LiveHttpUtil.getMicList(mLiveUid, 0, new HttpCallback() {
@ -359,36 +363,12 @@ public class LiveMicAnchorDialogFragment extends AbsDialogFragment implements Vi
no_more.setVisibility(View.GONE);
mDisconnectMic.setVisibility(View.INVISIBLE);
} else {
isOpenRoom = true;
MicStatusManager.getInstance().setAnchorOpenRoom(true);
}
}
});
}
private boolean isOpenRoom() {
return isOpenRoom;
}
private void closeMic() {
DialogUitl.showSimpleDialog(mContext, "是否確認關閉語音連麥", new DialogUitl.SimpleCallback() {
@Override
public void onConfirmClick(Dialog dialog, String content) {
API.get().pdLiveApi(mContext)
.delDrLm()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<ResponseModel<BaseModel>>() {
@Override
public void accept(ResponseModel<BaseModel> stringResponseModel) throws Exception {
System.out.println("stringResponseModel.getData() = " + stringResponseModel.getData());
LiveMicAnchorDialogFragment.this.dismiss();
}
}, Throwable::printStackTrace)
.isDisposed();
}
});
}
/**
* 用于更新连麦对话框数据

View File

@ -1,21 +1,25 @@
package com.yunbao.live.utils;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import com.yunbao.common.CommonAppConfig;
import com.yunbao.common.bean.BaseModel;
import com.yunbao.common.http.API;
import com.yunbao.common.http.HttpCallback;
import com.yunbao.common.http.HttpClient;
import com.yunbao.common.http.ResponseModel;
import com.yunbao.common.utils.ToastUtil;
import com.yunbao.live.activity.LiveActivity;
import org.greenrobot.eventbus.EventBus;
import cn.rongcloud.rtc.api.RCRTCEngine;
import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback;
import cn.rongcloud.rtc.api.callback.IRCRTCSwitchRoleCallback;
import cn.rongcloud.rtc.base.RTCErrorCode;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;
/**
* 统一管理连麦状态
@ -27,6 +31,7 @@ public class MicStatusManager {
private static MicStatusManager manager;
private int micStatus;//连麦状态
private String micLiveId;//主播uid
private boolean anchorOpenRoom = false;
public static MicStatusManager getInstance() {
if (manager == null) {
@ -43,6 +48,14 @@ public class MicStatusManager {
this.micStatus = micStatus;
}
public boolean isAnchorOpenRoom() {
return anchorOpenRoom;
}
public void setAnchorOpenRoom(boolean anchorOpenRoom) {
this.anchorOpenRoom = anchorOpenRoom;
}
public void clear() {
micStatus = 0;
micLiveId = "";
@ -125,4 +138,26 @@ public class MicStatusManager {
}
});
}
/**
* 主播关闭连麦权限
*/
public void closeMic(Context mContext) {
API.get().pdLiveApi(mContext)
.delDrLm()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<ResponseModel<BaseModel>>() {
@Override
public void accept(ResponseModel<BaseModel> stringResponseModel) throws Exception {
System.out.println("stringResponseModel.getData() = " + stringResponseModel.getData());
anchorOpenRoom = false;
}
}, Throwable::printStackTrace)
.isDisposed();
}
public boolean isMic() {
return micStatus == MIC_TYPE_OPEN;
}
}