完成了人数的判断
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>
|
||||
|
||||
@@ -34,11 +34,6 @@ public interface ILiveProgressListener {
|
||||
*/
|
||||
void onDisConnect();
|
||||
|
||||
/**
|
||||
* 房间在线人数变化
|
||||
*/
|
||||
void onRoomOnlineUserCountUpdate(int count);
|
||||
|
||||
/**
|
||||
* 调试错误信息回调
|
||||
*
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.mogo.cloud.live.listener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import im.zego.zegoexpress.constants.ZegoUpdateType;
|
||||
import im.zego.zegoexpress.entity.ZegoUser;
|
||||
|
||||
/**
|
||||
* 直播房间状态回调
|
||||
*/
|
||||
public interface ILiveRoomPersonListener {
|
||||
|
||||
/**
|
||||
* 房间在线人数变化
|
||||
*
|
||||
* @param count 剩余人数
|
||||
*/
|
||||
void onRoomOnlineUserCountUpdate(int count);
|
||||
|
||||
/**
|
||||
* 房间内其他用户增加或减少的通知回调
|
||||
*
|
||||
* @param updateType 类型
|
||||
* @param userList 当前房间内变更的用户列表
|
||||
*/
|
||||
void onRoomUserUpdate(ZegoUpdateType updateType, ArrayList<ZegoUser> userList);
|
||||
|
||||
}
|
||||
@@ -33,6 +33,7 @@ public class LiveStreamManagerImpl implements ILiveStreamManager {
|
||||
private static volatile int sCam1AvailableStatus = 0, sCam2AvailableStatus = 0;
|
||||
private static final int PUSH_START = 0; // 开始
|
||||
private static final int PUSH_STOP = 1; // 结束
|
||||
private static final int PUSH_FORCED_STOP = 2; // 强制结束直播,不考虑是否有观众
|
||||
private static final String C1 = "C_1"; //前置摄像头
|
||||
private static final String C2 = "C_2"; //后置摄像头
|
||||
private Handler mHandler; // 循环上报摄像头状态
|
||||
@@ -153,13 +154,20 @@ public class LiveStreamManagerImpl implements ILiveStreamManager {
|
||||
if (C1.equals(videoChannel)) {
|
||||
// 停止直播
|
||||
if (status == PUSH_STOP) {
|
||||
PushService.startService(mContext, PushService.ACTION_STOP_RTMP_PUSH, LiveStreamManagerImpl.mDevicesId);
|
||||
PushService.startService(mContext, PushService.ACTION_STOP_RTMP_PUSH,
|
||||
LiveStreamManagerImpl.mDevicesId);
|
||||
// 释放资源
|
||||
CameraFrameManager.getInstance().release();
|
||||
}
|
||||
// 开始直播
|
||||
else if (status == PUSH_START) {
|
||||
PushService.startService(mContext, PushService.ACTION_START_RTMP_PUSH, LiveStreamManagerImpl.mDevicesId);
|
||||
PushService.startService(mContext, PushService.ACTION_START_RTMP_PUSH,
|
||||
LiveStreamManagerImpl.mDevicesId);
|
||||
}
|
||||
// 强制关闭直播
|
||||
else if (status == PUSH_FORCED_STOP) {
|
||||
PushService.startService(mContext, PushService.ACTION_FORCED_STOP_RTMP_PUSH,
|
||||
LiveStreamManagerImpl.mDevicesId);
|
||||
}
|
||||
sCam1LiveStatus = status;
|
||||
} else {
|
||||
|
||||
@@ -3,9 +3,11 @@ package com.mogo.cloud.live.manager;
|
||||
import android.app.Application;
|
||||
import android.os.Environment;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.SurfaceView;
|
||||
|
||||
import com.mogo.cloud.live.listener.ILiveProgressListener;
|
||||
import com.mogo.cloud.live.listener.ILiveRoomPersonListener;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
import org.json.JSONObject;
|
||||
@@ -82,7 +84,11 @@ public class MoGoLiveManager {
|
||||
/**
|
||||
* 直播进度回调用
|
||||
*/
|
||||
private ILiveProgressListener listener;
|
||||
private ILiveProgressListener mProgressListener;
|
||||
/**
|
||||
* 直播房间状态
|
||||
*/
|
||||
private ILiveRoomPersonListener mRoomStatusListener;
|
||||
/**
|
||||
* 当前的房间ID
|
||||
*/
|
||||
@@ -142,6 +148,10 @@ public class MoGoLiveManager {
|
||||
return isCaptureStatus;
|
||||
}
|
||||
|
||||
public int getOnlineNumber() {
|
||||
return onlineNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化直播SDK
|
||||
*
|
||||
@@ -173,8 +183,8 @@ public class MoGoLiveManager {
|
||||
public void onDebugError(int errorCode, String funcName, String info) {
|
||||
super.onDebugError(errorCode, funcName, info);
|
||||
Logger.i(TAG, "onDebugError errorCode : " + errorCode);
|
||||
if (listener != null) {
|
||||
listener.onDebugError(errorCode, funcName, info);
|
||||
if (mProgressListener != null) {
|
||||
mProgressListener.onDebugError(errorCode, funcName, info);
|
||||
}
|
||||
// 停止推送数据
|
||||
stopPublishingStream();
|
||||
@@ -185,11 +195,11 @@ public class MoGoLiveManager {
|
||||
public void onEngineStateUpdate(ZegoEngineState state) {
|
||||
super.onEngineStateUpdate(state);
|
||||
Logger.i(TAG, "onEngineStateUpdate state : " + state.name());
|
||||
if (listener != null) {
|
||||
if (mProgressListener != null) {
|
||||
if (state == ZegoEngineState.START) {
|
||||
listener.onEngineStart();
|
||||
mProgressListener.onEngineStart();
|
||||
} else {
|
||||
listener.onEngineStop();
|
||||
mProgressListener.onEngineStop();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -200,13 +210,13 @@ public class MoGoLiveManager {
|
||||
super.onRoomStateUpdate(roomID, state, errorCode, extendedData);
|
||||
Logger.i(TAG, "onRoomStateUpdate roomID : " + roomID + " state:" + state + " errorCode:" + errorCode);
|
||||
//房间状态更新
|
||||
if (listener != null) {
|
||||
if (mProgressListener != null) {
|
||||
if (state == ZegoRoomState.CONNECTING) {
|
||||
listener.onConnecting();
|
||||
mProgressListener.onConnecting();
|
||||
} else if (state == ZegoRoomState.CONNECTED) {
|
||||
listener.onConnected(roomID);
|
||||
mProgressListener.onConnected(roomID);
|
||||
} else {
|
||||
listener.onDisConnect();
|
||||
mProgressListener.onDisConnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -217,8 +227,8 @@ public class MoGoLiveManager {
|
||||
super.onRoomOnlineUserCountUpdate(roomID, count);
|
||||
Logger.i(TAG, "onRoomOnlineUserCountUpdate roomID : " + roomID + " , count : " + count);
|
||||
onlineNumber = count;
|
||||
if (listener != null) {
|
||||
listener.onRoomOnlineUserCountUpdate(count);
|
||||
if (mRoomStatusListener != null) {
|
||||
mRoomStatusListener.onRoomOnlineUserCountUpdate(count);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,8 +236,11 @@ public class MoGoLiveManager {
|
||||
@Override
|
||||
public void onRoomUserUpdate(String roomID, ZegoUpdateType updateType, ArrayList<ZegoUser> userList) {
|
||||
super.onRoomUserUpdate(roomID, updateType, userList);
|
||||
//用户状态更新
|
||||
Logger.i(TAG, "onRoomUserUpdate roomId : " + roomID + " , updateType : " + updateType.name());
|
||||
onlineNumber = userList.size();
|
||||
if (mRoomStatusListener != null) {
|
||||
mRoomStatusListener.onRoomUserUpdate(updateType, userList);
|
||||
}
|
||||
}
|
||||
|
||||
// 推流状态回调
|
||||
@@ -256,7 +269,16 @@ public class MoGoLiveManager {
|
||||
* @param liveProgressListener 监听回调用
|
||||
*/
|
||||
public void setLiveProgressListener(ILiveProgressListener liveProgressListener) {
|
||||
this.listener = liveProgressListener;
|
||||
this.mProgressListener = liveProgressListener;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置直播间的人员监听
|
||||
*
|
||||
* @param roomPersonListener 监听回调用
|
||||
*/
|
||||
public void setLiveRoomPersonListener(ILiveRoomPersonListener roomPersonListener) {
|
||||
this.mRoomStatusListener = roomPersonListener;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -315,8 +337,8 @@ public class MoGoLiveManager {
|
||||
super.onStart(channel);
|
||||
Logger.i(TAG, "setCustomVideoCaptureHandler onStart");
|
||||
isCaptureStatus = true;
|
||||
if (listener != null) {
|
||||
listener.onEngineStart();
|
||||
if (mProgressListener != null) {
|
||||
mProgressListener.onEngineStart();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -325,8 +347,8 @@ public class MoGoLiveManager {
|
||||
super.onStop(channel);
|
||||
Logger.i(TAG, "setCustomVideoCaptureHandler onStop");
|
||||
isCaptureStatus = false;
|
||||
if (listener != null) {
|
||||
listener.onEngineStop();
|
||||
if (mProgressListener != null) {
|
||||
mProgressListener.onEngineStop();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -8,17 +8,25 @@ import android.os.IBinder;
|
||||
import android.os.SystemClock;
|
||||
import android.util.Log;
|
||||
|
||||
import com.mogo.cloud.live.listener.ILiveRoomPersonListener;
|
||||
import com.mogo.cloud.live.listener.IYUVDataListener;
|
||||
import com.mogo.cloud.live.manager.CameraFrameManager;
|
||||
import com.mogo.cloud.live.manager.MoGoLivePushConfig;
|
||||
import com.mogo.cloud.live.manager.MoGoLiveManager;
|
||||
import com.mogo.cloud.live.manager.MoGoLivePushConfig;
|
||||
import com.mogo.cloud.live.utils.ByteUtils;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import im.zego.zegoexpress.constants.ZegoUpdateType;
|
||||
import im.zego.zegoexpress.entity.ZegoUser;
|
||||
|
||||
|
||||
public class PushService extends Service
|
||||
implements IYUVDataListener {
|
||||
public static final String ACTION_START_RTMP_PUSH = "action_start_rtmp_push";
|
||||
public static final String ACTION_STOP_RTMP_PUSH = "action_stop_rtmp_push";
|
||||
public static final String ACTION_FORCED_STOP_RTMP_PUSH = "action_forced_stop_rtmp_push";
|
||||
|
||||
private static final String TAG = "PushService";
|
||||
|
||||
@@ -65,13 +73,13 @@ public class PushService extends Service
|
||||
mLivePushConfig.setAudioFormat(AudioFormat.ENCODING_PCM_16BIT);
|
||||
mLivePushConfig.setMute(true);
|
||||
|
||||
mLivePusher = MoGoLiveManager.getInstance();
|
||||
mLivePusher.init(getApplication(), mLivePushConfig);
|
||||
initZeGoLivePusher();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
if (intent != null) {
|
||||
// 开启直播
|
||||
if (ACTION_START_RTMP_PUSH.equals(intent.getAction())) {
|
||||
try {
|
||||
String devicesId = intent.getStringExtra(DEVICES_ID);
|
||||
@@ -79,7 +87,17 @@ public class PushService extends Service
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else if (ACTION_STOP_RTMP_PUSH.equals(intent.getAction())) {
|
||||
}
|
||||
// 关闭直播,如果还有人观看不关闭
|
||||
else if (ACTION_STOP_RTMP_PUSH.equals(intent.getAction())) {
|
||||
if (mLivePusher.getOnlineNumber() <= 1) {
|
||||
stopPush();
|
||||
} else {
|
||||
Logger.i(TAG, "房间还有 " + mLivePusher.getOnlineNumber() + " 位观众,不可以关闭直播");
|
||||
}
|
||||
}
|
||||
// 强制关闭直播
|
||||
else if (ACTION_FORCED_STOP_RTMP_PUSH.equals(intent.getAction())) {
|
||||
stopPush();
|
||||
}
|
||||
}
|
||||
@@ -104,10 +122,7 @@ public class PushService extends Service
|
||||
return;
|
||||
}
|
||||
mDevicesId = devicesId;
|
||||
if (mLivePusher == null) {
|
||||
mLivePusher = MoGoLiveManager.getInstance();
|
||||
mLivePusher.init(getApplication(), mLivePushConfig);
|
||||
}
|
||||
initZeGoLivePusher();
|
||||
// 登录房间
|
||||
mLivePusher.loginRoom(mDevicesId, mDevicesId);
|
||||
// 开始发布
|
||||
@@ -117,6 +132,32 @@ public class PushService extends Service
|
||||
Log.d(TAG, "startPush :mRoomId=" + mDevicesId + " mDevicesId=" + mDevicesId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化ZeGo直播推流
|
||||
*/
|
||||
private void initZeGoLivePusher() {
|
||||
if (mLivePusher == null) {
|
||||
mLivePusher = MoGoLiveManager.getInstance();
|
||||
mLivePusher.init(getApplication(), mLivePushConfig);
|
||||
// mLivePusher.setLiveRoomPersonListener(new ILiveRoomPersonListener() {
|
||||
// @Override
|
||||
// public void onRoomOnlineUserCountUpdate(int count) {
|
||||
// Logger.i(TAG, "房间还有 " + count + " 位观众,不可以关闭直播");
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onRoomUserUpdate(ZegoUpdateType updateType, ArrayList<ZegoUser> userList) {
|
||||
// if (userList.size() <= 1) {
|
||||
// Logger.i(TAG, "房间没有观众了,主动关闭直播");
|
||||
// stopPush();
|
||||
// } else {
|
||||
// Logger.i(TAG, "房间还有 " + mLivePusher.getOnlineNumber() + " 位观众,不可以关闭直播");
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 结束发布直播视频流
|
||||
*/
|
||||
|
||||
@@ -134,11 +134,6 @@ public class TrafficLiveManager implements ILiveProgressListener {
|
||||
callBack.onDisConnect();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRoomOnlineUserCountUpdate(int count) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDebugError(int errorCode, String funcName, String errorInfo) {
|
||||
Logger.e(TAG, "onDebugError errorCode : " + errorCode + " funcName : " + funcName + " errorInfo : " + errorInfo);
|
||||
|
||||
Reference in New Issue
Block a user