From b80b352b10bf3852de5eec8d0824be190a1ab49e Mon Sep 17 00:00:00 2001 From: liujing Date: Thu, 25 Feb 2021 11:45:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=97=A0=E7=94=A8=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scene/test/V2XTestConsoleWindow.java | 6 ++ .../module/v2x/view/CarZegoLiveVideoView.java | 91 ++++--------------- .../res/layout/view_video_layout_see_live.xml | 2 +- .../main/res/layout/window_test_console.xml | 14 +++ 4 files changed, 38 insertions(+), 75 deletions(-) diff --git a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/test/V2XTestConsoleWindow.java b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/test/V2XTestConsoleWindow.java index 682e52f760..6896982462 100644 --- a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/test/V2XTestConsoleWindow.java +++ b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/test/V2XTestConsoleWindow.java @@ -51,6 +51,7 @@ public class V2XTestConsoleWindow extends ConstraintLayout { private Button mBtnTriggerPushEvent; private Button mBtnTriggerPushLiveCarEvent; private Button mBtnTriggerAnimationEvent; + private Button mBtnbtnFrontCarLiveEvent; private Button mBtnTriggerFatigueDrivingEvent; private Button mBtnTriggerSeekHelpEvent; private Button mBtnTriggerParkEvent; @@ -112,6 +113,7 @@ public class V2XTestConsoleWindow extends ConstraintLayout { mBtnTriggerPushEvent = findViewById(R.id.btnTriggerPushEvent); mBtnTriggerPushLiveCarEvent = findViewById(R.id.btnTriggerPushLiveCarEvent); mBtnTriggerAnimationEvent = findViewById(R.id.btnTriggerAnimationEvent); + mBtnbtnFrontCarLiveEvent = findViewById(R.id.btnFrontCarLiveEvent); mBtnTriggerFatigueDrivingEvent = findViewById(R.id.btnTriggerFatigueDrivingEvent); mBtnTriggerSeekHelpEvent = findViewById(R.id.btnTriggerSeekHelpEvent); mBtnTriggerParkEvent = findViewById(R.id.btnTriggerParkEvent); @@ -236,6 +238,10 @@ public class V2XTestConsoleWindow extends ConstraintLayout { LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent); }); + mBtnbtnFrontCarLiveEvent.setOnClickListener(v->{ + + }); + mBtnTriggerFatigueDrivingEvent.setOnClickListener(v -> { V2XMessageEntity v2XMessageEntity = TestOnLineCarUtils.getV2XScenarioFatigueDrivingData(); diff --git a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/view/CarZegoLiveVideoView.java b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/view/CarZegoLiveVideoView.java index 5e1eb94ee1..143a3fa344 100644 --- a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/view/CarZegoLiveVideoView.java +++ b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/view/CarZegoLiveVideoView.java @@ -10,6 +10,7 @@ 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; @@ -37,6 +38,7 @@ import static com.mogo.module.v2x.V2XConst.MODULE_NAME; * @since: 2021/2/23 */ public class CarZegoLiveVideoView extends RoundLayout { + private static final String TAG = "CarZegoLiveVideoView"; private SurfaceView mSurfaceView; private ProgressBar mLoading; private ConstraintLayout mClLoadError; @@ -99,61 +101,31 @@ public class CarZegoLiveVideoView extends RoundLayout { /** * 开始直播 - * - * @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() { - @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(); - } - } + if (mSurfaceView != null && carLiveInfo != null) { + AIAssist.getInstance(AbsMogoApplication.getApp()).speakTTSVoice(AbsMogoApplication.getApp().getString(R.string.v2x_voice_see_front_car_live)); + playLiveVideo(carLiveInfo); + mClLoadError.setVisibility(GONE); + Logger.d(TAG, "startLive"); - @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); - } + } else { + AIAssist.getInstance(AbsMogoApplication.getApp()).speakTTSVoice(AbsMogoApplication.getApp().getString(R.string.v2x_voice_see_front_car_live_error)); + mLoading.setVisibility(GONE); + mClLoadError.setVisibility(VISIBLE); + Logger.d(TAG, "没有找到可直播车机"); } } /** - * 播放直播流,且开始心跳 + * 播放直播流 */ private void playLiveVideo(MarkerCarInfo.CarLiveInfo carLiveInfo) { - startHeartLive(carLiveInfo); if (mSurfaceView != null) { MoGoAiCloudTrafficLive.viewVehicleHeadLive(AbsMogoApplication.getApp(), carLiveInfo.getVideoSn(), mSurfaceView, new ITrafficLiveCallBack() { @Override public void onLive() { + Logger.d(TAG, "onLive"); mLoading.setVisibility(VISIBLE); mClLoadError.setVisibility(GONE); refreshStatusToListener(true); @@ -163,7 +135,7 @@ public class CarZegoLiveVideoView extends RoundLayout { @Override public void onDisConnect() { - + Logger.d(TAG, "失去连接onDisConnect"); } @Override @@ -184,41 +156,12 @@ public class CarZegoLiveVideoView extends RoundLayout { } } - // 刷新直播心跳 - 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, "心跳:关闭直播..."); + Logger.w(TAG, "心跳:关闭直播..."); // 暂停 MoGoAiCloudTrafficLive.stopLive(carLiveInfo.getVideoSn()); - // 停止推流 - V2XServiceManager - .getV2XRefreshModel() - .livePush(new V2XRefreshCallback() { - @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); + MoGoAiCloudTrafficLive.destroyLive(); } catch (Exception e) { e.printStackTrace(); } diff --git a/modules/mogo-module-v2x/src/main/res/layout/view_video_layout_see_live.xml b/modules/mogo-module-v2x/src/main/res/layout/view_video_layout_see_live.xml index e75175d07a..6a5a50343c 100644 --- a/modules/mogo-module-v2x/src/main/res/layout/view_video_layout_see_live.xml +++ b/modules/mogo-module-v2x/src/main/res/layout/view_video_layout_see_live.xml @@ -10,7 +10,7 @@ diff --git a/modules/mogo-module-v2x/src/main/res/layout/window_test_console.xml b/modules/mogo-module-v2x/src/main/res/layout/window_test_console.xml index 65c2618955..b9253925c9 100644 --- a/modules/mogo-module-v2x/src/main/res/layout/window_test_console.xml +++ b/modules/mogo-module-v2x/src/main/res/layout/window_test_console.xml @@ -280,6 +280,20 @@ android:textSize="@dimen/dp_22" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent" /> + +