123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307 |
- //
- // videoPlayByAVPlayerViewController.m
- // 双子星云手机
- //
- // Created by xd h on 2024/5/22.
- //
- #import "videoPlayByAVPlayerViewController.h"
- //#import <ZFPlayer/ZFAVPlayerManager.h>
- //#import <ZFPlayer/ZFIJKPlayerManager.h>
- //#import <ZFPlayer/ZFPlayerControlView.h>
- //#import <ZFPlayer/ZFPlayerConst.h>
- //#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 *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<ZFPlayerMediaPlayback> _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<ZFPlayerMediaPlayback> _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];
- }
- }
- - (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];
- }
- }
- #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];
-
- }
- @end
|