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 controlView を作成する

ここでの controlView には、主に、
動画の長さ、動画の進行状況バー、動画の早送りなど、動画操作に関連するスペースが含まれています。

- (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"];

おすすめ

転載: blog.csdn.net/LIUXIAOXIAOBO/article/details/125694012