跳到主要内容

存储卡

更新时间:2025-06-03 16:14:13
// 导入设备管理SDK头文件
#import <RTCXDeviceCenter/RTCXDeviceCenter.h>

SD卡存储录像调用接口

@protocol RTCXSDStorageProtocol <NSObject>
/**
* 查询SD卡录像列表
*
* @param req 请求参数对象
* @param onSuccess 成功回调
* @param onError 失败回调
*/
- (void)querySDRecordListWithReq:(nonnull RTCXSDStorageRecordReq *)req onSuccess:(nullable RTCXSDStorageOnSuccess)onSuccess onError:(nullable RTCXSDStorageOnError)onError;
/**
* 查询SD卡事件列表
*
* @param req 请求参数对象
* @param onSuccess 成功回调
* @param onError 失败回调
*/
- (void)querySDRecordEventListWithReq:(nonnull RTCXSDStorageRecordEventReq *)req onSuccess:(nullable RTCXSDStorageOnSuccess)onSuccess onError:(nullable RTCXSDStorageOnError)onError;
/**
* 查询录像文件列表
*
* @param req 请求参数对象
* @param onSuccess 成功回调
* @param onError 失败回调
*/
- (void)querySDRecordFileListWithReq:(nonnull RTCXSDStorageRecordFileReq *)req onSuccess:(nullable RTCXSDStorageOnSuccess)onSuccess onError:(nullable RTCXSDStorageOnError)onError;
/**
* 查询SD卡月录像
*
* @param req 请求参数对象
* @param onSuccess 成功回调
* @param onError 失败回调
*/
- (void)querySDMonthRecordWithReq:(nonnull RTCXSDStorageMonthRecordReq *)req onSuccess:(nullable RTCXSDStorageOnSuccess)onSuccess onError:(nullable RTCXSDStorageOnError)onError;
@end

SD卡录制列表

时间跨度不能超过7天,开始时间不能大于结束时间

备注:该接口默认一次性返回beginTime和endTime时间段内所有数据,(注意:如果该时间段跨度比较大,可能查询比较耗时,所以建议不要跨度太大,推荐按天查询,即:0点 - 24点,或者通过分页查询)

  • 分页规则:
    • 设置pageSize参数,如pageSize = @(50)

    • 当响应的RTCXCloudStorageRecordListRsp.nextValid = YES,说明可以继续查询下一页数据,否则没有可查询的更多数据了;

    • 查询下一页时,入参beginTime为上一次的beginTime,endTime为上一次的RTCXCloudStorageRecordListRsp.nextEndTime。

  • 请求入参说明:
    • “compressEnable”参数可控制接口返回数据是否需要压缩(压缩处理可以传输更多数据),所以如果设备支持压缩,推荐设置compressEnable = YES
    • 判断设备是否支持压缩,可以通过设备能力集属性“deviceSdkAbility"中的[1,2,4,7]是否包含7判断是否支持数据压缩
// sd卡回放
RTCXSDStorageRecordReq *sdRecordReq = [[RTCXSDStorageRecordReq alloc] init];
sdRecordReq.iotId = self.curDevice.iotId;
sdRecordReq.productKey = strongSelf.curDevice.productKey;
sdRecordReq.deviceName = strongSelf.curDevice.deviceName;
sdRecordReq.beginTime = @(beginTime);
sdRecordReq.endTime = @(endTime);
sdRecordReq.compressEnable = [self.curDevice isSupportDeviceAbility:DeviceSupportAbility_dataCompress];//是否支持数据压缩
[RTCXDeviceService(RTCXSDStorageProtocol) querySDRecordListWithReq:sdRecordReq onSuccess:^(id _Nullable data, id _Nullable rawData) {
NSArray *records = data;
NSMutableArray *sectionArray = [[NSMutableArray alloc] initWithCapacity:0];
[records enumerateObjectsUsingBlock:^(RTCXSDStorageRecordRsp *_Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
TimelineSectionClip *sectionClip = [[TimelineSectionClip alloc] init];
sectionClip.startTime = [NSDate dateWithTimeIntervalSince1970:obj.beginTime/1000];
sectionClip.endTime = [NSDate dateWithTimeIntervalSince1970:obj.endTime/1000];
[sectionArray addObject:sectionClip];
}];
[self.timelineData insertSectionDatas:sectionArray needUpdateWhenSameID:YES];
if (self.quickRefreshRecord) {// 第一次拿到Record数据快速刷新timeline
self.quickRefreshRecord = NO;
[self.timelineView updateCurrentPlayTime:[NSDate date] isPlayTimeline:NO];
}
} onError:^(NSError * _Nullable error) {
[self showToast:@"查询sd卡录像列表失败"];
}];

