Android 如何在ExoPlayer中实现缓存?
如何在ExoPlayer中实现缓存?真糟糕,它总是重新下载整个视频 我在RenderBuilder中尝试了以下方法:Android 如何在ExoPlayer中实现缓存?,android,caching,video,exoplayer,Android,Caching,Video,Exoplayer,如何在ExoPlayer中实现缓存?真糟糕,它总是重新下载整个视频 我在RenderBuilder中尝试了以下方法: Allocator allocator = new DefaultAllocator(BUFFER_SEGMENT_SIZE); DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(player.getMainHandler(), null); SimpleCache cache = (Si
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!试图对这个主题进行一些搜索,但每个问题都没有得到回答,也没有看到一个有效的例子