com.google.android.exoplayer2.upstream.cache.CacheDataSinkFactory Java Examples

The following examples show how to use com.google.android.exoplayer2.upstream.cache.CacheDataSinkFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExoPlayerHelper.java    From ExoPlayer-Wrapper with Apache License 2.0 6 votes vote down vote up
private void enableCache(int maxCacheSizeMb) {
    LeastRecentlyUsedCacheEvictor evictor = new LeastRecentlyUsedCacheEvictor(maxCacheSizeMb * 1024 * 1024);
    File file = new File(mContext.getCacheDir(), "media");
    Log.d("ZAQ", "enableCache (" + maxCacheSizeMb + " MB), file: " + file.getAbsolutePath());
    SimpleCache simpleCache = new SimpleCache(file, evictor);
    mDataSourceFactory = new CacheDataSourceFactory(
            simpleCache,
            mDataSourceFactory,
            new FileDataSourceFactory(),
            new CacheDataSinkFactory(simpleCache, 2 * 1024 * 1024),
            CacheDataSource.FLAG_BLOCK_ON_CACHE | CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR,
            new CacheDataSource.EventListener() {
                @Override
                public void onCacheIgnored(int reason) {
                    Log.d("ZAQ", "onCacheIgnored");
                }

                @Override
                public void onCachedBytesRead(long cacheSizeBytes, long cachedBytesRead) {
                    Log.d("ZAQ", "onCachedBytesRead , cacheSizeBytes: " + cacheSizeBytes + "   cachedBytesRead: " + cachedBytesRead);
                }
            });
}