Using https://google.github.io/ExoPlayer/doc/reference/com/google/android/exoplayer2/upstream/cache/CacheDataSourceFactory.html https://google.github.io/ExoPlayer/doc/reference/com/google/android/exoplayer2/upstream/cache/CacheDataSourceFactory.html有没有办法获取所有已缓存的 MediaSource?
缓存没有提供方便的 API 来获取所有完全缓存的 URI 或类似内容。
如果您创建自己的缓存清除器 https://github.com/google/ExoPlayer/blob/release-v2/library/core/src/main/java/com/google/android/exoplayer2/upstream/cache/CacheEvictor.java(例如通过包装最近最少使用的缓存退出器 https://github.com/google/ExoPlayer/blob/release-v2/library/core/src/main/java/com/google/android/exoplayer2/upstream/cache/LeastRecentlyUsedCacheEvictor.java)您可以在添加或删除跨度时进行自己的簿记,然后委托给 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));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)