SD卡事件列表

备注:该接口默认一次性返回beginTime和endTime时间段内所有数据,(注意:如果该时间段跨度比较大,可能查询比较耗时,所以建议不要跨度太大,推荐按天查询,即:0点 - 24点,或者通过分页查询)

  • 分页规则:
    • 设置pageSize参数,如pageSize = @(50)

    • 当响应的RTCXCloudStorageRecordListRsp.nextValid = YES,说明可以继续查询下一页数据,否则没有可查询的更多数据了;

    • 查询下一页时,入参beginTime为上一次的beginTime,endTime为上一次的RTCXCloudStorageRecordListRsp.nextEndTime。

// SD卡事件
RTCXSDStorageRecordEventReq *sdEventReq = [[RTCXSDStorageRecordEventReq alloc] init];
sdEventReq.iotId = self.curDevice.iotId;
sdEventReq.productKey = strongSelf.curDevice.productKey;
sdEventReq.deviceName = strongSelf.curDevice.deviceName;
sdEventReq.beginTime = @(beginTime);
sdEventReq.endTime = @(endTime);
sdEventReq.compressEnable = [self.curDevice isSupportDeviceAbility:DeviceSupportAbility_dataCompress];//是否支持数据压缩
[RTCXDeviceService(RTCXSDStorageProtocol) querySDRecordEventListWithReq:sdEventReq onSuccess:^(id _Nullable data, id _Nullable rawData) {
NSArray *events = data;
NSMutableArray *eventArray = [[NSMutableArray alloc] initWithCapacity:0];
[events enumerateObjectsUsingBlock:^(RTCXSDStorageRecordEventRsp *_Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
TimelineEventClip *eventClip = [[TimelineEventClip alloc] init];
eventClip.startTime = [NSDate dateWithTimeIntervalSince1970:obj.beginTime/1000];
eventClip.endTime = [NSDate dateWithTimeIntervalSince1970:obj.endTime/1000];
eventClip.eventType = [NSString stringWithFormat:@"%ld",(long)obj.recordType];
[eventArray addObject:eventClip];
}];
[self.timelineData insertEventDatas:eventArray needUpdateWhenSameID:YES];
if (self.quickRefreshEvent) {// 第一次拿到Event数据快速刷新timeline
self.quickRefreshEvent = NO;
[self.timelineView refresh:[NSDate date]];
}
} onError:^(NSError * _Nullable error) {
[self showToast:@"查询SD卡事件列表失败"];
}];

SD卡文件列表

备注:该接口默认一次性返回beginTime和endTime时间段内所有数据,(注意:如果该时间段跨度比较大,可能查询比较耗时,所以建议不要跨度太大,推荐按天查询,即:0点 - 24点,或者通过分页查询)

  • 分页规则:
    • 设置pageSize参数,如pageSize = @(50)

    • 当响应的RTCXCloudStorageRecordListRsp.nextValid = YES,说明可以继续查询下一页数据,否则没有可查询的更多数据了;

    • 查询下一页时,入参beginTime为上一次的beginTime,endTime为上一次的RTCXCloudStorageRecordListRsp.nextEndTime。

