[add]前车直播替换zego ps:获取失败
This commit is contained in:
@@ -69,6 +69,7 @@ dependencies {
|
||||
|
||||
kapt rootProject.ext.dependencies.roomAnnotationProcessor
|
||||
kapt rootProject.ext.dependencies.aroutercompiler
|
||||
api rootProject.ext.dependencies.mogoaicloudtrafficlive
|
||||
|
||||
if (Boolean.valueOf(RELEASE)) {
|
||||
implementation rootProject.ext.dependencies.mogomap
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.mogo.module.v2x.entity.net.V2XLiveCrossRoad;
|
||||
import com.mogo.module.v2x.network.V2XRefreshCallback;
|
||||
import com.mogo.module.v2x.network.V2XRefreshModel;
|
||||
import com.mogo.module.v2x.utils.ToastUtils;
|
||||
import com.mogo.module.v2x.view.V2XCarLiveVideoView;
|
||||
import com.mogo.module.v2x.voice.V2XVoiceCallbackListener;
|
||||
import com.mogo.module.v2x.voice.V2XVoiceManager;
|
||||
import com.mogo.service.statusmanager.StatusDescriptor;
|
||||
@@ -52,6 +53,7 @@ public class V2XVoiceCallLiveBiz {
|
||||
}
|
||||
|
||||
private Context mContext;
|
||||
private V2XVoiceCallLiveScenario mV2XVoiceCallLiveScenario = new V2XVoiceCallLiveScenario();
|
||||
|
||||
//语音词指令 查看前车视频回调
|
||||
private V2XVoiceCallbackListener v2XVoiceCallbackFrontLiveCarListener = (command, intent) -> {
|
||||
@@ -107,8 +109,7 @@ public class V2XVoiceCallLiveBiz {
|
||||
return;
|
||||
}
|
||||
V2XMessageEntity<V2XPushMessageEntity> v2XMessageEntity = buildCallLiveParams(liveCarSn, null);
|
||||
// V2XVoiceCallLiveScenario.getInstance().setV2XWindow(new V2XVoiceCallLiveCarWindow());
|
||||
// V2XVoiceCallLiveScenario.getInstance().init(v2XMessageEntity);
|
||||
mV2XVoiceCallLiveScenario.init(v2XMessageEntity);
|
||||
}
|
||||
|
||||
public void getOpenRoadCameraLive() {
|
||||
|
||||
@@ -6,7 +6,6 @@ import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.mogo.module.common.entity.MarkerCarInfo;
|
||||
@@ -16,7 +15,7 @@ import com.mogo.module.v2x.V2XServiceManager;
|
||||
import com.mogo.module.v2x.listener.V2XWindowStatusListener;
|
||||
import com.mogo.module.v2x.scenario.scene.V2XBasWindow;
|
||||
import com.mogo.module.v2x.scenario.view.IV2XWindow;
|
||||
import com.mogo.module.v2x.view.V2XCarLiveVideoView;
|
||||
import com.mogo.module.v2x.view.CarZegoLiveVideoView;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
import static com.mogo.module.v2x.V2XConst.MODULE_NAME;
|
||||
@@ -24,7 +23,7 @@ import static com.mogo.module.v2x.V2XConst.MODULE_NAME;
|
||||
public class V2XVoiceCallLiveCarWindow extends V2XBasWindow
|
||||
implements IV2XWindow<V2XPushMessageEntity> {
|
||||
|
||||
private V2XCarLiveVideoView mV2XCarLiveVideoView;
|
||||
private CarZegoLiveVideoView mV2XCarLiveVideoView;
|
||||
private TextView tvCountDown;
|
||||
private ImageView ivVideoPlayingSign;
|
||||
private boolean isVideoPlay = false;
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.mogo.module.v2x.V2XConst;
|
||||
import com.mogo.module.v2x.V2XServiceManager;
|
||||
import com.mogo.module.v2x.scenario.impl.AbsV2XScenario;
|
||||
import com.mogo.module.v2x.utils.V2XUtils;
|
||||
import com.mogo.module.v2x.view.CarZegoLiveVideoView;
|
||||
import com.mogo.service.windowview.IMogoTopViewStatusListener;
|
||||
import com.mogo.utils.TipToast;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
@@ -25,7 +26,7 @@ import static com.mogo.module.v2x.V2XConst.MODULE_NAME;
|
||||
public class V2XVoiceCallLiveScenario extends AbsV2XScenario<V2XPushMessageEntity> implements IMogoTopViewStatusListener {
|
||||
|
||||
public V2XVoiceCallLiveScenario() {
|
||||
|
||||
setV2XWindow(new V2XVoiceCallLiveCarWindow());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,261 @@
|
||||
package com.mogo.module.v2x.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.SurfaceView;
|
||||
import android.view.View;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.mogo.cloud.trafficlive.api.ITrafficLiveCallBack;
|
||||
import com.mogo.cloud.trafficlive.api.MoGoAiCloudTrafficLive;
|
||||
import com.mogo.commons.AbsMogoApplication;
|
||||
import com.mogo.commons.voice.AIAssist;
|
||||
import com.mogo.module.common.entity.MarkerCarInfo;
|
||||
import com.mogo.module.v2x.R;
|
||||
import com.mogo.module.v2x.V2XServiceManager;
|
||||
import com.mogo.module.v2x.entity.net.V2XLivePushVoRes;
|
||||
import com.mogo.module.v2x.network.V2XRefreshCallback;
|
||||
import com.mogo.module.v2x.utils.V2XUtils;
|
||||
import com.mogo.module.v2x.voice.V2XVoiceCallbackListener;
|
||||
import com.mogo.module.v2x.voice.V2XVoiceConstants;
|
||||
import com.mogo.module.v2x.voice.V2XVoiceManager;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.tencent.rtmp.ui.TXCloudVideoView;
|
||||
|
||||
import static com.mogo.module.v2x.V2XConst.MODULE_NAME;
|
||||
|
||||
/**
|
||||
* @author liujing
|
||||
* @description 描述
|
||||
* @since: 2021/2/23
|
||||
*/
|
||||
public class CarZegoLiveVideoView extends RoundLayout {
|
||||
private SurfaceView mSurfaceView;
|
||||
private ProgressBar mLoading;
|
||||
private ConstraintLayout mClLoadError;
|
||||
private TextView mTvRefreshButton;
|
||||
|
||||
private MarkerCarInfo.CarLiveInfo mCarLiveInfo;
|
||||
// 重新刷新直播流
|
||||
private V2XVoiceCallbackListener v2XVoiceCallbackRefreshListener = new V2XVoiceCallbackListener() {
|
||||
@Override
|
||||
public void onCallback(String command, Intent intent) {
|
||||
mLoading.setVisibility(VISIBLE);
|
||||
mClLoadError.setVisibility(GONE);
|
||||
if (mCarLiveInfo != null) {
|
||||
startLive(mCarLiveInfo);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public CarZegoLiveVideoView() {
|
||||
this(V2XServiceManager.getContext(), null);
|
||||
}
|
||||
|
||||
public CarZegoLiveVideoView(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public CarZegoLiveVideoView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
initView(context);
|
||||
}
|
||||
|
||||
private void initView(Context context) {
|
||||
LayoutInflater.from(context)
|
||||
.inflate(R.layout.view_video_layout_see_live, this);
|
||||
mSurfaceView = findViewById(R.id.surfaceView);
|
||||
mSurfaceView.setZOrderOnTop(true);
|
||||
mLoading = findViewById(R.id.loading);
|
||||
mLoading.getIndeterminateDrawable().setColorFilter(ContextCompat.getColor(context, R.color.live_video_progress_bar_loading_color), PorterDuff.Mode.MULTIPLY);
|
||||
|
||||
mClLoadError = findViewById(R.id.clLoadError);
|
||||
mTvRefreshButton = findViewById(R.id.tvRefreshButton);
|
||||
mTvRefreshButton.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mLoading.setVisibility(VISIBLE);
|
||||
mClLoadError.setVisibility(GONE);
|
||||
if (mCarLiveInfo != null) {
|
||||
startLive(mCarLiveInfo);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置直播信息
|
||||
*/
|
||||
public void setCarLiveInfo(MarkerCarInfo.CarLiveInfo carLiveInfo) {
|
||||
mCarLiveInfo = carLiveInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始直播
|
||||
*
|
||||
* @param carLiveInfo 要直播的车机,如果没有直播的地址需要重新获取最新的直播地址
|
||||
*/
|
||||
public void startLive(MarkerCarInfo.CarLiveInfo carLiveInfo) {
|
||||
// 进行直播播放
|
||||
if (mSurfaceView != null
|
||||
&& carLiveInfo != null) {
|
||||
if (!TextUtils.isEmpty(carLiveInfo.getVideoUrl())) {
|
||||
AIAssist.getInstance(AbsMogoApplication.getApp()).speakTTSVoice(AbsMogoApplication.getApp().getString(R.string.v2x_voice_see_front_car_live));
|
||||
setCarLiveInfo(carLiveInfo);
|
||||
playLiveVideo(carLiveInfo);
|
||||
}
|
||||
// 根据SN重新获取直播流地址
|
||||
else {
|
||||
V2XServiceManager
|
||||
.getV2XRefreshModel()
|
||||
.livePush(new V2XRefreshCallback<V2XLivePushVoRes>() {
|
||||
@Override
|
||||
public void onSuccess(V2XLivePushVoRes result) {
|
||||
AIAssist.getInstance(AbsMogoApplication.getApp()).speakTTSVoice(AbsMogoApplication.getApp().getString(R.string.v2x_voice_see_front_car_live));
|
||||
mClLoadError.setVisibility(GONE);
|
||||
mClLoadError.setVisibility(GONE);
|
||||
try {
|
||||
MarkerCarInfo.CarLiveInfo carRealLiveInfo = new MarkerCarInfo.CarLiveInfo();
|
||||
carRealLiveInfo.setVideoUrl(result.getResult().getPlayUrl().getRtmp());
|
||||
carRealLiveInfo.setVideoSn(carLiveInfo.getVideoSn());
|
||||
carRealLiveInfo.setVideoChannel(result.getResult().getVideoChannel());
|
||||
setCarLiveInfo(carLiveInfo);
|
||||
playLiveVideo(carRealLiveInfo);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(String msg) {
|
||||
Logger.e(MODULE_NAME, "播放器:" + msg);
|
||||
AIAssist.getInstance(AbsMogoApplication.getApp()).speakTTSVoice(AbsMogoApplication.getApp().getString(R.string.v2x_voice_see_front_car_live_error));
|
||||
mLoading.setVisibility(GONE);
|
||||
mClLoadError.setVisibility(VISIBLE);
|
||||
}
|
||||
}, carLiveInfo.getVideoSn(), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 播放直播流,且开始心跳
|
||||
*/
|
||||
private void playLiveVideo(MarkerCarInfo.CarLiveInfo carLiveInfo) {
|
||||
startHeartLive(carLiveInfo);
|
||||
if (mSurfaceView != null) {
|
||||
MoGoAiCloudTrafficLive.viewVehicleHeadLive(AbsMogoApplication.getApp(), carLiveInfo.getVideoSn(), mSurfaceView, new ITrafficLiveCallBack() {
|
||||
@Override
|
||||
public void onLive() {
|
||||
mLoading.setVisibility(VISIBLE);
|
||||
mClLoadError.setVisibility(GONE);
|
||||
refreshStatusToListener(true);
|
||||
mLoading.setVisibility(GONE);
|
||||
mClLoadError.setVisibility(GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisConnect() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String errorMsg) {
|
||||
refreshStatusToListener(false);
|
||||
AIAssist.getInstance(V2XUtils.getApp()).speakTTSVoice("直播获取识败,可以对我说重试", null);
|
||||
stopLive(mCarLiveInfo);
|
||||
mLoading.setVisibility(GONE);
|
||||
mClLoadError.setVisibility(VISIBLE);
|
||||
// 注册语音交互
|
||||
V2XVoiceManager.INSTANCE
|
||||
.registerWakeCmd(V2XVoiceConstants.COMMAND_ZHIDAO_V2X_REFRESH_CAR_LIVE,
|
||||
v2XVoiceCallbackRefreshListener)
|
||||
.registerUnWakeVoice(V2XVoiceConstants.COMMAND_ZHIDAO_V2X_REFRESH_LIVE_UN_WAKEUP,
|
||||
v2XVoiceCallbackRefreshListener);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 刷新直播心跳
|
||||
private void startHeartLive(MarkerCarInfo.CarLiveInfo carLiveInfo) {
|
||||
try {
|
||||
if (!TextUtils.isEmpty(carLiveInfo.getVideoSn())
|
||||
&& !TextUtils.isEmpty(carLiveInfo.getVideoChannel())) {
|
||||
V2XServiceManager
|
||||
.getV2XRefreshModel()
|
||||
.refreshHeartBeat(carLiveInfo.getVideoSn(),
|
||||
carLiveInfo.getVideoChannel(),
|
||||
null);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void stopLive(MarkerCarInfo.CarLiveInfo carLiveInfo) {
|
||||
try {
|
||||
Logger.w(MODULE_NAME, "心跳:关闭直播...");
|
||||
// 暂停
|
||||
MoGoAiCloudTrafficLive.stopLive(carLiveInfo.getVideoSn());
|
||||
// 停止推流
|
||||
V2XServiceManager
|
||||
.getV2XRefreshModel()
|
||||
.livePush(new V2XRefreshCallback<V2XLivePushVoRes>() {
|
||||
@Override
|
||||
public void onSuccess(V2XLivePushVoRes result) {
|
||||
Logger.d(MODULE_NAME, "播放器:" + result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(String msg) {
|
||||
Logger.e(MODULE_NAME, "播放器:" + msg);
|
||||
}
|
||||
}, carLiveInfo.getVideoSn(), 1);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
if (mCarLiveInfo != null) {
|
||||
startLive(mCarLiveInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
stopLive(mCarLiveInfo);
|
||||
mLoading.setVisibility(VISIBLE);
|
||||
// 反注册语音交互
|
||||
V2XVoiceManager.INSTANCE
|
||||
.unRegisterWakeCmd(V2XVoiceConstants.COMMAND_ZHIDAO_V2X_REFRESH_CAR_LIVE)
|
||||
.unRegisterUnWakeVoice(V2XVoiceConstants.COMMAND_ZHIDAO_V2X_REFRESH_LIVE_UN_WAKEUP);
|
||||
super.onDetachedFromWindow();
|
||||
}
|
||||
|
||||
private void refreshStatusToListener(boolean videoPlaying) {
|
||||
if (onVideoStatusChange != null) {
|
||||
onVideoStatusChange.videoPlaying(videoPlaying);
|
||||
}
|
||||
}
|
||||
|
||||
private V2XCarLiveVideoView.OnVideoStatusChange onVideoStatusChange;
|
||||
|
||||
public void addOnVideoStatusChangeListener(V2XCarLiveVideoView.OnVideoStatusChange onVideoStatusChange) {
|
||||
this.onVideoStatusChange = onVideoStatusChange;
|
||||
}
|
||||
|
||||
public interface OnVideoStatusChange {
|
||||
void videoPlaying(boolean videoPlaying);
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@
|
||||
android:layout_centerInParent="true"
|
||||
android:src="@drawable/v2x_icon_live_logo" />
|
||||
|
||||
<com.mogo.module.v2x.view.V2XCarLiveVideoView
|
||||
<com.mogo.module.v2x.view.CarZegoLiveVideoView
|
||||
android:id="@+id/videoPlayer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/module_v2x_event_see_live_window_height"
|
||||
|
||||
@@ -7,9 +7,10 @@
|
||||
android:background="@color/live_video_background_color"
|
||||
app:roundLayoutRadius="@dimen/dp_20">
|
||||
|
||||
<com.tencent.rtmp.ui.TXCloudVideoView
|
||||
android:id="@+id/txcVideoView"
|
||||
<SurfaceView
|
||||
android:id="@+id/surfaceView"
|
||||
android:layout_width="match_parent"
|
||||
android:background="#003F4057"
|
||||
android:layout_height="@dimen/module_v2x_event_see_live_window_height"
|
||||
android:gravity="center" />
|
||||
|
||||
|
||||
Reference in New Issue
Block a user