隨着視頻直播APP的迅速發展,許多APP也都會加入直播的功能,提高用戶量。在網上也是尋找了許多直播的播放器,無意間發現Bilibili開源了一款播放器ijkplayer,想從最開始的步驟集成的同學可以點進去查看集成教程。當然,我這里為大家已經都封裝好啦,只要簡單的幾步就可以使用該播放器了。LZH_IJKPlayer點擊這個就可以下載源代碼了。那如何集成到你的項目中呢。
1、先看Demo
將箭頭所指的兩個文件夾添加到你的工程中。ijkplayer已經打包成framework了,就是圖中的IJKMediaFramework
當然以下幾個依賴包,肯定是要你重新手動添加的啦。相信大家知道在哪里添加,我就不一一贅述啦。
2、如何使用?再看DEMO
我把視頻播放的視圖添加在下面這個控制器中。
打開.m文件,需要實現的跟視頻相關的代碼如下。
//初始化視頻播放控制器
self.playerView = [XYVideoPlayerView videoPlayerView];
self.playerView.delegate = self;
[_headPlayerView addSubview:self.playerView];
self.playerView = self.playerView;
//視頻的Model,將視頻地址和視頻文件的名稱作為Model
XYVideoModel *model = [[XYVideoModel alloc]init];
model.url = [NSURL URLWithString:@"http://bos.nj.bpc.baidu.com/tieba-smallvideo/11772_3c435014fb2dd9a5fd56a57cc369f6a.mp4"];
model.name = @"video1";
self.playerView.videoModel = model;
//點擊全屏按鈕的代理事件
- (void)fullScreenWithPlayerView:(XYVideoPlayerView *)videoPlayerView
{
if (self.playerView.isRotate) {
[UIView animateWithDuration:0.3 animations:^{
_headPlayerView.transform = CGAffineTransformRotate(_headPlayerView.transform, M_PI_2);
_headPlayerView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
self.playerView.frame = _headPlayerView.bounds;
}];
}else{
[UIView animateWithDuration:0.3 animations:^{
_headPlayerView.transform = CGAffineTransformIdentity;
_headPlayerView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.width*9/16);
self.playerView.frame = _headPlayerView.bounds;
}];
}
}
//點擊返回按鈕的代理事件
- (void)backToBeforeVC{
if (!self.playerView.isRotate) {
[self.navigationController popViewControllerAnimated:YES];
}
}
//控制器銷毀時必須要實現的方法。
- (void)dealloc{
[self.playerView deallocPlayer];
}
3、說明
播放器實現了左半邊屏幕上下滑動調節亮度,右半邊屏幕,上下滑動調節音量,左右滑動是快進和快退。
Github源碼地址:https://github.com/Harvyluo/LZH_IJKPlayer
以上就是該播放器的集成過程,使用中有什么問題,可以加官方群。群號:156760711 (LZH_IJKPlayer交流群)
歡迎轉載,不過請注明該地址,謝謝合作。