// // videoPlayByAVPlayerViewController.m // 双子星云手机 // // Created by xd h on 2024/5/22. // #import "videoPlayByAVPlayerViewController.h" //#import //#import //#import //#import //#import "ZFUtilities.h" #import "ZFAVPlayerManager.h" #import "ZFIJKPlayerManager.h" #import "ZFPlayerControlView.h" #import "ZFPlayerConst.h" #import "ZFUtilities.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 *landScapeToPortraitBtn; @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]; }); }; } - (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]; } } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDarkContent]; } - (BOOL)shouldAutorotate { return NO; } /// 如果不好用则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.portraitControlView.topToolView addSubview:self.portraitBackBtn]; 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.portraitToLandScapeBtn]; [self.portraitToLandScapeBtn 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.landScapeControlView.fullScreenBtn.hidden = YES; UILabel *titleLabInlandScape = _controlView.landScapeControlView.titleLabel; titleLabInlandScape.textAlignment = NSTextAlignmentCenter; titleLabInlandScape.lineBreakMode = NSLineBreakByTruncatingMiddle; CGRect titleLabFrameInlandScape = titleLabInlandScape.frame; [titleLabInlandScape mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(45); make.right.mas_equalTo(-45); make.height.mas_equalTo(titleLabFrameInlandScape.size.height); make.top.mas_equalTo(titleLabFrameInlandScape.origin.y); }]; [_controlView.landScapeControlView.topToolView addSubview:self.landScapeToPortraitBtn]; [self.landScapeToPortraitBtn 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); }]; } - (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 *)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; } #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]; } } @end