如何在ExoPlayer中实现缓存?它总是重新下载整个视频真的很糟糕......
我在RendererBuilder中尝试了以下方法:
Allocator allocator = new DefaultAllocator(BUFFER_SEGMENT_SIZE);
DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(player.getMainHandler(),
null);
SimpleCache cache = (SimpleCache) Singleton.getSingleton(context).getCache();
// Always prints 0, that's the problem!
Log.d("CacheSize", String.valueOf(cache.getCacheSpace()));
DataSource dataSource = new DefaultUriDataSource(context, bandwidthMeter, userAgent);
CacheDataSource cacheDataSource = new CacheDataSource(cache, dataSource, false, false);
ExtractorSampleSource sampleSource = new ExtractorSampleSource(uri, cacheDataSource, allocator,
BUFFER_SEGMENT_COUNT * BUFFER_SEGMENT_SIZE);
在我的Singleton的构造函数中:
this.cache = new SimpleCache(context.getApplicationContext().getCacheDir(), new LeastRecentlyUsedCacheEvictor(1024 * 1024 * 8));
但它似乎无法正常工作,因为视频需要一段时间才能加载,并且打印的缓存空间始终为0!试图对这个主题进行一些搜索,但是关于它的每个问题都没有得到回答,从未见过一个有效的例子。