Search in sources :

Example 1 with CacheDataSink

use of com.google.android.exoplayer2.upstream.cache.CacheDataSink in project ExoPlayer by google.

the class CacheDataSourceTest method createCacheDataSource.

private CacheDataSource createCacheDataSource(boolean setReadException, boolean simulateUnknownLength, @CacheDataSource.Flags int flags, CacheDataSink cacheWriteDataSink) {
    FakeDataSource.Builder builder = new FakeDataSource.Builder();
    if (setReadException) {
        builder.appendReadError(new IOException("Shouldn't read from upstream"));
    }
    FakeDataSource upstream = builder.setSimulateUnknownLength(simulateUnknownLength).appendReadData(TEST_DATA).build();
    return new CacheDataSource(simpleCache, upstream, new FileDataSource(), cacheWriteDataSink, flags, null);
}
Also used : FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) FileDataSource(com.google.android.exoplayer2.upstream.FileDataSource) IOException(java.io.IOException)

Example 2 with CacheDataSink

use of com.google.android.exoplayer2.upstream.cache.CacheDataSink in project Slide by ccrama.

the class SlideVideoControls method createDataSource.

@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);
}
Also used : CacheDataSink(com.google.android.exoplayer2.upstream.cache.CacheDataSink) SimpleCache(com.google.android.exoplayer2.upstream.cache.SimpleCache) LeastRecentlyUsedCacheEvictor(com.google.android.exoplayer2.upstream.cache.LeastRecentlyUsedCacheEvictor) CacheDataSource(com.google.android.exoplayer2.upstream.cache.CacheDataSource) FileDataSource(com.google.android.exoplayer2.upstream.FileDataSource) File(java.io.File)

Example 3 with CacheDataSink

use of com.google.android.exoplayer2.upstream.cache.CacheDataSink in project ExoPlayer by google.

the class CacheDataSourceTest2 method buildCacheDataSource.

private static CacheDataSource buildCacheDataSource(Context context, DataSource upstreamSource, boolean useAesEncryption) throws CacheException {
    File cacheDir = context.getExternalCacheDir();
    Cache cache = new SimpleCache(new File(cacheDir, EXO_CACHE_DIR), new NoOpCacheEvictor(), TestUtil.getInMemoryDatabaseProvider());
    emptyCache(cache);
    // Source and cipher
    final String secretKey = "testKey:12345678";
    DataSource file = new FileDataSource();
    DataSource cacheReadDataSource = useAesEncryption ? new AesCipherDataSource(Util.getUtf8Bytes(secretKey), file) : file;
    // Sink and cipher
    CacheDataSink cacheSink = new CacheDataSink(cache, EXO_CACHE_MAX_FILESIZE);
    byte[] scratch = new byte[3897];
    DataSink cacheWriteDataSink = useAesEncryption ? new AesCipherDataSink(Util.getUtf8Bytes(secretKey), cacheSink, scratch) : cacheSink;
    return new CacheDataSource(cache, upstreamSource, cacheReadDataSource, cacheWriteDataSink, CacheDataSource.FLAG_BLOCK_ON_CACHE, // eventListener
    null);
}
Also used : AesCipherDataSink(com.google.android.exoplayer2.upstream.crypto.AesCipherDataSink) DataSink(com.google.android.exoplayer2.upstream.DataSink) FileDataSource(com.google.android.exoplayer2.upstream.FileDataSource) AesCipherDataSource(com.google.android.exoplayer2.upstream.crypto.AesCipherDataSource) DataSource(com.google.android.exoplayer2.upstream.DataSource) FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) AesCipherDataSink(com.google.android.exoplayer2.upstream.crypto.AesCipherDataSink) FileDataSource(com.google.android.exoplayer2.upstream.FileDataSource) AesCipherDataSource(com.google.android.exoplayer2.upstream.crypto.AesCipherDataSource) File(java.io.File)

Example 4 with CacheDataSink

use of com.google.android.exoplayer2.upstream.cache.CacheDataSink in project NewPipe by TeamNewPipe.

the class CacheFactory method createDataSource.

@Override
public DataSource createDataSource() {
    Log.d(TAG, "initExoPlayerCache: cacheDir = " + cacheDir.getAbsolutePath());
    final DefaultDataSource dataSource = dataSourceFactory.createDataSource();
    final FileDataSource fileSource = new FileDataSource();
    final CacheDataSink dataSink = new CacheDataSink(cache, maxFileSize);
    return new CacheDataSource(cache, dataSource, fileSource, dataSink, CACHE_FLAGS, null);
}
Also used : CacheDataSink(com.google.android.exoplayer2.upstream.cache.CacheDataSink) DefaultDataSource(com.google.android.exoplayer2.upstream.DefaultDataSource) CacheDataSource(com.google.android.exoplayer2.upstream.cache.CacheDataSource) FileDataSource(com.google.android.exoplayer2.upstream.FileDataSource)

Aggregations

FileDataSource (com.google.android.exoplayer2.upstream.FileDataSource)4 FakeDataSource (com.google.android.exoplayer2.testutil.FakeDataSource)2 CacheDataSink (com.google.android.exoplayer2.upstream.cache.CacheDataSink)2 CacheDataSource (com.google.android.exoplayer2.upstream.cache.CacheDataSource)2 File (java.io.File)2 DataSink (com.google.android.exoplayer2.upstream.DataSink)1 DataSource (com.google.android.exoplayer2.upstream.DataSource)1 DefaultDataSource (com.google.android.exoplayer2.upstream.DefaultDataSource)1 LeastRecentlyUsedCacheEvictor (com.google.android.exoplayer2.upstream.cache.LeastRecentlyUsedCacheEvictor)1 SimpleCache (com.google.android.exoplayer2.upstream.cache.SimpleCache)1 AesCipherDataSink (com.google.android.exoplayer2.upstream.crypto.AesCipherDataSink)1 AesCipherDataSource (com.google.android.exoplayer2.upstream.crypto.AesCipherDataSource)1 IOException (java.io.IOException)1