VideoFileDownloadConfig.mm 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //
  2. // VideoFileDownloadConfig.m
  3. // FunSDKDemo
  4. //
  5. // Created by XM on 2018/11/15.
  6. // Copyright © 2018年 XM. All rights reserved.
  7. //
  8. #import "VideoFileDownloadConfig.h"
  9. @implementation VideoFileDownloadConfig
  10. #pragma mark - 开始下载录像
  11. - (void)downloadFile:(RecordInfo*)record {
  12. //获取通道
  13. ChannelObject *channel = [[DeviceControl getInstance] getSelectChannel];
  14. //初始化请求结构体
  15. H264_DVR_FILE_DATA info;
  16. memset(&info, 0, sizeof(info));
  17. info.size = (int)record.fileSize;
  18. //开始时间
  19. XM_SYSTEM_TIME timeBegin = record.timeBegin;
  20. memcpy(&info.stBeginTime, (char *)&timeBegin, sizeof(SDK_SYSTEM_TIME));
  21. //结束时间
  22. XM_SYSTEM_TIME timeEnd = record.timeEnd;
  23. memcpy(&info.stEndTime, (char*)&timeEnd,sizeof(SDK_SYSTEM_TIME));
  24. //通道号
  25. strncpy(info.sFileName, [record.fileName UTF8String], sizeof(info.sFileName));
  26. info.ch = (int)record.channelNo;
  27. //存储路径
  28. NSString *directoryPath = [NSString getVideoPath];
  29. NSString *timeString = [NSString stringWithFormat:@"%04d-%02d-%02d %02d:%02d:%02d",timeBegin.year,timeBegin.month,timeBegin.day,timeBegin.hour,timeBegin.minute,timeBegin.second];
  30. //后缀 如果是鱼眼设备,需要特殊保存,然后用鱼眼播放器进行播放,参考鱼眼视频剪切和本地播放
  31. // if (self.isFish) {
  32. // movieFilePath = [directoryPath stringByAppendingFormat:@"/%@.fvideo",timeString];
  33. // }
  34. NSString *movieFilePath = [directoryPath stringByAppendingFormat:@"/%@.mp4",timeString];
  35. //开始下载
  36. FUN_DevDowonLoadByFile(self.msgHandle, SZSTR(channel.deviceMac), &info, SZSTR(movieFilePath));
  37. }
  38. #pragma mark - SDK回调
  39. -(void)OnFunSDKResult:(NSNumber *) pParam{
  40. NSInteger nAddr = [pParam integerValue];
  41. MsgContent *msg = (MsgContent *)nAddr;
  42. switch (msg->id) {
  43. #pragma mark 开始下载录像回调
  44. case EMSG_ON_FILE_DOWNLOAD: {// 开始下载
  45. if ([self.delegate respondsToSelector:@selector(fileDownloadStartResult:)]) {
  46. [self.delegate fileDownloadStartResult:msg->param1];
  47. }
  48. }
  49. break;
  50. #pragma mark 录像下载的进度
  51. case EMSG_ON_FILE_DLD_POS: {//下载的进度
  52. if ([self.delegate respondsToSelector:@selector(fileDownloadProgressResult:)]) {
  53. if (msg->param1 > 0 && msg->param2 >0) {
  54. [self.delegate fileDownloadProgressResult:(CGFloat)msg->param2 / (CGFloat)msg->param1];
  55. }
  56. }
  57. }
  58. break;
  59. #pragma mark 录像下载完成
  60. case EMSG_ON_FILE_DLD_COMPLETE: { //下载完成
  61. if ([self.delegate respondsToSelector:@selector(fileDownloadEndResult)]) {
  62. [self.delegate fileDownloadEndResult];
  63. NSLog(@"录像下载成功:%s",msg->szStr);
  64. }
  65. }
  66. break;
  67. }
  68. }
  69. @end