ZFPlayer运用代码

在一个VC里,导入头文件

#import "ZFPlayer.h"

VC遵守这个协议

ZFPlayerDelegate

vc有两个属性

@property (nonatomic) ZFPlayerView *playerView;
@property (nonatomic) ZFPlayerModel *playerModel;

懒加载

- (ZFPlayerView *)playerView {
    if (!_playerView) {
        _playerView = [[ZFPlayerView alloc] init];
        
        /*****************************************************************************************
         *   // 指定控制层(可自定义)
         *   // ZFPlayerControlView *controlView = [[ZFPlayerControlView alloc] init];
         *   // 设置控制层和播放模型
         *   // 控制层传nil,默认使用ZFPlayerControlView(如自定义可传自定义的控制层)
         *   // 等效于 [_playerView playerModel:self.playerModel];
         ******************************************************************************************/
        [_playerView playerControlView:nil playerModel:self.playerModel];
        
        // 设置代理
        _playerView.delegate = self;
        
        //(可选设置)可以设置视频的填充模式,内部设置默认(ZFPlayerLayerGravityResizeAspect:等比例填充,直到一个维度到达区域边界)
        // _playerView.playerLayerGravity = ZFPlayerLayerGravityResize;
        
        // 打开下载功能(默认没有这个功能)
        _playerView.hasDownload    = YES;
        
        // 打开预览图
        self.playerView.hasPreviewView = YES;

    }
    return _playerView;
}

vc的viewDidLoad方法里可加入

// 自动播放,默认不自动播放
[self.playerView autoPlayTheVideo];

懒加载

- (ZFPlayerModel *)playerModel {
    NSString*titleStr=@"";
    if (self.videoType==PlayViewTypePlayBack) {
        titleStr=self.videoModel.room_name;
    }else{
        titleStr=[NSString stringWithFormat:@"%@",self.meiPaiModel.title];
    }
    
    
    
    if (!_playerModel) {
        _playerModel                  = [[ZFPlayerModel alloc] init];
        _playerModel.title            =titleStr;
        _playerModel.videoURL         = self.videoURL;
        _playerModel.placeholderImage = [UIImage imageNamed:@"loading_bgView1"];
        _playerModel.fatherView       = self.playerFatherView;
//        _playerModel.resolutionDic = @{@"高清" : self.videoURL.absoluteString,
//                                       @"标清" : self.videoURL.absoluteString};
    }
    return _playerModel;
}

实现代理

#pragma mark - ZFPlayerDelegate

- (void)zf_playerBackAction {
    [self.navigationController popViewControllerAnimated:YES];
}

//- (void)zf_playerDownload:(NSString *)url {
//    // 此处是截取的下载地址,可以自己根据服务器的视频名称来赋值
//    NSString *name = [url lastPathComponent];
//    [[ZFDownloadManager sharedDownloadManager] downFileUrl:url filename:name fileimage:nil];
//    // 设置最多同时下载个数(默认是3)
//    [ZFDownloadManager sharedDownloadManager].maxCount = 4;
//}


//分享啊
- (void)zf_playerDownload:(NSString *)url{
    MyLog(@"这里是分享");
  //得到分享的东西
     [self ToGetShareDatas];
    
    
    
    
    
}




- (void)zf_playerControlViewWillShow:(UIView *)controlView isFullscreen:(BOOL)fullscreen {
//    self.backBtn.hidden = YES;
    [UIView animateWithDuration:0.25 animations:^{
        self.backBtn.alpha = 0;
    }];
}

- (void)zf_playerControlViewWillHidden:(UIView *)controlView isFullscreen:(BOOL)fullscreen {
//    self.backBtn.hidden = fullscreen;
    [UIView animateWithDuration:0.25 animations:^{
        self.backBtn.alpha = !fullscreen;
    }];
}


另外一个项目里的用法

image.png

控制器里操作

#import 

托线 播放

@property (weak, nonatomic) IBOutlet ZFPlayerView *playerView;

- (void)viewDidLoad {
    [super viewDidLoad];
    ZFPlayerModel *playerModel = [[ZFPlayerModel alloc] init];
    self.playerView.delegate = self;
    playerModel.videoURL = self.videoURL;
    [self.playerView playerModel:playerModel];
    // 返回按钮事件

}

你可能感兴趣的:(ZFPlayer运用代码)