iOS使用ZFPlayer 实现视频播放

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];
    
  • 4
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值