本文主要记录在iOS上集成VLC的过程。
VLC是一个很强大的播放器,并给开发者提供了播放器接口。
1,下载编译
下载过程比Webrtc要好很多,不那么虐心。
参照 https://wiki.videolan.org/VLCKit/ 的步骤一步步来即可。
下载如果没问题,直接执行./buildMobileVLCKit.sh完成编译。
编译过程也是很顺利的,我编译的时候提示缺少了libtasn1和libdsm两个组件,但是事实上可以直接打开MobileVLCKit.xcodeproj,在编译设置中找到Other Librarian Flag设置,删除掉$(DSM)配置重新编译即可。
MobileVLCKit的编译其实分为两步,
第一步首先编译libvlc,主要通过MobileVLCKit/ImportedSources/vlc/extras/package/ios/build.sh脚本来编译,buildMobileVLCKit.sh会调用这个脚本。
第二步编译封装层MobileVLCKit.framework,这个步骤通过根目录下的buildMobileVLCKit.sh -l和MobileVLCKit/AggregateStaticPlugins.sh两个脚本编译。
如果在编译时执行./buildMobileVLCKit.sh -f会在build目录下生成MobileVLCKit.framework,否则生成相应的静态库。
如果不想自己编译,也可以使用官方的build版本,下载地址:http://nightlies.videolan.org/build/ios/
2,集成调用
MobileVLCKit调用过程:
VLCMediaPlayer * mediaPlayer = [[VLCMediaPlayeralloc] initWithOptions:nil];
self.mediaPlayer = mediaPlayer;
self.mediaPlayer.media = [VLCMediamediaWithURL:mediaURL];
self.mediaPlayer.delegate =self;
self.videoView.frame =self.view.frame;
self.mediaPlayer.drawable =self.videoView;
initWithOptions接口,通过传入特定的参数可以实现定制化。
比如通过如下方法设置流媒体的播放缓存:
NSUInteger vlcCache = 2000;
NSString *cacheOption = [NSStringstringWithFormat:@"--network-caching=[0 .. %d]", vlcCache];
NSArray* options = @[cacheOption];
VLCMediaPlayer * mediaPlayer = [[VLCMediaPlayeralloc] initWithOptions:options];
理论上这个应该是可行的,但是经过测试似乎并没有效果。