VLC 是一款强大的全平台播放器, 几乎支持所有的音频�、视频格式文件播放, 官网地址:http://www.videolan.org/, 在iOS 中也可以集成 VLC 的 SDK 进行开发, 使用之前需要先去官网下载 SDK, 然后编译成 iOS 中使用的库文件才能使用, 这�种集成方法在编译的过程中需要 VPN 翻墙进行联网编译, 如果网速不好或者不稳定, 很容易编译出错, 如果网速好, 可以按照 wiki 的说明去编译: https://wiki.videolan.org/iOSCompile.
还有一种简单的集成方式, 不用编译, 直接下载编译好的MobileVLCKit.framework
就可以了. 下面开始一步一步做.
一.下载MobileVLCKit.framework
下载地址:http://nightlies.videolan.org/build/ios/.
打开页面之后, 拉到网页最下面可以看到最新的MobileVLCKit.framework
, 不过最新的�在使用时会报错(以后更新后不知道还会不会报错, 如果更新了可以自己再尝试最新的), 可以下载4月16日的, 如下图:

下载完解压后, 里面的MobileVLCKit.framework
就是我们要使用的 framework 了, 如下图:

二. iOS工程中集成MobileVLCKit.framework
新建工程, 将MobileVLCKit.framework
导入工程并添加相关的依赖框架, 依赖框架有:
AudioToolbox.framework
VideoToolbox.framework
CoreMedia.framework
CoreVideo.framework
CoreAudio.framework
AVFoundation.framework
MediaPlayer.framework
libstdc++.6.0.9.tbd
libiconv.2.tbd
libc++.1.tbd
libz.1.tbd
libbz2.1.0.tbd
导入全部框架后, 如下图:

导入后, 在ViewController.m
中引人头文件: #import <MobileVLCKit/MobileVLCKit.h>
, 如果没有报错, 说明集成成功.
三. 测试
在ViewController.m
中引人头文件进行测试, 主要代码如下:
UIView *videoView = [[UIView alloc] initWithFrame:CGRectMake(0, 50, self.view.bounds.size.width, 200)];
[self.view addSubview:videoView];
VLCMediaPlayer *player = [[VLCMediaPlayer alloc] initWithOptions:nil];
self.player = player;
self.player.drawable = videoView;
self.player.media = [VLCMedia mediaWithPath:[[NSBundle mainBundle] pathForResource:@"test" ofType:@"wmv"]];
[self.player play];
运行结果如下:

如果要获取播放视频需要的总时间, 可以从VLCMedia
类中的length
属性获取, 如下:
NSInteger *AllTime = self.media.length.intValue;
如果要获取视频的当前播放进度, 需要给player
设置delegate
, 然后在代理方法中通过player
的time
属性获取当前进度, 获取当前播放进度的代理方法如下:
- (void)mediaPlayerTimeChanged:(NSNotification *)aNotification{
//获取当前的播放进度
NSInteger *currentProgress = self.player.time.intValue;
}
如果需要�控制播放进度(比如快进或回放), 可以�设置player
类的position
属性, position
范围为0.0~1.0之间, 如下:
//设置播放进度, 0.0~1.0
[self.player setPosition:0.5];
如果需要获取视频的缩略图, 则需要用到VLCMediaThumbnailer
类, 并设置代理进行监听获取, 如下:
//初始化并设置代理
VLCMediaThumbnailer *thumbnailer = [VLCMediaThumbnailer thumbnailerWithMedia:media andDelegate:self];
self.thumbnailer = thumbnailer;
//开始获取缩略图
[self.thumbnailer fetchThumbnail];
代理方法如下:
//获取缩略图超时
- (void)mediaThumbnailerDidTimeOut:(VLCMediaThumbnailer *)mediaThumbnailer{
NSLog(@"getThumbnailer time out.");
}
//获取缩略图成功
- (void)mediaThumbnailer:(VLCMediaThumbnailer *)mediaThumbnailer didFinishThumbnail:(CGImageRef)thumbnail{
//获取缩略图
UIImage *image = [UIImage imageWithCGImage:thumbnail];
}
网友评论
Q:
播放本地视频时,用这个怎么拿取封面图,现在只知道在播放中,可以拿到,那我想在显示的时候,就拿到封面,该如何做呢?
http://upload-images.jianshu.io/upload_images/2791500-c8c863e7306dfb4b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240
看到demo 有AudioUnit.framework但是加上后 编译又报错通不过,楼主 能否交流下这个怎么办?
2017-05-12 16:20:42.285 XPlayer[54345:5967721] creating player instance using shared library
[00007faf0d60a298] core generic error: option marq-color does not exist
[00007faf0d60a298] core generic error: option marq-opacity does not exist
[00007faf0d60a298] core generic error: option marq-position does not exist
[00007faf0d60a298] core generic error: option marq-refresh does not exist
[00007faf0d60a298] core generic error: option marq-size does not exist
[00007faf0d60a298] core generic error: option marq-timeout does not exist
[00007faf0d60a298] core generic error: option marq-x does not exist
[00007faf0d60a298] core generic error: option marq-y does not exist
然后设置一个属性就行了
@property (nonatomic,strong)VLCMediaPlayer *player