Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/209.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在ExoPlayer中实现缓存?_Android_Caching_Video_Exoplayer - Fatal编程技术网

Android 如何在ExoPlayer中实现缓存?

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

如何在ExoPlayer中实现缓存?真糟糕,它总是重新下载整个视频

我在RenderBuilder中尝试了以下方法:

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!试图对这个主题进行一些搜索,但每个问题都没有得到回答,也没有看到一个有效的例子