拆分了房间状态调用函数,以及退出房间没有销毁handle导致崩溃问题。
This commit is contained in:
1
.idea/gradle.xml
generated
1
.idea/gradle.xml
generated
@@ -26,7 +26,6 @@
|
||||
</set>
|
||||
</option>
|
||||
<option name="resolveModulePerSourceSet" value="false" />
|
||||
<option name="useQualifiedModuleNames" value="true" />
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
|
||||
@@ -116,6 +116,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:textOff="登录第二个房间"
|
||||
android:textOn="退出第二个房间"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintLeft_toLeftOf="@+id/etLookRoomId" />
|
||||
|
||||
|
||||
@@ -17,23 +17,6 @@ public interface ILiveProgressListener {
|
||||
default void onEngineStop() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 正在连接
|
||||
*/
|
||||
void onConnecting();
|
||||
|
||||
/**
|
||||
* 连接成功
|
||||
*
|
||||
* @param roomId 房间ID
|
||||
*/
|
||||
void onConnected(String roomId);
|
||||
|
||||
/**
|
||||
* 断开连接
|
||||
*/
|
||||
void onDisConnect();
|
||||
|
||||
/**
|
||||
* 调试错误信息回调
|
||||
*
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.mogo.cloud.live.listener;
|
||||
|
||||
/**
|
||||
* 直播房间的状态回调
|
||||
*/
|
||||
public interface ILiveRoomStatusListener {
|
||||
|
||||
/**
|
||||
* 自己的房间连接中回调
|
||||
*/
|
||||
void onCurrentRoomConnecting();
|
||||
|
||||
/**
|
||||
* 自己的房间连接成功回调
|
||||
*/
|
||||
void onCurrentRoomConnected();
|
||||
|
||||
/**
|
||||
* 自己的房间断开连接回调
|
||||
*/
|
||||
void onCurrentRoomDisconnected();
|
||||
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* 与他人房间连接中回调
|
||||
*/
|
||||
void onMultiRoomConnecting();
|
||||
|
||||
/**
|
||||
* 与他人房间连接成功回调
|
||||
*/
|
||||
void onMultiRoomConnected();
|
||||
|
||||
/**
|
||||
* 与他人房间断开连接回调
|
||||
*/
|
||||
void onMultiRoomDisconnected();
|
||||
|
||||
}
|
||||
@@ -145,6 +145,8 @@ public class LiveStreamManagerImpl implements ILiveStreamManager {
|
||||
@Override
|
||||
public void release() {
|
||||
try {
|
||||
mHandler.removeCallbacks(mCamStatusRun);
|
||||
mHandler = null;
|
||||
mSocketMsgUtils.release();
|
||||
sCam1LiveStatus = 0;
|
||||
sCam2LiveStatus = 0;
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.view.SurfaceView;
|
||||
|
||||
import com.mogo.cloud.live.listener.ILiveProgressListener;
|
||||
import com.mogo.cloud.live.listener.ILiveRoomPersonListener;
|
||||
import com.mogo.cloud.live.listener.ILiveRoomStatusListener;
|
||||
import com.mogo.cloud.live.listener.ILiveStatusListener;
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClientConfig;
|
||||
import com.mogo.cloud.utils.logger.Logger;
|
||||
@@ -92,9 +93,13 @@ public class MoGoLiveManager {
|
||||
*/
|
||||
private ILiveProgressListener mProgressListener;
|
||||
/**
|
||||
* 直播房间状态
|
||||
* 直播房间连接状态
|
||||
*/
|
||||
private ILiveRoomPersonListener mRoomStatusListener;
|
||||
private ILiveRoomStatusListener mRoomStatusListener;
|
||||
/**
|
||||
* 直播房间人员状态
|
||||
*/
|
||||
private ILiveRoomPersonListener mRoomPersonListener;
|
||||
/**
|
||||
* 直播状态回调
|
||||
*/
|
||||
@@ -229,19 +234,35 @@ public class MoGoLiveManager {
|
||||
@Override
|
||||
public void onRoomStateUpdate(String roomID, ZegoRoomState state, int errorCode, JSONObject extendedData) {
|
||||
super.onRoomStateUpdate(roomID, state, errorCode, extendedData);
|
||||
// 这里只处理当前设备登录的房间中的用户总数
|
||||
// 这里回调的是当前用户的房间状态
|
||||
if (currentRoomId.equals(roomID)) {
|
||||
Logger.i(TAG, "onRoomStateUpdate roomID : " + roomID +
|
||||
" state:" + state +
|
||||
" errorCode:" + errorCode);
|
||||
//房间状态更新
|
||||
if (mProgressListener != null) {
|
||||
if (mRoomStatusListener != null) {
|
||||
if (state == ZegoRoomState.CONNECTING) {
|
||||
mProgressListener.onConnecting();
|
||||
mRoomStatusListener.onCurrentRoomConnecting();
|
||||
} else if (state == ZegoRoomState.CONNECTED) {
|
||||
mProgressListener.onConnected(roomID);
|
||||
mRoomStatusListener.onCurrentRoomConnected();
|
||||
} else {
|
||||
mProgressListener.onDisConnect();
|
||||
mRoomStatusListener.onCurrentRoomDisconnected();
|
||||
}
|
||||
}
|
||||
}
|
||||
// 这里回调的是登录的他人房间的状态
|
||||
if (multiRoomId.equals(roomID)) {
|
||||
Logger.i(TAG, "onRoomStateUpdate multiRoomId : " + roomID +
|
||||
" state:" + state +
|
||||
" errorCode:" + errorCode);
|
||||
//房间状态更新
|
||||
if (mRoomStatusListener != null) {
|
||||
if (state == ZegoRoomState.CONNECTING) {
|
||||
mRoomStatusListener.onMultiRoomConnecting();
|
||||
} else if (state == ZegoRoomState.CONNECTED) {
|
||||
mRoomStatusListener.onMultiRoomConnected();
|
||||
} else {
|
||||
mRoomStatusListener.onMultiRoomDisconnected();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -256,8 +277,8 @@ public class MoGoLiveManager {
|
||||
onlineNumber = count;
|
||||
Logger.i(TAG, "onRoomOnlineUserCountUpdate roomID : " + roomID +
|
||||
" , online user number : " + onlineNumber);
|
||||
if (mRoomStatusListener != null) {
|
||||
mRoomStatusListener.onRoomOnlineUserCountUpdate(count);
|
||||
if (mRoomPersonListener != null) {
|
||||
mRoomPersonListener.onRoomOnlineUserCountUpdate(count);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -271,8 +292,8 @@ public class MoGoLiveManager {
|
||||
Logger.i(TAG, "onRoomUserUpdate roomId : " + roomID +
|
||||
" , updateType : " + updateType.name() +
|
||||
" , online user number : " + onlineNumber);
|
||||
if (mRoomStatusListener != null) {
|
||||
mRoomStatusListener.onRoomUserUpdate(updateType, userList);
|
||||
if (mRoomPersonListener != null) {
|
||||
mRoomPersonListener.onRoomUserUpdate(updateType, userList);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -330,13 +351,22 @@ public class MoGoLiveManager {
|
||||
this.mProgressListener = liveProgressListener;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置直播间连接状态监听
|
||||
*
|
||||
* @param roomStatusListener 监听回调用
|
||||
*/
|
||||
public void setLiveRoomPersonListener(ILiveRoomStatusListener roomStatusListener) {
|
||||
this.mRoomStatusListener = roomStatusListener;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置直播间的人员监听
|
||||
*
|
||||
* @param roomPersonListener 监听回调用
|
||||
*/
|
||||
public void setLiveRoomPersonListener(ILiveRoomPersonListener roomPersonListener) {
|
||||
this.mRoomStatusListener = roomPersonListener;
|
||||
this.mRoomPersonListener = roomPersonListener;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -470,6 +500,7 @@ public class MoGoLiveManager {
|
||||
* 退出房间
|
||||
*/
|
||||
public void logoutRoom() {
|
||||
Logger.i(TAG, "logoutRoom: " + currentRoomId);
|
||||
if (mExpressEngine == null) {
|
||||
return;
|
||||
}
|
||||
@@ -490,6 +521,7 @@ public class MoGoLiveManager {
|
||||
* 退出多房间
|
||||
*/
|
||||
public void logoutMultiRoom() {
|
||||
Logger.i(TAG, "logoutMultiRoom: " + multiRoomId);
|
||||
if (mExpressEngine == null) {
|
||||
return;
|
||||
}
|
||||
@@ -502,7 +534,7 @@ public class MoGoLiveManager {
|
||||
* 开始推送
|
||||
*/
|
||||
public void startPush() {
|
||||
Logger.d(TAG, "startPush currentStreamId: " + currentStreamId);
|
||||
Logger.i(TAG, "startPush currentStreamId: " + currentStreamId);
|
||||
mExpressEngine.startPublishingStream(currentStreamId);
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +47,13 @@ public class RequestLiveManager {
|
||||
return requestLiveManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求服务器查看指定车机开启或关闭直播
|
||||
*
|
||||
* @param type
|
||||
* @param liveSn
|
||||
* @param requestLiveListener
|
||||
*/
|
||||
public void requestVehicleHeadLive(String type, String liveSn, IRequestLiveListener requestLiveListener) {
|
||||
Gson gson = new Gson();
|
||||
LivePush livePush = new LivePush(liveSn, type, FRONT_CAMERA);
|
||||
|
||||
@@ -27,7 +27,7 @@ SNAPSHOT_REPOSITORY_URL=http://nexus.zhidaoauto.com/repository/maven-snapshots/
|
||||
USERNAME=xintai
|
||||
PASSWORD=xintai2018
|
||||
# 编译模式: false - 依赖本地版本, true - 依赖 maven 版本
|
||||
RELEASE=true
|
||||
RELEASE=false
|
||||
# AI CLOUD 云平台
|
||||
# 工具类
|
||||
MOGO_UTILS_VERSION=1.0.51
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.text.TextUtils;
|
||||
import android.view.SurfaceView;
|
||||
|
||||
import com.mogo.cloud.live.listener.ILiveProgressListener;
|
||||
import com.mogo.cloud.live.listener.ILiveRoomStatusListener;
|
||||
import com.mogo.cloud.live.listener.IRequestLiveListener;
|
||||
import com.mogo.cloud.live.manager.MoGoLiveManager;
|
||||
import com.mogo.cloud.live.manager.MoGoLivePushConfig;
|
||||
@@ -18,11 +19,11 @@ import static com.mogo.cloud.live.constant.LiveConstant.LIVE_TYPE_CLOSE;
|
||||
import static com.mogo.cloud.live.constant.LiveConstant.LIVE_TYPE_OPEN;
|
||||
import static com.mogo.cloud.trafficlive.constant.TrafficLiveConstant.TAG;
|
||||
|
||||
public class TrafficLiveManager implements ILiveProgressListener {
|
||||
public class TrafficLiveManager implements ILiveProgressListener, ILiveRoomStatusListener {
|
||||
|
||||
private static volatile TrafficLiveManager mInstance;
|
||||
private final RequestLiveManager requestLiveManager;
|
||||
private ITrafficLiveCallBack callBack;
|
||||
private ITrafficLiveCallBack trafficLiveCallBack;
|
||||
private SurfaceView surfaceView;
|
||||
private String mStreamId;
|
||||
private boolean isLoginSuccess = false;
|
||||
@@ -57,7 +58,7 @@ public class TrafficLiveManager implements ILiveProgressListener {
|
||||
throw new Exception("liveSn can not be null");
|
||||
}
|
||||
|
||||
this.callBack = trafficLiveCallBack;
|
||||
this.trafficLiveCallBack = trafficLiveCallBack;
|
||||
this.surfaceView = surfaceView;
|
||||
Logger.i(TAG, "申请拉流 systemClock :" + SystemClock.elapsedRealtime() + " SystemTime : " + System.currentTimeMillis());
|
||||
requestLiveManager.requestVehicleHeadLive(LIVE_TYPE_OPEN, liveSn, new IRequestLiveListener() {
|
||||
@@ -77,15 +78,15 @@ public class TrafficLiveManager implements ILiveProgressListener {
|
||||
|
||||
// 直接 查看对应SN的直播
|
||||
MoGoLiveManager.getInstance().startLive(surfaceView);
|
||||
if (callBack != null) {
|
||||
callBack.onLive();
|
||||
if (TrafficLiveManager.this.trafficLiveCallBack != null) {
|
||||
TrafficLiveManager.this.trafficLiveCallBack.onLive();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
if (callBack != null) {
|
||||
callBack.onError(e.getMessage());
|
||||
if (TrafficLiveManager.this.trafficLiveCallBack != null) {
|
||||
TrafficLiveManager.this.trafficLiveCallBack.onError(e.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -103,14 +104,14 @@ public class TrafficLiveManager implements ILiveProgressListener {
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
if (callBack != null) {
|
||||
callBack.onError(e.getMessage());
|
||||
if (trafficLiveCallBack != null) {
|
||||
trafficLiveCallBack.onError(e.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
MoGoLiveManager.getInstance().stopLive();
|
||||
surfaceView = null;
|
||||
callBack = null;
|
||||
trafficLiveCallBack = null;
|
||||
isLoginSuccess = false;
|
||||
mStreamId = null;
|
||||
}
|
||||
@@ -121,46 +122,61 @@ public class TrafficLiveManager implements ILiveProgressListener {
|
||||
|
||||
@Override
|
||||
public void onEngineStart() {
|
||||
if (callBack != null) {
|
||||
callBack.onLiveStart();
|
||||
if (trafficLiveCallBack != null) {
|
||||
trafficLiveCallBack.onLiveStart();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEngineStop() {
|
||||
if (callBack != null) {
|
||||
callBack.onLiveStop();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnecting() {
|
||||
if (callBack != null) {
|
||||
callBack.onLiveConnecting();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnected(String roomId) {
|
||||
isLoginSuccess = true;
|
||||
if (callBack != null) {
|
||||
callBack.onLiveConnected();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisConnect() {
|
||||
isLoginSuccess = false;
|
||||
if (callBack != null) {
|
||||
callBack.onDisConnect();
|
||||
if (trafficLiveCallBack != null) {
|
||||
trafficLiveCallBack.onLiveStop();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDebugError(int errorCode, String funcName, String errorInfo) {
|
||||
Logger.e(TAG, "onDebugError errorCode : " + errorCode + " funcName : " + funcName + " errorInfo : " + errorInfo);
|
||||
if (callBack != null) {
|
||||
callBack.onError(errorInfo);
|
||||
if (trafficLiveCallBack != null) {
|
||||
trafficLiveCallBack.onError(errorInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCurrentRoomConnecting() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCurrentRoomConnected() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCurrentRoomDisconnected() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMultiRoomConnecting() {
|
||||
if (trafficLiveCallBack != null) {
|
||||
trafficLiveCallBack.onLiveConnecting();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMultiRoomConnected() {
|
||||
isLoginSuccess = true;
|
||||
if (trafficLiveCallBack != null) {
|
||||
trafficLiveCallBack.onLiveConnected();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMultiRoomDisconnected() {
|
||||
isLoginSuccess = false;
|
||||
if (trafficLiveCallBack != null) {
|
||||
trafficLiveCallBack.onDisConnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user