// // videoPlayByAVPlayerViewController.m // 双子星云手机 // // Created by xd h on 2024/5/22. // #import "videoPlayByAVPlayerViewController.h" #import "previewVideoPortraitTopMoreView.h" #import "editShareView.h" #import "uploadFileRecordViewController.h" #import "previewVideoLandscapeTopMoreView.h" #import "UIInterface+HXRotation.h" //#import //#import //#import //#import //#import "ZFUtilities.h" #import "ZFAVPlayerManager.h" #import "ZFIJKPlayerManager.h" #import "ZFPlayerControlView.h" #import "ZFPlayerConst.h" #import "ZFUtilities.h" #import "lastFileManager.h" @interface videoPlayByAVPlayerViewController () @property (nonatomic, strong) ZFPlayerController *player; @property (nonatomic, strong) ZFPlayerControlView *controlView; @property (nonatomic, strong)ZFAVPlayerManager *playerManager; @property (nonatomic, strong)UIView *bgView; @property (nonatomic, strong)UIButton *portraitBackBtn; @property (nonatomic, strong)UIButton *portraitToLandScapeBtn; @property (nonatomic, strong)UIButton *portraitTopMoreBtn; @property (nonatomic, strong)previewVideoPortraitTopMoreView *previewVideoPortraitTopMoreV; @property (nonatomic, strong)UIButton *landScapeToPortraitBtn; @property (nonatomic, strong)UIButton *landScapeTopMoreBtn; @property (nonatomic, strong)previewVideoLandscapeTopMoreView *previewVideoLandscapeTopMoreV; @property(nonatomic,strong) editShareView *editShareV; @property(nonatomic,assign) BOOL isPortraitType;//竖屏状态 @end @implementation videoPlayByAVPlayerViewController - (void)viewDidLoad { [super viewDidLoad]; [self.toolBar setHidden:YES]; [self.navigationBar setHidden:YES]; [self.navBarBGView setHidden:YES]; //self.navBarBGView.backgroundColor = [UIColor blackColor]; self.view.backgroundColor = [UIColor blackColor]; _bgView = [[UIView alloc] init]; [self.view addSubview:_bgView]; [_bgView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.bottom.mas_equalTo(-safeArea); make.top.mas_equalTo(H_STATE_BAR); }]; @zf_weakify(self) self.controlView.backBtnClickCallback = ^{ @zf_strongify(self) [self didClickBackBtnFun]; // [self.player rotateToOrientation:UIInterfaceOrientationPortrait animated:NO completion:nil]; // [self.player stop]; //[self dismissViewControllerAnimated:NO completion:nil]; }; _playerManager = [[ZFAVPlayerManager alloc] init]; /// 播放器相关 self.player = [[ZFPlayerController alloc] initWithPlayerManager:_playerManager containerView:_bgView]; self.player.controlView = self.controlView; // self.player.orientationObserver.supportInterfaceOrientation = ZFInterfaceOrientationMaskLandscape; // [self.player rotateToOrientation:UIInterfaceOrientationLandscapeRight animated:NO completion:nil]; self.playerManager.playerPlayFailed = ^(id _Nonnull asset, id _Nonnull error) { mainBlock(^{ @zf_strongify(self) self.controlView.failBtn.hidden = YES; [[iToast makeText:NSLocalizedString(@"play_video_fail_tip",nil)] show]; }); }; self.playerManager.playerReadyToPlay = ^(id _Nonnull asset, NSURL * _Nonnull assetURL) { @zf_strongify(self) [self videoPlayerDidFun]; }; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; if(!self.playerManager.assetURL){ NSString *filePath = _VideoDataMode.path; NSString *urlStr = ksharedAppDelegate.NASFileByBoxService; NSString *fileUrl = [[NSString alloc] initWithFormat:@"%@getFile?path=%@",urlStr,filePath]; // NSString *string = filePath; // NSString *filePathBase64 = [iTools base64UrlEncoder:string]; // NSString *fileUrl = [[NSString alloc] initWithFormat:@"%@getFiles/%@",urlStr,filePathBase64]; NSString *showUrl = [[NSString alloc] initWithFormat:@"%@getThumbnail?path=%@",urlStr,filePath]; HLog(@"video url:%@",fileUrl); //fileUrl = @"http://transfertest.armclouding.com:10010/getFile?path=/sdcard/bb.mp4"; //fileUrl = @"http://testprivacy.phone.armclouding.com:1801/h5/123.mp4";//可以播放 //fileUrl = @"http://testprivacy.phone.armclouding.com:1801/h5/movTest.mov";//可以播放 //fileUrl = @"http://testprivacy.phone.armclouding.com:1801/h5/yinwei4.mp4";//可以播放 //fileUrl = @"http://testprivacy.phone.armclouding.com:1801/h5/fuchouzhe2.mp4";//可以播放 //fileUrl = @"http://testprivacy.phone.armclouding.com:1801/h5/fuchouzhe.m4v";//可以播放 //fileUrl = @"http://testprivacy.phone.armclouding.com:1801/h5/qisheng.ts";//加载失败 //fileUrl = @"http://testprivacy.phone.armclouding.com:1801/h5/wmvTest.wmv";//加载失败 //fileUrl = @"http://testprivacy.phone.armclouding.com:1801/h5/复仇者联盟.3gp";//加载失败 //fileUrl = @"http://testprivacy.phone.armclouding.com:1801/h5/fuchouzhe3.mpeg";//加载失败 //fileUrl = @"http://testprivacy.phone.armclouding.com:1801/h5/fuchouzhe4.mpg";//加载失败 //fileUrl = @"http://testprivacy.phone.armclouding.com:1801/h5/fuchouzhe5.rm";//加载失败 //fileUrl = @"http://testprivacy.phone.armclouding.com:1801/h5/fuchouzhe5.vob";//加载失败 //fileUrl = @"http://testprivacy.phone.armclouding.com:1801/h5/gamemkv.mkv";//加载失败 //fileUrl = @"http://testprivacy.phone.armclouding.com:1801/h5/j14_yinyue.ogg";// //fileUrl = @"http://file.phone.androidscloud.com:8210/document/newFile/download/1/ikIm5C0KjKNvusTF6tIH/LowLevelMultipartUpload_45050149837826456388";//可以播放 //fileUrl = @"http://testprivacy.phone.armclouding.com:1801/h5/我的视频.mp4"; fileUrl = [fileUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; showUrl = [showUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; //HLog(@"video url:%@",fileUrl); NSURL * sourceMovieURL= [NSURL URLWithString:fileUrl]; self.playerManager.assetURL = sourceMovieURL; [self.controlView showTitle:_VideoDataMode.name coverURLString:showUrl fullScreenMode:ZFFullScreenModeAutomatic]; [self customControlViewUIFun]; } //开始生成 设备旋转 通知 [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; //添加 设备旋转 通知 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientChange:) name:UIDeviceOrientationDidChangeNotification object:nil]; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDarkContent]; //销毁 设备旋转 通知 [[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil]; //结束 设备旋转通知 [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; } - (BOOL)shouldAutorotate { return NO; } /**屏幕旋转的通知回调*/ - (void)orientChange:(NSNotification *)noti { UIDeviceOrientation orient = [UIDevice currentDevice].orientation; switch (orient) { case UIDeviceOrientationPortrait: NSLog(@"竖直屏幕"); if(!_isPortraitType){ [self.player rotateToOrientation:UIInterfaceOrientationPortrait animated:NO completion:^{ [self screenLandscapeToPortraitFun]; }]; } break; case UIDeviceOrientationLandscapeLeft: NSLog(@"手机左转"); if(_isPortraitType){ [self.player rotateToOrientation:UIInterfaceOrientationLandscapeRight animated:NO completion:^{ [self screenPortraitToLandscapeFun]; }]; } break; case UIDeviceOrientationPortraitUpsideDown: // NSLog(@"手机竖直"); break; case UIDeviceOrientationLandscapeRight: NSLog(@"手机右转"); if(_isPortraitType){ [self.player rotateToOrientation:UIInterfaceOrientationLandscapeLeft animated:NO completion:^{ [self screenPortraitToLandscapeFun]; }]; } break; case UIDeviceOrientationUnknown: //NSLog(@"未知"); break; case UIDeviceOrientationFaceUp: //NSLog(@"手机屏幕朝上"); break; case UIDeviceOrientationFaceDown: //NSLog(@"手机屏幕朝下"); break; default: break; } } #pragma mark 竖屏转横屏 - (void)screenPortraitToLandscapeFun{ _isPortraitType = NO; if(_editShareV){ _editShareV.isPortraitType = _isPortraitType; [_controlView.landScapeControlView addSubview:_editShareV]; [self->_editShareV mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.bottom.mas_equalTo(0); make.top.mas_equalTo(0); }]; } } #pragma mark 横屏转竖屏 - (void)screenLandscapeToPortraitFun{ _isPortraitType = YES; if(_editShareV){ _editShareV.isPortraitType = _isPortraitType; [self.view addSubview:_editShareV]; [_editShareV mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.bottom.mas_equalTo(0); make.top.mas_equalTo(0); }]; } } /// 如果不好用则copy VC中 加一下 - (UIInterfaceOrientationMask)supportedInterfaceOrientations { if (self.player.isFullScreen) { return UIInterfaceOrientationMaskLandscape; } return UIInterfaceOrientationMaskPortrait; } //- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { // return UIInterfaceOrientationLandscapeRight; //} - (ZFPlayerControlView *)controlView { if (!_controlView) { _controlView = [ZFPlayerControlView new]; _controlView.fastViewAnimated = YES; _controlView.effectViewShow = NO; _controlView.prepareShowLoading = YES; //_controlView.showCustomStatusBar = YES; } return _controlView; } #pragma mark reset controlView UI - (void)customControlViewUIFun { //竖屏 _controlView.portraitControlView.fullScreenBtn.hidden = YES; //totalTimeLabel slider //隐藏 缓存条 // _controlView.bottomPgrogress.hidden = YES; // _controlView.fastProgressView.hidden = YES; UILabel *titleLab = _controlView.portraitControlView.titleLabel; titleLab.textAlignment = NSTextAlignmentCenter; titleLab.lineBreakMode = NSLineBreakByTruncatingMiddle; CGRect titleLabFrame = titleLab.frame; HLog(@"%f %f %f %f",titleLabFrame.origin.x,titleLabFrame.origin.y,titleLabFrame.size.width,titleLabFrame.size.height); HLog(@""); [titleLab mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(45); make.right.mas_equalTo(-45); make.height.mas_equalTo(titleLabFrame.size.height); make.top.mas_equalTo(titleLabFrame.origin.y); }]; [_controlView.portraitControlView.topToolView addSubview:self.portraitBackBtn]; [self.portraitBackBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(15); make.width.mas_equalTo(28); make.height.mas_equalTo(28); make.top.mas_equalTo(titleLabFrame.origin.y); }]; [_controlView.portraitControlView.topToolView addSubview:self.portraitTopMoreBtn]; [self.portraitTopMoreBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-15); make.width.mas_equalTo(28); make.height.mas_equalTo(28); make.top.mas_equalTo(titleLabFrame.origin.y); }]; [_controlView.portraitControlView.topToolView addSubview:self.portraitToLandScapeBtn]; [self.portraitToLandScapeBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.portraitTopMoreBtn.mas_left).offset(-10); make.width.mas_equalTo(28); make.height.mas_equalTo(28); make.top.mas_equalTo(titleLabFrame.origin.y); }]; /*************************************************************************/ //横屏 //_controlView.landScapeControlView.fullScreenBtn.hidden = YES; UILabel *titleLabInlandScape = _controlView.landScapeControlView.titleLabel; titleLabInlandScape.textAlignment = NSTextAlignmentCenter; titleLabInlandScape.lineBreakMode = NSLineBreakByTruncatingMiddle; CGRect titleLabFrameInlandScape = titleLabInlandScape.frame; //titleLabInlandScape.backgroundColor = [UIColor greenColor]; [titleLabInlandScape mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(_controlView.landScapeControlView.backBtn.mas_right).offset(10); //make.right.mas_equalTo(-45); make.right.mas_equalTo(-25 -90); //make.height.mas_equalTo(titleLabFrameInlandScape.size.height); make.top.equalTo(_controlView.landScapeControlView.backBtn.mas_top).offset(0); make.bottom.equalTo(_controlView.landScapeControlView.backBtn.mas_bottom).offset(0); }]; [_controlView.landScapeControlView.topToolView addSubview:self.landScapeTopMoreBtn]; [self.landScapeTopMoreBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-15 - 20); make.width.mas_equalTo(28); make.height.mas_equalTo(28); //make.top.mas_equalTo(titleLabFrame.origin.y); make.centerY.equalTo(_controlView.landScapeControlView.backBtn.mas_centerY).offset(0); }]; [_controlView.landScapeControlView.topToolView addSubview:self.landScapeToPortraitBtn]; [self.landScapeToPortraitBtn mas_makeConstraints:^(MASConstraintMaker *make) { //make.right.mas_equalTo(-15); make.right.equalTo(self.landScapeTopMoreBtn.mas_left).offset(-20); make.width.mas_equalTo(28); make.height.mas_equalTo(28); //make.top.mas_equalTo(titleLabFrame.origin.y); make.centerY.equalTo(_controlView.landScapeControlView.backBtn.mas_centerY).offset(0); }]; } - (UIButton *)portraitBackBtn { if (!_portraitBackBtn) { _portraitBackBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_portraitBackBtn setImage:ZFPlayer_Image(@"ZFPlayer_back_full") forState:UIControlStateNormal]; [_portraitBackBtn addTarget:self action:@selector(didClickBackBtnFun) forControlEvents:UIControlEventTouchUpInside]; } return _portraitBackBtn; } - (UIButton *)portraitToLandScapeBtn { if (!_portraitToLandScapeBtn) { _portraitToLandScapeBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_portraitToLandScapeBtn setImage:[UIImage imageNamed:@"portraitFullScreen_icon"] forState:UIControlStateNormal]; [_portraitToLandScapeBtn addTarget:self action:@selector(portraitOrLandScapeFun:) forControlEvents:UIControlEventTouchUpInside]; //_portraitToLandScapeBtn.backgroundColor = [UIColor greenColor]; } return _portraitToLandScapeBtn; } - (UIButton*)portraitTopMoreBtn{ if (!_portraitTopMoreBtn) { _portraitTopMoreBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_portraitTopMoreBtn setImage:[UIImage imageNamed:@"nas_preview_more_white"] forState:UIControlStateNormal]; [_portraitTopMoreBtn addTarget:self action:@selector(didClickMoreButFun:) forControlEvents:UIControlEventTouchUpInside]; //_portraitTopMoreBtn.backgroundColor = [UIColor greenColor]; } return _portraitTopMoreBtn; } - (UIButton *)landScapeToPortraitBtn { if (!_landScapeToPortraitBtn) { _landScapeToPortraitBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_landScapeToPortraitBtn setImage:[UIImage imageNamed:@"landScapeToPortrait_icon"] forState:UIControlStateNormal]; [_landScapeToPortraitBtn addTarget:self action:@selector(portraitOrLandScapeFun:) forControlEvents:UIControlEventTouchUpInside]; //_portraitToLandScapeBtn.backgroundColor = [UIColor greenColor]; } return _landScapeToPortraitBtn; } - (UIButton*)landScapeTopMoreBtn{ if (!_landScapeTopMoreBtn) { _landScapeTopMoreBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_landScapeTopMoreBtn setImage:[UIImage imageNamed:@"nas_preview_more_white"] forState:UIControlStateNormal]; [_landScapeTopMoreBtn addTarget:self action:@selector(didClickMoreButFun:) forControlEvents:UIControlEventTouchUpInside]; //_portraitTopMoreBtn.backgroundColor = [UIColor greenColor]; } return _landScapeTopMoreBtn; } #pragma mark 点击返回键 - (void)didClickBackBtnFun { [self.player stop]; [self.navigationController popViewControllerAnimated:YES]; } #pragma mark 横竖屏切换 - (void)portraitOrLandScapeFun:(UIButton*)but { if(but ==_portraitToLandScapeBtn){ //[self.player enterFullScreen:YES animated:YES];; [self.player rotateToOrientation:UIInterfaceOrientationLandscapeRight animated:YES completion:nil]; } else{ [self.player rotateToOrientation:UIInterfaceOrientationPortrait animated:YES completion:nil]; } } #pragma mark 点击顶部更多 获取 分享 下载 更多 - (void)didClickMoreButFun:(UIButton*)but { if(but ==_portraitTopMoreBtn){ _previewVideoPortraitTopMoreV = [[previewVideoPortraitTopMoreView alloc] init]; [self.view addSubview:_previewVideoPortraitTopMoreV]; [_previewVideoPortraitTopMoreV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.bottom.mas_equalTo(0); make.top.mas_equalTo(0); }]; KWeakSelf _previewVideoPortraitTopMoreV.didClickButtonFun = ^(NSInteger tag) { if(tag == 10){ [weakSelf gotoShareViewFun:NO]; } else if (tag == 11){ [weakSelf gotoDownLoadFileFun:NO]; } else if (tag == 12){ [weakSelf showDeleteAlearViewFun]; } }; } else{ _previewVideoLandscapeTopMoreV = [[previewVideoLandscapeTopMoreView alloc] init]; [_controlView.landScapeControlView addSubview:_previewVideoLandscapeTopMoreV]; [_previewVideoLandscapeTopMoreV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.bottom.mas_equalTo(0); make.top.mas_equalTo(0); }]; KWeakSelf _previewVideoLandscapeTopMoreV.didClickButtonFun = ^(NSInteger tag) { if(tag == 10){ [weakSelf gotoShareViewFun:YES]; } else if (tag == 11){ [weakSelf gotoDownLoadFileFun:YES]; } else if (tag == 12){ [weakSelf didClickDeleteInLandscapeFun]; } }; } } #pragma mark 横屏点击删除 - (void)didClickDeleteInLandscapeFun { //横屏的删除 要转竖屏 [self.player rotateToOrientation:UIInterfaceOrientationPortrait animated:NO completion:^{ [self screenLandscapeToPortraitFun]; [self showDeleteAlearViewFun]; }]; } #pragma mark 视频可以播放 加入最近文件 - (void)videoPlayerDidFun{ NASFileAndFolderDataModel *dataModel = _VideoDataMode; lastFileModel *lastFileMod = [lastFileModel new]; lastFileMod.path = dataModel.path; lastFileMod.name = dataModel.name; lastFileMod.time = dataModel.time; lastFileMod.size = dataModel.size; lastFileMod.duration = dataModel.duration; lastFileMod.type = @"video"; lastFileMod.lastPreTime = [iTools getNowTimeStamp]; [[lastFileManager shareManager] saveFileInfoWith:lastFileMod with:dataModel.path]; } #pragma mark 用户点击分享 - (void)gotoShareViewFun:(BOOL)isLandscapeType { if(!_VideoDataMode){ return; } _editShareV = [[editShareView alloc] init]; _editShareV.didSelectListArr = [NSMutableArray arrayWithArray:@[_VideoDataMode]]; _editShareV.shareFileType = @"3"; if(isLandscapeType){ _editShareV.isPortraitType = NO; [_controlView.landScapeControlView addSubview:_editShareV]; } else{ [self.view addSubview:_editShareV]; } [_editShareV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.bottom.mas_equalTo(0); make.top.mas_equalTo(0); }]; } #pragma mark 删除图片 - (void)showDeleteAlearViewFun { NSString *titleStr = NSLocalizedString(@"delete_file_title_msg",nil); NSString *tipStr = NSLocalizedString(@"delete_file_tip_msg",nil); KWeakSelf ComontAlretViewController *curAlretVC= [[ComontAlretViewController alloc] initWithTiTle:titleStr msg:tipStr imageStr:nil cancelTitle:NSLocalizedString(@"other_cancel",nil) okTitle:NSLocalizedString(@"other_confirm",nil) isOkBtnHighlight:YES didClickOk:^{ [weakSelf delFileListFun]; } didClickCancel:^{ }]; curAlretVC.modalPresentationStyle = UIModalPresentationCustom; [self presentViewController:curAlretVC animated:YES completion:^{ curAlretVC.view.superview.backgroundColor = [UIColor clearColor]; }]; } #pragma mark 删除文件数据 - (void)delFileListFun { NSMutableDictionary*paraDict = [NSMutableDictionary new]; if(_VideoDataMode){ NSArray *pathArr = @[_VideoDataMode.path]; [paraDict setValue:pathArr forKey:@"path"]; } [self showNewIndicatorWithCanBack:YES canTouch:NO]; //NSString*code = [[NSString alloc] initWithFormat:@"delFile?path=%@",paraDict[@"path"]]; //delFile?path=[/storage/emulated/0/Download/IMG_6464.HEIC] KWeakSelf //@"delFile" [[netWorkManager shareInstance] cloudPhonePostCallBackCode:@"delFile" Parameters:paraDict success:^(id _Nonnull responseObject) { [weakSelf removeNewIndicator]; SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil]; if(model && model.status == 0){ [[iToast makeText:NSLocalizedString(@"delete_file_suc_msg",nil)] show]; if(weakSelf.didNeedToRegetDataFun){ weakSelf.didNeedToRegetDataFun(); } [weakSelf.navigationController popViewControllerAnimated:YES]; } else{ } } failure:^(NSError * _Nonnull error) { [weakSelf removeNewIndicator]; }]; } #pragma mark 去下载文件 - (void)gotoDownLoadFileFun:(BOOL)isLandscapeType { if(_VideoDataMode){ if(isLandscapeType){ //切换到竖屏 //[self hx_rotateToInterfaceOrientation:UIInterfaceOrientationPortrait]; [self.player rotateToOrientation:UIInterfaceOrientationPortrait animated:YES completion:nil]; } couldPhoneFileModel* fileModel = [couldPhoneFileModel new]; fileModel.fileType = @"video"; fileModel.path = _VideoDataMode.path; fileModel.name = _VideoDataMode.name; fileModel.length = _VideoDataMode.size; NSMutableArray *arr = [NSMutableArray new]; [arr addObject:fileModel]; uploadFileRecordViewController *vc = [uploadFileRecordViewController new]; [self.navigationController pushViewController:vc animated:YES]; vc.isDownloadingType = YES; [vc gotoDownloadFile:arr]; } } @end