版本記錄
版本號 | 時間 |
---|---|
V1.0 | 2017.12.31 |
前言
iOS系統(tǒng)中有很多方式可以播放視頻文件,這里我們就詳細的說明下播放視頻文件的原理和實例酌毡。希望能幫助到大家话原,大家能喜歡倚聚。感興趣的可以參考上面幾篇线衫。
1. 幾種播放視頻文件的方式(一) —— 總結(jié)播放視頻的幾種方式(一)
2. 幾種播放視頻文件的方式(二) —— 基于MediaPlayer框架的視頻播放(一)
3. 幾種播放視頻文件的方式(三) —— 基于AVFoundation框架視頻播放(一)
4. 幾種播放視頻文件的方式(四) —— 基于AVKit框架的視頻播放(一)
5. 幾種播放視頻文件的方式(五) —— 基于MobileVLCKit框架的視頻播放(一)
功能需求
基于MobileVLCKit框架視頻播放的簡單實例。
功能實現(xiàn)
下面我們就看一下功能實現(xiàn)惑折。
1. 下載庫文件
這個文件很大好幾百M授账,但是編譯之后只有幾M而已,如下:
2. 項目庫中添加文件
Linked Frameworks and Libraries
中添加下載完成的MobileVLCKit
3. 添加依賴框架惨驶,如下圖所示白热。
4. 修改編譯選項,由于該框架底層由C++所編寫粗卜,所以我們需要更改相關(guān)的編譯選項
5. 修改Framework Search Paths屋确,否則工程無法找到該框架
6. 代碼實現(xiàn)
下面我們就看一下代碼實現(xiàn)。
1. 本地視頻播放
//控制器
- (void)localPlay
{
//這個是播放器
JJVLCPlayer *player = [[JJVLCPlayer alloc] init];
player.bounds = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.width / 16 * 9);
player.center = self.view.center;
player.mediaURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] URLForResource:@"movie.mp4" withExtension:nil]];
[player showInView:self.view.window];
}
//播放器
- (void)showInView:(UIView *)view
{
NSAssert(_mediaURL != nil, @"JJVLCPlayer Exception: mediaURL could not be nil!");
[view addSubview:self];
self.alpha = 0.0;
[UIView animateWithDuration:kVideoPlayerAnimationTimeinterval animations:^{
self.alpha = 1.0;
} completion:^(BOOL finished) {
[self play];
}];
}
2. 網(wǎng)絡(luò)視頻播放
//控制器
- (void)localPlay
{
JJVLCPlayer *player = [[JJVLCPlayer alloc] init];
player.bounds = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.width / 16 * 9);
player.center = self.view.center;
player.mediaURL = [NSURL URLWithString:@"http://202.198.176.113/video002/2015/mlrs.rmvb"];
[player showInView:self.view.window];
}
//播放器
- (void)showInView:(UIView *)view
{
NSAssert(_mediaURL != nil, @"JJVLCPlayer Exception: mediaURL could not be nil!");
[view addSubview:self];
self.alpha = 0.0;
[UIView animateWithDuration:kVideoPlayerAnimationTimeinterval animations:^{
self.alpha = 1.0;
} completion:^(BOOL finished) {
[self play];
}];
}
上面只是簡單的播放器播放實現(xiàn)续扔,具體的皮膚還需要大家自己根據(jù)項目需求添加攻臀。
后記
未完,待續(xù)~~~~