【问题标题】:VOD cache using Exoplayer 2.2使用 Exoplayer 2.2 的 VOD 缓存
【发布时间】:2017-03-16 06:43:47
【问题描述】:

在使用 exoplayer 缓存视频/音频内容做了一些工作后,我觉得 Jacek Using cache in ExoPlayer 在这里给出的答案是实现无限范围请求缓存的正确方法,而不是使用 @ 支持的内置 Exocache 987654322@ & https://github.com/google/ExoPlayer/issues/57。 但是他没有说任何关于配置 OkHttp 和缓存请求的内容。

谁能给我一些关于如何配置 okhttp 和缓存请求的链接。

【问题讨论】:

  • 我遇到了同样的问题.. 没有得到任何官方文档或示例来配置 okhttp 缓存。
  • @comeback4you 那么 VOD 的缓存是怎么做的呢?
  • 还没,还在找
  • 你能说明一下你是如何尝试缓存视频内容的吗@comeback4you
  • 我试过 github.com/saeednt/ExoCacheDataSource 但在库中找不到 ExtractorSampleSource 类。

标签: android caching okhttp3 exoplayer


【解决方案1】:

通过如下改变 buildDataSourceFactory 配置,我们可以缓存视频内容

  private DataSource.Factory buildDataSourceFactory(final boolean useBandwidthMeter) {
//    return new DefaultDataSourceFactory(this, useBandwidthMeter ? BANDWIDTH_METER : null,
//        buildHttpDataSourceFactory(useBandwidthMeter));
    return new DataSource.Factory() {
      @Override
      public DataSource createDataSource() {
        LeastRecentlyUsedCacheEvictor evictor = new LeastRecentlyUsedCacheEvictor(100 * 1024 * 1024);
        SimpleCache simpleCache = new SimpleCache(new File(getCacheDir(), "media_cache"), evictor);
        return new CacheDataSource(simpleCache, buildMyDataSourceFactory(useBandwidthMeter).createDataSource(),
                CacheDataSource.FLAG_BLOCK_ON_CACHE | CacheDataSource.FLAG_CACHE_UNBOUNDED_REQUESTS,
                10 * 1024 * 1024);
      }
    };
  }

  private DefaultDataSource.Factory buildMyDataSourceFactory(boolean useBandwidthMeter) {
    return new DefaultDataSourceFactory(PlayerActivity.this, userAgent, useBandwidthMeter ? BANDWIDTH_METER : null);
  }

【讨论】:

  • 我正在使用上面的代码并且能够缓存视频但是如何从缓存中播放视频?
猜你喜欢
  • 1970-01-01
  • 2014-11-23
  • 2015-04-26
  • 1970-01-01
  • 2015-03-16
  • 2019-03-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多