add new func of live module and realTime add new field
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package com.mogo.cloud.trafficlive.api;
|
||||
|
||||
public interface ITrafficLiveCallBack {
|
||||
public interface ITrafficCarLiveCallBack {
|
||||
|
||||
|
||||
default void onLiveConnecting() {
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.mogo.cloud.trafficlive.api;
|
||||
|
||||
public interface ITrafficIntersectionLiveCallBack {
|
||||
|
||||
void liveUrlResult(String liveUrl);
|
||||
|
||||
void onError(String errorMsg);
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.mogo.cloud.trafficlive.api;
|
||||
|
||||
import android.app.Application;
|
||||
import android.view.SurfaceView;
|
||||
|
||||
import com.mogo.cloud.trafficlive.core.TrafficLiveCurrentManager;
|
||||
@@ -11,37 +10,92 @@ import static com.mogo.cloud.trafficlive.constant.TrafficLiveConstant.TAG;
|
||||
public class MoGoAiCloudTrafficLive {
|
||||
|
||||
/**
|
||||
* 查看指定SN车辆直播
|
||||
* 查看前方车辆直播
|
||||
*
|
||||
* @param lat 纬度
|
||||
* @param lon 经度
|
||||
* @param bearing 方向角
|
||||
* @param surfaceView 直播界面
|
||||
* @param callBack {@link ITrafficCarLiveCallBack}直播回调
|
||||
*/
|
||||
public static void viewVehicleHeadLive(Application application, String liveSn, SurfaceView surfaceView, ITrafficLiveCallBack callBack) {
|
||||
public static void viewFrontVehicleLive(double lat, double lon, int bearing, SurfaceView surfaceView, ITrafficCarLiveCallBack callBack) {
|
||||
try {
|
||||
TrafficLiveCurrentManager.getInstance().viewVehicleHeadLive(application, liveSn, surfaceView, callBack);
|
||||
TrafficLiveCurrentManager.getInstance().viewFrontVehicleLive(lat, lon, bearing, surfaceView, callBack);
|
||||
} catch (Exception e) {
|
||||
Logger.e(TAG, " viewVehicleHeadLive error : " + e);
|
||||
Logger.e(TAG, " viewFrontVehicleLive error : " + e);
|
||||
callBack.onError(e != null ? e.getMessage() : "check input param");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看指定SN车辆直播
|
||||
*
|
||||
* @param liveSn 直播车辆SN
|
||||
* @param surfaceView 直播界面
|
||||
* @param callBack {@link ITrafficCarLiveCallBack}直播回调
|
||||
*/
|
||||
public static void viewDesignativeVehicleLive(String liveSn, SurfaceView surfaceView, ITrafficCarLiveCallBack callBack) {
|
||||
try {
|
||||
TrafficLiveCurrentManager.getInstance().viewDesignativeVehicleLive(liveSn, surfaceView, callBack);
|
||||
} catch (Exception e) {
|
||||
Logger.e(TAG, " viewDesignativeVehicleLive error : " + e);
|
||||
callBack.onError(e != null ? e.getMessage() : "check input param");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看前方路口直播
|
||||
*
|
||||
* @param lat 纬度
|
||||
* @param lon 经度
|
||||
* @param bearing 方向角
|
||||
* @param callBack {@link ITrafficIntersectionLiveCallBack}直播回调
|
||||
*/
|
||||
public static void viewIntersectionLive(ITrafficLiveCallBack callBack) {
|
||||
TrafficLiveCurrentManager.getInstance().viewIntersectionLive(callBack);
|
||||
public static void viewFrontIntersectionLive(double lat, double lon, int bearing, ITrafficIntersectionLiveCallBack callBack) {
|
||||
try {
|
||||
TrafficLiveCurrentManager.getInstance().viewFrontIntersectionLive(lat, lon, bearing, callBack);
|
||||
} catch (Exception e) {
|
||||
Logger.e(TAG, " viewFrontIntersectionLive error : " + e);
|
||||
callBack.onError(e != null ? e.getMessage() : "check input param");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止观看直播
|
||||
* 查看指定路口摄像头直播
|
||||
*
|
||||
* @param cameraId 设备id
|
||||
* @param lat 纬度
|
||||
* @param lon 经度
|
||||
* @param callBack {@link ITrafficIntersectionLiveCallBack}直播回调
|
||||
*/
|
||||
public static void stopLive(String liveSn) {
|
||||
TrafficLiveCurrentManager.getInstance().stopLive(liveSn);
|
||||
public static void viewDesignativeIntersectionLive(int cameraId, double lat, double lon, ITrafficIntersectionLiveCallBack callBack) {
|
||||
try {
|
||||
TrafficLiveCurrentManager.getInstance().viewDesignativeIntersectionLive(cameraId, lat, lon, callBack);
|
||||
} catch (Exception e) {
|
||||
Logger.e(TAG, " viewDesignativeIntersectionLive error : " + e);
|
||||
callBack.onError(e != null ? e.getMessage() : "check input param");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否在直播中
|
||||
* 停止观看车辆直播
|
||||
*
|
||||
* @param liveSn 车辆SN
|
||||
*/
|
||||
public static void stopCarLive(String liveSn) {
|
||||
TrafficLiveCurrentManager.getInstance().stopCarLive(liveSn);
|
||||
}
|
||||
|
||||
/**
|
||||
* 车辆是否在直播中
|
||||
*
|
||||
* @return 直播状态
|
||||
*/
|
||||
public static boolean isOnLive() {
|
||||
return TrafficLiveCurrentManager.getInstance().isOnLive();
|
||||
public static boolean isCarOnLive() {
|
||||
return TrafficLiveCurrentManager.getInstance().isCarOnLive();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.mogo.cloud.trafficlive.core;
|
||||
|
||||
import android.app.Application;
|
||||
import android.os.SystemClock;
|
||||
import android.text.TextUtils;
|
||||
import android.view.SurfaceView;
|
||||
|
||||
@@ -12,7 +10,8 @@ import com.mogo.cloud.live.manager.MoGoLiveManager;
|
||||
import com.mogo.cloud.live.manager.MoGoLivePushConfig;
|
||||
import com.mogo.cloud.live.manager.RequestLiveManager;
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClient;
|
||||
import com.mogo.cloud.trafficlive.api.ITrafficLiveCallBack;
|
||||
import com.mogo.cloud.trafficlive.api.ITrafficCarLiveCallBack;
|
||||
import com.mogo.cloud.trafficlive.api.ITrafficIntersectionLiveCallBack;
|
||||
import com.mogo.cloud.utils.logger.Logger;
|
||||
|
||||
import static com.mogo.cloud.live.constant.LiveConstant.LIVE_TYPE_CLOSE;
|
||||
@@ -24,10 +23,7 @@ public class TrafficLiveCurrentManager
|
||||
|
||||
private static volatile TrafficLiveCurrentManager mInstance;
|
||||
private final RequestLiveManager requestLiveManager;
|
||||
private ITrafficLiveCallBack trafficLiveCallBack;
|
||||
private SurfaceView surfaceView;
|
||||
private String mStreamId;
|
||||
private boolean isLoginSuccess = false;
|
||||
private ITrafficCarLiveCallBack trafficLiveCallBack;
|
||||
|
||||
private TrafficLiveCurrentManager() {
|
||||
requestLiveManager = RequestLiveManager.getInstance();
|
||||
@@ -45,12 +41,40 @@ public class TrafficLiveCurrentManager
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
public boolean isOnLive() {
|
||||
public boolean isCarOnLive() {
|
||||
return MoGoLiveManager.getInstance().getLiveStatusModel().isPlaying();
|
||||
}
|
||||
|
||||
public void viewVehicleHeadLive(Application application, String liveSn, SurfaceView surfaceView, ITrafficLiveCallBack trafficLiveCallBack) throws Exception {
|
||||
if (trafficLiveCallBack == null) {
|
||||
public void viewFrontVehicleLive(double lat, double lon, int bearing, SurfaceView surfaceView, ITrafficCarLiveCallBack callBack) throws Exception {
|
||||
if (callBack == null) {
|
||||
throw new Exception("ITrafficLiveCallBack can not be null");
|
||||
}
|
||||
if (surfaceView == null) {
|
||||
throw new Exception("SurfaceView can not be null");
|
||||
}
|
||||
if (lat == 0.0 || lon == 0.0) {
|
||||
throw new Exception("param lat and lon can not be 0.0f");
|
||||
}
|
||||
if (bearing < 0) {
|
||||
throw new Exception("param bearing can not less than 0");
|
||||
}
|
||||
|
||||
this.trafficLiveCallBack = callBack;
|
||||
requestLiveManager.requestFrontVehicleLive(lat, lon, bearing, new IRequestLiveListener() {
|
||||
@Override
|
||||
public void onSuccess(String liveSn, String liveUrl, double lat, double lon) {
|
||||
onVehicleLiveSuccess(liveSn, surfaceView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
onVehicleLiveError(e.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void viewDesignativeVehicleLive(String liveSn, SurfaceView surfaceView, ITrafficCarLiveCallBack callBack) throws Exception {
|
||||
if (callBack == null) {
|
||||
throw new Exception("ITrafficLiveCallBack can not be null");
|
||||
}
|
||||
if (surfaceView == null) {
|
||||
@@ -60,45 +84,42 @@ public class TrafficLiveCurrentManager
|
||||
throw new Exception("liveSn can not be null");
|
||||
}
|
||||
|
||||
this.trafficLiveCallBack = trafficLiveCallBack;
|
||||
this.surfaceView = surfaceView;
|
||||
Logger.i(TAG, "申请拉流 systemClock :" + SystemClock.elapsedRealtime() + " SystemTime : " + System.currentTimeMillis());
|
||||
requestLiveManager.requestVehicleHeadLive(LIVE_TYPE_OPEN, liveSn, new IRequestLiveListener() {
|
||||
this.trafficLiveCallBack = callBack;
|
||||
requestLiveManager.requestDesignativeVehicleLive(LIVE_TYPE_OPEN, liveSn, new IRequestLiveListener() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
Logger.i(TAG, "主播开始直播了 systemClock :" + SystemClock.elapsedRealtime() + " SystemTime : " + System.currentTimeMillis());
|
||||
String sn = MoGoAiCloudClient.getInstance().getAiCloudClientConfig().getSn();
|
||||
mStreamId = MoGoLiveManager.STREAM_ID_PREFIX + liveSn;
|
||||
|
||||
// 初始化配置文件
|
||||
MoGoLivePushConfig mLivePushConfig = MoGoLivePushConfig.getInstance();
|
||||
mLivePushConfig.setDevicesId(sn);
|
||||
|
||||
// 登录要查看的SN房间
|
||||
MoGoLiveManager.getInstance().loginMultiRoom(liveSn);
|
||||
|
||||
// 直接 查看对应SN的直播
|
||||
MoGoLiveManager.getInstance().startLive(surfaceView);
|
||||
if (TrafficLiveCurrentManager.this.trafficLiveCallBack != null) {
|
||||
TrafficLiveCurrentManager.this.trafficLiveCallBack.onLive();
|
||||
}
|
||||
onVehicleLiveSuccess(liveSn, surfaceView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
if (TrafficLiveCurrentManager.this.trafficLiveCallBack != null) {
|
||||
TrafficLiveCurrentManager.this.trafficLiveCallBack.onError(e.getMessage());
|
||||
}
|
||||
onVehicleLiveError(e.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void viewIntersectionLive(ITrafficLiveCallBack callBack) {
|
||||
|
||||
private void onVehicleLiveSuccess(String liveSn, SurfaceView surfaceView) {
|
||||
String sn = MoGoAiCloudClient.getInstance().getAiCloudClientConfig().getSn();
|
||||
// 初始化配置文件
|
||||
MoGoLivePushConfig mLivePushConfig = MoGoLivePushConfig.getInstance();
|
||||
mLivePushConfig.setDevicesId(sn);
|
||||
// 登录要查看的SN房间
|
||||
MoGoLiveManager.getInstance().loginMultiRoom(liveSn);
|
||||
// 直接 查看对应SN的直播
|
||||
MoGoLiveManager.getInstance().startLive(surfaceView);
|
||||
if (TrafficLiveCurrentManager.this.trafficLiveCallBack != null) {
|
||||
TrafficLiveCurrentManager.this.trafficLiveCallBack.onLive();
|
||||
}
|
||||
}
|
||||
|
||||
public void stopLive(String liveSn) {
|
||||
requestLiveManager.requestVehicleHeadLive(LIVE_TYPE_CLOSE, liveSn, new IRequestLiveListener() {
|
||||
private void onVehicleLiveError(String errorMsg) {
|
||||
if (TrafficLiveCurrentManager.this.trafficLiveCallBack != null) {
|
||||
TrafficLiveCurrentManager.this.trafficLiveCallBack.onError(errorMsg);
|
||||
}
|
||||
}
|
||||
|
||||
public void stopCarLive(String liveSn) {
|
||||
requestLiveManager.requestDesignativeVehicleLive(LIVE_TYPE_CLOSE, liveSn, new IRequestLiveListener() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
}
|
||||
@@ -111,10 +132,47 @@ public class TrafficLiveCurrentManager
|
||||
}
|
||||
});
|
||||
MoGoLiveManager.getInstance().stopLive();
|
||||
surfaceView = null;
|
||||
trafficLiveCallBack = null;
|
||||
isLoginSuccess = false;
|
||||
mStreamId = null;
|
||||
}
|
||||
|
||||
public void viewFrontIntersectionLive(double lat, double lon, int bearing, ITrafficIntersectionLiveCallBack callBack) throws Exception {
|
||||
if (lat == 0.0 || lon == 0.0) {
|
||||
throw new Exception("param lat and lon can not be 0.0f");
|
||||
}
|
||||
if (bearing < 0) {
|
||||
throw new Exception("param bearing can not less than 0");
|
||||
}
|
||||
requestLiveManager.requestFrontIntersectionLive(lat, lon, bearing, new IRequestLiveListener() {
|
||||
@Override
|
||||
public void onSuccess(String liveUrl) {
|
||||
callBack.liveUrlResult(liveUrl);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
callBack.onError(e.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void viewDesignativeIntersectionLive(int cameraId, double lat, double lon, ITrafficIntersectionLiveCallBack callBack) throws Exception {
|
||||
if (lat == 0.0 || lon == 0.0) {
|
||||
throw new Exception("param lat and lon can not be 0.0f");
|
||||
}
|
||||
if (cameraId < 0) {
|
||||
throw new Exception("param bearing can not less than 0");
|
||||
}
|
||||
requestLiveManager.requestDesignativeIntersectionLive(cameraId, lat, lon, new IRequestLiveListener() {
|
||||
@Override
|
||||
public void onSuccess(String liveUrl) {
|
||||
callBack.liveUrlResult(liveUrl);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
callBack.onError(e.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -135,7 +193,6 @@ public class TrafficLiveCurrentManager
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onMultiRoomConnecting() {
|
||||
if (trafficLiveCallBack != null) {
|
||||
@@ -145,7 +202,6 @@ public class TrafficLiveCurrentManager
|
||||
|
||||
@Override
|
||||
public void onMultiRoomConnected() {
|
||||
isLoginSuccess = true;
|
||||
if (trafficLiveCallBack != null) {
|
||||
trafficLiveCallBack.onLiveConnected();
|
||||
}
|
||||
@@ -153,9 +209,9 @@ public class TrafficLiveCurrentManager
|
||||
|
||||
@Override
|
||||
public void onMultiRoomDisconnected() {
|
||||
isLoginSuccess = false;
|
||||
if (trafficLiveCallBack != null) {
|
||||
trafficLiveCallBack.onDisConnect();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user