Merge branch 'hj' into dev2_aiSdk

This commit is contained in:
liujing
2021-02-25 11:46:11 +08:00
4 changed files with 38 additions and 75 deletions

View File

@@ -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<V2XPushMessageEntity> v2XMessageEntity =
TestOnLineCarUtils.getV2XScenarioFatigueDrivingData();

View File

@@ -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<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();
}
}
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<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);
MoGoAiCloudTrafficLive.destroyLive();
} catch (Exception e) {
e.printStackTrace();
}

View File

@@ -10,7 +10,7 @@
<SurfaceView
android:id="@+id/surfaceView"
android:layout_width="match_parent"
android:background="#003F4057"
android:background="@drawable/v2x_bg_video_tip_vr"
android:layout_height="@dimen/module_v2x_event_see_live_window_height"
android:gravity="center" />

View File

@@ -280,6 +280,20 @@
android:textSize="@dimen/dp_22"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<Button
android:id="@+id/btnFrontCarLiveEvent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/dp_10"
android:layout_marginBottom="@dimen/dp_10"
android:background="#C6BE2C"
android:padding="@dimen/dp_10"
android:text="查看前车直播"
android:textColor="#FFFFFF"
android:textSize="@dimen/dp_22"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</com.google.android.flexbox.FlexboxLayout>
<com.google.android.flexbox.FlexboxLayout