添加第一帧画面和错误相关的回调函数
This commit is contained in:
@@ -3,6 +3,7 @@ package com.mogo.cloud;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import com.mogo.cloud.live.listener.ILiveStatusListener;
|
||||
import com.mogo.cloud.live.manager.LiveStreamManagerImpl;
|
||||
@@ -124,6 +125,12 @@ public class LivePlayAndPushActivity extends BaseLiveActivity
|
||||
Logger.d(TAG, "开始直播 onLive");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFirstFrame() {
|
||||
surfacePlayView.setVisibility(View.VISIBLE);
|
||||
Logger.d(TAG, "onFirstFrame");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisConnect() {
|
||||
Logger.d(TAG, "失去连接 onDisConnect");
|
||||
|
||||
@@ -152,11 +152,26 @@ public class MainActivity extends AppCompatActivity {
|
||||
MoGoAiCloudTrafficLive.viewFrontVehicleLive(40.11547, 116.22544,
|
||||
60, surfacePreviewView, new ITrafficCarLiveCallBack() {
|
||||
|
||||
@Override
|
||||
public void onLiveConnecting() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLiveConnected() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLive(String liveSn) {
|
||||
Logger.e(TAG, "liveSn : " + liveSn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFirstFrame() {
|
||||
Logger.e(TAG, "onFirstFrame");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisConnect() {
|
||||
Logger.e(TAG, "onDisConnect");
|
||||
|
||||
@@ -46,7 +46,7 @@ public class MoGoApplication extends MultiDexApplication {
|
||||
// 配置云服务API
|
||||
MoGoAiCloudClientConfig clientConfig = MoGoAiCloudClientConfig.getInstance();
|
||||
// 设置网络环境:HTTP_DNS_ENV_QA、HTTP_DNS_ENV_RELEASE、HTTP_DNS_ENV_DEV
|
||||
clientConfig.setNetMode(MogoHttpDnsConfig.HTTP_DNS_ENV_RELEASE);
|
||||
clientConfig.setNetMode(MogoHttpDnsConfig.HTTP_DNS_ENV_QA);
|
||||
// 设置是否是第三APP登录,false:自有车机 true:外部三方车机
|
||||
clientConfig.setThirdLogin(true);
|
||||
// 设置是否输出日志
|
||||
@@ -58,7 +58,7 @@ public class MoGoApplication extends MultiDexApplication {
|
||||
// 设置AI云平台分配给三方应用的签名密钥,需要从AI云平台申请
|
||||
// 设置车机设备的唯一标识(这些表识必须是通过后台录入的设备)
|
||||
// TODO 这里使用的是测试的sn
|
||||
clientConfig.setThirdPartyDeviceId("B95ACB94DF240C89");
|
||||
clientConfig.setThirdPartyDeviceId("C95ACB94DF240C89");
|
||||
// 设置应用服务AppId 长链、鉴权 //todo 需要卸载智慧驾驶、行车记录仪
|
||||
clientConfig.setServiceAppId("com.mogo.launcher");
|
||||
// 设置循环检测间隔时间
|
||||
|
||||
@@ -23,7 +23,9 @@
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/surfacePreviewView"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
android:visibility="invisible"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvLocalPreview"
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.mogo.cloud.live.listener;
|
||||
|
||||
public interface IMediaPlayerStateListener {
|
||||
void onVideoFirstFrame();
|
||||
|
||||
/**
|
||||
* 远程设备异常
|
||||
*/
|
||||
void remoteDeviceError();
|
||||
|
||||
/**
|
||||
* 拉流出现错误
|
||||
* @param errorCode
|
||||
*/
|
||||
void onPullStreamError(int errorCode);
|
||||
|
||||
/**
|
||||
* 设备错误
|
||||
*/
|
||||
void onDeviceError(int errorCode);
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import com.mogo.cloud.live.listener.ILiveMultiRoomStatusListener;
|
||||
import com.mogo.cloud.live.listener.ILiveProgressListener;
|
||||
import com.mogo.cloud.live.listener.ILiveRoomPersonListener;
|
||||
import com.mogo.cloud.live.listener.ILiveStatusListener;
|
||||
import com.mogo.cloud.live.listener.IMediaPlayerStateListener;
|
||||
import com.mogo.cloud.live.model.LiveStatusModel;
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClientConfig;
|
||||
|
||||
@@ -24,9 +25,11 @@ import im.zego.zegoexpress.callback.IZegoCustomVideoCaptureHandler;
|
||||
import im.zego.zegoexpress.callback.IZegoEventHandler;
|
||||
import im.zego.zegoexpress.constants.ZegoEngineState;
|
||||
import im.zego.zegoexpress.constants.ZegoLanguage;
|
||||
import im.zego.zegoexpress.constants.ZegoPlayerMediaEvent;
|
||||
import im.zego.zegoexpress.constants.ZegoPlayerState;
|
||||
import im.zego.zegoexpress.constants.ZegoPublishChannel;
|
||||
import im.zego.zegoexpress.constants.ZegoPublisherState;
|
||||
import im.zego.zegoexpress.constants.ZegoRemoteDeviceState;
|
||||
import im.zego.zegoexpress.constants.ZegoRoomState;
|
||||
import im.zego.zegoexpress.constants.ZegoScenario;
|
||||
import im.zego.zegoexpress.constants.ZegoUpdateType;
|
||||
@@ -46,6 +49,7 @@ import static com.mogo.cloud.httpdns.MogoHttpDnsConfig.HTTP_DNS_ENV_DEMO;
|
||||
import static com.mogo.cloud.httpdns.MogoHttpDnsConfig.HTTP_DNS_ENV_DEV;
|
||||
import static com.mogo.cloud.httpdns.MogoHttpDnsConfig.HTTP_DNS_ENV_QA;
|
||||
import static com.mogo.cloud.httpdns.MogoHttpDnsConfig.HTTP_DNS_ENV_RELEASE;
|
||||
import static im.zego.zegoexpress.constants.ZegoRemoteDeviceState.OPEN;
|
||||
|
||||
/**
|
||||
* 即构直播管理
|
||||
@@ -117,6 +121,7 @@ public class MoGoLiveManager {
|
||||
* 房间配置
|
||||
*/
|
||||
private final ZegoRoomConfig zeGoRoomConfig;
|
||||
private IMediaPlayerStateListener mMediaPlayerStateListener;
|
||||
|
||||
private static final class Holder {
|
||||
private static final MoGoLiveManager manager = new MoGoLiveManager();
|
||||
@@ -323,6 +328,9 @@ public class MoGoLiveManager {
|
||||
if (mLiveStatusModel.getMultiStreamId().equals(streamID)) {
|
||||
// 如果不是非播放状态则判定为直播状态
|
||||
mLiveStatusModel.setPlaying(state != ZegoPlayerState.NO_PLAY);
|
||||
if (mMediaPlayerStateListener != null && errorCode != 0) {
|
||||
mMediaPlayerStateListener.onPullStreamError(errorCode);
|
||||
}
|
||||
Log.i(TAG, " 拉流状态变更回调 onPlayerStateUpdate streamId : " + streamID +
|
||||
" , isPlaying : " + mLiveStatusModel.isPlaying() +
|
||||
" , state : " + state.name() +
|
||||
@@ -338,6 +346,44 @@ public class MoGoLiveManager {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerRecvAudioFirstFrame(String streamID) {
|
||||
super.onPlayerRecvAudioFirstFrame(streamID);
|
||||
Log.d(TAG, "onPlayerRecvAudioFirstFrame");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerRenderVideoFirstFrame(String streamID) {
|
||||
super.onPlayerRenderVideoFirstFrame(streamID);
|
||||
Log.d(TAG, "onPlayerRenderVideoFirstFrame");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerRecvVideoFirstFrame(String streamID) {
|
||||
super.onPlayerRecvVideoFirstFrame(streamID);
|
||||
Log.d(TAG, "onPlayerRecvVideoFirstFrame");
|
||||
if (mMediaPlayerStateListener != null) mMediaPlayerStateListener.onVideoFirstFrame();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemoteCameraStateUpdate(String streamID, ZegoRemoteDeviceState state) {
|
||||
super.onRemoteCameraStateUpdate(streamID, state);
|
||||
if (state != OPEN) {
|
||||
Log.e(TAG, "onRemoteCameraStateUpdate:" + state);
|
||||
if (mMediaPlayerStateListener != null) {
|
||||
mMediaPlayerStateListener.remoteDeviceError();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeviceError(int errorCode, String deviceName) {
|
||||
super.onDeviceError(errorCode, deviceName);
|
||||
Log.e(TAG, "onDeviceError:" + errorCode);
|
||||
if (mMediaPlayerStateListener != null && errorCode != 0) {
|
||||
mMediaPlayerStateListener.onDeviceError(errorCode);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -595,6 +641,10 @@ public class MoGoLiveManager {
|
||||
mExpressEngine.stopPublishingStream();
|
||||
}
|
||||
|
||||
public void setMediaPlayerStateListener(IMediaPlayerStateListener mediaPlayerStateListener) {
|
||||
mMediaPlayerStateListener = mediaPlayerStateListener;
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始播放直播
|
||||
*
|
||||
|
||||
@@ -13,6 +13,10 @@ public interface ITrafficCarLiveCallBack {
|
||||
|
||||
void onLive(String liveSn);
|
||||
|
||||
default void onFirstFrame() {
|
||||
|
||||
}
|
||||
|
||||
void onDisConnect();
|
||||
|
||||
void onError(String errorMsg);
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.view.SurfaceView;
|
||||
|
||||
import com.mogo.cloud.live.listener.ILiveMultiRoomStatusListener;
|
||||
import com.mogo.cloud.live.listener.ILiveProgressListener;
|
||||
import com.mogo.cloud.live.listener.IMediaPlayerStateListener;
|
||||
import com.mogo.cloud.live.listener.IRequestLiveListener;
|
||||
import com.mogo.cloud.live.manager.MoGoLiveManager;
|
||||
import com.mogo.cloud.live.manager.MoGoLivePushConfig;
|
||||
@@ -113,6 +114,7 @@ public class TrafficLiveCurrentManager
|
||||
mLivePushConfig.setDevicesId(sn);
|
||||
// 登录要查看的SN房间
|
||||
MoGoLiveManager.getInstance().loginMultiRoom(liveSn);
|
||||
MoGoLiveManager.getInstance().setMediaPlayerStateListener(mediaPlayerStateListener);
|
||||
// 直接 查看对应SN的直播
|
||||
MoGoLiveManager.getInstance().startLive(surfaceView);
|
||||
if (TrafficLiveCurrentManager.this.trafficLiveCallBack != null) {
|
||||
@@ -218,5 +220,33 @@ public class TrafficLiveCurrentManager
|
||||
trafficLiveCallBack.onDisConnect();
|
||||
}
|
||||
}
|
||||
private IMediaPlayerStateListener mediaPlayerStateListener = new IMediaPlayerStateListener() {
|
||||
@Override
|
||||
public void onVideoFirstFrame() {
|
||||
if (trafficLiveCallBack != null) {
|
||||
trafficLiveCallBack.onFirstFrame();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remoteDeviceError() {
|
||||
if (trafficLiveCallBack != null) {
|
||||
trafficLiveCallBack.onError("");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPullStreamError(int errorCode) {
|
||||
if (trafficLiveCallBack != null) {
|
||||
trafficLiveCallBack.onError("" + errorCode);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeviceError(int errorCode) {
|
||||
if (trafficLiveCallBack != null) {
|
||||
trafficLiveCallBack.onError("" + errorCode);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user