// // VideoPlayViewController.m // jiaPei // // Created by 张嵘 on 2018/10/18. // Copyright © 2018 JCZ. All rights reserved. // #import "VideoPlayViewController.h" #import "VideoDownLoadListVC.h" static NSString *kVideoCover = @"https://upload-images.jianshu.io/upload_images/635942-14593722fe3f0695.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240"; @interface VideoPlayViewController () @end @implementation VideoPlayViewController - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; self.player.viewControllerDisappear = NO; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; self.player.viewControllerDisappear = YES; } - (void)viewDidLoad { [super viewDidLoad]; [self initUI]; } #pragma mark - Private Method - (void)initUI { [self initBase]; [self initPlayView]; [self initTableView]; } - (void)initBase { self.title = self.currentModel.title; self.view.backgroundColor = backGroundColor; [self configNavigationBarFirstVC]; } - (void)initTableView { if (@available(iOS 11.0, *)) { _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; }else { self.automaticallyAdjustsScrollViewInsets = NO; _tableView.sectionHeaderHeight = 30; } _tableView.rowHeight = UITableViewAutomaticDimension; _tableView.backgroundColor = backGroundColor; _tableView.separatorStyle = UITableViewCellSeparatorStyleNone; UIView *testView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, CGFLOAT_MIN)]; self.tableView.tableHeaderView = testView; } - (void)initPlayView { __weak typeof(self) weakSelf = self; ZFAVPlayerManager *playerManager = [[ZFAVPlayerManager alloc] init]; /// 播放器相关 [self.containerView sd_setImageWithURL:[NSURL URLWithString:self.currentModel.imageUrl] placeholderImage:[UIImage imageNamed:@""]]; self.player = [ZFPlayerController playerWithPlayerManager:playerManager containerView:self.containerView]; self.player.controlView = self.controlView; /// 设置退到后台继续播放 self.player.pauseWhenAppResignActive = NO; self.player.orientationWillChange = ^(ZFPlayerController * _Nonnull player, BOOL isFullScreen) { // [weakSelf setNeedsStatusBarAppearanceUpdate]; myDelegate.allowOrentitaionRotation = isFullScreen; }; /// 播放完成 self.player.playerDidToEnd = ^(id _Nonnull asset) { [weakSelf.player.currentPlayerManager replay]; }; self.player.playerPrepareToPlay = ^(id _Nonnull asset, NSURL * _Nonnull assetURL) { NSLog(@"======开始播放了"); }; // NSString *path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] stringByAppendingPathComponent:[NSString stringWithFormat:@"videoFinish%@%@",_dataDic[@"id"],[self getVideoFormat]]]; // 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"]]; NSURL *pathURL; if (self.currentModel.status == RQDownloadStatus_Completed) { pathURL = [NSURL fileURLWithPath:self.currentModel.destinationPath]; }else { RQDownloadModel *model = [kRQDownloadDataBaseManager getModelWithUrl:self.currentModel.urlString]; if (model && model.status == RQDownloadStatus_Completed) { pathURL = [NSURL fileURLWithPath:model.destinationPath]; }else { pathURL = [NSURL URLWithString:self.currentModel.urlString]; } } self.assetURLs = @[pathURL]; self.player.assetURLs = self.assetURLs; } - (NSString *)getVideoFormat { NSString *format = [NSString stringWithFormat:@".%@",[[self.currentModel.urlString componentsSeparatedByString:@"."] lastObject]]; return format; } - (IBAction)playClick:(id)sender { [self.player playTheIndex:0]; self.playBtn.hidden = YES; [self.controlView showTitle:self.currentModel.title coverURLString:kVideoCover fullScreenMode:ZFFullScreenModeLandscape]; } #pragma mark - System Method - (void)viewWillLayoutSubviews { [super viewWillLayoutSubviews]; } - (UIStatusBarStyle)preferredStatusBarStyle { if (self.player.isFullScreen) { return UIStatusBarStyleLightContent; } return UIStatusBarStyleDefault; } - (BOOL)prefersStatusBarHidden { return NO; } - (UIStatusBarAnimation)preferredStatusBarUpdateAnimation { return UIStatusBarAnimationSlide; } - (BOOL)shouldAutorotate { return NO; } - (UIInterfaceOrientationMask)supportedInterfaceOrientations { if (self.player.isFullScreen) { return UIInterfaceOrientationMaskLandscape; } return UIInterfaceOrientationMaskPortrait; } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [self.view endEditing:YES]; } #pragma mark - UITableViewDataSource And UITableViewDelegate - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 1; } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UITableViewHeaderFooterView *headerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"header"]; if (!headerView) { headerView = [[UITableViewHeaderFooterView alloc] initWithReuseIdentifier:@"header"]; headerView.contentView.backgroundColor = backGroundColor; headerView.textLabel.font = [UIFont scaleSize:FontTitle]; headerView.textLabel.textColor = kTitleColor; } headerView.textLabel.text = @"内容详情"; return headerView; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"]; cell.backgroundColor = backGroundColor; cell.textLabel.numberOfLines = 0; cell.textLabel.font = [UIFont scaleSize:Font17]; cell.textLabel.textColor = contentTextColor; } cell.textLabel.text = self.currentModel.content? self.currentModel.content : @""; return cell; } #pragma mark - Lazy Loading - (ZFPlayerControlView *)controlView { if (!_controlView) { _controlView = [ZFPlayerControlView new]; _controlView.fastViewAnimated = YES; } return _controlView; } - (RQDownloadModel *)currentModel { if (!_currentModel) { _currentModel = [[RQDownloadModel alloc] init]; _currentModel.title = @""; _currentModel.urlString = @""; _currentModel.imageUrl = @""; _currentModel.content = @""; } return _currentModel; } @end