关于这个库你们都不陌生,下面小结下本身使用过程当中的经验,主要是关于全屏横竖屏的几个小点。app
使用cell上直接播放的建立方式(先小屏播放,而后点击全屏按钮),全屏后彻底取决于外部设置的全屏模式(强制改变后会有问题)ide
_player = [ZFPlayerController playerWithScrollView:self.tableView playerManager:playerManager containerViewTag:100];
使用普通模式实现下面的分享有效果spa
_player = [[ZFPlayerController alloc] initWithPlayerManager:playerManager containerView:[UIApplication sharedApplication].keyWindow];
全屏的两种方式code
一、ZFPlayerControllerorm
[self.player enterFullScreen:YES animated:NO];blog
全屏 ZFPlayerControlView设置的全屏模式必须创建在player存在的状况下animation
二、ZFPlayerControlViewit
fullScreenOnlyio
全屏, 竖屏有全屏按钮 无返回按钮 必须到横屏才有返回按钮 设置的模式再也不受影响table
横竖屏的两个影响属性(ZFPlayerController)
一、 lockedScreen 默认NO
锁定屏幕, 什么操做都添加不了, 设置为YES时不论系统是否锁定竖屏 ,均可以按照预约的横竖屏显示
二、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<ZFPlayerMediaPlayback> _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]; }