fix bug of pull live
This commit is contained in:
1
.idea/gradle.xml
generated
1
.idea/gradle.xml
generated
@@ -26,6 +26,7 @@
|
||||
</set>
|
||||
</option>
|
||||
<option name="resolveModulePerSourceSet" value="false" />
|
||||
<option name="useQualifiedModuleNames" value="true" />
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
|
||||
@@ -52,6 +52,7 @@ dependencies {
|
||||
implementation project(":modules:mogo-tanlu")
|
||||
implementation project(":modules:mogo-realtime")
|
||||
implementation project(":foudations:mogo-live")
|
||||
implementation project(":modules:mogo-trafficlive")
|
||||
}
|
||||
|
||||
annotationProcessor 'com.elegant.spi:compiler:1.0.3' //编译时库
|
||||
|
||||
@@ -9,12 +9,11 @@ import android.widget.ToggleButton;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.mogo.cloud.live.listener.ILiveProgressListener;
|
||||
import com.mogo.cloud.live.manager.MoGoLiveManager;
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClientConfig;
|
||||
import com.mogo.cloud.trafficlive.api.ITrafficLiveCallBack;
|
||||
import com.mogo.cloud.trafficlive.api.MoGoAiCloudTrafficLive;
|
||||
|
||||
|
||||
public class LivePlayActivity extends AppCompatActivity {
|
||||
public class LivePlayActivity extends AppCompatActivity implements ITrafficLiveCallBack {
|
||||
private String TAG = "LiveActivity";
|
||||
|
||||
private SurfaceView surfaceView;
|
||||
@@ -35,65 +34,32 @@ public class LivePlayActivity extends AppCompatActivity {
|
||||
Toast.makeText(getApplicationContext(), buttonView.getText(), Toast.LENGTH_SHORT).show();
|
||||
if (isChecked) {
|
||||
String roomId = etLookRoomId.getText().toString().trim();
|
||||
MoGoLiveManager.getInstance().init(this.getApplication(), null);
|
||||
MoGoLiveManager.getInstance().loginRoom(MoGoAiCloudClientConfig.getInstance().getSn(), roomId);
|
||||
MoGoLiveManager.getInstance().setLiveProgressListener(listener);
|
||||
MoGoAiCloudTrafficLive.viewVehicleHeadLive(this.getApplication(), roomId, surfaceView, this);
|
||||
} else {
|
||||
MoGoLiveManager.getInstance().stopLive();
|
||||
MoGoAiCloudTrafficLive.stopLive();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private ILiveProgressListener listener = new ILiveProgressListener() {
|
||||
|
||||
@Override
|
||||
public void onConnecting() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnected(String roomId) {
|
||||
Log.i(TAG, "onConnected:" + roomId);
|
||||
isLoginSuccess = true;
|
||||
toggleLive(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisConnect() {
|
||||
Log.i(TAG, "onDisConnect:");
|
||||
isLoginSuccess = false;
|
||||
toggleLive(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDebugError(int errorCode, String funcName, String errorInfo) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRoomStreamUpdate(String streamId, boolean isLive) {
|
||||
Log.i(TAG, "onRoomStreamUpdate:" + streamId);
|
||||
if (streamId != null && isLive) {
|
||||
Toast.makeText(LivePlayActivity.this, "主播开始直播了", Toast.LENGTH_SHORT).show();
|
||||
mStreamId = streamId;
|
||||
} else {
|
||||
Toast.makeText(LivePlayActivity.this, "主播已离线", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private void toggleLive(boolean isChecked) {
|
||||
if (isChecked) {
|
||||
mStreamId = MoGoLiveManager.getInstance().startLive(surfaceView);
|
||||
} else {
|
||||
MoGoLiveManager.getInstance().stopLive();
|
||||
}
|
||||
Log.i(TAG, "toggleLive status : " + isChecked + " , mStreamId : " + mStreamId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
MoGoLiveManager.getInstance().onDestroyLive();
|
||||
MoGoAiCloudTrafficLive.stopLive();
|
||||
MoGoAiCloudTrafficLive.destroyLive();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLive() {
|
||||
Log.d(TAG, "开始直播 onLive");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisConnect() {
|
||||
Log.d(TAG, "失去连接 onDisConnect");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String errorMsg) {
|
||||
Log.d(TAG, "发生错误 onError msg: " + errorMsg);
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="请输入要查看的车机SN"
|
||||
android:text="X1020210128F803EB2046PZD00149"
|
||||
android:text="F803EB2046PZD00273"
|
||||
android:textColor="#FFFF"
|
||||
app:layout_constraintBottom_toTopOf="@+id/liveToggleBtn"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
|
||||
@@ -38,6 +38,8 @@ dependencies {
|
||||
api 'com.zhidao.libyuv:libyuv:1.0.1.0'
|
||||
implementation 'com.zhidao.ptech:connsvr-protoco:0.1.23'
|
||||
implementation 'com.google.protobuf:protobuf-java:3.5.1'
|
||||
implementation rootProject.ext.dependencies.rxjava
|
||||
implementation rootProject.ext.dependencies.rxandroid
|
||||
|
||||
if (Boolean.valueOf(RELEASE)) {
|
||||
implementation "com.mogo.cloud:network:${MOGO_NETWORK_VERSION}"
|
||||
|
||||
@@ -367,7 +367,9 @@ public class MoGoLiveManager {
|
||||
* 退出房间
|
||||
*/
|
||||
private void logOutRoom() {
|
||||
mExpressEngine.logoutRoom(currentRoomId);
|
||||
if (!TextUtils.isEmpty(currentRoomId)) {
|
||||
mExpressEngine.logoutRoom(currentRoomId);
|
||||
}
|
||||
mExpressEngine.enableCustomVideoCapture(false, customVideoCaptureConfig, ZegoPublishChannel.MAIN);
|
||||
mExpressEngine.setEventHandler(null);
|
||||
}
|
||||
@@ -401,7 +403,9 @@ public class MoGoLiveManager {
|
||||
* 停止直播
|
||||
*/
|
||||
public void stopLive() {
|
||||
mExpressEngine.stopPlayingStream(currentStreamId);
|
||||
if (!TextUtils.isEmpty(currentRoomId)) {
|
||||
mExpressEngine.stopPlayingStream(currentStreamId);
|
||||
}
|
||||
stopPreview();
|
||||
logOutRoom();
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import android.app.Application;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.mogo.cloud.live.constant.LiveConstant;
|
||||
import com.mogo.cloud.live.listener.ILiveProgressListener;
|
||||
import com.mogo.cloud.live.listener.IRequestLiveListener;
|
||||
import com.mogo.cloud.live.model.BaseData;
|
||||
import com.mogo.cloud.live.model.LivePush;
|
||||
@@ -17,9 +16,12 @@ import com.mogo.utils.logger.Logger;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import rx.Observer;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.schedulers.Schedulers;
|
||||
import io.reactivex.Observer;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.annotations.NonNull;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
|
||||
/**
|
||||
* 请求直播管理类
|
||||
@@ -51,29 +53,34 @@ public class RequestLiveManager {
|
||||
String sn = MoGoAiCloudClient.getInstance().getAiCloudClientConfig().getSn();
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("sn", sn);
|
||||
map.put("type", gson.toJson(livePush));
|
||||
map.put("data", gson.toJson(livePush));
|
||||
liveApiServer.getVehicleHeadLive(map)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<BaseData>() {
|
||||
@Override
|
||||
public void onCompleted() {
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
if(requestLiveListener != null){
|
||||
public void onNext(@NonNull BaseData baseData) {
|
||||
if (requestLiveListener != null) {
|
||||
requestLiveListener.onSuccess();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
if (requestLiveListener != null) {
|
||||
requestLiveListener.onError(e);
|
||||
}
|
||||
Logger.e(LiveConstant.TAG, "requestVehicleHeadLive exception : " + e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(BaseData baseData) {
|
||||
if(requestLiveListener != null){
|
||||
requestLiveListener.onSuccess();
|
||||
}
|
||||
public void onComplete() {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -6,13 +6,13 @@ import com.mogo.cloud.live.model.StartCarAlarmInfo;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import okhttp3.RequestBody;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.FieldMap;
|
||||
import retrofit2.http.FormUrlEncoded;
|
||||
import retrofit2.http.Headers;
|
||||
import retrofit2.http.POST;
|
||||
import rx.Observable;
|
||||
|
||||
/**
|
||||
* 直播功能使用到的接口
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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() 回调时机 前后顺序
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user