从ExoPlayer缓存中获取所有内容 [英] Get everything in from ExoPlayer Cache

查看:553
本文介绍了从ExoPlayer缓存中获取所有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Using https://google.github.io/ExoPlayer/doc/reference/com/google/android/exoplayer2/upstream/cache/CacheDataSourceFactory.html is there a way to grab all the MediaSources that have been cached?

推荐答案

缓存不提供便捷的API来获取所有完全缓存的URI或类似内容.

The Cache offers no convenient API to get all completely cached URIs or similar.

如果您创建自己的

If you create your own CacheEvictor (for instance by wrapping a LeastRecentlyUsedCacheEvictor) you can do your own book keeping when spans are added or removed and then delegate to the LRUCacheEvictor. This way you can maintain a list of cached URLs.

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

You can check what portions for a given uri is cached:

// 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的数据仅部分缓存,则可以检查可用的跨度,如下所示:

If the data for a given uri is only partially cached you can check what spans are available like this:

NavigableSet<CacheSpan> cachedSpans =
   cache.getCachedSpans(CacheUtil.generateKey(uri));

这篇关于从ExoPlayer缓存中获取所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