PhotosViewController.mm 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. //
  2. // PhotosViewController.m
  3. // FunSDKDemo
  4. //
  5. // Created by XM on 2018/11/30.
  6. // Copyright © 2018年 XM. All rights reserved.
  7. //
  8. #import "PhotosViewController.h"
  9. #import "FileControl.h"
  10. #import "XMPlayerVC.h"
  11. #import "FishEyeVideoVC.h"
  12. #import <AVKit/AVKit.h>
  13. #import <AVFoundation/AVFoundation.h>
  14. #import "Header.h"
  15. @interface PhotosViewController ()<UITableViewDelegate,UITableViewDataSource>
  16. {
  17. NSMutableArray *imageArray;
  18. NSMutableArray *videoArray;
  19. UITableView *imageTableView;
  20. UITableView *videoTableView;
  21. FileControl *fileControl; //文件管理类
  22. }
  23. @property (nonatomic, strong) UIBarButtonItem *rightBarBtn;
  24. @end
  25. @implementation PhotosViewController
  26. - (void)viewDidLoad {
  27. [super viewDidLoad];
  28. //设置导航栏样式
  29. [self setNaviStyle];
  30. [self initData];
  31. //配置子试图
  32. [self configSubView];
  33. }
  34. - (void)chageFileType {
  35. if (imageTableView.hidden == YES) {
  36. imageTableView.hidden = NO;
  37. videoTableView.hidden = YES;
  38. }else{
  39. imageTableView.hidden = YES;
  40. videoTableView.hidden = NO;
  41. }
  42. }
  43. - (void)setNaviStyle {
  44. self.navigationItem.title = TS("photos");
  45. self.rightBarBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(chageFileType)];
  46. self.navigationItem.rightBarButtonItem = self.rightBarBtn;
  47. self.rightBarBtn.width = 15;
  48. self.rightBarBtn.tintColor = [UIColor whiteColor];
  49. }
  50. - (void)initData {
  51. fileControl = [[FileControl alloc] init];
  52. imageArray = [[fileControl getLocalImage] mutableCopy];
  53. videoArray = [[fileControl getLocalVideo] mutableCopy];
  54. }
  55. - (void)configSubView {
  56. [self.view addSubview:self.imageTableView];
  57. [self.view addSubview:self.videoTableView];
  58. }
  59. #pragma mark -- UITableViewDelegate/dataSource
  60. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  61. return 60;
  62. }
  63. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  64. if (tableView.tag == 0) {
  65. return imageArray.count;
  66. }
  67. return videoArray.count;
  68. }
  69. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  70. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"mainCell"];
  71. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  72. if (tableView.tag == 0) {
  73. NSString *path = [imageArray objectAtIndex:indexPath.row];
  74. cell.imageView.image = [UIImage imageWithContentsOfFile:path];
  75. cell.textLabel.text = path.lastPathComponent;
  76. }else {
  77. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  78. NSString *path = [videoArray objectAtIndex:indexPath.row];
  79. cell.textLabel.text = path.lastPathComponent;
  80. }
  81. return cell;
  82. }
  83. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  84. if (tableView.tag == 0) {
  85. //图片 (鱼眼图片可以使用鱼眼视频同样的方式展示来获得鱼眼效果,或者直接按照普通图片显示)
  86. // if (鱼眼图片 || fishImage) {
  87. // FishEyeVideoVC *fishvc = [[FishEyeVideoVC alloc]init];
  88. // fishvc.fileName = path;
  89. // fishvc.fisheyephotoOrvideo = 1;
  90. // [self presentViewController:fishvc animated:YES completion:nil];
  91. // }
  92. }else{
  93. //播放本地视频文件,先获取文件路径
  94. NSString *path = [videoArray objectAtIndex:indexPath.row];
  95. //如果录像类型是 .h265文件,特殊处理
  96. if ([fileControl getVideoTypeH265:path]) {
  97. XMPlayerVC *playerVC = [[XMPlayerVC alloc] init];
  98. playerVC.filePath = path;
  99. [self presentViewController:playerVC animated:YES completion:nil];
  100. return;
  101. }
  102. //如果是鱼眼视频文件,需要使用鱼眼播放器来播放
  103. if ([fileControl getVideoTypeFish:path]) {
  104. FishEyeVideoVC *fishvc = [[FishEyeVideoVC alloc]init];
  105. fishvc.fileName = path;
  106. fishvc.fisheyephotoOrvideo = 1;
  107. [self presentViewController:fishvc animated:YES completion:nil];
  108. return;
  109. }
  110. //普通的视频文件,就是通用的mp4文件
  111. AVPlayer *player = [AVPlayer playerWithURL:[NSURL fileURLWithPath:path]];
  112. AVPlayerViewController *playerViewController = [AVPlayerViewController new];
  113. playerViewController.player = player;
  114. [self presentViewController:playerViewController animated:YES completion:nil];
  115. [playerViewController.player play];
  116. }
  117. }
  118. - (UITableView *)imageTableView {
  119. if (!imageTableView) {
  120. imageTableView = [[UITableView alloc] initWithFrame:CGRectMake(10, 0, ScreenWidth - 20, ScreenHeight) style:UITableViewStylePlain];
  121. imageTableView.delegate = self;
  122. imageTableView.dataSource = self;
  123. [imageTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"mainCell"];
  124. imageTableView.tag = 0;
  125. }
  126. return imageTableView;
  127. }
  128. - (UITableView *)videoTableView {
  129. if (!videoTableView) {
  130. videoTableView = [[UITableView alloc] initWithFrame:CGRectMake(10, 0, ScreenWidth - 20, ScreenHeight) style:UITableViewStylePlain];
  131. videoTableView.delegate = self;
  132. videoTableView.dataSource = self;
  133. [videoTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"mainCell"];
  134. videoTableView.tag = 1;
  135. videoTableView.hidden = YES;
  136. }
  137. return videoTableView;
  138. }
  139. - (void)didReceiveMemoryWarning {
  140. [super didReceiveMemoryWarning];
  141. // Dispose of any resources that can be recreated.
  142. }
  143. @end