从ExoPlayer Cache获取所有内容

问题描述 投票:1回答:1

使用https://google.github.io/ExoPlayer/doc/reference/com/google/android/exoplayer2/upstream/cache/CacheDataSourceFactory.html有没有办法获取所有已缓存的MediaSource?

android android-mediaplayer exoplayer exoplayer2.x
1个回答
2
投票

Cache没有提供方便的API来获取所有完全缓存的URI或类似的URI。

如果你创建自己的CacheEvictor(例如通过包装LeastRecentlyUsedCacheEvictor),你可以在添加或删除跨度时自己保存书籍,然后委托给LRUCacheEvictor。这样您就可以维护缓存的URL列表。

您可以检查给定uri的哪些部分被缓存:

// create the data spec of a given media file
Uri uri = Uri.parse("http://cool.stuff.com/song-123.mp3")
DataSpec dataSpec = new DataSpec(uri);
// get information about what is cached for the given data spec
CacheUtil.CachingCounters counters = new CacheUtil.CachingCounters();
CacheUtil.getCached(dataSpec, cache, counters);
if (counters.contentLength == counters.totalCachedBytes()) {
  // all bytes cached
} else if (counters.totalCachedBytes() == 0){
  // not cached at all
} else {
  // partially cached
}

如果给定uri的数据仅部分缓存,您可以检查可用的跨度,如下所示:

NavigableSet<CacheSpan> cachedSpans =
   cache.getCachedSpans(CacheUtil.generateKey(uri));
© www.soinside.com 2019 - 2024. All rights reserved.