DownloadViewController.mm 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. //
  2. // DownloadViewController.m
  3. // FunSDKDemo
  4. //
  5. // Created by XM on 2018/11/15.
  6. // Copyright © 2018年 XM. All rights reserved.
  7. //
  8. #import "DownloadViewController.h"
  9. #import "VideoFileDownloadConfig.h"
  10. #import "ItemTableviewCell.h"
  11. @interface DownloadViewController () <UITableViewDelegate,UITableViewDataSource,FileDownloadDelegate>
  12. {
  13. VideoFileDownloadConfig *config;
  14. UITableView *tableV;
  15. RecordInfo *record;
  16. float progres;
  17. }
  18. @end
  19. @implementation DownloadViewController
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. [self configSubView];
  23. }
  24. #pragma mark - 开始下载设备录像
  25. - (void)startDownloadRecord:(RecordInfo*)recordInfo {
  26. [SVProgressHUD show];
  27. record = recordInfo;
  28. if (config == nil) {
  29. config = [[VideoFileDownloadConfig alloc] init];
  30. config.delegate = self;
  31. }
  32. [config downloadFile:record];
  33. }
  34. #pragma mark -下载录像开始回调
  35. - (void)fileDownloadStartResult:(NSInteger)result {
  36. if (result <0) {
  37. [MessageUI ShowErrorInt:(int)result];
  38. }
  39. }
  40. #pragma mark -下载进度回调
  41. - (void)fileDownloadProgressResult:(float)progress {
  42. progres = progress;
  43. NSIndexPath *path = [NSIndexPath indexPathForRow:2 inSection:0];
  44. NSArray *array = [NSArray arrayWithObject:path];
  45. [tableV reloadRowsAtIndexPaths:array withRowAnimation:nil];
  46. }
  47. #pragma mark -下载录像结果回调
  48. - (void)fileDownloadEndResult {
  49. [SVProgressHUD dismiss];
  50. progres = 1;
  51. NSIndexPath *path = [NSIndexPath indexPathForRow:2 inSection:0];
  52. NSArray *array = [NSArray arrayWithObject:path];
  53. [tableV reloadRowsAtIndexPaths:array withRowAnimation:nil];
  54. }
  55. #pragma mark - tableView代理方法
  56. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  57. return 4;
  58. }
  59. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  60. ItemTableviewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ItemTableviewCell"];
  61. if (!cell) {
  62. cell = [[ItemTableviewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ItemTableviewCell"];
  63. }
  64. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  65. cell.textLabel.numberOfLines = 0;
  66. cell.textLabel.lineBreakMode = NSLineBreakByWordWrapping;
  67. if (indexPath.row == 0) {
  68. cell.textLabel.text = record.fileName;
  69. }else if (indexPath.row == 1) {
  70. cell.textLabel.text = [NSString stringWithFormat:@"fileSize:%ldK",record.fileSize];
  71. }else if (indexPath.row == 2) {
  72. cell.textLabel.text = [NSString stringWithFormat:@"DownloadProgress: %04f%@",progres*100,@"%"];
  73. }
  74. return cell;
  75. }
  76. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  77. }
  78. #pragma mark - 界面和数据初始化
  79. - (void)configSubView {
  80. self.title = TS("video_download");
  81. [self.view addSubview:self.tableV];
  82. }
  83. - (UITableView *)tableV {
  84. if (!tableV) {
  85. tableV = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight ) style:UITableViewStylePlain];
  86. tableV.delegate = self;
  87. tableV.dataSource = self;
  88. [tableV registerClass:[ItemTableviewCell class] forCellReuseIdentifier:@"ItemTableviewCell"];
  89. }
  90. return tableV;
  91. }
  92. - (void)didReceiveMemoryWarning {
  93. [super didReceiveMemoryWarning];
  94. // Dispose of any resources that can be recreated.
  95. }
  96. @end