CloudVideoDownloadViewController.mm 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. //
  2. // CloudVideoDownloadViewController.m
  3. // FunSDKDemo
  4. //
  5. // Created by XM on 2019/1/7.
  6. // Copyright © 2019年 XM. All rights reserved.
  7. //
  8. #import "CloudVideoDownloadViewController.h"
  9. #import "ItemTableviewCell.h"
  10. #import "Header.h"
  11. @interface CloudVideoDownloadViewController ()
  12. <UITableViewDelegate,UITableViewDataSource,CloudVideoConfigDelegate>
  13. {
  14. CloudVideoConfig *config;
  15. CLouldVideoResource *resource;
  16. UITableView *tableV;
  17. NSString *thumbPath;
  18. NSString *videoPath;
  19. float progres;
  20. }
  21. @end
  22. @implementation CloudVideoDownloadViewController
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. [self configSubView];
  26. }
  27. #pragma mark - 开始下载云视频录像
  28. - (void)startDownloadCloudVideo:(CLouldVideoResource*)msgResource {
  29. resource = msgResource;
  30. [SVProgressHUD show];
  31. if (config == nil) {
  32. config = [[CloudVideoConfig alloc] init];
  33. config.delegate = self;
  34. }
  35. //下载云视频缩略图
  36. [config downloadSmallCloudThumb:resource];
  37. //下载云视频
  38. [config downloadCloudVideoFile:resource];
  39. }
  40. #pragma mark - 缩略图下载回调
  41. - (void)downloadSmallCloudThumbResult:(int)result path:(NSString *)path {
  42. if (result < 0) {
  43. [MessageUI ShowErrorInt:(int)result];
  44. }else{
  45. thumbPath = path;
  46. [tableV reloadData];
  47. }
  48. }
  49. #pragma mark - 下载云存储视频开始
  50. - (void)downloadCloudVideoStartResult:(int)result {
  51. if (result <0) {
  52. [MessageUI ShowErrorInt:result];
  53. }else{
  54. }
  55. }
  56. #pragma mark 下载视频进度
  57. - (void)downloadCloudVideoProgress:(float)progress {
  58. progres = progress;
  59. NSIndexPath *path = [NSIndexPath indexPathForRow:2 inSection:0];
  60. NSArray *array = [NSArray arrayWithObject:path];
  61. [tableV reloadRowsAtIndexPaths:array withRowAnimation:nil];
  62. }
  63. #pragma mark 下载视频完成
  64. - (void)downloadCloudVideoComplete:(int)result path:(NSString*)path {
  65. [SVProgressHUD dismiss];
  66. progres = 1;
  67. videoPath = @"";
  68. [tableV reloadData];
  69. }
  70. #pragma mark - tableView代理方法
  71. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  72. return 60;
  73. }
  74. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  75. return 4;
  76. }
  77. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  78. ItemTableviewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ItemTableviewCell"];
  79. if (!cell) {
  80. cell = [[ItemTableviewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ItemTableviewCell"];
  81. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  82. }
  83. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  84. cell.textLabel.numberOfLines = 0;
  85. cell.textLabel.lineBreakMode = NSLineBreakByWordWrapping;
  86. if (indexPath.row == 0) {
  87. //云视频时间日期
  88. cell.textLabel.text = resource.beginDate;
  89. cell.Labeltext.text = resource.beginTime;
  90. }else if (indexPath.row == 1) {
  91. //每一段云视频的缩略图
  92. if (thumbPath && thumbPath.length >1) {
  93. NSData *data = [NSData dataWithContentsOfFile:thumbPath];
  94. cell.imageView.image = [UIImage imageWithData:data];
  95. }
  96. }else if (indexPath.row == 2) {
  97. //云视频下载进度
  98. cell.textLabel.text = [NSString stringWithFormat:@"Progress: %04f%@",progres*100,@"%"];
  99. }else if (indexPath.row == 3) {
  100. //云视频下载路径
  101. cell.textLabel.text = videoPath;
  102. }
  103. return cell;
  104. }
  105. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  106. }
  107. #pragma mark - 界面和数据初始化
  108. - (void)configSubView {
  109. self.title = TS("video_download");
  110. [self.view addSubview:self.tableV];
  111. }
  112. - (UITableView *)tableV {
  113. if (!tableV) {
  114. tableV = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight ) style:UITableViewStylePlain];
  115. tableV.delegate = self;
  116. tableV.dataSource = self;
  117. [tableV registerClass:[ItemTableviewCell class] forCellReuseIdentifier:@"ItemTableviewCell"];
  118. }
  119. return tableV;
  120. }
  121. - (void)didReceiveMemoryWarning {
  122. [super didReceiveMemoryWarning];
  123. // Dispose of any resources that can be recreated.
  124. }
  125. @end