ZFPlayer 全屏、横竖屏使用小记
发布日期:2022-04-05 00:52:12
浏览次数:3
分类:博客文章
本文共 5775 字,大约阅读时间需要 19 分钟。
关于这个库大家都不陌生,下面小结下自己使用过程中的经验,主要是关于全屏横竖屏的几个小点。
使用cell上直接播放的创建方式(先小屏播放,然后点击全屏按钮),全屏后完全取决于外部设置的全屏模式(强制改变后会有问题)
_player = [ZFPlayerController playerWithScrollView:self.tableView playerManager:playerManager containerViewTag:100];
使用普通模式实现下面的分享有效果
_player = [[ZFPlayerController alloc] initWithPlayerManager:playerManager containerView:[UIApplication sharedApplication].keyWindow];
全屏的两种方式
1、ZFPlayerController
[self.player enterFullScreen:YES animated:NO];
全屏 ZFPlayerControlView设置的全屏模式必须建立在player存在的情况下
2、ZFPlayerControlView
fullScreenOnly
全屏, 竖屏有全屏按钮 无返回按钮 必须到横屏才有返回按钮 设置的模式不再受影响
横竖屏的两个影响属性(ZFPlayerController)
1、 lockedScreen 默认NO
锁定屏幕, 什么操作都添加不了, 设置为YES时不论系统是否锁定竖屏 ,都可以按照预定的横竖屏显示
2、allowOrentitaionRotation 默认YES
是否允许播放器旋转 ,可以正常自定义添加标题、时间、返回按钮等等 ,设置为NO时不论系统是否锁定竖屏, 都可以按照预定的横竖屏显示。
设置为YES时,会根据手机旋转方向自动调整,但初始化时会按照自定义的方向初始化
- (ZFPlayerController *)player { if (!_player) { ZFAVPlayerManager *playerManager = [[ZFAVPlayerManager alloc] init]; _player = [[ZFPlayerController alloc] initWithPlayerManager:playerManager containerView:[UIApplication sharedApplication].keyWindow]; _player.controlView = self.controlView; _player.disableGestureTypes = ZFPlayerDisableGestureTypesDoubleTap | ZFPlayerDisableGestureTypesPan | ZFPlayerDisableGestureTypesPinch; _player.WWANAutoPlay = YES;// 锁定屏幕 什么操作都添加不了// _player.lockedScreen = YES;// 不允许屏幕旋转 _player.allowOrentitaionRotation = NO; @weakify(self) _player.playerLoadStateChanged = ^(id_Nonnull asset, ZFPlayerLoadState loadState) { if (loadState == ZFPlayerLoadStatePlaythroughOK) { [UIView animateWithDuration:0.5 animations:^{ @strongify(self) self.controlView.backgroundColor = [UIColor clearColor]; }]; } }; } return _player;}- (ZFPlayerControlView *)controlView { if (!_controlView) { _controlView = [[ZFPlayerControlView alloc] init];// 全屏 竖屏有全屏按钮 无返回按钮 必须到横屏才有返回按钮// _controlView.fullScreenOnly = YES; } return _controlView;}#pragma mark - Event- (void)playVideo:(NSString *) videoUrl videoSnapshotUrl:(NSString *) videoSnapshotUrl { if (!videoUrl.length) { return; } if (self.controlView) { self.controlView = nil; } self.controlView.backgroundColor = [UIColor blackColor]; if (self.player) { self.player = nil; } @weakify(self) self.player.gestureControl.singleTapped = ^(ZFPlayerGestureControl * _Nonnull control) { @strongify(self) [UIView animateWithDuration:0.2 animations:^{ self.player.containerView.alpha = 0.5; }completion:^(BOOL finished) { [self.player stop]; self.player.containerView.alpha = 1; self.player = nil; }]; }; self.player.playerDidToEnd = ^(id _Nonnull asset) { @strongify(self) [self.player.currentPlayerManager replay]; };// [self.player enterFullScreen:YES animated:NO]; 情况下必须放到这里 不然会失效 _controlView.fullScreenOnly = YES; 情况下不需要这样 但是竖屏无法返回 必须到横屏才有返回按钮 [self.controlView showTitle:@"" coverURLString:videoSnapshotUrl fullScreenMode: ZFFullScreenModePortrait]; [self.player enterFullScreen:YES animated:NO]; self.player.currentPlayerManager.assetURL = [NSURL URLWithString:videoUrl]; }- (void)playVideo:(NSString *) videoUrl videoSnapshotUrl:(NSString *) videoSnapshotUrl videoName:(NSString *) videoName imageFormat:(iComeImageFormat) imageFormat{ if (!videoUrl.length) { return; } if (self.controlView) { self.controlView = nil; } self.controlView.backgroundColor = [UIColor blackColor]; @weakify(self) self.controlView.backBtnClickCallback = ^{ @strongify(self) [UIView animateWithDuration:0.2 animations:^{ self.player.containerView.alpha = 0.5; }completion:^(BOOL finished) { [self.player stop]; self.player.containerView.alpha = 1; self.player = nil; }]; }; if (self.player) { self.player = nil; } self.player.playerDidToEnd = ^(id _Nonnull asset) { @strongify(self) [self.player.currentPlayerManager seekToTime:0 completionHandler:^(BOOL finished) { [self.player.currentPlayerManager pause]; }]; }; [self.controlView showTitle:videoName coverURLString:videoSnapshotUrl fullScreenMode: (imageFormat == iComeImageFormatVertical ? ZFFullScreenModePortrait : ZFFullScreenModeLandscape)]; [self.player enterFullScreen:YES animated:NO]; self.player.currentPlayerManager.assetURL = [NSURL URLWithString:videoUrl];}- (void)playVideo:(NSString *) videoPath coverImage:(UIImage *) coverImage { if (!videoPath.length) { return; } if (self.controlView) { self.controlView = nil; } if (self.player) { self.player = nil; } @weakify(self) self.player.gestureControl.singleTapped = ^(ZFPlayerGestureControl * _Nonnull control) { @strongify(self) [UIView animateWithDuration:0.2 animations:^{ self.player.containerView.alpha = 0.5; }completion:^(BOOL finished) { [self.player stop]; self.player.containerView.alpha = 1; self.player = nil; }]; }; self.player.playerDidToEnd = ^(id _Nonnull asset) { @strongify(self) [self.player.currentPlayerManager replay]; }; [self.controlView showTitle:@"" coverImage:coverImage fullScreenMode:ZFFullScreenModePortrait]; [self.player enterFullScreen:YES animated:NO]; self.player.currentPlayerManager.assetURL = [NSURL fileURLWithPath:videoPath];}
转载地址:https://www.cnblogs.com/lijianyi/p/11593356.html 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
逛到本站,mark一下
[***.202.152.39]2024年04月03日 02时48分49秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
Power oj 2540 (FFT卷积)
2019-04-26
hdu 6165(dfs or bfs or tarjan+topsort)
2019-04-26
hdu 6168(stl)
2019-04-26
hdu 6170(正则表达式)
2019-04-26
排列组合 "n个球放入m个盒子m"问题 总结(转)
2019-04-26
codeforces845C(stl)
2019-04-26
图的几种存储方式(邻接矩阵+邻接表+vector)
2019-04-26
[LeetCode] 67. 二进制求和(简单模拟二进制求和)
2019-04-26
HDU1233(基础最小生成树 prim和 kruskal)
2019-04-26
终于找到可以一文多发的平台了!
2019-04-26
IntelliJ IDEA 2019 快捷键终极大全,速度收藏!
2019-04-26
第3章-5 字符转换 (15分)【python】
2019-04-26
L1-068 调和平均 (10 分)
2019-04-26
L1-069 胎压监测 (15 分)
2019-04-26
L1-071 前世档案 (20 分)
2019-04-26
L1-072 刮刮彩票 (20 分)
2019-04-26
L2-012 关于堆的判断 (25 分)
2019-04-26
L1-064 估值一亿的AI核心代码 (20 分)
2019-04-26
L2-033 简单计算器 (25 分)
2019-04-26
L2-034 口罩发放 (25 分)
2019-04-26