完成了多房间查看的逻辑重构
在停止直播后会退出当前房间
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>
|
||||
|
||||
@@ -50,7 +50,6 @@ public class LivePlayActivity extends AppCompatActivity implements ITrafficLiveC
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
MoGoAiCloudTrafficLive.stopLive(liveSn);
|
||||
MoGoAiCloudTrafficLive.destroyLive();
|
||||
WifiStateManager.getInstance().unRegisterWifiStateListener(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -118,7 +118,6 @@ public class LivePlayAndPushActivity extends BaseLiveActivity
|
||||
}
|
||||
|
||||
MoGoAiCloudTrafficLive.stopLive(liveSn);
|
||||
MoGoAiCloudTrafficLive.destroyLive();
|
||||
// WifiStateManager.getInstance().unRegisterWifiStateListener(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ public class MoGoApplication extends MultiDexApplication {
|
||||
// 设置车机设备的唯一标识(这些表识必须是通过后台录入的设备)
|
||||
clientConfig.setThirdPartyDeviceId(Devices.getSn());
|
||||
// 设置应用服务AppId 长链、鉴权 //todo 需要卸载智慧驾驶、行车记录仪
|
||||
clientConfig.setServiceAppId("com.mogo.launcher");
|
||||
clientConfig.setServiceAppId("com.zhidao.carcorder");
|
||||
// 设置循环检测间隔时间
|
||||
clientConfig.setLoopCheckDelay(15 * 1000);
|
||||
// 设置是否属于高精定位设备
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.mogo.cloud.live.listener;
|
||||
|
||||
/**
|
||||
* 直播房间的状态回调
|
||||
*/
|
||||
public interface ILiveCurrentRoomStatusListener {
|
||||
|
||||
/**
|
||||
* 自己的房间连接中回调
|
||||
*/
|
||||
void onCurrentRoomConnecting();
|
||||
|
||||
/**
|
||||
* 自己的房间连接成功回调
|
||||
*/
|
||||
void onCurrentRoomConnected();
|
||||
|
||||
/**
|
||||
* 自己的房间断开连接回调
|
||||
*/
|
||||
void onCurrentRoomDisconnected();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.mogo.cloud.live.listener;
|
||||
|
||||
/**
|
||||
* 直播第二个房间的状态回调
|
||||
*/
|
||||
public interface ILiveMultiRoomStatusListener {
|
||||
|
||||
/**
|
||||
* 与他人房间连接中回调
|
||||
*/
|
||||
void onMultiRoomConnecting();
|
||||
|
||||
/**
|
||||
* 与他人房间连接成功回调
|
||||
*/
|
||||
void onMultiRoomConnected();
|
||||
|
||||
/**
|
||||
* 与他人房间断开连接回调
|
||||
*/
|
||||
void onMultiRoomDisconnected();
|
||||
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package com.mogo.cloud.live.listener;
|
||||
|
||||
/**
|
||||
* 直播房间的状态回调
|
||||
*/
|
||||
public interface ILiveRoomStatusListener {
|
||||
|
||||
/**
|
||||
* 自己的房间连接中回调
|
||||
*/
|
||||
void onCurrentRoomConnecting();
|
||||
|
||||
/**
|
||||
* 自己的房间连接成功回调
|
||||
*/
|
||||
void onCurrentRoomConnected();
|
||||
|
||||
/**
|
||||
* 自己的房间断开连接回调
|
||||
*/
|
||||
void onCurrentRoomDisconnected();
|
||||
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* 与他人房间连接中回调
|
||||
*/
|
||||
void onMultiRoomConnecting();
|
||||
|
||||
/**
|
||||
* 与他人房间连接成功回调
|
||||
*/
|
||||
void onMultiRoomConnected();
|
||||
|
||||
/**
|
||||
* 与他人房间断开连接回调
|
||||
*/
|
||||
void onMultiRoomDisconnected();
|
||||
|
||||
}
|
||||
@@ -28,7 +28,7 @@ public class LiveStreamManagerImpl implements ILiveStreamManager {
|
||||
private final Application mApplication;
|
||||
|
||||
// 循环上报摄像头可直播状态间隔时间
|
||||
private static final int PUSH_CAM_TIME = 40 * 1000;
|
||||
private static final int PUSH_CAM_TIME = 60 * 1000;
|
||||
private static volatile int sCam1LiveStatus = 0, sCam2LiveStatus = 0;
|
||||
private static volatile int sCam1AvailableStatus = 0, sCam2AvailableStatus = 0;
|
||||
private static final int PUSH_START = 0; // 开始
|
||||
@@ -39,8 +39,7 @@ public class LiveStreamManagerImpl implements ILiveStreamManager {
|
||||
private Handler mHandler; // 循环上报摄像头状态
|
||||
private SocketMsgUtils mSocketMsgUtils; // Socket 长链接
|
||||
private MoGoLiveManager mLivePusher; // 自研直播SDK
|
||||
private static final int WIDTH = 1280;
|
||||
private static final int HEIGHT = 720;
|
||||
private MoGoLivePushConfig mLivePushConfig;
|
||||
|
||||
|
||||
public static LiveStreamManagerImpl getInstance(Application application, String devicesId) {
|
||||
@@ -51,6 +50,7 @@ public class LiveStreamManagerImpl implements ILiveStreamManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
@@ -58,22 +58,8 @@ public class LiveStreamManagerImpl implements ILiveStreamManager {
|
||||
private LiveStreamManagerImpl(Application application, String devicesId) {
|
||||
mApplication = application;
|
||||
mHandler = new Handler();
|
||||
|
||||
// 初始化配置文件
|
||||
// 直播参数
|
||||
MoGoLivePushConfig mLivePushConfig = MoGoLivePushConfig.getInstance();
|
||||
mLivePushConfig.setWidth(WIDTH);
|
||||
mLivePushConfig.setHeight(HEIGHT);
|
||||
mLivePushConfig.setVideoBitrate(6000);
|
||||
mLivePushConfig.setVideoFPS(30);
|
||||
mLivePushConfig.setAudioChannels(2);
|
||||
mLivePushConfig.setAudioSampleRate(44100);
|
||||
mLivePushConfig.setAudioFormat(AudioFormat.ENCODING_PCM_16BIT);
|
||||
mLivePushConfig.setMute(true);
|
||||
mLivePushConfig.setDevicesId(devicesId);
|
||||
// 初始化直播
|
||||
mLivePusher = MoGoLiveManager.getInstance().init(mApplication, mLivePushConfig);
|
||||
|
||||
// 初始化直播推流
|
||||
initLivePush(devicesId);
|
||||
// 初始化Socket长连接通道
|
||||
mSocketMsgUtils = SocketMsgUtils.getInstance(mApplication,
|
||||
new IMogoCloudSocketOnMessageListener<CommandModel>() {
|
||||
@@ -94,6 +80,27 @@ public class LiveStreamManagerImpl implements ILiveStreamManager {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化直播推流
|
||||
*
|
||||
* @param devicesId 设备ID
|
||||
*/
|
||||
private void initLivePush(String devicesId) {
|
||||
// 初始化配置文件
|
||||
mLivePushConfig = MoGoLivePushConfig.getInstance();
|
||||
mLivePushConfig.setWidth(1280);
|
||||
mLivePushConfig.setHeight(720);
|
||||
mLivePushConfig.setVideoBitrate(6000);
|
||||
mLivePushConfig.setVideoFPS(30);
|
||||
mLivePushConfig.setAudioChannels(2);
|
||||
mLivePushConfig.setAudioSampleRate(44100);
|
||||
mLivePushConfig.setAudioFormat(AudioFormat.ENCODING_PCM_16BIT);
|
||||
mLivePushConfig.setMute(true);
|
||||
mLivePushConfig.setDevicesId(devicesId);
|
||||
// 初始化直播
|
||||
mLivePusher = MoGoLiveManager.getInstance().init(mApplication, mLivePushConfig);
|
||||
}
|
||||
|
||||
public MoGoLiveManager getLivePusher() {
|
||||
return mLivePusher;
|
||||
}
|
||||
@@ -120,7 +127,7 @@ public class LiveStreamManagerImpl implements ILiveStreamManager {
|
||||
|
||||
@Override
|
||||
public void uploadCamStatus(int frontStatus, int backStatus) {
|
||||
Logger.i(TAG, "uploadCamStatus frontStatus is:" + frontStatus + " backStatus is:" + backStatus);
|
||||
Logger.i(TAG, "上传摄像头状态 frontStatus is:" + frontStatus + " backStatus is:" + backStatus);
|
||||
sCam1AvailableStatus = frontStatus;
|
||||
sCam2AvailableStatus = backStatus;
|
||||
MsgBody msgBody = new MsgBody();
|
||||
@@ -174,10 +181,11 @@ public class LiveStreamManagerImpl implements ILiveStreamManager {
|
||||
uploadCamStatus(sCam1AvailableStatus, sCam2AvailableStatus);
|
||||
restartCamStatusLoop();
|
||||
// 判断当前观众的个数,如果没人观看了的情况则停止直播
|
||||
Logger.i(TAG, "直播状态为: " + mLivePusher.isPushing() +
|
||||
" 观众人数:" + mLivePusher.getOnlineNumber());
|
||||
Logger.i(TAG, "直播状态为:" + mLivePusher.getLiveStatusModel().isPushing() +
|
||||
" 观众人数:" + mLivePusher.getLiveStatusModel().getOnlineNumber());
|
||||
|
||||
if (mLivePusher.isPushing() && mLivePusher.getOnlineNumber() <= 1) {
|
||||
if (mLivePusher.getLiveStatusModel().isPushing() &&
|
||||
mLivePusher.getLiveStatusModel().getOnlineNumber() <= 1) {
|
||||
livePushHandler(PUSH_STOP, C1);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -4,10 +4,12 @@ import android.app.Application;
|
||||
import android.text.TextUtils;
|
||||
import android.view.SurfaceView;
|
||||
|
||||
import com.mogo.cloud.live.listener.ILiveCurrentRoomStatusListener;
|
||||
import com.mogo.cloud.live.listener.ILiveMultiRoomStatusListener;
|
||||
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.live.model.LiveStatusModel;
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClientConfig;
|
||||
import com.mogo.cloud.utils.logger.Logger;
|
||||
|
||||
@@ -15,6 +17,7 @@ import org.json.JSONObject;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import im.zego.zegoexpress.ZegoExpressEngine;
|
||||
import im.zego.zegoexpress.callback.IZegoCustomVideoCaptureHandler;
|
||||
@@ -34,9 +37,7 @@ import im.zego.zegoexpress.constants.ZegoVideoFrameFormat;
|
||||
import im.zego.zegoexpress.constants.ZegoViewMode;
|
||||
import im.zego.zegoexpress.entity.ZegoCanvas;
|
||||
import im.zego.zegoexpress.entity.ZegoCustomVideoCaptureConfig;
|
||||
import im.zego.zegoexpress.entity.ZegoEngineConfig;
|
||||
import im.zego.zegoexpress.entity.ZegoRoomConfig;
|
||||
import im.zego.zegoexpress.entity.ZegoRoomExtraInfo;
|
||||
import im.zego.zegoexpress.entity.ZegoUser;
|
||||
import im.zego.zegoexpress.entity.ZegoVideoConfig;
|
||||
import im.zego.zegoexpress.entity.ZegoVideoFrameParam;
|
||||
@@ -91,11 +92,15 @@ public class MoGoLiveManager {
|
||||
/**
|
||||
* 直播进度回调用
|
||||
*/
|
||||
private ILiveProgressListener mProgressListener;
|
||||
private List<ILiveProgressListener> mProgressListener = new ArrayList<>();
|
||||
/**
|
||||
* 直播房间连接状态
|
||||
*/
|
||||
private ILiveRoomStatusListener mRoomStatusListener;
|
||||
private List<ILiveCurrentRoomStatusListener> mRoomStatusListener = new ArrayList<>();
|
||||
/**
|
||||
* 直播第二个房间连接状态
|
||||
*/
|
||||
private List<ILiveMultiRoomStatusListener> mMultiRoomStatusListener = new ArrayList<>();
|
||||
/**
|
||||
* 直播房间人员状态
|
||||
*/
|
||||
@@ -105,41 +110,13 @@ public class MoGoLiveManager {
|
||||
*/
|
||||
private ILiveStatusListener mLiveStatusListener;
|
||||
/**
|
||||
* 当前的房间ID
|
||||
* 直播数据
|
||||
*/
|
||||
private String currentRoomId = "";
|
||||
private LiveStatusModel mLiveStatusModel;
|
||||
/**
|
||||
* 当前的多房间ID
|
||||
* 房间配置
|
||||
*/
|
||||
private String multiRoomId = "";
|
||||
/**
|
||||
* 当前直播流ID
|
||||
*/
|
||||
private String currentStreamId = "";
|
||||
/**
|
||||
* MultiRoom中直播流ID
|
||||
*/
|
||||
private String multiStreamId = "";
|
||||
/**
|
||||
* 自定义采集状态,true-初始化完成,false-没有初始化
|
||||
*/
|
||||
private boolean isCaptureStatus;
|
||||
/**
|
||||
* 推送状态,true-推流中,false-没有推流
|
||||
*/
|
||||
private boolean isPushing;
|
||||
/**
|
||||
* 播放状态,true-播放中,false-没有播放
|
||||
*/
|
||||
private boolean isPlaying;
|
||||
/**
|
||||
* 当前在直播间的人数,只剩下一个人的时候需要停掉直播推送
|
||||
*/
|
||||
private int onlineNumber;
|
||||
/**
|
||||
* 多房间配置
|
||||
*/
|
||||
private ZegoRoomConfig zeGoMultiRoomConfig;
|
||||
private ZegoRoomConfig zeGoRoomConfig;
|
||||
|
||||
private static final class Holder {
|
||||
private static final MoGoLiveManager manager = new MoGoLiveManager();
|
||||
@@ -153,6 +130,12 @@ public class MoGoLiveManager {
|
||||
}
|
||||
|
||||
private MoGoLiveManager() {
|
||||
Logger.i(TAG, "初始化 MoGoLiveManager");
|
||||
mLiveStatusModel = new LiveStatusModel();
|
||||
|
||||
zeGoRoomConfig = new ZegoRoomConfig();
|
||||
zeGoRoomConfig.isUserStatusNotify = true;
|
||||
|
||||
}
|
||||
|
||||
public void setAppId(long appId) {
|
||||
@@ -163,20 +146,8 @@ public class MoGoLiveManager {
|
||||
this.appKey = appKey;
|
||||
}
|
||||
|
||||
public boolean isPlaying() {
|
||||
return isPlaying;
|
||||
}
|
||||
|
||||
public boolean isPushing() {
|
||||
return isPushing;
|
||||
}
|
||||
|
||||
public boolean isCaptureStatus() {
|
||||
return isCaptureStatus;
|
||||
}
|
||||
|
||||
public int getOnlineNumber() {
|
||||
return onlineNumber;
|
||||
public LiveStatusModel getLiveStatusModel() {
|
||||
return mLiveStatusModel;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -188,14 +159,7 @@ public class MoGoLiveManager {
|
||||
public MoGoLiveManager init(Application application, MoGoLivePushConfig livePushConfig) {
|
||||
mApplication = application;
|
||||
mLivePushConfig = livePushConfig;
|
||||
// 通过 advancedConfig 设置 uuid 过滤字段,设置之后 SDK 只会抛出前 12 个字节为开发者所设置 uuid 的 SEI
|
||||
ZegoEngineConfig zegoEngineConfig = new ZegoEngineConfig();
|
||||
// 设置配置到引擎中
|
||||
ZegoExpressEngine.setEngineConfig(zegoEngineConfig);
|
||||
|
||||
// 登录以前用户SN为房间ID的房间
|
||||
loginRoom(mLivePushConfig.getDevicesId(), mLivePushConfig.getDevicesId());
|
||||
|
||||
initExpressEngine();
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -208,24 +172,30 @@ public class MoGoLiveManager {
|
||||
@Override
|
||||
public void onDebugError(int errorCode, String funcName, String info) {
|
||||
super.onDebugError(errorCode, funcName, info);
|
||||
Logger.i(TAG, "onDebugError errorCode : " + errorCode);
|
||||
Logger.i(TAG, "调试错误信息回调 onDebugError errorCode : " + errorCode);
|
||||
if (mProgressListener != null) {
|
||||
mProgressListener.onDebugError(errorCode, funcName, info);
|
||||
for (ILiveProgressListener iLiveProgressListener : mProgressListener) {
|
||||
iLiveProgressListener.onDebugError(errorCode, funcName, info);
|
||||
}
|
||||
}
|
||||
// 停止推送数据
|
||||
stopPublishingStream();
|
||||
stopPublish();
|
||||
}
|
||||
|
||||
// 音视频引擎状态更新回调
|
||||
@Override
|
||||
public void onEngineStateUpdate(ZegoEngineState state) {
|
||||
super.onEngineStateUpdate(state);
|
||||
Logger.i(TAG, "onEngineStateUpdate state : " + state.name());
|
||||
Logger.i(TAG, "音视频引擎状态更新回调 onEngineStateUpdate state : " + state.name());
|
||||
if (mProgressListener != null) {
|
||||
if (state == ZegoEngineState.START) {
|
||||
mProgressListener.onEngineStart();
|
||||
for (ILiveProgressListener iLiveProgressListener : mProgressListener) {
|
||||
iLiveProgressListener.onEngineStart();
|
||||
}
|
||||
} else {
|
||||
mProgressListener.onEngineStop();
|
||||
for (ILiveProgressListener iLiveProgressListener : mProgressListener) {
|
||||
iLiveProgressListener.onEngineStop();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -235,34 +205,48 @@ public class MoGoLiveManager {
|
||||
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 +
|
||||
if (mLiveStatusModel.getCurrentRoomId().equals(roomID)) {
|
||||
Logger.i(TAG, "房间状态变化通知 onRoomStateUpdate currentRoomId : " + roomID +
|
||||
" state:" + state +
|
||||
" errorCode:" + errorCode);
|
||||
|
||||
// 设置当前登录状态
|
||||
mLiveStatusModel.setLoginCurrentRoom(state == ZegoRoomState.CONNECTED);
|
||||
//房间状态更新
|
||||
if (mRoomStatusListener != null) {
|
||||
if (state == ZegoRoomState.CONNECTING) {
|
||||
mRoomStatusListener.onCurrentRoomConnecting();
|
||||
} else if (state == ZegoRoomState.CONNECTED) {
|
||||
mRoomStatusListener.onCurrentRoomConnected();
|
||||
} else {
|
||||
mRoomStatusListener.onCurrentRoomDisconnected();
|
||||
if (state == ZegoRoomState.CONNECTING) {
|
||||
for (ILiveCurrentRoomStatusListener iLiveRoomStatusListener : mRoomStatusListener) {
|
||||
iLiveRoomStatusListener.onCurrentRoomConnecting();
|
||||
}
|
||||
} else if (state == ZegoRoomState.CONNECTED) {
|
||||
for (ILiveCurrentRoomStatusListener iLiveRoomStatusListener : mRoomStatusListener) {
|
||||
iLiveRoomStatusListener.onCurrentRoomConnected();
|
||||
}
|
||||
} else {
|
||||
for (ILiveCurrentRoomStatusListener iLiveRoomStatusListener : mRoomStatusListener) {
|
||||
iLiveRoomStatusListener.onCurrentRoomDisconnected();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// 这里回调的是登录的他人房间的状态
|
||||
if (multiRoomId.equals(roomID)) {
|
||||
Logger.i(TAG, "onRoomStateUpdate multiRoomId : " + roomID +
|
||||
if (mLiveStatusModel.getMultiRoomId().equals(roomID)) {
|
||||
Logger.i(TAG, "这里回调的是登录的他人房间的状态 onRoomStateUpdate multiRoomId : " + roomID +
|
||||
" state:" + state +
|
||||
" errorCode:" + errorCode);
|
||||
// 设置第二个房间登录状态
|
||||
mLiveStatusModel.setLoginMultiRoom(state == ZegoRoomState.CONNECTED);
|
||||
//房间状态更新
|
||||
if (mRoomStatusListener != null) {
|
||||
if (state == ZegoRoomState.CONNECTING) {
|
||||
mRoomStatusListener.onMultiRoomConnecting();
|
||||
} else if (state == ZegoRoomState.CONNECTED) {
|
||||
mRoomStatusListener.onMultiRoomConnected();
|
||||
} else {
|
||||
mRoomStatusListener.onMultiRoomDisconnected();
|
||||
if (state == ZegoRoomState.CONNECTING) {
|
||||
for (ILiveMultiRoomStatusListener iLiveMultiRoomStatusListener : mMultiRoomStatusListener) {
|
||||
iLiveMultiRoomStatusListener.onMultiRoomConnecting();
|
||||
}
|
||||
} else if (state == ZegoRoomState.CONNECTED) {
|
||||
for (ILiveMultiRoomStatusListener iLiveMultiRoomStatusListener : mMultiRoomStatusListener) {
|
||||
iLiveMultiRoomStatusListener.onMultiRoomConnected();
|
||||
}
|
||||
} else {
|
||||
for (ILiveMultiRoomStatusListener iLiveMultiRoomStatusListener : mMultiRoomStatusListener) {
|
||||
iLiveMultiRoomStatusListener.onMultiRoomDisconnected();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -273,10 +257,10 @@ public class MoGoLiveManager {
|
||||
public void onRoomOnlineUserCountUpdate(String roomID, int count) {
|
||||
super.onRoomOnlineUserCountUpdate(roomID, count);
|
||||
// 这里只处理当前设备登录的房间中的用户总数
|
||||
if (currentRoomId.equals(roomID)) {
|
||||
onlineNumber = count;
|
||||
Logger.i(TAG, "onRoomOnlineUserCountUpdate roomID : " + roomID +
|
||||
" , online user number : " + onlineNumber);
|
||||
if (mLiveStatusModel.getCurrentRoomId().equals(roomID)) {
|
||||
Logger.i(TAG, "房间内当前在线用户数量回调 onRoomOnlineUserCountUpdate roomID : " + roomID +
|
||||
" , online user number : " + count);
|
||||
mLiveStatusModel.setOnlineNumber(count);
|
||||
if (mRoomPersonListener != null) {
|
||||
mRoomPersonListener.onRoomOnlineUserCountUpdate(count);
|
||||
}
|
||||
@@ -288,39 +272,37 @@ public class MoGoLiveManager {
|
||||
public void onRoomUserUpdate(String roomID, ZegoUpdateType updateType, ArrayList<ZegoUser> userList) {
|
||||
super.onRoomUserUpdate(roomID, updateType, userList);
|
||||
// 这里只处理当前设备登录的房间中的用户总数
|
||||
if (currentRoomId.equals(roomID)) {
|
||||
Logger.i(TAG, "onRoomUserUpdate roomId : " + roomID +
|
||||
if (mLiveStatusModel.getCurrentRoomId().equals(roomID)) {
|
||||
Logger.i(TAG, "房间内其他用户增加或减少的通知回调 onRoomUserUpdate roomId : " + roomID +
|
||||
" , updateType : " + updateType.name() +
|
||||
" , online user number : " + onlineNumber);
|
||||
" , online user number : " + mLiveStatusModel.getOnlineNumber());
|
||||
if (mRoomPersonListener != null) {
|
||||
mRoomPersonListener.onRoomUserUpdate(updateType, userList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRoomExtraInfoUpdate(String roomID, ArrayList<ZegoRoomExtraInfo> roomExtraInfoList) {
|
||||
super.onRoomExtraInfoUpdate(roomID, roomExtraInfoList);
|
||||
// 这里只处理当前设备登录的房间中的用户总数
|
||||
if (currentRoomId.equals(roomID)) {
|
||||
Logger.i(TAG, "onRoomExtraInfoUpdate roomId : " + roomID +
|
||||
" , roomExtraInfoList : " + roomExtraInfoList.size());
|
||||
}
|
||||
}
|
||||
|
||||
// 推流状态回调
|
||||
@Override
|
||||
public void onPublisherStateUpdate(String streamID, ZegoPublisherState state,
|
||||
int errorCode, JSONObject extendedData) {
|
||||
super.onPublisherStateUpdate(streamID, state, errorCode, extendedData);
|
||||
// 这里只处理当前设备登录的房间中的用户总数
|
||||
if (currentStreamId.equals(streamID)) {
|
||||
Logger.i(TAG, "onPublisherStateUpdate streamID : " + streamID +
|
||||
if (mLiveStatusModel.getCurrentStreamId().equals(streamID)) {
|
||||
// 判断不是非推流状态则为推流
|
||||
mLiveStatusModel.setPushing(state != ZegoPublisherState.NO_PUBLISH);
|
||||
Logger.i(TAG, "推流状态回调 onPublisherStateUpdate streamID : " + streamID +
|
||||
" , isPushing : " + mLiveStatusModel.isPushing() +
|
||||
" , state : " + state.name() +
|
||||
" , errorCode : " + errorCode);
|
||||
isPushing = state == ZegoPublisherState.PUBLISHING;
|
||||
|
||||
// 判断如果处于非播放和非推流状态则进行登出操作,并释放引擎
|
||||
if (!mLiveStatusModel.isPlaying() && !mLiveStatusModel.isPushing()) {
|
||||
logoutCurrentRoom();
|
||||
}
|
||||
|
||||
if (mLiveStatusListener != null) {
|
||||
mLiveStatusListener.onChange(isPushing ? 0 : 1);
|
||||
mLiveStatusListener.onChange(mLiveStatusModel.isPushing() ? 0 : 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -330,25 +312,31 @@ public class MoGoLiveManager {
|
||||
public void onPlayerStateUpdate(String streamID, ZegoPlayerState state, int errorCode, JSONObject extendedData) {
|
||||
super.onPlayerStateUpdate(streamID, state, errorCode, extendedData);
|
||||
// 这里查看的是别的房间
|
||||
if (multiStreamId.equals(streamID)) {
|
||||
Logger.i(TAG, "onPlayerStateUpdate streamId : " + streamID +
|
||||
if (mLiveStatusModel.getMultiStreamId().equals(streamID)) {
|
||||
// 如果不是非播放状态则判定为直播状态
|
||||
mLiveStatusModel.setPlaying(state != ZegoPlayerState.NO_PLAY);
|
||||
Logger.i(TAG, " 拉流状态变更回调 onPlayerStateUpdate streamId : " + streamID +
|
||||
" , isPlaying : " + mLiveStatusModel.isPlaying() +
|
||||
" , state : " + state.name() +
|
||||
" , errorCode : " + errorCode +
|
||||
" , extendData : " + extendedData.toString());
|
||||
isPlaying = state == ZegoPlayerState.PLAYING;
|
||||
|
||||
// 判断如果处于非播放和非推流状态则进行登出操作,并释放引擎
|
||||
if (!mLiveStatusModel.isPlaying() && !mLiveStatusModel.isPushing()) {
|
||||
logoutCurrentRoom();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* 设置直播进度监听
|
||||
*
|
||||
* @param liveProgressListener 监听回调用
|
||||
*/
|
||||
public void setLiveProgressListener(ILiveProgressListener liveProgressListener) {
|
||||
this.mProgressListener = liveProgressListener;
|
||||
public void addLiveProgressListener(ILiveProgressListener liveProgressListener) {
|
||||
this.mProgressListener.add(liveProgressListener);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -356,8 +344,8 @@ public class MoGoLiveManager {
|
||||
*
|
||||
* @param roomStatusListener 监听回调用
|
||||
*/
|
||||
public void setLiveRoomPersonListener(ILiveRoomStatusListener roomStatusListener) {
|
||||
this.mRoomStatusListener = roomStatusListener;
|
||||
public void addLiveRoomStatusListener(ILiveCurrentRoomStatusListener roomStatusListener) {
|
||||
this.mRoomStatusListener.add(roomStatusListener);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -365,7 +353,7 @@ public class MoGoLiveManager {
|
||||
*
|
||||
* @param roomPersonListener 监听回调用
|
||||
*/
|
||||
public void setLiveRoomPersonListener(ILiveRoomPersonListener roomPersonListener) {
|
||||
public void addLiveRoomPersonListener(ILiveRoomPersonListener roomPersonListener) {
|
||||
this.mRoomPersonListener = roomPersonListener;
|
||||
}
|
||||
|
||||
@@ -378,42 +366,10 @@ public class MoGoLiveManager {
|
||||
this.mLiveStatusListener = mLiveStatusListener;
|
||||
}
|
||||
|
||||
/**
|
||||
* 进入房间
|
||||
*
|
||||
* @param userId 当前用户ID
|
||||
* @param roomId 要进入的房间ID
|
||||
*/
|
||||
public void loginRoom(String userId, String roomId) {
|
||||
initCustomVideoCapture();
|
||||
currentRoomId = ROOM_ID_PREFIX + roomId;
|
||||
currentStreamId = STREAM_ID_PREFIX + roomId;
|
||||
ZegoUser zegoUser = new ZegoUser(userId, NAME_PREFIX + userId);
|
||||
ZegoRoomConfig zegoRoomConfig = new ZegoRoomConfig();
|
||||
zegoRoomConfig.isUserStatusNotify = true;
|
||||
mExpressEngine.loginRoom(currentRoomId, zegoUser, zegoRoomConfig);
|
||||
Logger.i(TAG, "loginRoom userId:" + userId + " currentRoomId : " + currentRoomId
|
||||
+ " currentStreamId:" + currentStreamId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 进入多房间
|
||||
*
|
||||
* @param otherRoomId 房间ID
|
||||
*/
|
||||
public void loginMultiRoom(String otherRoomId) {
|
||||
multiRoomId = ROOM_ID_PREFIX + otherRoomId;
|
||||
multiStreamId = STREAM_ID_PREFIX + otherRoomId;
|
||||
zeGoMultiRoomConfig = new ZegoRoomConfig();
|
||||
zeGoMultiRoomConfig.isUserStatusNotify = true;
|
||||
mExpressEngine.loginMultiRoom(multiRoomId, zeGoMultiRoomConfig);
|
||||
Logger.i(TAG, "loginMultiRoom currentMultiRoomId : " + multiRoomId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化自定义采集
|
||||
*/
|
||||
private void initCustomVideoCapture() {
|
||||
private void initExpressEngine() {
|
||||
Logger.i(TAG, "initCustomVideoCapture 初始化引擎");
|
||||
|
||||
// 创建 enging 对象, appID, appSign 为开发者在 ZEGO 管理控制台申请的凭证信息,
|
||||
@@ -437,39 +393,10 @@ public class MoGoLiveManager {
|
||||
mEventHandler);
|
||||
// 关闭日志
|
||||
mExpressEngine.setDebugVerbose(MoGoAiCloudClientConfig.getInstance().isShowDebugLog(), ZegoLanguage.CHINESE);
|
||||
// true 表示静音(关闭)
|
||||
mExpressEngine.muteMicrophone(true);
|
||||
if (mLivePushConfig != null) {
|
||||
// 创建自定义视频采集对象
|
||||
customVideoCaptureConfig = new ZegoCustomVideoCaptureConfig();
|
||||
// 设置自定义视频采集视频帧数据类型
|
||||
customVideoCaptureConfig.bufferType = ZegoVideoBufferType.RAW_DATA;
|
||||
// true 表示静音(关闭)
|
||||
mExpressEngine.muteMicrophone(true);
|
||||
// 开始或停止自定义视频采集,支持设置其他通道的推流
|
||||
mExpressEngine.enableCustomVideoCapture(true, customVideoCaptureConfig, ZegoPublishChannel.MAIN);
|
||||
// 设置自定义视频采集回调
|
||||
mExpressEngine.setCustomVideoCaptureHandler(new IZegoCustomVideoCaptureHandler() {
|
||||
@Override
|
||||
public void onStart(ZegoPublishChannel channel) {
|
||||
super.onStart(channel);
|
||||
Logger.i(TAG, "setCustomVideoCaptureHandler onStart");
|
||||
isCaptureStatus = true;
|
||||
if (mProgressListener != null) {
|
||||
mProgressListener.onEngineStart();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop(ZegoPublishChannel channel) {
|
||||
super.onStop(channel);
|
||||
Logger.i(TAG, "setCustomVideoCaptureHandler onStop");
|
||||
isCaptureStatus = false;
|
||||
if (mProgressListener != null) {
|
||||
mProgressListener.onEngineStop();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 视频配追
|
||||
// 视频配置
|
||||
ZegoVideoConfig zegoVideoConfig = new ZegoVideoConfig(ZegoVideoConfigPreset.PRESET_720P);
|
||||
// 采集分辨率,控制摄像头图像采集的分辨率。SDK 要求将宽和高设置为偶数。
|
||||
zegoVideoConfig.setCaptureResolution(mLivePushConfig.getWidth(), mLivePushConfig.getHeight());
|
||||
@@ -481,83 +408,130 @@ public class MoGoLiveManager {
|
||||
zegoVideoConfig.setVideoBitrate(mLivePushConfig.getVideoBitrate());
|
||||
// 设置转码的ID,使用H.264
|
||||
zegoVideoConfig.setCodecID(ZegoVideoCodecID.DEFAULT);
|
||||
|
||||
// 将视频信息设置到推流引擎
|
||||
mExpressEngine.setVideoConfig(zegoVideoConfig);
|
||||
}
|
||||
initCustomVideoCapture();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化自定义视频采集
|
||||
*/
|
||||
private void initCustomVideoCapture() {
|
||||
// 创建自定义视频采集对象
|
||||
customVideoCaptureConfig = new ZegoCustomVideoCaptureConfig();
|
||||
// 设置自定义视频采集视频帧数据类型
|
||||
customVideoCaptureConfig.bufferType = ZegoVideoBufferType.RAW_DATA;
|
||||
// 开始或停止自定义视频采集,支持设置其他通道的推流
|
||||
mExpressEngine.enableCustomVideoCapture(true, customVideoCaptureConfig, ZegoPublishChannel.MAIN);
|
||||
// 设置自定义视频采集回调
|
||||
mExpressEngine.setCustomVideoCaptureHandler(new IZegoCustomVideoCaptureHandler() {
|
||||
@Override
|
||||
public void onStart(ZegoPublishChannel channel) {
|
||||
super.onStart(channel);
|
||||
Logger.i(TAG, "SDK 通知将要开始采集视频帧 setCustomVideoCaptureHandler onStart");
|
||||
mLiveStatusModel.setCaptureStatus(true);
|
||||
if (mProgressListener != null) {
|
||||
for (ILiveProgressListener iLiveProgressListener : mProgressListener) {
|
||||
iLiveProgressListener.onEngineStart();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop(ZegoPublishChannel channel) {
|
||||
super.onStop(channel);
|
||||
Logger.i(TAG, "SDK 通知将要停止采集视频帧 setCustomVideoCaptureHandler onStop");
|
||||
mLiveStatusModel.setCaptureStatus(false);
|
||||
if (mProgressListener != null) {
|
||||
for (ILiveProgressListener iLiveProgressListener : mProgressListener) {
|
||||
iLiveProgressListener.onEngineStop();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 进入自己房间
|
||||
*/
|
||||
public synchronized void loginRoom() {
|
||||
// 当前用户ID
|
||||
String userId = mLivePushConfig.getDevicesId();
|
||||
Logger.i(TAG,
|
||||
"进入自己房间 loginRoom userId : " + userId
|
||||
+ " currentRoomId:" + mLiveStatusModel.getCurrentRoomId()
|
||||
+ " currentStreamId:" + mLiveStatusModel.getCurrentStreamId());
|
||||
mLiveStatusModel.setCurrentRoomId(ROOM_ID_PREFIX + mLivePushConfig.getDevicesId());
|
||||
mLiveStatusModel.setCurrentStreamId(STREAM_ID_PREFIX + mLivePushConfig.getDevicesId());
|
||||
if (!mLiveStatusModel.isLoginCurrentRoom()) {
|
||||
ZegoUser zegoUser = new ZegoUser(userId, NAME_PREFIX + userId);
|
||||
mExpressEngine.loginRoom(mLiveStatusModel.getCurrentRoomId(), zegoUser, zeGoRoomConfig);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出房间
|
||||
* 退出自己房间
|
||||
*/
|
||||
public void logoutRoom() {
|
||||
Logger.i(TAG, "logoutRoom: " + currentRoomId);
|
||||
if (mExpressEngine == null) {
|
||||
return;
|
||||
public synchronized void logoutCurrentRoom() {
|
||||
Logger.i(TAG, "退出自己房间 logoutRoom : " + mLiveStatusModel.getCurrentRoomId());
|
||||
if (mLiveStatusModel.isLoginCurrentRoom()) {
|
||||
if (mExpressEngine == null) {
|
||||
return;
|
||||
}
|
||||
if (!TextUtils.isEmpty(mLiveStatusModel.getCurrentRoomId())) {
|
||||
mExpressEngine.logoutRoom(mLiveStatusModel.getCurrentRoomId());
|
||||
}
|
||||
if (customVideoCaptureConfig == null) {
|
||||
// 创建自定义视频采集对象
|
||||
customVideoCaptureConfig = new ZegoCustomVideoCaptureConfig();
|
||||
// 设置自定义视频采集视频帧数据类型
|
||||
customVideoCaptureConfig.bufferType = ZegoVideoBufferType.RAW_DATA;
|
||||
}
|
||||
}
|
||||
if (!TextUtils.isEmpty(currentRoomId)) {
|
||||
mExpressEngine.logoutRoom(currentRoomId);
|
||||
currentRoomId = "";
|
||||
}
|
||||
|
||||
/**
|
||||
* 进入多房间
|
||||
*
|
||||
* @param otherRoomId 房间ID
|
||||
*/
|
||||
public synchronized void loginMultiRoom(String otherRoomId) {
|
||||
if (!mLiveStatusModel.isLoginCurrentRoom()) {
|
||||
loginRoom();
|
||||
}
|
||||
if (customVideoCaptureConfig == null) {
|
||||
// 创建自定义视频采集对象
|
||||
customVideoCaptureConfig = new ZegoCustomVideoCaptureConfig();
|
||||
// 设置自定义视频采集视频帧数据类型
|
||||
customVideoCaptureConfig.bufferType = ZegoVideoBufferType.RAW_DATA;
|
||||
mLiveStatusModel.setMultiRoomId(ROOM_ID_PREFIX + otherRoomId);
|
||||
mLiveStatusModel.setMultiStreamId(STREAM_ID_PREFIX + otherRoomId);
|
||||
Logger.i(TAG,
|
||||
"进入多房间 loginMultiRoom multiRoomId : " + mLiveStatusModel.getMultiRoomId()
|
||||
+ " currentStreamId : " + mLiveStatusModel.getMultiStreamId());
|
||||
if (!mLiveStatusModel.isLoginMultiRoom()) {
|
||||
mExpressEngine.loginMultiRoom(mLiveStatusModel.getMultiRoomId(), zeGoRoomConfig);
|
||||
}
|
||||
mExpressEngine.enableCustomVideoCapture(false, customVideoCaptureConfig, ZegoPublishChannel.MAIN);
|
||||
mExpressEngine.setEventHandler(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出多房间
|
||||
*/
|
||||
public void logoutMultiRoom() {
|
||||
Logger.i(TAG, "logoutMultiRoom: " + multiRoomId);
|
||||
if (mExpressEngine == null) {
|
||||
return;
|
||||
}
|
||||
if (!TextUtils.isEmpty(multiRoomId)) {
|
||||
mExpressEngine.logoutRoom(multiRoomId);
|
||||
multiRoomId = "";
|
||||
public synchronized void logoutMultiRoom() {
|
||||
Logger.i(TAG, "退出多房间 logoutMultiRoom multiRoomId : " + mLiveStatusModel.getMultiRoomId());
|
||||
if (mLiveStatusModel.isLoginMultiRoom()) {
|
||||
if (mExpressEngine == null) {
|
||||
return;
|
||||
}
|
||||
if (!TextUtils.isEmpty(mLiveStatusModel.getMultiRoomId())) {
|
||||
mExpressEngine.logoutRoom(mLiveStatusModel.getMultiRoomId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始推送
|
||||
* 开始推流到ZeGo
|
||||
*/
|
||||
public void startPush() {
|
||||
Logger.i(TAG, "startPush currentStreamId: " + currentStreamId);
|
||||
mExpressEngine.startPublishingStream(currentStreamId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始播放直播
|
||||
*
|
||||
* @param surfaceView 渲染直播的视图
|
||||
*/
|
||||
public String startLive(SurfaceView surfaceView) {
|
||||
if (!TextUtils.isEmpty(multiStreamId) &&
|
||||
!multiStreamId.equals(STREAM_ID_PREFIX)) {
|
||||
ZegoCanvas zegoCanvas = new ZegoCanvas(surfaceView);
|
||||
zegoCanvas.viewMode = ZegoViewMode.SCALE_TO_FILL;
|
||||
Logger.i(TAG, "startLive multiStreamId: " + multiStreamId);
|
||||
mExpressEngine.startPlayingStream(multiStreamId, zegoCanvas);
|
||||
} else {
|
||||
Logger.e(TAG, "直播ID有误,请重试");
|
||||
}
|
||||
return multiStreamId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止播放直播
|
||||
*/
|
||||
public void stopLive() {
|
||||
Logger.i(TAG, "stopLive multiStreamId: " + multiStreamId);
|
||||
if (!TextUtils.isEmpty(multiStreamId) && mExpressEngine != null) {
|
||||
mExpressEngine.stopPlayingStream(multiStreamId);
|
||||
}
|
||||
stopPreview();
|
||||
public void startPublish() {
|
||||
Logger.i(TAG, "开始推流到ZeGo startPublish currentStreamId : " + mLiveStatusModel.getCurrentStreamId());
|
||||
mExpressEngine.startPublishingStream(mLiveStatusModel.getCurrentStreamId());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -580,27 +554,43 @@ public class MoGoLiveManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* 结束发布的直播
|
||||
* 停止推流到ZeGo
|
||||
*/
|
||||
public void onDestroyPublish() {
|
||||
stopPublish();
|
||||
public void stopPublish() {
|
||||
Logger.i(TAG, "停止推流到ZeGo stopPublish currentStreamId : " + mLiveStatusModel.getCurrentStreamId());
|
||||
if (mExpressEngine == null) {
|
||||
return;
|
||||
}
|
||||
// 停止推送
|
||||
mExpressEngine.stopPublishingStream();
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始预览
|
||||
* 开始播放直播
|
||||
*
|
||||
* @param surfaceView 预览承载视图
|
||||
* @param surfaceView 渲染直播的视图
|
||||
*/
|
||||
public void startPreview(SurfaceView surfaceView) {
|
||||
ZegoCanvas zegoCanvas = new ZegoCanvas(surfaceView);
|
||||
zegoCanvas.viewMode = ZegoViewMode.SCALE_TO_FILL; //填充整个View
|
||||
mExpressEngine.startPreview(zegoCanvas);
|
||||
public String startLive(SurfaceView surfaceView) {
|
||||
Logger.i(TAG, "开始播放直播 startLive multiStreamId : " + mLiveStatusModel.getMultiStreamId());
|
||||
if (!TextUtils.isEmpty(mLiveStatusModel.getMultiStreamId()) &&
|
||||
mLiveStatusModel.getMultiStreamId().startsWith(STREAM_ID_PREFIX)) {
|
||||
ZegoCanvas zegoCanvas = new ZegoCanvas(surfaceView);
|
||||
zegoCanvas.viewMode = ZegoViewMode.SCALE_TO_FILL;
|
||||
mExpressEngine.startPlayingStream(mLiveStatusModel.getMultiStreamId(), zegoCanvas);
|
||||
} else {
|
||||
Logger.e(TAG, "直播ID有误,请重试");
|
||||
}
|
||||
return mLiveStatusModel.getMultiStreamId();
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止预览
|
||||
* 停止播放直播
|
||||
*/
|
||||
private void stopPreview() {
|
||||
public void stopLive() {
|
||||
Logger.i(TAG, "停止播放直播 stopLive multiStreamId : " + mLiveStatusModel.getMultiStreamId());
|
||||
if (!TextUtils.isEmpty(mLiveStatusModel.getMultiStreamId()) && mExpressEngine != null) {
|
||||
mExpressEngine.stopPlayingStream(mLiveStatusModel.getMultiStreamId());
|
||||
}
|
||||
if (mExpressEngine == null) {
|
||||
return;
|
||||
}
|
||||
@@ -610,28 +600,13 @@ public class MoGoLiveManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止推送
|
||||
* 销毁即构引擎
|
||||
*/
|
||||
public void stopPublish() {
|
||||
stopPublishingStream();
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止推送数据
|
||||
*/
|
||||
private void stopPublishingStream() {
|
||||
if (mExpressEngine == null) {
|
||||
return;
|
||||
}
|
||||
// 停止推送
|
||||
mExpressEngine.stopPublishingStream();
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止观看直播
|
||||
*/
|
||||
public void onDestroyLive() {
|
||||
|
||||
private void destroyEngine() {
|
||||
mExpressEngine.enableCustomVideoCapture(false, customVideoCaptureConfig, ZegoPublishChannel.MAIN);
|
||||
ZegoExpressEngine.destroyEngine(() -> {
|
||||
Logger.i(TAG, "销毁ZeGo引擎");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
package com.mogo.cloud.live.model;
|
||||
|
||||
/**
|
||||
* 直播状态数据模型
|
||||
*/
|
||||
public class LiveStatusModel {
|
||||
/**
|
||||
* 当前的房间ID
|
||||
*/
|
||||
private String currentRoomId = "";
|
||||
/**
|
||||
* 是否登录了当前车机的房间
|
||||
*/
|
||||
private boolean isLoginCurrentRoom = false;
|
||||
/**
|
||||
* 当前的多房间ID
|
||||
*/
|
||||
private String multiRoomId = "";
|
||||
/**
|
||||
* 是否登录了第二个车机的直播房间
|
||||
*/
|
||||
private boolean isLoginMultiRoom = false;
|
||||
/**
|
||||
* 当前直播流ID
|
||||
*/
|
||||
private String currentStreamId = "";
|
||||
/**
|
||||
* MultiRoom中直播流ID
|
||||
*/
|
||||
private String multiStreamId = "";
|
||||
/**
|
||||
* 自定义采集状态,true-初始化完成,false-没有初始化
|
||||
*/
|
||||
private boolean isCaptureStatus;
|
||||
/**
|
||||
* 推送状态,true-推流中,false-没有推流
|
||||
*/
|
||||
private boolean isPushing;
|
||||
/**
|
||||
* 播放状态,true-播放中,false-没有播放
|
||||
*/
|
||||
private boolean isPlaying;
|
||||
/**
|
||||
* 当前在直播间的人数,只剩下一个人的时候需要停掉直播推送
|
||||
*/
|
||||
private int onlineNumber;
|
||||
|
||||
public String getCurrentRoomId() {
|
||||
return currentRoomId;
|
||||
}
|
||||
|
||||
public void setCurrentRoomId(String currentRoomId) {
|
||||
this.currentRoomId = currentRoomId;
|
||||
}
|
||||
|
||||
public boolean isLoginCurrentRoom() {
|
||||
return isLoginCurrentRoom;
|
||||
}
|
||||
|
||||
public void setLoginCurrentRoom(boolean loginCurrentRoom) {
|
||||
isLoginCurrentRoom = loginCurrentRoom;
|
||||
}
|
||||
|
||||
public String getMultiRoomId() {
|
||||
return multiRoomId;
|
||||
}
|
||||
|
||||
public void setMultiRoomId(String multiRoomId) {
|
||||
this.multiRoomId = multiRoomId;
|
||||
}
|
||||
|
||||
public boolean isLoginMultiRoom() {
|
||||
return isLoginMultiRoom;
|
||||
}
|
||||
|
||||
public void setLoginMultiRoom(boolean loginMultiRoom) {
|
||||
isLoginMultiRoom = loginMultiRoom;
|
||||
}
|
||||
|
||||
public String getCurrentStreamId() {
|
||||
return currentStreamId;
|
||||
}
|
||||
|
||||
public void setCurrentStreamId(String currentStreamId) {
|
||||
this.currentStreamId = currentStreamId;
|
||||
}
|
||||
|
||||
public String getMultiStreamId() {
|
||||
return multiStreamId;
|
||||
}
|
||||
|
||||
public void setMultiStreamId(String multiStreamId) {
|
||||
this.multiStreamId = multiStreamId;
|
||||
}
|
||||
|
||||
public boolean isCaptureStatus() {
|
||||
return isCaptureStatus;
|
||||
}
|
||||
|
||||
public void setCaptureStatus(boolean captureStatus) {
|
||||
isCaptureStatus = captureStatus;
|
||||
}
|
||||
|
||||
public boolean isPushing() {
|
||||
return isPushing;
|
||||
}
|
||||
|
||||
public void setPushing(boolean pushing) {
|
||||
isPushing = pushing;
|
||||
}
|
||||
|
||||
public boolean isPlaying() {
|
||||
return isPlaying;
|
||||
}
|
||||
|
||||
public void setPlaying(boolean playing) {
|
||||
isPlaying = playing;
|
||||
}
|
||||
|
||||
public int getOnlineNumber() {
|
||||
return onlineNumber;
|
||||
}
|
||||
|
||||
public void setOnlineNumber(int onlineNumber) {
|
||||
this.onlineNumber = onlineNumber;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LiveStatusModel{" +
|
||||
"currentRoomId='" + currentRoomId + '\'' +
|
||||
", isLoginCurrentRoom=" + isLoginCurrentRoom +
|
||||
", multiRoomId='" + multiRoomId + '\'' +
|
||||
", isLoginMultiRoom=" + isLoginMultiRoom +
|
||||
", currentStreamId='" + currentStreamId + '\'' +
|
||||
", multiStreamId='" + multiStreamId + '\'' +
|
||||
", isCaptureStatus=" + isCaptureStatus +
|
||||
", isPushing=" + isPushing +
|
||||
", isPlaying=" + isPlaying +
|
||||
", onlineNumber=" + onlineNumber +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,8 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.IBinder;
|
||||
import android.os.SystemClock;
|
||||
import android.util.Log;
|
||||
|
||||
import com.mogo.cloud.live.listener.ILiveCurrentRoomStatusListener;
|
||||
import com.mogo.cloud.live.listener.IYUVDataListener;
|
||||
import com.mogo.cloud.live.manager.CameraFrameManager;
|
||||
import com.mogo.cloud.live.manager.MoGoLiveManager;
|
||||
@@ -15,7 +15,7 @@ import com.mogo.cloud.utils.logger.Logger;
|
||||
|
||||
|
||||
public class PushService extends Service
|
||||
implements IYUVDataListener {
|
||||
implements IYUVDataListener, ILiveCurrentRoomStatusListener {
|
||||
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";
|
||||
@@ -39,8 +39,11 @@ public class PushService extends Service
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
Log.d(TAG, "初始化推流服务……");
|
||||
initZeGoLivePusher();
|
||||
Logger.i(TAG, "初始化推流服务……");
|
||||
if (mLivePusher == null) {
|
||||
mLivePusher = MoGoLiveManager.getInstance();
|
||||
mLivePusher.addLiveRoomStatusListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -58,10 +61,10 @@ public class PushService extends Service
|
||||
// 关闭直播,如果还有人观看不关闭
|
||||
else if (ACTION_STOP_RTMP_PUSH.equals(intent.getAction())) {
|
||||
Logger.i(TAG, "关闭直播推送");
|
||||
if (mLivePusher.getOnlineNumber() <= 1) {
|
||||
if (mLivePusher.getLiveStatusModel().getOnlineNumber() <= 1) {
|
||||
stopPush();
|
||||
} else {
|
||||
Logger.i(TAG, "房间还有 " + mLivePusher.getOnlineNumber() + " 位观众,不可以关闭直播");
|
||||
Logger.i(TAG, "房间还有 " + mLivePusher.getLiveStatusModel().getOnlineNumber() + " 位观众,不可以关闭直播");
|
||||
}
|
||||
}
|
||||
// 强制关闭直播
|
||||
@@ -82,26 +85,26 @@ public class PushService extends Service
|
||||
* 启动发布直播视频流
|
||||
*/
|
||||
private void startPush() {
|
||||
Logger.i(TAG, "startPush");
|
||||
if (mLivePusher != null
|
||||
&& mLivePusher.isCaptureStatus()
|
||||
&& mLivePusher.isPushing()) {
|
||||
&& mLivePusher.getLiveStatusModel().isPushing()) {
|
||||
Logger.w(TAG, "已经开启了推流,无需重复开启");
|
||||
return;
|
||||
}
|
||||
initZeGoLivePusher();
|
||||
// 开始发布
|
||||
mLivePusher.startPush();
|
||||
// 注册视频YUV回调监听
|
||||
CameraFrameManager.getInstance().addYuvDataCallback(this);
|
||||
Log.d(TAG, "startPush");
|
||||
if (mLivePusher != null && !mLivePusher.getLiveStatusModel().isLoginCurrentRoom()) {
|
||||
// 推流之前必须先登录房间
|
||||
mLivePusher.loginRoom();
|
||||
} else {
|
||||
realStartPublish();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化ZeGo直播推流
|
||||
*/
|
||||
private void initZeGoLivePusher() {
|
||||
if (mLivePusher == null) {
|
||||
mLivePusher = MoGoLiveManager.getInstance();
|
||||
}
|
||||
private void realStartPublish() {
|
||||
Logger.i(TAG, "realStartPublish");
|
||||
// 开始发布
|
||||
mLivePusher.startPublish();
|
||||
// 注册视频YUV回调监听
|
||||
CameraFrameManager.getInstance().addYuvDataCallback(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -110,9 +113,11 @@ public class PushService extends Service
|
||||
private void stopPush() {
|
||||
try {
|
||||
// 是否处于发布状态
|
||||
if (mLivePusher.isPushing()) {
|
||||
if (mLivePusher != null && mLivePusher.getLiveStatusModel().isPushing()) {
|
||||
// 停止发布
|
||||
mLivePusher.stopPublish();
|
||||
// 退出房间
|
||||
mLivePusher.loginRoom();
|
||||
}
|
||||
// 移除视频回碉监听
|
||||
CameraFrameManager.getInstance().rmYuvDataCallback(this);
|
||||
@@ -123,12 +128,31 @@ public class PushService extends Service
|
||||
|
||||
@Override
|
||||
public void onFrame(byte[] data) {
|
||||
if (mLivePusher != null && mLivePusher.isCaptureStatus()
|
||||
&& mLivePusher.isPushing() && data != null) {
|
||||
if (mLivePusher != null
|
||||
&& mLivePusher.getLiveStatusModel().isCaptureStatus()
|
||||
&& mLivePusher.getLiveStatusModel().isPushing()
|
||||
&& data != null) {
|
||||
// 将YUV数据发布到即构
|
||||
mLivePusher.startPublishingStream(
|
||||
ByteUtils.getBuffer(data, data.length), data.length,
|
||||
SystemClock.elapsedRealtime());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCurrentRoomConnecting() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCurrentRoomConnected() {
|
||||
Logger.i(TAG, "登录房间成功开启推流");
|
||||
realStartPublish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCurrentRoomDisconnected() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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.55
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.mogo.cloud.trafficlive.api;
|
||||
import android.app.Application;
|
||||
import android.view.SurfaceView;
|
||||
|
||||
import com.mogo.cloud.trafficlive.core.TrafficLiveManager;
|
||||
import com.mogo.cloud.trafficlive.core.TrafficLiveCurrentManager;
|
||||
import com.mogo.cloud.utils.logger.Logger;
|
||||
|
||||
import static com.mogo.cloud.trafficlive.constant.TrafficLiveConstant.TAG;
|
||||
@@ -15,7 +15,7 @@ public class MoGoAiCloudTrafficLive {
|
||||
*/
|
||||
public static void viewVehicleHeadLive(Application application, String liveSn, SurfaceView surfaceView, ITrafficLiveCallBack callBack) {
|
||||
try {
|
||||
TrafficLiveManager.getInstance().viewVehicleHeadLive(application, liveSn, surfaceView, callBack);
|
||||
TrafficLiveCurrentManager.getInstance().viewVehicleHeadLive(application, liveSn, surfaceView, callBack);
|
||||
} catch (Exception e) {
|
||||
Logger.e(TAG, " viewVehicleHeadLive error : " + e);
|
||||
e.printStackTrace();
|
||||
@@ -26,21 +26,14 @@ public class MoGoAiCloudTrafficLive {
|
||||
* 查看前方路口直播
|
||||
*/
|
||||
public static void viewIntersectionLive(ITrafficLiveCallBack callBack) {
|
||||
TrafficLiveManager.getInstance().viewIntersectionLive(callBack);
|
||||
TrafficLiveCurrentManager.getInstance().viewIntersectionLive(callBack);
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止观看直播
|
||||
*/
|
||||
public static void stopLive(String liveSn) {
|
||||
TrafficLiveManager.getInstance().stopLive(liveSn);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭直播组件
|
||||
*/
|
||||
public static void destroyLive() {
|
||||
TrafficLiveManager.getInstance().destroyLive();
|
||||
TrafficLiveCurrentManager.getInstance().stopLive(liveSn);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,6 +42,6 @@ public class MoGoAiCloudTrafficLive {
|
||||
* @return 直播状态
|
||||
*/
|
||||
public static boolean isOnLive() {
|
||||
return TrafficLiveManager.getInstance().isOnLive();
|
||||
return TrafficLiveCurrentManager.getInstance().isOnLive();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,9 @@ import android.os.SystemClock;
|
||||
import android.text.TextUtils;
|
||||
import android.view.SurfaceView;
|
||||
|
||||
import com.mogo.cloud.live.listener.ILiveMultiRoomStatusListener;
|
||||
import com.mogo.cloud.live.listener.ILiveProgressListener;
|
||||
import com.mogo.cloud.live.listener.ILiveRoomStatusListener;
|
||||
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;
|
||||
@@ -19,24 +20,26 @@ 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, ILiveRoomStatusListener {
|
||||
public class TrafficLiveCurrentManager
|
||||
implements ILiveProgressListener, ILiveMultiRoomStatusListener {
|
||||
|
||||
private static volatile TrafficLiveManager mInstance;
|
||||
private static volatile TrafficLiveCurrentManager mInstance;
|
||||
private final RequestLiveManager requestLiveManager;
|
||||
private ITrafficLiveCallBack trafficLiveCallBack;
|
||||
private SurfaceView surfaceView;
|
||||
private String mStreamId;
|
||||
private boolean isLoginSuccess = false;
|
||||
|
||||
private TrafficLiveManager() {
|
||||
private TrafficLiveCurrentManager() {
|
||||
requestLiveManager = RequestLiveManager.getInstance();
|
||||
}
|
||||
|
||||
public static TrafficLiveManager getInstance() {
|
||||
public static TrafficLiveCurrentManager getInstance() {
|
||||
if (mInstance == null) {
|
||||
synchronized (TrafficLiveManager.class) {
|
||||
synchronized (TrafficLiveCurrentManager.class) {
|
||||
if (mInstance == null) {
|
||||
mInstance = new TrafficLiveManager();
|
||||
mInstance = new TrafficLiveCurrentManager();
|
||||
MoGoLiveManager.getInstance().addLiveProgressListener(mInstance);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -44,7 +47,7 @@ public class TrafficLiveManager implements ILiveProgressListener, ILiveRoomStatu
|
||||
}
|
||||
|
||||
public boolean isOnLive() {
|
||||
return MoGoLiveManager.getInstance().isPlaying();
|
||||
return MoGoLiveManager.getInstance().getLiveStatusModel().isPlaying();
|
||||
}
|
||||
|
||||
public void viewVehicleHeadLive(Application application, String liveSn, SurfaceView surfaceView, ITrafficLiveCallBack trafficLiveCallBack) throws Exception {
|
||||
@@ -74,19 +77,18 @@ public class TrafficLiveManager implements ILiveProgressListener, ILiveRoomStatu
|
||||
|
||||
// 登录要查看的SN房间
|
||||
MoGoLiveManager.getInstance().loginMultiRoom(liveSn);
|
||||
MoGoLiveManager.getInstance().setLiveProgressListener(TrafficLiveManager.this);
|
||||
|
||||
// 直接 查看对应SN的直播
|
||||
MoGoLiveManager.getInstance().startLive(surfaceView);
|
||||
if (TrafficLiveManager.this.trafficLiveCallBack != null) {
|
||||
TrafficLiveManager.this.trafficLiveCallBack.onLive();
|
||||
if (TrafficLiveCurrentManager.this.trafficLiveCallBack != null) {
|
||||
TrafficLiveCurrentManager.this.trafficLiveCallBack.onLive();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
if (TrafficLiveManager.this.trafficLiveCallBack != null) {
|
||||
TrafficLiveManager.this.trafficLiveCallBack.onError(e.getMessage());
|
||||
if (TrafficLiveCurrentManager.this.trafficLiveCallBack != null) {
|
||||
TrafficLiveCurrentManager.this.trafficLiveCallBack.onError(e.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -116,10 +118,6 @@ public class TrafficLiveManager implements ILiveProgressListener, ILiveRoomStatu
|
||||
mStreamId = null;
|
||||
}
|
||||
|
||||
public void destroyLive() {
|
||||
MoGoLiveManager.getInstance().onDestroyLive();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEngineStart() {
|
||||
if (trafficLiveCallBack != null) {
|
||||
@@ -142,20 +140,7 @@ public class TrafficLiveManager implements ILiveProgressListener, ILiveRoomStatu
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCurrentRoomConnecting() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCurrentRoomConnected() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCurrentRoomDisconnected() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMultiRoomConnecting() {
|
||||
Reference in New Issue
Block a user