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

The following examples show how to use com.google.android.exoplayer2.upstream.cache.CacheDataSink. 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: DownloaderConstructorHelper.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns a new {@link CacheDataSource} instance. If {@code offline} is true, it can only read
 * data from the cache.
 */
public CacheDataSource buildCacheDataSource(boolean offline) {
  DataSource cacheReadDataSource = cacheReadDataSourceFactory != null
      ? cacheReadDataSourceFactory.createDataSource() : new FileDataSource();
  if (offline) {
    return new CacheDataSource(cache, DummyDataSource.INSTANCE,
        cacheReadDataSource, null, CacheDataSource.FLAG_BLOCK_ON_CACHE, null);
  } else {
    DataSink cacheWriteDataSink = cacheWriteDataSinkFactory != null
        ? cacheWriteDataSinkFactory.createDataSink()
        : new CacheDataSink(cache, CacheDataSource.DEFAULT_MAX_CACHE_FILE_SIZE);
    DataSource upstream = upstreamDataSourceFactory.createDataSource();
    upstream = priorityTaskManager == null ? upstream
        : new PriorityDataSource(upstream, priorityTaskManager, C.PRIORITY_DOWNLOAD);
    return new CacheDataSource(cache, upstream, cacheReadDataSource,
        cacheWriteDataSink, CacheDataSource.FLAG_BLOCK_ON_CACHE, null);
  }
}
 
Example #2
Source File: DownloaderConstructorHelper.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns a new {@link CacheDataSource} instance. If {@code offline} is true, it can only read
 * data from the cache.
 */
public CacheDataSource buildCacheDataSource(boolean offline) {
  DataSource cacheReadDataSource = cacheReadDataSourceFactory != null
      ? cacheReadDataSourceFactory.createDataSource() : new FileDataSource();
  if (offline) {
    return new CacheDataSource(cache, DummyDataSource.INSTANCE,
        cacheReadDataSource, null, CacheDataSource.FLAG_BLOCK_ON_CACHE, null);
  } else {
    DataSink cacheWriteDataSink = cacheWriteDataSinkFactory != null
        ? cacheWriteDataSinkFactory.createDataSink()
        : new CacheDataSink(cache, CacheDataSource.DEFAULT_MAX_CACHE_FILE_SIZE);
    DataSource upstream = upstreamDataSourceFactory.createDataSource();
    upstream = priorityTaskManager == null ? upstream
        : new PriorityDataSource(upstream, priorityTaskManager, C.PRIORITY_DOWNLOAD);
    return new CacheDataSource(cache, upstream, cacheReadDataSource,
        cacheWriteDataSink, CacheDataSource.FLAG_BLOCK_ON_CACHE, null);
  }
}
 
Example #3
Source File: MediaVideoView.java    From Slide with GNU General Public License v3.0 5 votes vote down vote up
@Override
public DataSource createDataSource() {
    LeastRecentlyUsedCacheEvictor evictor = new LeastRecentlyUsedCacheEvictor(maxCacheSize);
    SimpleCache simpleCache =
            new SimpleCache(new File(context.getCacheDir(), "media"), evictor);
    return new CacheDataSource(simpleCache, defaultDatasourceFactory.createDataSource(),
            new FileDataSource(), new CacheDataSink(simpleCache, maxFileSize),
            CacheDataSource.FLAG_BLOCK_ON_CACHE | CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR,
            null);
}