音视频播放
更新时间:2025-07-04 09:56:20
专属版设备播放接口与通用版基本相同,请先阅读【通用版-音视频播放】相关接口
设备对象
专属版对象继承自通用版设备对象DeviceInfo
import com.polaris.iot.appsdk.libuserdevicemgr.model.DeviceInfo
/**
* 专属版设备信息,播放时使用
*
* @param iotId 平台为设备颁发的ID,设备的唯一标识符。
* @param productKey 产品型号唯一值
* @param deviceName 设备序列号
* @param isSupportP2P 是否支持P2P
* @param lensCount 设备镜头数 默认一个镜头
* @param deviceWorkMode 设备工作模式 默认常上电
* @param videoCodec 设备视频编码
* @param audioCodec 设备音频编码
* @param isSupportCompressData 设备信令是否支持压缩数据
*/
open class SpecialDeviceInfo(
iotId: String,
productKey: String,
deviceName: String,
isSupportP2P: Boolean? = false,
lensCount: Int? = null,
deviceWorkMode: String? = null,
videoCodec: String? = null,
audioCodec: String? = null,
isSupportCompressData: Boolean? = false,
) : DeviceInfo(
iotId, productKey, deviceName, DeviceStatus.ONLINE.status,
) {
constructor(iotId: String, productKey: String, deviceName: String, isSupportP2P: Boolean) : this(iotId, productKey, deviceName, isSupportP2P, 1)
constructor(iotId: String, productKey: String, deviceName: String, isSupportP2P: Boolean, lensCount: Int) : this(iotId, productKey, deviceName, isSupportP2P, lensCount, "2")
}
播放示例
提供播放器使用示例,请先阅读【通用版-音视频播放-播放示例】
- 请先构建专属版设备对象 可选参数isSupportP2P、lensCount、deviceWorkMode、videoCodec、audioCodec、isSupportCompress可由设备物模型上报
- 其它同通用版音视频播放
private SpecialDeviceInfo mDeviceInfo;
private IoTDeviceInfo iotDevice;
private IoTPlayerCtrl playerCtrl;
private void initPlayer() {
if (mDeviceInfo == null) throw new IllegalStateException("need device info");
if (playerCtrl == null) {
// 是否支持P2P
boolean isSuppurtP2P = true
//设备工作模式
String deviceWorkMode = "2"
//视频编码
String videoCodec = "H265"
//音频编码
String audioCodec = "G711"
//设备镜头数 多目设备有多个镜头
int lensCount = 1
SpecialDeviceInfo deviceInfo = SpecialDeviceInfo("{iotId}","{productKey}","{deviceName}",
isSuppurtP2P,lensCount,deviceWorkMode, videoCodec,audioCodec)
iotDevice = IoTDeviceInfo.copyFrom(mDeviceInfo);
IoTPlayerViewInitParam param = new IoTPlayerViewInitParam(VideoDecodeModeEnum.HARDWARE, iotDevice);
param.setStreamType(IoTStreamTypeEnum.MAIN);
//IoTPlayerCtrl 的初始化
binding.iotPlayerView.init(param);
playerCtrl = binding.iotPlayerView.getPlayerCtrl();
playerCtrl.setOnPlayerListener(this);
}
playerCtrl.prepare(new IoTPlayerParam());
playerCtrl.start();
}