RTCXSDStorageRecordFileReq *req = [[RTCXSDStorageRecordFileReq alloc] init];
req.iotId = self.curDevice.iotId;
req.productKey = self.curDevice.productKey;
req.deviceName = self.curDevice.deviceName;
req.beginTime = @(beginTime);
req.endTime = @(endTime);
req.compressEnable = [self.curDevice isSupportDeviceAbility:DeviceSupportAbility_dataCompress];//是否支持数据压缩
[RTCXDeviceService(RTCXSDStorageProtocol) querySDRecordFileListWithReq:req onSuccess:^(id _Nullable data, id _Nullable rawData) {
RTCXSDStorageRecordFileListRsp *recordFileList = data;
self.recordFileList = recordFileList;
NSArray *files = recordFileList.recordFileList;
NSMutableArray *fileArray = [[NSMutableArray alloc] initWithCapacity:0];
[files enumerateObjectsUsingBlock:^(RTCXSDStorageRecordFileRsp *_Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
TimelineSectionClip *sectionClip = [[TimelineSectionClip alloc] init];
sectionClip.startTime = [NSDate dateWithTimeIntervalSince1970:obj.beginTime/1000];
sectionClip.endTime = [NSDate dateWithTimeIntervalSince1970:obj.endTime/1000];
sectionClip.fileName = obj.fileName;
[fileArray addObject:sectionClip];
}];
TimelineData *timelinedata = [[TimelineData alloc] init];
timelinedata.arraySections = [[NSMutableArray alloc] initWithCapacity:0];
timelinedata.arrayEvents = [[NSMutableArray alloc] initWithCapacity:0];
self.timelineData = timelinedata;
[self.timelineData insertSectionDatas:fileArray needUpdateWhenSameID:YES];
[self reloadTableview];
} onError:^(NSError * _Nullable error) {
[self showToast:@"查询SD卡文件列表失败"];
}];

SD卡月录像列表

RTCXSDStorageMonthRecordReq *req = [[RTCXSDStorageMonthRecordReq alloc] init];
req.iotId = self.curDevice.iotId;
req.productKey = self.curDevice.productKey;
req.deviceName = self.curDevice.deviceName;
req.year = @(year);
req.month = @(month);
[RTCXDeviceService(RTCXSDStorageProtocol) querySDMonthRecordWithReq:req onSuccess:^(id _Nullable data, id _Nullable rawData) {
RTCXSDStorageMonthRecordRsp *rsp = data;
self.sdMonthRecordRsp = rsp;
[self reloadTableview];
} onError:^(NSError * _Nullable error) {
[self showToast:@"查询SD卡录像统计列表失败"];
}];

SD卡录制播放

// 云回放或SD卡回放
LVPlaybackInfo *playbackInfo = [[LVPlaybackInfo alloc] init];
playbackInfo.startTime = [startTime timeIntervalSince1970];
playbackInfo.endTime = [startTime timeIntervalSince1970];
playbackInfo.playbackType = IOTPlaybackTypeSDCardRecord;
[self.playerView.playerController seekToTime:playbackInfo];

SD卡文件播放

// 云回放或SD卡回放
LVPlaybackInfo *playbackInfo = [[LVPlaybackInfo alloc] init];
playbackInfo.startTime = [startTime timeIntervalSince1970];
playbackInfo.endTime = [startTime timeIntervalSince1970];
playbackInfo.playbackType = IOTPlaybackTypeSDCardRecord;
playbackInfo.sdFileName = self.sectionClipInfo.fileName;
playbackInfo.sdFileStartTime = [self.sectionClipInfo.startTime timeIntervalSince1970];
[self.playerView.playerController seekToTime:playbackInfo];

SD卡事件播放

// 云回放或SD卡回放
LVPlaybackInfo *playbackInfo = [[LVPlaybackInfo alloc] init];
playbackInfo.startTime = [startTime timeIntervalSince1970];
playbackInfo.endTime = [startTime timeIntervalSince1970];
playbackInfo.playbackType = IOTPlaybackTypeSDCardEvent;
[self.playerView.playerController seekToTime:playbackInfo];

当SD卡事件播放时,播放器不会主动上抛事件播放结束的状态,该逻辑需要APP自行实现,实现逻辑如下:

  1. APP通过定时器(定时间隔设置1秒)实时调用播放器 【- (NSTimeInterval)getCurrentTime】方法获取当前播放时间currenTime
  2. 使用获取到的实时播放时间currenTime与正在播放事件的结束时间endTime比较,如果currenTime >= endTime,则认为该事件播放结束
  3. APP判定事件播放结束后,需要调用播放器【- (void)releasePlayer】方法主动结束事件播放,否则播放器会一直往下播