[Update]增加api支持TextureView播放直播

This commit is contained in:
chenfufeng
2021-11-25 11:20:55 +08:00
parent ffb1ebbf54
commit 7f7e2b7f89
7 changed files with 108 additions and 21 deletions

View File

@@ -4,6 +4,7 @@ import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.SurfaceHolder; import android.view.SurfaceHolder;
import android.view.SurfaceView; import android.view.SurfaceView;
import android.view.TextureView;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
import android.widget.ToggleButton; import android.widget.ToggleButton;
@@ -38,7 +39,7 @@ public abstract class BaseLiveActivity extends AppCompatActivity {
protected SurfaceView surfacePreviewView; protected SurfaceView surfacePreviewView;
// 查看指定车机的画面 // 查看指定车机的画面
protected SurfaceView surfacePlayView; protected TextureView textureView;
// 查看直播按钮 // 查看直播按钮
protected ToggleButton liveToggleBtn; protected ToggleButton liveToggleBtn;
// 登录第二个房间的按钮 // 登录第二个房间的按钮
@@ -79,7 +80,7 @@ public abstract class BaseLiveActivity extends AppCompatActivity {
tvLiveStatus = findViewById(R.id.tvLiveStatus); tvLiveStatus = findViewById(R.id.tvLiveStatus);
surfacePlayView = findViewById(R.id.surfacePlayView); textureView = findViewById(R.id.textureView);
etLookRoomId = findViewById(R.id.etLookRoomId); etLookRoomId = findViewById(R.id.etLookRoomId);
liveToggleBtn = findViewById(R.id.liveToggleBtn); liveToggleBtn = findViewById(R.id.liveToggleBtn);
liveToggleBtn.setOnCheckedChangeListener((buttonView, isChecked) -> { liveToggleBtn.setOnCheckedChangeListener((buttonView, isChecked) -> {

View File

@@ -90,7 +90,7 @@ public class LivePlayAndPushActivity extends BaseLiveActivity
public void togglePlay(boolean isPlay) { public void togglePlay(boolean isPlay) {
if (isPlay) { if (isPlay) {
liveSn = etLookRoomId.getText().toString().trim(); liveSn = etLookRoomId.getText().toString().trim();
MoGoAiCloudTrafficLive.viewDesignativeVehicleLive(liveSn, surfacePlayView, this); MoGoAiCloudTrafficLive.viewDesignativeVehicleLive(liveSn, textureView, this);
} else { } else {
MoGoAiCloudTrafficLive.stopCarLive(liveSn); MoGoAiCloudTrafficLive.stopCarLive(liveSn);
} }
@@ -127,7 +127,7 @@ public class LivePlayAndPushActivity extends BaseLiveActivity
@Override @Override
public void onFirstFrame() { public void onFirstFrame() {
surfacePlayView.setVisibility(View.VISIBLE); textureView.setVisibility(View.VISIBLE);
Logger.d(TAG, "onFirstFrame"); Logger.d(TAG, "onFirstFrame");
} }

View File

@@ -11,12 +11,24 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="1" android:layout_weight="1"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/surfacePlayView" app:layout_constraintEnd_toStartOf="@+id/textureView"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<SurfaceView <!-- <SurfaceView-->
android:id="@+id/surfacePlayView" <!-- android:id="@+id/textureView"-->
<!-- android:layout_width="0dp"-->
<!-- android:layout_height="match_parent"-->
<!-- android:layout_weight="1"-->
<!-- app:layout_constraintBottom_toBottomOf="parent"-->
<!-- app:layout_constraintEnd_toEndOf="parent"-->
<!-- app:layout_constraintStart_toEndOf="@+id/surfacePreviewView"-->
<!-- app:layout_constraintTop_toTopOf="parent"-->
<!-- android:visibility="invisible"-->
<!-- />-->
<TextureView
android:id="@+id/textureView"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="1" android:layout_weight="1"
@@ -47,8 +59,8 @@
android:textColor="#FF5722" android:textColor="#FF5722"
android:textSize="25dp" android:textSize="25dp"
android:textStyle="bold" android:textStyle="bold"
app:layout_constraintEnd_toEndOf="@+id/surfacePlayView" app:layout_constraintEnd_toEndOf="@+id/textureView"
app:layout_constraintStart_toStartOf="@+id/surfacePlayView" app:layout_constraintStart_toStartOf="@+id/textureView"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
@@ -110,7 +122,7 @@
android:textColor="#000" android:textColor="#000"
app:layout_constraintBottom_toTopOf="@+id/liveToggleBtn" app:layout_constraintBottom_toTopOf="@+id/liveToggleBtn"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/surfacePlayView" /> app:layout_constraintStart_toStartOf="@+id/textureView" />
<ToggleButton <ToggleButton
android:id="@+id/tbLoginMultiRoom" android:id="@+id/tbLoginMultiRoom"

View File

@@ -4,6 +4,7 @@ import android.app.Application;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.SurfaceView; import android.view.SurfaceView;
import android.view.TextureView;
import com.mogo.cloud.live.listener.ILiveCurrentRoomStatusListener; import com.mogo.cloud.live.listener.ILiveCurrentRoomStatusListener;
import com.mogo.cloud.live.listener.ILiveMultiRoomStatusListener; import com.mogo.cloud.live.listener.ILiveMultiRoomStatusListener;
@@ -666,6 +667,18 @@ public class MoGoLiveManager {
} }
} }
public void startLive(TextureView textureView) {
Log.i(TAG, "尝试开始播放直播 startLive multiStreamId : " + mLiveStatusModel.getMultiStreamId());
if (!TextUtils.isEmpty(mLiveStatusModel.getMultiStreamId()) &&
mLiveStatusModel.getMultiStreamId().startsWith(STREAM_ID_PREFIX)) {
ZegoCanvas zegoCanvas = new ZegoCanvas(textureView);
zegoCanvas.viewMode = ZegoViewMode.SCALE_TO_FILL;
mExpressEngine.startPlayingStream(mLiveStatusModel.getMultiStreamId(), zegoCanvas);
} else {
Log.e(TAG, "直播ID有误请重试");
}
}
/** /**
* 停止播放直播 * 停止播放直播
*/ */

View File

@@ -33,25 +33,25 @@ SNAPSHOT_REPOSITORY_URL=http://nexus.zhidaoauto.com/repository/maven-snapshots/
USERNAME=xintai USERNAME=xintai
PASSWORD=xintai2018 PASSWORD=xintai2018
# 编译模式: false - 依赖本地版本, true - 依赖 maven 版本 # 编译模式: false - 依赖本地版本, true - 依赖 maven 版本
RELEASE=false RELEASE=true
# AI CLOUD 云平台 # AI CLOUD 云平台
# 工具类 # 工具类
MOGO_UTILS_VERSION=1.3.8 MOGO_UTILS_VERSION=1.3.9
# 网络请求 # 网络请求
MOGO_NETWORK_VERSION=1.3.8 MOGO_NETWORK_VERSION=1.3.9
# 网络DNS # 网络DNS
MOGO_HTTPDNS_VERSION=1.3.8 MOGO_HTTPDNS_VERSION=1.3.9
# 鉴权 # 鉴权
MOGO_PASSPORT_VERSION=1.3.8 MOGO_PASSPORT_VERSION=1.3.9
# 常链接 # 常链接
MOGO_SOCKET_VERSION=1.3.8 MOGO_SOCKET_VERSION=1.3.9
# 数据采集 # 数据采集
MOGO_REALTIME_VERSION=1.3.8 MOGO_REALTIME_VERSION=1.3.9
# 探路,道路事件发布,获取 # 探路,道路事件发布,获取
MOGO_TANLU_VERSION=1.3.8 MOGO_TANLU_VERSION=1.3.9
# 直播推流 # 直播推流
MOGO_LIVE_VERSION=1.3.8 MOGO_LIVE_VERSION=1.3.9
# 直播拉流 # 直播拉流
MOGO_TRAFFICLIVE_VERSION=1.3.8 MOGO_TRAFFICLIVE_VERSION=1.3.9
# 定位服务 # 定位服务
MOGO_LOCATION_VERSION=1.3.8 MOGO_LOCATION_VERSION=1.3.9

View File

@@ -1,6 +1,7 @@
package com.mogo.cloud.trafficlive.api; package com.mogo.cloud.trafficlive.api;
import android.view.SurfaceView; import android.view.SurfaceView;
import android.view.TextureView;
import com.elegant.log.simplelog.Logger; import com.elegant.log.simplelog.Logger;
import com.mogo.cloud.trafficlive.core.TrafficLiveCurrentManager; import com.mogo.cloud.trafficlive.core.TrafficLiveCurrentManager;
@@ -45,6 +46,16 @@ public class MoGoAiCloudTrafficLive {
} }
} }
public static void viewDesignativeVehicleLive(String liveSn, TextureView textureView, ITrafficCarLiveCallBack callBack) {
try {
TrafficLiveCurrentManager.getInstance().viewDesignativeVehicleLive(liveSn, textureView, callBack);
} catch (Exception e) {
Logger.e(TAG, " viewDesignativeVehicleLive error : " + e);
callBack.onError(e != null ? e.getMessage() : "check input param");
e.printStackTrace();
}
}
/** /**
* 查看前方路口直播 * 查看前方路口直播
* *

View File

@@ -2,6 +2,7 @@ package com.mogo.cloud.trafficlive.core;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.SurfaceView; import android.view.SurfaceView;
import android.view.TextureView;
import com.elegant.log.simplelog.Logger; import com.elegant.log.simplelog.Logger;
import com.mogo.cloud.live.listener.ILiveMultiRoomStatusListener; import com.mogo.cloud.live.listener.ILiveMultiRoomStatusListener;
@@ -74,6 +75,31 @@ public class TrafficLiveCurrentManager
}); });
} }
public void viewDesignativeVehicleLive(String liveSn, TextureView textureView, ITrafficCarLiveCallBack callBack) throws Exception {
if (callBack == null) {
throw new Exception("ITrafficLiveCallBack can not be null");
}
if (textureView == null) {
throw new Exception("SurfaceView can not be null");
}
if (TextUtils.isEmpty(liveSn)) {
throw new Exception("liveSn can not be null");
}
this.trafficLiveCallBack = callBack;
requestLiveManager.requestDesignativeVehicleLive(LIVE_TYPE_OPEN, liveSn, new IRequestLiveListener() {
@Override
public void onSuccess() {
onVehicleLiveSuccess(liveSn, textureView);
}
@Override
public void onError(Throwable e) {
onVehicleLiveError(e.getMessage());
}
});
}
public void viewDesignativeVehicleLive(String liveSn, SurfaceView surfaceView, ITrafficCarLiveCallBack callBack) throws Exception { public void viewDesignativeVehicleLive(String liveSn, SurfaceView surfaceView, ITrafficCarLiveCallBack callBack) throws Exception {
if (callBack == null) { if (callBack == null) {
throw new Exception("ITrafficLiveCallBack can not be null"); throw new Exception("ITrafficLiveCallBack can not be null");
@@ -99,6 +125,7 @@ public class TrafficLiveCurrentManager
}); });
} }
private void onVehicleLiveSuccess(String liveSn, SurfaceView surfaceView) { private void onVehicleLiveSuccess(String liveSn, SurfaceView surfaceView) {
if (TextUtils.isEmpty(liveSn)) { if (TextUtils.isEmpty(liveSn)) {
if (TrafficLiveCurrentManager.this.trafficLiveCallBack != null) { if (TrafficLiveCurrentManager.this.trafficLiveCallBack != null) {
@@ -122,6 +149,29 @@ public class TrafficLiveCurrentManager
} }
} }
private void onVehicleLiveSuccess(String liveSn, TextureView textureView) {
if (TextUtils.isEmpty(liveSn)) {
if (TrafficLiveCurrentManager.this.trafficLiveCallBack != null) {
TrafficLiveCurrentManager.this.trafficLiveCallBack.onError("There are no live vehicles ahead !");
} else {
Logger.e(TAG, "onVehicleLiveSuccess , but result liveSn is null");
}
return;
}
String sn = MoGoAiCloudClient.getInstance().getAiCloudClientConfig().getSn();
// 初始化配置文件
MoGoLivePushConfig mLivePushConfig = MoGoLivePushConfig.getInstance();
mLivePushConfig.setDevicesId(sn);
// 登录要查看的SN房间
MoGoLiveManager.getInstance().loginMultiRoom(liveSn);
MoGoLiveManager.getInstance().setMediaPlayerStateListener(mediaPlayerStateListener);
// 直接 查看对应SN的直播
MoGoLiveManager.getInstance().startLive(textureView);
if (TrafficLiveCurrentManager.this.trafficLiveCallBack != null) {
TrafficLiveCurrentManager.this.trafficLiveCallBack.onLive(liveSn);
}
}
private void onVehicleLiveError(String errorMsg) { private void onVehicleLiveError(String errorMsg) {
if (TrafficLiveCurrentManager.this.trafficLiveCallBack != null) { if (TrafficLiveCurrentManager.this.trafficLiveCallBack != null) {
TrafficLiveCurrentManager.this.trafficLiveCallBack.onError(errorMsg); TrafficLiveCurrentManager.this.trafficLiveCallBack.onError(errorMsg);