Using cache in ExoPlayer

后端 未结 10 2189
暖寄归人
暖寄归人 2020-11-29 18:29

I\'m looking for any example of implementing cache in ExoPlayer.

ExoPlayer has in its library different classes concerning cache and Google explain in this video th

10条回答
  •  萌比男神i
    2020-11-29 18:44

    I've implemented it like this in the renderer builder

    private static final int BUFFER_SEGMENT_SIZE = 64 * 1024;
    private static final int BUFFER_SEGMENT_COUNT = 160;
    
    final String userAgent = Util.getUserAgent(mContext, appName);
    final DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
    final Allocator allocator = new DefaultAllocator(BUFFER_SEGMENT_SIZE);*
    
    Cache cache = new SimpleCache(context.getCacheDir(), new LeastRecentlyUsedCacheEvictor(1024 * 1024 * 10));
    DataSource dataSource = new DefaultUriDataSource(context, bandwidthMeter, userAgent);
    CacheDataSource cacheDataSource = new CacheDataSource(cache, dataSource, false, false);
    ExtractorSampleSource sampleSource = new ExtractorSampleSource(uri
                    , cacheDataSource
                    , allocator
                    , BUFFER_SEGMENT_COUNT * BUFFER_SEGMENT_SIZE
                    , new Mp4Extractor());
    

提交回复
热议问题