跳到主要内容

音视频播放

更新时间:2025-07-04 11:30:46

专属版设备播放接口与通用版基本相同,请先阅读【通用版-音视频播放】相关接口,只是在构建RTCXPlayInfo播放对象时,需要设置RTCXPlayInfo.deviceType = 1,即私有化设备

// 导入媒体播放SDK头文件
#import <RTCXMedia/RTCXMedia.h>

播放器初始化

@interface RTCXPlayInfo : NSObject
// 设备型号 如:xLeWcoelZbyOePbJludl 必选
@property (nonatomic, copy) NSString *productKey;
// 设备序列号SN 如:TEST20240820002 必选
@property (nonatomic, copy) NSString *deviceName;
// 平台为设备颁发的ID,设备的唯一标识符 必选
@property (nonatomic, copy) NSString *iotId;
// 是否需要播放预连接 YES: 预连接, NO: 不预连接; 默认NO 可选
@property (nonatomic, assign) BOOL preConnectEnable;
// 设备镜头ID 可选
@property (nonatomic, strong) NSNumber *lensId;
// 码流类型,0:主码流 1:辅码流,默认为0
@property (nonatomic, assign) int streamType;
// 设备属性值字典 必选
@property (nonatomic, strong) NSDictionary *propertyMap;
// 设备套餐信息 必选
@property (nonatomic, strong) NSDictionary *cloudServicesDic;
// 设备类型 0:普通设备;1:私有化设备;2:AP设备;默认0,可选
@property (nonatomic, assign) NSInteger deviceType;
@end

@interface RTCXPlayerView : UIView
/**
player相关接口调用
*/
@property (nonatomic, strong) RTCXPlayerController *playerController;

/**
初始化View
@param frame 需要展示视频的frame
@param playInfo 播放设备信息
*/
- (id)initWithFrame:(CGRect)frame withPlayInfo:(RTCXPlayInfo *)playInfo;
@end

调用示例如下:

RTCXPlayInfo *playInfo = [[RTCXPlayInfo alloc] init];
playInfo.iotId = self.curDevice.iotId;
playInfo.productKey = self.curDevice.productKey;
playInfo.deviceName = self.curDevice.deviceName;
playInfo.lensId = self.lensCount == 2?@(self.lensType):nil;
playInfo.propertyMap = self.curDevice.propertyMap;
playInfo.cloudServicesDic = [self.curDevice.cloudServices iotyy_modelToJSONObject];
playInfo.deviceType = 1;// 区分私有化设备
// 初始化播放器,传入frame和设备model
self.playerView = [[RTCXPlayerView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH * 9.0 / 16.0) withDevice:playInfo];
self.playerView.playerController.delegate = self;// 创建player控制类并设置代理监听player状态,playeview.playerController会懒加载创建控制类
self.playerView.playerController.dataSource = self;// 设置playeview.playerController的dataSource
// 初始化player播放的视图,可以把该playerView加到任意view上
[self.view addSubview:self.playerView];

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