文章目录
ZFPlayer 视频播放使用
1 创建 ZFAVPlayerManager 对象
ZFAVPlayerManager *manager = [[ZFAVPlayerManager alloc] init];
2创建containerView, 也就是视频视图的父视图
我们可以在该containerView 中添加和视频相关信息,
比如视频名称,作者信息,内容简介等等,一般情况下,视频的
第一帧的图片也是放在该containerView中的
- (TPVerticalLivingVideoContentView *)contentView
{
if (!_contentView) {
_contentView = [[TPVerticalLivingVideoContentView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
_contentView.delegate = self;
}
return _contentView;
}
3 创建 controllView
这里的controllView 主要包括视频操作相关的空间,比如
视频时长,视频进度条,视频快进等等
- (TPVerticalLivingVideoControlView *)controlView
{
if (!_controlView) {
_controlView = [[TPVerticalLivingVideoControlView alloc] init];
_controlView.contentView = self.contentView;
WEAKSELF
_controlView.doubleClickPraiseCompletion = ^{
//[weakSelf bigDataDoubleClickPraiseCompletion];
};
_controlView.sliderTouchBeganBlock = ^{
[weakSelf.contentView hiddenContent:YES];
};
_controlView.sliderTouchEnded = ^{
[weakSelf.contentView hiddenContent:NO];
};
}
return _controlView;
}
注意: controlView 需要遵循 ZFPlayerMediaControl 协议
4 创建 ZFPlayerController
- (ZFPlayerController *)player
{
if (!_player) {
ZFAVPlayerManager *manager = [[ZFAVPlayerManager alloc] init];
UIView *containerView = [self.contentView viewWithTag:VerticalLivingPlayViewTag];
_player = [ZFPlayerController playerWithPlayerManager:manager containerView:containerView];
if (![[TPUserDefault instance].network isEqualToString:@"1"]) {
_player.isCellularVideo = YES;
}else {
_player.isCellularVideo = NO;
}
WEAKSELF
_player.show4GAlertBlock = ^{
[weakSelf.controlView pause];
};
_player.currentPlayerManager.scalingMode = ZFPlayerScalingModeAspectFill;
_player.controlView = self.controlView;
_player.currentPlayerManager.view.backgroundColor = [UIColor clearColor];
_player.shouldAutoPlay = YES;
_player.WWANAutoPlay = YES;
_player.canGetAnalysisModelFromTopVC = YES;
//这里是为了和视频新闻详情页面逻辑相同
_player.allowOrentitaionRotation = NO;
_player.disablePanMovingDirection = ZFPlayerDisablePanMovingDirectionAll;
//1.0 是消失100% 时候
_player.playerDisapperaPercent = 1.0;
_player.orientationWillChange = ^(ZFPlayerController * _Nonnull player, BOOL isFullScreen) {
if (isFullScreen) {
weakSelf.player.disablePanMovingDirection = ZFPlayerDisablePanMovingDirectionNone;
} else {
weakSelf.player.disablePanMovingDirection = ZFPlayerDisablePanMovingDirectionAll;
}
};
_player.playerDidToEnd = ^(id<ZFPlayerMediaPlayback> _Nonnull asset) {
[weakSelf.player.currentPlayerManager replay];
};
}
return _player;
}
播放视频
//传入视频链接
self.player.assetURL = [NSURL URLWithString:@"http:。。。b.mp4"];
判断视频的横竖
判断竖视频
self.player.orientationObserver.fullScreenMode == ZFFullScreenModePortrait
进入全屏播放
[self.player enterPortraitFullScreen:YES animated:YES];