1

After doing some workarround on caching the Video/Audio content using exoplayer,i feel like the answer given here by Jacek Using cache in ExoPlayer is the proper way to implement the caching for unbounded range requests instead of using the inbuilt Exocache supported by https://github.com/google/ExoPlayer/issues/420 & https://github.com/google/ExoPlayer/issues/57. But he hasn't said anything on configuring the OkHttp & caching the request.

Can any one provide me some links on how to configure the okhttp & caching the request.

Community
  • 1
  • 1
Pranesh Sahu
  • 595
  • 5
  • 26

1 Answers1

0

By making buildDataSourceFactory configuration change as below we can cache the video content

  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);
  }
Pranesh Sahu
  • 595
  • 5
  • 26