From a903d6c225226b6f2191307d0d93def0ab0e249f Mon Sep 17 00:00:00 2001 From: lixiaopeng Date: Tue, 23 Feb 2021 19:34:28 +0800 Subject: [PATCH 1/3] opt upload --- .idea/gradle.xml | 1 + .../service/CarCorderController.kt | 90 +++++++++---------- 2 files changed, 46 insertions(+), 45 deletions(-) diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 83405b8de1..4ff10f68a5 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -91,6 +91,7 @@ diff --git a/libraries/tanlulib/src/main/java/com/zhidao/roadcondition/service/CarCorderController.kt b/libraries/tanlulib/src/main/java/com/zhidao/roadcondition/service/CarCorderController.kt index 159f420e5c..c64ffaec9a 100644 --- a/libraries/tanlulib/src/main/java/com/zhidao/roadcondition/service/CarCorderController.kt +++ b/libraries/tanlulib/src/main/java/com/zhidao/roadcondition/service/CarCorderController.kt @@ -170,7 +170,7 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { // mFromType // ) - getInfo("", "", mLongitude, mLatitude, mType, 1.0f, "", "", 1, mFromType, CarCorderController.mainInfoId)?.let { uploadRoadInfo(it) } + getInfo("", mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 1, mFromType, CarCorderController.mainInfoId)?.let { uploadRoadInfo(it) } //地图上打点 taskAsync(3_000) { @@ -213,7 +213,7 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { // mFromType // ) - getInfo("", "", mLongitude, mLatitude, mType, 1.0f, "", "", 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } + getInfo("", mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } } @@ -259,7 +259,7 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { // mLatitude, mSpeed) if (photoPath != null) { - getInfo(photoPath, "", mLongitude, mLatitude, mType, 1.0f, "", "", 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } + getInfo(photoPath, mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } } } else { @@ -283,7 +283,7 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { // ) if (photoPath != null) { - getInfo(photoPath, "", mLongitude, mLatitude, mType, 1.0f, "", "", 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } + getInfo(photoPath, mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } } } } @@ -303,7 +303,7 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { // ) if (photoPath != null) { - getInfo(photoPath, "", mLongitude, mLatitude, mType, 1.0f, "", "", 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } + getInfo(photoPath, mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } } } @@ -343,13 +343,11 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { entity?.let { if (it.isCustom) { -// compressVideo(videoPath, thumbnailPath, it) - getInfo(videoPath, "", mLongitude, mLatitude, mType, 1.0f, "", "", 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } + compressVideo(videoPath, thumbnailPath, it) } else if (entity.fromType in STRATEGY_UPLOAD_TYPE_ARRAY) { // 属于策略上报 -// compressVideo(videoPath, thumbnailPath, it) - getInfo(videoPath, "", mLongitude, mLatitude, mType, 1.0f, "", "", 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } + compressVideo(videoPath, thumbnailPath, it) } else { Log.d( @@ -360,16 +358,14 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { Log.d(TAG, "onTakeVideoSuccess 111 abs =" + (abs(minSpeedVideo) / 3.6f)) if (speed >= (abs(minSpeedVideo) / 3.6f)) { //获取视频以及缩略图成功,开始上报 -// compressVideo(videoPath, thumbnailPath, it) - getInfo(videoPath, "", mLongitude, mLatitude, mType, 1.0f, "", "", 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } + compressVideo(videoPath, thumbnailPath, it) } } if (minSpeedVideo > 0 && maxSpeedVideo > 0) { Log.d(TAG, "onTakeVideoSuccess minSpeedVideo > 0 -- speed = $speed") if ((speed >= (minSpeedVideo / 3.6f)) && speed <= (maxSpeedVideo / 3.6f)) { -// compressVideo(videoPath, thumbnailPath, it) - getInfo(videoPath, "", mLongitude, mLatitude, mType, 1.0f, "", "", 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } + compressVideo(videoPath, thumbnailPath, it) } else { } } else { @@ -414,7 +410,7 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { // mFromType // ) - getInfo("", "", mLongitude, mLatitude, mType, 1.0f, "", "", 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } + getInfo("", mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } //地图上打点 taskAsync(3_000) { @@ -429,24 +425,24 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { /** * 压缩视频并且上传 */ -// private fun compressVideo(videoPath: String, thumbnailPath: String, entity: TakeEntity) { -// Log.d( -// TAG, -// "outputVideoPath = " + outputVideoPath + ">> videoPath=" + videoPath + " isCustom = ${entity.isCustom}" -// ) -// val startTime = System.currentTimeMillis() -// Thread(Runnable { -// try { -// VideoProcessor.processor(AbsMogoApplication.getApp().applicationContext) -// .input(videoPath) -// .output(outputVideoPath) -// .removeAudio(true) -// .outWidth(1920) -// .outHeight(1080) -// .bitrate(2000 * 1024) -// .frameRate(25) -// .process() -// Log.d(TAG, "compress cost time =" + (System.currentTimeMillis() - startTime)) + private fun compressVideo(videoPath: String, thumbnailPath: String, entity: TakeEntity) { + Log.d( + TAG, + "outputVideoPath = " + outputVideoPath + ">> videoPath=" + videoPath + " isCustom = ${entity.isCustom}" + ) + val startTime = System.currentTimeMillis() + Thread(Runnable { + try { + VideoProcessor.processor(AbsMogoApplication.getApp().applicationContext) + .input(videoPath) + .output(outputVideoPath) + .removeAudio(true) + .outWidth(1920) + .outHeight(1080) + .bitrate(2000 * 1024) + .frameRate(25) + .process() + Log.d(TAG, "compress cost time =" + (System.currentTimeMillis() - startTime)) // CosStatusController().uploadFile( // mutableListOf(outputVideoPath, thumbnailPath), // entity, @@ -457,17 +453,19 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { // mLatitude, // mSpeed // ) -// -// //删除压缩前的视频 -// deletePicFile(videoPath) -// } catch (e: Exception) { -// Log.e(TAG, "compressVideo e = $e") -// //删除压缩前的视频 -// deletePicFile(videoPath) -// e.printStackTrace() -// } -// }).start() -// } + + getInfo(outputVideoPath, mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } + + //删除压缩前的视频 + deletePicFile(videoPath) + } catch (e: Exception) { + Log.e(TAG, "compressVideo e = $e") + //删除压缩前的视频 + deletePicFile(videoPath) + e.printStackTrace() + } + }).start() + } /** * 上报路况的视频和图片 @@ -475,7 +473,9 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { fun uploadRoadInfo(info: UploadInfo) { MogoUploadManager.getInstance(AbsMogoApplication.getApp().applicationContext).uploadInfo(info, object : ITanluUploadCallback { override fun onSuccess(result: BaseData) { - + if (result != null) { + Log.d(TAG, "result =" + result.result); + } } override fun onFailure(code: Int) { @@ -531,7 +531,7 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { // mFromType // ) - getInfo("", "", mLongitude, mLatitude, mType, 1.0f, "", "", 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } + getInfo("", mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } } From 7d994c1937aa4fe104945e0a3508705921ffc186 Mon Sep 17 00:00:00 2001 From: liujing Date: Tue, 23 Feb 2021 19:46:07 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E7=9B=B4=E6=92=AD=E6=8B=89=E6=B5=81?= =?UTF-8?q?=E6=8D=A2zego->view=E6=B7=BB=E5=8A=A0=20=20=E5=BE=85=E9=AA=8C?= =?UTF-8?q?=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/mogo-module-v2x/build.gradle | 1 + .../module/v2x/view/CarZegoLiveVideoView.java | 272 ++++++++++++++++++ .../res/layout/view_video_layout_see_live.xml | 10 +- 3 files changed, 281 insertions(+), 2 deletions(-) create mode 100644 modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/view/CarZegoLiveVideoView.java diff --git a/modules/mogo-module-v2x/build.gradle b/modules/mogo-module-v2x/build.gradle index 2eaadb3a28..b84e556603 100644 --- a/modules/mogo-module-v2x/build.gradle +++ b/modules/mogo-module-v2x/build.gradle @@ -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 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 new file mode 100644 index 0000000000..99e264edaf --- /dev/null +++ b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/view/CarZegoLiveVideoView.java @@ -0,0 +1,272 @@ +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.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.voice.V2XVoiceCallbackListener; +import com.mogo.module.v2x.voice.V2XVoiceConstants; +import com.mogo.module.v2x.voice.V2XVoiceManager; +import com.mogo.utils.logger.Logger; + +import static com.mogo.module.v2x.V2XConst.MODULE_NAME; + +/** + * @author liujing + * @description 描述 + * @since: 2021/2/23 + */ +public class CarZegoLiveVideoView extends RoundLayout { + private SurfaceView mTxcVideoView; + private ProgressBar mLoading; + // private TXLivePlayer mLivePlayer; + 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(Context context) { + this(context, 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); + //mPlayerView 即 step1 中添加的界面 view + mTxcVideoView = findViewById(R.id.surface); +// //创建 player 对象 +// mLivePlayer = new TXLivePlayer(context); +// //关键 player 对象与界面 view +// mLivePlayer.setPlayerView(mTxcVideoView); +// mLivePlayer.setMute(true); +// mLivePlayer.enableHardwareDecode(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 (mTxcVideoView != 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(); + } + } + + @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 (mTxcVideoView != null) { +// MoGoAiCloudTrafficLive.viewVehicleHeadLive(this.getApplication(), liveSn, surfaceView, this); +// mLivePlayer.startPlay(carLiveInfo.getVideoUrl(), TXLivePlayer.PLAY_TYPE_LIVE_RTMP); +// mLivePlayer.setPlayListener(new ITXLivePlayListener() { +// @Override +// public void onPlayEvent(int event, Bundle bundle) { +// Logger.w(MODULE_NAME, "播放器:onPlayEvent==" + event + "===bundle===" + bundle); +// if (event == TXLiveConstants.PLAY_EVT_PLAY_LOADING) { +// mLoading.setVisibility(VISIBLE); +// mClLoadError.setVisibility(GONE); +// } else if (event == TXLiveConstants.PLAY_EVT_PLAY_BEGIN) { +// refreshStatusToListener(true); +// mLoading.setVisibility(GONE); +// mClLoadError.setVisibility(GONE); +// } else if (event < 0) { +// 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); +// } +// } +// +// @Override +// public void onNetStatus(Bundle bundle) { +// //Logger.w(MODULE_NAME, "播放器:onNetStatus===bundle===" + bundle); +// } +// }); + } + } + + // 刷新直播心跳 + 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, "心跳:关闭直播..."); + // 暂停 +// mLivePlayer.pause(); +// // true 代表清除最后一帧画面 +// mLivePlayer.stopPlay(true); +// mTxcVideoView.onDestroy(); + // 停止推流 + 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); + } 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); + } +} 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 0ad6257f83..303b339fe0 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 @@ -7,8 +7,14 @@ android:background="@color/live_video_background_color" app:roundLayoutRadius="@dimen/dp_20"> - + + + + + + From 874e9f80d641308b1458fb8346d79504409ecbcb Mon Sep 17 00:00:00 2001 From: liujing Date: Tue, 23 Feb 2021 19:50:54 +0800 Subject: [PATCH 3/3] =?UTF-8?q?Revert=20"=E7=9B=B4=E6=92=AD=E6=8B=89?= =?UTF-8?q?=E6=B5=81=E6=8D=A2zego->view=E6=B7=BB=E5=8A=A0=20=20=E5=BE=85?= =?UTF-8?q?=E9=AA=8C=E8=AF=81"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 7d994c1937aa4fe104945e0a3508705921ffc186. --- modules/mogo-module-v2x/build.gradle | 1 - .../module/v2x/view/CarZegoLiveVideoView.java | 272 ------------------ .../res/layout/view_video_layout_see_live.xml | 10 +- 3 files changed, 2 insertions(+), 281 deletions(-) delete mode 100644 modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/view/CarZegoLiveVideoView.java diff --git a/modules/mogo-module-v2x/build.gradle b/modules/mogo-module-v2x/build.gradle index b84e556603..2eaadb3a28 100644 --- a/modules/mogo-module-v2x/build.gradle +++ b/modules/mogo-module-v2x/build.gradle @@ -69,7 +69,6 @@ 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 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 deleted file mode 100644 index 99e264edaf..0000000000 --- a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/view/CarZegoLiveVideoView.java +++ /dev/null @@ -1,272 +0,0 @@ -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.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.voice.V2XVoiceCallbackListener; -import com.mogo.module.v2x.voice.V2XVoiceConstants; -import com.mogo.module.v2x.voice.V2XVoiceManager; -import com.mogo.utils.logger.Logger; - -import static com.mogo.module.v2x.V2XConst.MODULE_NAME; - -/** - * @author liujing - * @description 描述 - * @since: 2021/2/23 - */ -public class CarZegoLiveVideoView extends RoundLayout { - private SurfaceView mTxcVideoView; - private ProgressBar mLoading; - // private TXLivePlayer mLivePlayer; - 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(Context context) { - this(context, 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); - //mPlayerView 即 step1 中添加的界面 view - mTxcVideoView = findViewById(R.id.surface); -// //创建 player 对象 -// mLivePlayer = new TXLivePlayer(context); -// //关键 player 对象与界面 view -// mLivePlayer.setPlayerView(mTxcVideoView); -// mLivePlayer.setMute(true); -// mLivePlayer.enableHardwareDecode(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 (mTxcVideoView != 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(); - } - } - - @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 (mTxcVideoView != null) { -// MoGoAiCloudTrafficLive.viewVehicleHeadLive(this.getApplication(), liveSn, surfaceView, this); -// mLivePlayer.startPlay(carLiveInfo.getVideoUrl(), TXLivePlayer.PLAY_TYPE_LIVE_RTMP); -// mLivePlayer.setPlayListener(new ITXLivePlayListener() { -// @Override -// public void onPlayEvent(int event, Bundle bundle) { -// Logger.w(MODULE_NAME, "播放器:onPlayEvent==" + event + "===bundle===" + bundle); -// if (event == TXLiveConstants.PLAY_EVT_PLAY_LOADING) { -// mLoading.setVisibility(VISIBLE); -// mClLoadError.setVisibility(GONE); -// } else if (event == TXLiveConstants.PLAY_EVT_PLAY_BEGIN) { -// refreshStatusToListener(true); -// mLoading.setVisibility(GONE); -// mClLoadError.setVisibility(GONE); -// } else if (event < 0) { -// 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); -// } -// } -// -// @Override -// public void onNetStatus(Bundle bundle) { -// //Logger.w(MODULE_NAME, "播放器:onNetStatus===bundle===" + bundle); -// } -// }); - } - } - - // 刷新直播心跳 - 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, "心跳:关闭直播..."); - // 暂停 -// mLivePlayer.pause(); -// // true 代表清除最后一帧画面 -// mLivePlayer.stopPlay(true); -// mTxcVideoView.onDestroy(); - // 停止推流 - 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); - } 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); - } -} 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 303b339fe0..0ad6257f83 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 @@ -7,14 +7,8 @@ android:background="@color/live_video_background_color" app:roundLayoutRadius="@dimen/dp_20"> - - - - - - -