拖拽SBPlayer文件夹到项目中,并添加Masonry约束第三方库,然后导入SBPlayer.h
即可
//纯代码请用此种方法
//http://ivi.bupt.edu.cn/hls/cctv1hd.m3u8 直播网址
//初始化播放器
self.player = [[SBPlayer alloc]initWithUrl:[NSURL URLWithString:@"http://download.3g.joy.cn/video/236/60236937/1451280942752_hd.mp4"]];
//设置标题
[self.player setTitle:@"这是一个标题"];
//设置播放器背景颜色
self.player.backgroundColor = [UIColor blackColor];
//设置播放器填充模式 默认SBLayerVideoGravityResizeAspectFill,可以不添加此语句
self.player.mode = SBLayerVideoGravityResizeAspectFill;
//添加播放器到视图
[self.view addSubview:self.player];
//约束,也可以使用Frame
[self.player mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.right.left.mas_equalTo(self.view);
make.height.mas_equalTo(@250);
}];
/**
使用xib请用第二种方法
[self.player assetWithURL:[NSURL URLWithString:@"http://download.3g.joy.cn/video/236/60236937/1451280942752_hd.mp4"]];
[self.player setTitle:@"这是一个标题"];
*/
SBPlayer macOS版 : http://www.jianshu.com/p/1ad52c702190
- github: github
- 详细请看简书: iOS通过AVPlayer打造自己的视频播放器