VideoPlayViewController.m 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. //
  2. // VideoPlayViewController.m
  3. // jiaPei
  4. //
  5. // Created by 张嵘 on 2018/10/18.
  6. // Copyright © 2018 JCZ. All rights reserved.
  7. //
  8. #import "VideoPlayViewController.h"
  9. #import "VideoDownLoadListVC.h"
  10. static NSString *kVideoCover = @"https://upload-images.jianshu.io/upload_images/635942-14593722fe3f0695.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240";
  11. @interface VideoPlayViewController () <UITableViewDataSource, UITableViewDelegate>
  12. @end
  13. @implementation VideoPlayViewController
  14. - (void)viewWillAppear:(BOOL)animated {
  15. [super viewWillAppear:animated];
  16. self.player.viewControllerDisappear = NO;
  17. }
  18. - (void)viewWillDisappear:(BOOL)animated {
  19. [super viewWillDisappear:animated];
  20. self.player.viewControllerDisappear = YES;
  21. }
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. [self initUI];
  25. }
  26. #pragma mark - Private Method
  27. - (void)initUI {
  28. [self initBase];
  29. [self initPlayView];
  30. [self initTableView];
  31. }
  32. - (void)initBase {
  33. self.title = self.currentModel.title;
  34. self.view.backgroundColor = backGroundColor;
  35. [self configNavigationBarFirstVC];
  36. }
  37. - (void)initTableView {
  38. if (@available(iOS 11.0, *)) {
  39. _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  40. }else {
  41. self.automaticallyAdjustsScrollViewInsets = NO;
  42. _tableView.sectionHeaderHeight = 30;
  43. }
  44. _tableView.rowHeight = UITableViewAutomaticDimension;
  45. _tableView.backgroundColor = backGroundColor;
  46. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  47. UIView *testView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, CGFLOAT_MIN)];
  48. self.tableView.tableHeaderView = testView;
  49. }
  50. - (void)initPlayView {
  51. __weak typeof(self) weakSelf = self;
  52. ZFAVPlayerManager *playerManager = [[ZFAVPlayerManager alloc] init];
  53. /// 播放器相关
  54. [self.containerView sd_setImageWithURL:[NSURL URLWithString:self.currentModel.imageUrl] placeholderImage:[UIImage imageNamed:@""]];
  55. self.player = [ZFPlayerController playerWithPlayerManager:playerManager containerView:self.containerView];
  56. self.player.controlView = self.controlView;
  57. /// 设置退到后台继续播放
  58. self.player.pauseWhenAppResignActive = NO;
  59. self.player.orientationWillChange = ^(ZFPlayerController * _Nonnull player, BOOL isFullScreen) {
  60. // [weakSelf setNeedsStatusBarAppearanceUpdate];
  61. myDelegate.allowOrentitaionRotation = isFullScreen;
  62. };
  63. /// 播放完成
  64. self.player.playerDidToEnd = ^(id _Nonnull asset) {
  65. [weakSelf.player.currentPlayerManager replay];
  66. };
  67. self.player.playerPrepareToPlay = ^(id<ZFPlayerMediaPlayback> _Nonnull asset, NSURL * _Nonnull assetURL) {
  68. NSLog(@"======开始播放了");
  69. };
  70. // NSString *path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] stringByAppendingPathComponent:[NSString stringWithFormat:@"videoFinish%@%@",_dataDic[@"id"],[self getVideoFormat]]];
  71. // self.assetURLs = @[[NSURL URLWithString:@"https://www.apple.com/105/media/us/iphone-x/2017/01df5b43-28e4-4848-bf20-490c34a926a7/films/feature/iphone-x-feature-tpl-cc-us-20170912_1280x720h.mp4"]];
  72. NSURL *pathURL;
  73. if (self.currentModel.status == RQDownloadStatus_Completed) {
  74. pathURL = [NSURL fileURLWithPath:self.currentModel.destinationPath];
  75. }else {
  76. RQDownloadModel *model = [kRQDownloadDataBaseManager getModelWithUrl:self.currentModel.urlString];
  77. if (model && model.status == RQDownloadStatus_Completed) {
  78. pathURL = [NSURL fileURLWithPath:model.destinationPath];
  79. }else {
  80. pathURL = [NSURL URLWithString:self.currentModel.urlString];
  81. }
  82. }
  83. self.assetURLs = @[pathURL];
  84. self.player.assetURLs = self.assetURLs;
  85. }
  86. - (NSString *)getVideoFormat {
  87. NSString *format = [NSString stringWithFormat:@".%@",[[self.currentModel.urlString componentsSeparatedByString:@"."] lastObject]];
  88. return format;
  89. }
  90. - (IBAction)playClick:(id)sender {
  91. [self.player playTheIndex:0];
  92. self.playBtn.hidden = YES;
  93. [self.controlView showTitle:self.currentModel.title coverURLString:kVideoCover fullScreenMode:ZFFullScreenModeLandscape];
  94. }
  95. #pragma mark - System Method
  96. - (void)viewWillLayoutSubviews {
  97. [super viewWillLayoutSubviews];
  98. }
  99. - (UIStatusBarStyle)preferredStatusBarStyle {
  100. if (self.player.isFullScreen) {
  101. return UIStatusBarStyleLightContent;
  102. }
  103. return UIStatusBarStyleDefault;
  104. }
  105. - (BOOL)prefersStatusBarHidden {
  106. return NO;
  107. }
  108. - (UIStatusBarAnimation)preferredStatusBarUpdateAnimation {
  109. return UIStatusBarAnimationSlide;
  110. }
  111. - (BOOL)shouldAutorotate {
  112. return NO;
  113. }
  114. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  115. if (self.player.isFullScreen) {
  116. return UIInterfaceOrientationMaskLandscape;
  117. }
  118. return UIInterfaceOrientationMaskPortrait;
  119. }
  120. - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
  121. [self.view endEditing:YES];
  122. }
  123. #pragma mark - UITableViewDataSource And UITableViewDelegate
  124. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  125. return 1;
  126. }
  127. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  128. UITableViewHeaderFooterView *headerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"header"];
  129. if (!headerView) {
  130. headerView = [[UITableViewHeaderFooterView alloc] initWithReuseIdentifier:@"header"];
  131. headerView.contentView.backgroundColor = backGroundColor;
  132. headerView.textLabel.font = [UIFont scaleSize:FontTitle];
  133. headerView.textLabel.textColor = kTitleColor;
  134. }
  135. headerView.textLabel.text = @"内容详情";
  136. return headerView;
  137. }
  138. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  139. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  140. if (!cell) {
  141. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
  142. cell.backgroundColor = backGroundColor;
  143. cell.textLabel.numberOfLines = 0;
  144. cell.textLabel.font = [UIFont scaleSize:Font17];
  145. cell.textLabel.textColor = contentTextColor;
  146. }
  147. cell.textLabel.text = self.currentModel.content? self.currentModel.content : @"";
  148. return cell;
  149. }
  150. #pragma mark - Lazy Loading
  151. - (ZFPlayerControlView *)controlView {
  152. if (!_controlView) {
  153. _controlView = [ZFPlayerControlView new];
  154. _controlView.fastViewAnimated = YES;
  155. }
  156. return _controlView;
  157. }
  158. - (RQDownloadModel *)currentModel {
  159. if (!_currentModel) {
  160. _currentModel = [[RQDownloadModel alloc] init];
  161. _currentModel.title = @"";
  162. _currentModel.urlString = @"";
  163. _currentModel.imageUrl = @"";
  164. _currentModel.content = @"";
  165. }
  166. return _currentModel;
  167. }
  168. @end