fix bug of pull live

This commit is contained in:
zhongchao
2021-02-07 11:33:04 +08:00
parent 6a9fcbd28c
commit d7a3baa4ae
11 changed files with 70 additions and 92 deletions

View File

@@ -2,19 +2,19 @@ package com.mogo.cloud.trafficlive.api;
public interface ITrafficLiveCallBack {
default void onStart(){
default void onLiveStart() {
}
default void onStop(){
default void onLiveStop() {
}
default void onConnecting(){
default void onLiveConnecting() {
}
default void onConnected(){
default void onLiveConnected() {
}
@@ -24,5 +24,4 @@ public interface ITrafficLiveCallBack {
void onError(String errorMsg);
// void onError(int errorCode, String errorMsg);
}

View File

@@ -1,6 +1,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.utils.logger.Logger;
@@ -12,9 +13,9 @@ public class MoGoAiCloudTrafficLive {
/**
* 查看前方车辆直播
*/
public static void viewVehicleHeadLive(Application application, String liveSn, ITrafficLiveCallBack callBack) {
public static void viewVehicleHeadLive(Application application, String liveSn, SurfaceView surfaceView, ITrafficLiveCallBack callBack) {
try {
TrafficLiveManager.getInstance().viewVehicleHeadLive(application, liveSn, callBack);
TrafficLiveManager.getInstance().viewVehicleHeadLive(application, liveSn, surfaceView, callBack);
} catch (Exception e) {
Logger.e(TAG, " viewVehicleHeadLive error : " + e);
e.printStackTrace();
@@ -38,7 +39,7 @@ public class MoGoAiCloudTrafficLive {
/**
* 关闭直播组件
*/
public static void destroyLive(){
public static void destroyLive() {
TrafficLiveManager.getInstance().destroyLive();
}

View File

@@ -17,13 +17,14 @@ import static com.mogo.cloud.trafficlive.constant.TrafficLiveConstant.TAG;
public class TrafficLiveManager implements ILiveProgressListener {
private static volatile TrafficLiveManager mInstance;
private RequestLiveManager requestLiveManager;
private final RequestLiveManager requestLiveManager;
private ITrafficLiveCallBack callBack;
private SurfaceView surfaceView;
private String mStreamId;
private boolean isLoginSuccess = false;
private TrafficLiveManager() {
requestLiveManager = RequestLiveManager.getInstance();
}
public static TrafficLiveManager getInstance() {
@@ -52,17 +53,13 @@ public class TrafficLiveManager implements ILiveProgressListener {
throw new Exception("liveSn can not be null");
}
if (!isLoginSuccess) {
callBack.onError("暂未进房,请勿重复请求");
return;
}
if (MoGoLiveManager.getInstance().isPlaying()) {
callBack.onError("正在直播中,请勿重复请求");
trafficLiveCallBack.onError("正在直播中,请勿重复请求");
return;
}
this.surfaceView = surfaceView;
this.callBack = trafficLiveCallBack;
this.surfaceView = surfaceView;
requestLiveManager.requestVehicleHeadLive(application, liveSn, new IRequestLiveListener() {
@Override
public void onSuccess() {
@@ -98,23 +95,23 @@ public class TrafficLiveManager implements ILiveProgressListener {
@Override
public void onStart() {
callBack.onStart();
callBack.onLiveStart();
}
@Override
public void onStop() {
callBack.onStop();
callBack.onLiveStop();
}
@Override
public void onConnecting() {
callBack.onConnecting();
callBack.onLiveConnecting();
}
@Override
public void onConnected(String roomId) {
isLoginSuccess = true;
callBack.onConnected();
callBack.onLiveConnected();
}
@Override
@@ -132,7 +129,7 @@ public class TrafficLiveManager implements ILiveProgressListener {
callBack.onLive();
} else {
Logger.i(TAG, "主播已离线");
callBack.onStop(); //todo 验证 onStop() 与 onRoomStreamUpdate() 回调时机 前后顺序
callBack.onLiveStop(); //todo 验证 onStop() 与 onRoomStreamUpdate() 回调时机 前后顺序
}
}