ZFPlayer 全屏、橫豎屏使用小記

關於這個庫你們都不陌生,下面小結下本身使用過程當中的經驗,主要是關於全屏橫豎屏的幾個小點。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]; }
相關文章
相關標籤/搜索