跳到主要内容

音视频播放

更新时间:2026-10-29 10:05:40

专属版设备播放接口与通用版相同,请先阅读【通用版-音视频播放】相关接口,区别在于构建 IPlayInfo 播放对象时,需要设置 deviceType = 1,即专属版设备。

// 导入媒体播放头文件
import { RTCXMediaControl, RTCXMediaService, RTCXMediaType, RTCXPlayerView } from 'rtcxsdk'

播放器初始化​

const playInfo: RTCXMediaType.IPlayInfo = {
iotId: this.curDevice.iotId,
productKey: this.curDevice.productKey,
deviceName: this.curDevice.deviceName,
lensId: 0,
streamType: 0,
deviceType: 1 // 1:专属版设备
}
this.playInfo = playInfo

// 创建播放控制器
this.playerController = new RTCXMediaControl.PlayerController(playInfo, this.playerListener)

IPlayInfo.deviceType 取值说明:

值说明
0普通设备,默认值
1专属版设备
2局域网 AP 设备

创建播放器后,直播、回放、截图、录制、静音、倍速、旋转等接口的调用方式同通用版音视频播放。SDK 会根据 deviceType 自动选择专属版信令、STUN 与播放通道。

设备在线状态​

专属版设备在创建物模型对象时,同样需要将设备信息中的 deviceType 设置为 1,再用于创建 PlayDeviceInfo 与物模型对象:

import { RTCXThingModel, RTCXThingModelType, RTCXDeviceMgrTypes, RTCXLogger } from 'rtcxsdk'

const deviceInfo: RTCXDeviceMgrTypes.IDeviceInfo = {
iotId: this.curDevice.iotId,
productKey: this.curDevice.productKey,
deviceName: this.curDevice.deviceName,
deviceType: 1 // 1:专属版设备
}
const playDeviceInfo = new RTCXDeviceMgrTypes.PlayDeviceInfo(deviceInfo)
this.thingModel = new RTCXThingModel(playDeviceInfo)

通过订阅 DEVICE_STATUS 事件获取设备上下线状态:

this.msgNotify = (iotId: string, eventType: RTCXThingModelType.SubscribeEventTypeEnum, data?: Object) => {
if (eventType === RTCXThingModelType.SubscribeEventTypeEnum.DEVICE_STATUS) {
// data 中包含设备生命周期 status:0:未激活;1:上线;2:休眠;3:离线;8:禁用
RTCXLogger.i(TAG, `设备${iotId}状态发生变化`)
this.loadNewData()
}
}
this.thingModel.subscribe(this.msgNotify)

取消订阅:

this.thingModel.unsubscribe(this.msgNotify)

其它功能调用同【通用版-音视频播放】即可。