修复关闭停止推流的时候没有退出自己房间

This commit is contained in:
董宏宇
2021-03-11 14:40:02 +08:00
parent 80299c4ef9
commit 4a29240dbd
6 changed files with 52 additions and 33 deletions

View File

@@ -104,7 +104,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="请输入要查看的车机SN"
android:text="F803EB2046PZD00149"
android:text="F803BB2037EZD00072"
android:textColor="#FFFF"
app:layout_constraintBottom_toTopOf="@+id/liveToggleBtn"
app:layout_constraintEnd_toEndOf="parent"

View File

@@ -297,7 +297,9 @@ public class MoGoLiveManager {
" , errorCode : " + errorCode);
// 判断如果处于非播放和非推流状态则进行登出操作,并释放引擎
if (!mLiveStatusModel.isPlaying() && !mLiveStatusModel.isPushing()) {
if (!mLiveStatusModel.isPlaying()
&& !mLiveStatusModel.isPushing()
&& mLiveStatusModel.getOnlineNumber() <= 1) {
logoutCurrentRoom();
}
@@ -322,7 +324,9 @@ public class MoGoLiveManager {
" , extendData : " + extendedData.toString());
// 判断如果处于非播放和非推流状态则进行登出操作,并释放引擎
if (!mLiveStatusModel.isPlaying() && !mLiveStatusModel.isPushing()) {
if (!mLiveStatusModel.isPlaying()
&& !mLiveStatusModel.isPushing()
&& mLiveStatusModel.getOnlineNumber() <= 1) {
logoutCurrentRoom();
}
}
@@ -339,6 +343,15 @@ public class MoGoLiveManager {
this.mProgressListener.add(liveProgressListener);
}
/**
* 删除直播进度监听
*
* @param liveProgressListener 监听回调用
*/
public void removeLiveProgressListener(ILiveProgressListener liveProgressListener) {
this.mProgressListener.remove(liveProgressListener);
}
/**
* 设置直播间连接状态监听
*
@@ -348,6 +361,15 @@ public class MoGoLiveManager {
this.mRoomStatusListener.add(roomStatusListener);
}
/**
* 删除直播间连接状态监听
*
* @param roomStatusListener 监听回调用
*/
public void removeLiveRoomStatusListener(ILiveCurrentRoomStatusListener roomStatusListener) {
this.mRoomStatusListener.remove(roomStatusListener);
}
/**
* 设置直播间的人员监听
*
@@ -371,7 +393,7 @@ public class MoGoLiveManager {
*/
private void initExpressEngine() {
Logger.i(TAG, "initCustomVideoCapture 初始化引擎");
mLiveStatusModel.setExpressEngineCanUse(true);
// 创建 enging 对象, appID, appSign 为开发者在 ZEGO 管理控制台申请的凭证信息,
// 未上线的开发者 isTestEnvironment 为 true, application 为安卓应用的上下文
boolean isTestEnv = false;
@@ -432,11 +454,6 @@ public class MoGoLiveManager {
super.onStart(channel);
Logger.i(TAG, "SDK 通知将要开始采集视频帧 setCustomVideoCaptureHandler onStart");
mLiveStatusModel.setCaptureStatus(true);
if (mProgressListener != null) {
for (ILiveProgressListener iLiveProgressListener : mProgressListener) {
iLiveProgressListener.onEngineStart();
}
}
}
@Override
@@ -444,11 +461,6 @@ public class MoGoLiveManager {
super.onStop(channel);
Logger.i(TAG, "SDK 通知将要停止采集视频帧 setCustomVideoCaptureHandler onStop");
mLiveStatusModel.setCaptureStatus(false);
if (mProgressListener != null) {
for (ILiveProgressListener iLiveProgressListener : mProgressListener) {
iLiveProgressListener.onEngineStop();
}
}
}
});
}
@@ -606,6 +618,7 @@ public class MoGoLiveManager {
mExpressEngine.enableCustomVideoCapture(false, customVideoCaptureConfig, ZegoPublishChannel.MAIN);
ZegoExpressEngine.destroyEngine(() -> {
Logger.i(TAG, "销毁ZeGo引擎");
mLiveStatusModel.setExpressEngineCanUse(false);
});
}
}

