Giter VIP home page Giter VIP logo

clplayer's Introduction

使用AVPlayer自定义支持全屏的播放器

#功能     本视频播放器主要自定义了带缓冲显示的进度条,可以拖动调节视频播放进度的播放条,具有当前播放时间和总时间的Label,全屏播放功能,定时消失的工具条。支持旋转屏幕自动全屏,可以添加到UItableView上。

#接口与用法

  • 接口
/**视频url*/
@property (nonatomic,strong) NSURL *url;
/**旋转自动全屏,默认Yes*/
@property (nonatomic,assign) BOOL autoFullScreen;
/**重复播放,默认No*/
@property (nonatomic,assign) BOOL repeatPlay;
/**是否支持横屏,默认No*/
@property (nonatomic,assign) BOOL isLandscape;
/**播放*/
- (void)playVideo;
/**暂停*/
- (void)pausePlay;
/**返回按钮回调方法*/
- (void)backButton:(BackButtonBlock) backButton;
/**播放完成回调*/
- (void)endPlay:(EndBolck) end;
/**销毁播放器*/
- (void)destroyPlayer;
/**
 根据播放器所在位置计算是否滑出屏幕,

 @param tableView Cell所在tableView
 @param cell 播放器所在Cell
 @param beyond 滑出后的回调
 */
- (void)calculateWith:(UITableView *)tableView cell:(UITableViewCell *)cell beyond:(BeyondBlock) beyond;

  • 使用方法

    直接使用cocoapods导入,`pod 'CLPlayer', '~> 1.0.0'`
    
  • TableView使用方法

#pragma mark - 点击播放代理
- (void)PlayVideoWithCell:(TableViewCell *)cell;
{
//记录被点击的cell
    _cell = cell;
    
    //销毁播放器
    [_playerView destroyPlayer];
    _playerView = nil;
    
    _playerView = [[CLPlayerView alloc] initWithFrame:CGRectMake(0, 0, cell.width, cell.height)];
    [cell.contentView addSubview:_playerView];
    
    //根据旋转自动支持全屏,默认支持
    //    playerView.autoFullScreen = NO;
    //重复播放,默认不播放
    //    playerView.repeatPlay     = YES;
    //如果播放器所在页面支持横屏,需要设置为Yes,不支持不需要设置(默认不支持)
    //    playerView.isLandscape    = YES;
    
    //视频地址
    _playerView.url = [NSURL URLWithString:cell.model.videoUrl];
    
    //播放
    [_playerView playVideo];
    
    //返回按钮点击事件回调
    [_playerView backButton:^(UIButton *button) {
        NSLog(@"返回按钮被点击");
    }];
    
    //播放完成回调
    [_playerView endPlay:^{
        
        //销毁播放器
        [_playerView destroyPlayer];
        _playerView = nil;
        NSLog(@"播放完成");
    }];
 
}

    在tableView滑动代理中,需要使用- (void)calculateWith:(UITableView *)tableView cell:(UITableViewCell *)cell beyond:(BeyondBlock) beyond方法,将tableView和播放器所在cell传递给播放器,播放器会在内部计算播放器所在位置,在超出屏幕的时候,会调用超出的block,在block回调中对播放器销毁。

#pragma mark - 滑动代理
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    [_playerView calculateWith:self.tableView cell:_cell beyond:^{
        //销毁播放器
        [_playerView destroyPlayer];
        _playerView = nil;
    }];
}

#播放器效果图

#详细请看简书

http://www.jianshu.com/p/83191c7bc840

clplayer's People

Contributors

jmovxia avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.