在使用exoplayer缓存视频/音频内容方面做了一些变通之后,我觉得Jacek在这里给出的答案是实现无限范围请求缓存的正确方法,而不是使用https://github.com/google/ExoPlayer/issues/420 & https://github.com/google/ExoPlayer/issues/57支持的内置Exocache。但是他没有说任何关于配置OkHttp和缓存请求的内容。
谁能给我提供一些关于如何配置okhttp和缓存请求的链接。
发布于 2017-04-24 18:24:48
通过如下所示的buildDataSourceFactory配置更改,我们可以缓存视频内容
private DataSource.Factory buildDataSourceFactory(final boolean useBandwidthMeter) {
// return new DefaultDataSourceFactory(this, useBandwidthMeter ? BANDWIDTH_METER : null,
// buildHttpDataSourceFactory(useBandwidthMeter));
return new DataSource.Factory() {
@Override
public DataSource createDataSource() {
LeastRecentlyUsedCacheEvictor evictor = new LeastRecentlyUsedCacheEvictor(100 * 1024 * 1024);
SimpleCache simpleCache = new SimpleCache(new File(getCacheDir(), "media_cache"), evictor);
return new CacheDataSource(simpleCache, buildMyDataSourceFactory(useBandwidthMeter).createDataSource(),
CacheDataSource.FLAG_BLOCK_ON_CACHE | CacheDataSource.FLAG_CACHE_UNBOUNDED_REQUESTS,
10 * 1024 * 1024);
}
};
}
private DefaultDataSource.Factory buildMyDataSourceFactory(boolean useBandwidthMeter) {
return new DefaultDataSourceFactory(PlayerActivity.this, userAgent, useBandwidthMeter ? BANDWIDTH_METER : null);
}https://stackoverflow.com/questions/42827009
复制相似问题