View File

@@ -40,6 +40,10 @@ public class LiveStatusModel {
* 播放状态true-播放中false-没有播放
*/
private boolean isPlaying;
/**
* ZeGo引擎状态true-ZeGo引擎可用false-ZeGo引擎不可用
*/
private boolean isExpressEngineCanUse;
/**
* 当前在直播间的人数,只剩下一个人的时候需要停掉直播推送
*/
@@ -117,6 +121,14 @@ public class LiveStatusModel {
isPlaying = playing;
}
public boolean isExpressEngineCanUse() {
return isExpressEngineCanUse;
}
public void setExpressEngineCanUse(boolean expressEngineCanUse) {
isExpressEngineCanUse = expressEngineCanUse;
}
public int getOnlineNumber() {
return onlineNumber;
}
@@ -137,6 +149,7 @@ public class LiveStatusModel {
", isCaptureStatus=" + isCaptureStatus +
", isPushing=" + isPushing +
", isPlaying=" + isPlaying +
", isExpressEngineCanUse=" + isExpressEngineCanUse +
", onlineNumber=" + onlineNumber +
'}';
}

View File

@@ -51,7 +51,7 @@ public class PushService extends Service
if (intent != null) {
// 开启直播
if (ACTION_START_RTMP_PUSH.equals(intent.getAction())) {
Logger.i(TAG, "开启直播推送");
Logger.i(TAG, "接收指令开启直播推送");
try {
startPush();
} catch (Exception e) {
@@ -60,7 +60,7 @@ public class PushService extends Service
}
// 关闭直播,如果还有人观看不关闭
else if (ACTION_STOP_RTMP_PUSH.equals(intent.getAction())) {
Logger.i(TAG, "关闭直播推送");
Logger.i(TAG, "接受指令关闭直播推送");
if (mLivePusher.getLiveStatusModel().getOnlineNumber() <= 1) {
stopPush();
} else {
@@ -69,7 +69,7 @@ public class PushService extends Service
}
// 强制关闭直播
else if (ACTION_FORCED_STOP_RTMP_PUSH.equals(intent.getAction())) {
Logger.i(TAG, "强制关闭直播推送");
Logger.i(TAG, "接收指令强制关闭直播推送");
stopPush();
}
}
@@ -81,6 +81,12 @@ public class PushService extends Service
return null;
}
@Override
public void onDestroy() {
super.onDestroy();
mLivePusher.removeLiveRoomStatusListener(this);
}
/**
* 启动发布直播视频流
*/
@@ -117,7 +123,7 @@ public class PushService extends Service
// 停止发布
mLivePusher.stopPublish();
// 退出房间
mLivePusher.loginRoom();
mLivePusher.logoutCurrentRoom();
}
// 移除视频回碉监听
CameraFrameManager.getInstance().rmYuvDataCallback(this);

View File

@@ -2,13 +2,6 @@ package com.mogo.cloud.trafficlive.api;
public interface ITrafficLiveCallBack {
default void onLiveStart() {
}
default void onLiveStop() {
}
default void onLiveConnecting() {

View File

@@ -7,7 +7,6 @@ import android.view.SurfaceView;
import com.mogo.cloud.live.listener.ILiveMultiRoomStatusListener;
import com.mogo.cloud.live.listener.ILiveProgressListener;
import com.mogo.cloud.live.listener.ILiveCurrentRoomStatusListener;
import com.mogo.cloud.live.listener.IRequestLiveListener;
import com.mogo.cloud.live.manager.MoGoLiveManager;
import com.mogo.cloud.live.manager.MoGoLivePushConfig;
@@ -120,16 +119,12 @@ public class TrafficLiveCurrentManager
@Override
public void onEngineStart() {
if (trafficLiveCallBack != null) {
trafficLiveCallBack.onLiveStart();
}
}
@Override
public void onEngineStop() {
if (trafficLiveCallBack != null) {
trafficLiveCallBack.onLiveStop();
}
}
@Override
@@ -141,7 +136,6 @@ public class TrafficLiveCurrentManager
}
@Override
public void onMultiRoomConnecting() {
if (trafficLiveCallBack != null) {