最近接受一个视频播放的项目 发现一个问题视频在拖动的时候 需要等很久才能播放 看了下代码使用的是B站开源的ijkplayer 查了下资料很多人说没有ijkplayer每次都seek时都重新链接获取数据导致耗时很长。查了下资料发现很少涉及到播放器缓存这块,更有人说ijkplayer不支持缓存。
于是下了ijkplayer的源码 编译一下 编译过程不说了 很方便的 代码里简单搜索下cache 搜到了cache的相关信息说明ijkplayer还是支持的。又查了下代码和资料完成这功能seek时能够做到秒开。
具体实现代码如何:
NSString *libraryPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Library"];
libraryPath = [libraryPath stringByAppendingString:@"/Caches/"];
NSString *fileName = [self.url.pathComponents lastObject];
libraryPath = [libraryPath stringByAppendingString:fileName];
NSString *mapPath = [libraryPath stringByAppendingString:@"/map/"];
mapPath = [mapPath stringByAppendingString:fileName];
mapPath = [mapPath stringByAppendingString:@".tmp"];
[options setFormatOptionValue:libraryPath forKey:@"cache_file_path"];
[options setFormat