V2.5.100 媒体中心教程
1. 概述
V2.5.100版本的媒体中心,支持多码流播放,启动播放,找飞机预录制, 获取实时码流信息, 支持多路推流。
注意:2.5.100版本与2.5.2相比媒体中心的改动点
- 新增多路推流功能
- 相关的组件包名由com.autel.module_player改为com.autel.player
- 新增了多路推流功能,RTMP推流改为RTMPPublisherNew实现,同时兼容老接口
- 优化部分接口回调,如IPublishListener
2. 新媒体中心API说明
2.1 多码流播放器
2.1.1 多码流播放器说明
支持多码流同时播放(红外、可见光等),支持启动播放。
2.1.2 多码流播放器API说明
使用AutelPlayerManager这个类的单实例及AutelPlayer、AutelPlayerView类的实例来调用接口。
- AutelPlayerManager.java相关接口说明
import com.autel.player.player.AutelPlayerManager
import com.autel.player.player.autelplayer.AutelPlayer
/**
* AutelPlayerManager的单例类对象
*/
public synchronized static AutelPlayerManager getInstance()
/**
* 添加AutelPlayer实例到mAutelPlayerList中
*
* @param player 要添加的AutelPlayer实例
*/
public void addAutelPlayer(AutelPlayer player)
/**
* 添加MediaCodec监听器
* @param key 键值
* @param callbackWith 回调接口OnRenderFrameInfoListener
*/
public void addCodecListeners(String key, final OnRenderFrameInfoListener callbackWith)
- AutelPlayer.java相关接口说明
import com.autel.player.player.autelplayer.AutelPlayer
/**
* 构造方法
* @param channelId: 通道ID 参看SDKConstants定义
*/
public AutelPlayer(int channelId)
/**
* 添加用于视频的视图
* @param view AutelPlayerView对象,用于显示视频的视图
*/
public void addVideoView(AutelPlayerView view)
/**
* 移除视频视图
*/
public void removeVideoView()
/**
* 设置视频流监听器
* @param ls 实现了IVideoStreamListener接口的监听器对象
*/
public void setVideoInfoListener(IVideoStreamListener ls)
- AutelPlayerView.java相关接口说明
/**
* 创建一个新的AutelPlayerView视图。
*
* @param context 与该视图关联的上下文Context。
*/
public AutelPlayerView(Context context)
/**
* 创建一个新的AutelPlayerView视图。
*
* @param context 与该视图关联的上下文Context。
* @param attrs 用于填充该视图的XML标签的属性。
*/
public AutelPlayerView(Context context, AttributeSet attrs)
2.1.3 多码流播放器接口调用实例
//播放器管理单实例初始化
SDKManager.get().init(applicationContext, true)
//创建播放TextureView
private fun createAutelCodecView(): AutelPlayerView? {
val codecView = AutelPlayerView(activity)
val params = LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT
)
codecView.layoutParams = params
return codecView
}
val codecView = createAutelCodecView()
uiBinding.root.addView(codecView, 0)
//创建播放器AutelPlayer
mAutelPlayer = AutelPlayerManager.getInstance().getAutelPlayer(SDKConstants.STREAM_CHANNEL_16110);
//把播放TextureView传入播放器
mAutelPlayer?.addVideoView(codecView)
//设置码流信息回调接口
mAutelPlayer?.setVideoInfoListener(object : IVideoStreamListener {
override fun onVideoSizeChanged(playerId: Int, width: Int, height: Int) {
isFrameSaved = false;
}
override fun onVideoInfoCallback(playerId: Int, x: Int, y: Int, w: Int, h: Int) {
}
override fun onFrameYuv(yuv: ByteBuffer?, mediaInfo: MediaInfo?) {
Log.i("MuiltCodecFragment", " yuv ${yuv?.capacity()} mediaInfo ${mediaInfo.toString()}")
if (!isFrameSaved && yuv != null && mediaInfo != null){
isFrameSaved = true;
if (mediaInfo.pixelFormat == MediaInfo.PixelFormat.PIX_FMT_NV12){
saveYuvToFile(yuv, mediaInfo.width, mediaInfo.height, mediaInfo.stride, mediaInfo.sliceHeight)
}
}
}
override fun onVideoErrorCallback(playerId: Int, type: Int, errorContent: String?) {
}
override fun onStreamSourceChanged(playerId: Int, newType: StreamData.StreamSourceType) {
}
})
2.2 直播推流
2.2.1 Rtmp开启推流
import com.autel.publisher.IPublishListener
private var mPublisher = RTMPPublisherNew()
var iCurrentPort: Int = SDKConstants.STREAM_CHANNEL_16110
private var rtmpUrl: String = "rtmp://116.205.231.28/live/livestream/zoom77"
var param = PublishParam.Builder().setUrl(rtmpUrl).setStreamSource(iCurrentPort).build()
mPublisher.configure(param)
mPublisher.setOnPublishListener(object : IPublishListener {
override fun onConnecting() {
SDKLog.d(TAG, "Rtmp Status : connecting")
connectStatus = 0;
}
override fun onConnected() {
SDKLog.d(TAG, "Rtmp Status : connected.")
connectStatus = 1;
}
override fun onConnectedFailed(code: PublishErrorCode) {
SDKLog.d(TAG, "Rtmp Status : connected failed code=" + code)
connectStatus = 2;
}
override fun onStartPublish() {
SDKLog.d(TAG, "Rtmp Status : start publish stream")
}
override fun onStopPublish() {
SDKLog.d(TAG, "Rtmp Status : stoppublish now")
}
override fun onFpsStatistic(fps: Int, channelName: String) {
SDKLog.d(TAG, "Rtmp upload fps : " + fps)
}
override fun onVideoBitrate(value: Int, channelName: String) {
SDKLog.d(TAG, "Rtmp onVideoBriate : " + value + " KBPS")
}
override fun onAudioBitrate(value: Int) {
SDKLog.d(TAG, "Rtmp onAudioBriate : " + value + " KBPS")
}
override fun onPublishSuccess() {
SDKLog.d(TAG, "Rtmp onPublishSuccess")
}
override fun onPublishFailed(errorCode: PublishErrorCode) {
SDKLog.d(TAG, "Rtmp onPublishFailed errcode" + errorCode)
}
override fun onPublishFailed(channelName: String, errorCode: PublishErrorCode) {
SDKLog.d(TAG, "Rtmp onPublishFailed errcode" + errorCode)
}
override fun onReconnect() {
SDKLog.d(TAG, "Rtmp onReconnect")
}
})
mPublisher.start()
2.2.2 Rtmp停止推流
mPublisher.stop()
2.2.3 Rtmp切换推流镜头
if(iCurrentPort == SDKConstants.STREAM_CHANNEL_16110){
iCurrentPort = SDKConstants.STREAM_CHANNEL_16115
mPublisher.switchStreamSource(iCurrentPort, true)
} else {
iCurrentPort = SDKConstants.STREAM_CHANNEL_16110
mPublisher.switchStreamSource(iCurrentPort, true)
}
2.3 找飞机预录制
2.3.1 找飞机预录制说明
当开启了找飞机预录制,会每次录制大约30秒的内容,就会保存为一个固定名字文件并覆盖之前的保存的文件,这样总能保留飞机最近30秒的视频内容,如果飞机失联,则可以利用这个视频内容来协助找到飞机。
2.3.2 找飞机预录制API说明
找飞机预录制AutelPlayerManager这个类的单实例的API如下所示。
/**
* 开启对应视频类型(可以是可见光、夜视、红外)的录制,最长约30秒,返回true: 启动成功, false:启动失败(传的参数错误)
* @param videoType: the video type
* @param cacheDuration: use ms*/
public boolean openVideoCache(VideoType videoType, long cacheDuration)
/**
* 关闭对应视频类型(可见光、夜视)的录制, 返回true: 关闭成功, false:关闭失败(传的参数错误)
* @param videoType the video type
*/
public boolean closeVideoCache(VideoType videoType)
/**
* 设置保存录制视频的路径,如果不设置就默认保存在根目录
* @param path the video path
*/
public void setCachePath(String path)
/**
* 是否开启对应视频类型(可见光、夜视)的录制
*/
public boolean isOpenVideoCache(VideoType videoType)
2.3.4 找飞机预录接口调用示例代码
//开启30s时光回溯功能
AutelPlayerManager.getInstance().openVideoCache(VideoType.VISIBLE_LIGHT, 30_000)
//关闭30s时光回溯功能
AutelPlayerManager.getInstance().closeVideoCache(VideoType.VISIBLE_LIGHT)
//设置保存录制视频的路径,如果不设置就默认保存在根目录
AutelPlayerManager.getInstance().setCachePath(AutelDirPathUtils.getLookFlightVideoCachePath())
//判断是否开启对应视频类型30s时光回溯功能
AutelPlayerManager.getInstance().isOpenVideoCache(VideoType.VISIBLE_LIGHT)
2.4 获取码流的实时信息
2.4.1 获取码流实时信息说明
可以获取到码流的实时信息,方便调试定位问题。
2.4.2 获取码流实时信息API说明
AutelPlayer类的实例调用接口
//解码帧率
public int getVideoFps()
//接收帧率
public int getRecvFps()
//刷新帧率
public int getRenderFps()
//接收的码率
public int getRecvBitrate()
//60秒内接收到的关键帧数量
public int getKeyFrameNum()
//60秒内请求关键帧次数
public int getKeyFrameReqNum()
//1秒内丢包数
public int getPktLossNum()
//视频的宽度
public int getVideoWidth()
//视频的高度
public int getVideoHeigh()