版本记录
| 版本号 | 时间 |
|---|---|
| V1.0 | 2017.12.31 |
前言
iOS系统中有很多方式可以播放视频文件,这里我们就详细的说明下播放视频文件的原理和实例。希望能帮助到大家,大家能喜欢。感兴趣的可以参考上面几篇。
1. 几种播放视频文件的方式(一) —— 总结播放视频的几种方式(一)
2. 几种播放视频文件的方式(二) —— 基于MediaPlayer框架的视频播放(一)
3. 几种播放视频文件的方式(三) —— 基于AVFoundation框架视频播放(一)
4. 几种播放视频文件的方式(四) —— 基于AVKit框架的视频播放(一)
5. 几种播放视频文件的方式(五) —— 基于MobileVLCKit框架的视频播放(一)
功能需求
基于MobileVLCKit框架视频播放的简单实例。
功能实现
下面我们就看一下功能实现。
1. 下载库文件
这个文件很大好几百M,但是编译之后只有几M而已,如下:

2. 项目库中添加文件
Linked Frameworks and Libraries中添加下载完成的MobileVLCKit
3. 添加依赖框架,如下图所示。

4. 修改编译选项,由于该框架底层由C++所编写,所以我们需要更改相关的编译选项

5. 修改Framework Search Paths,否则工程无法找到该框架

6. 代码实现
下面我们就看一下代码实现。
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. 网络视频播放
//控制器
- (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];
}];
}
上面只是简单的播放器播放实现,具体的皮肤还需要大家自己根据项目需求添加。
后记
未完,待续~~~~
