use of com.google.android.exoplayer2.upstream.cache.CacheDataSource in project ExoPlayer by google.
the class CacheDataSourceTest method testUnsatisfiableRange.
public void testUnsatisfiableRange() throws Exception {
// Bounded request but the content length is unknown. This forces all data to be cached but not
// the length
assertCacheAndRead(false, true);
// Now do an unbounded request. This will read all of the data from cache and then try to read
// more from upstream which will cause to a 416 so CDS will store the length.
CacheDataSource cacheDataSource = createCacheDataSource(true, true);
assertReadDataContentLength(cacheDataSource, true, true);
// If the user try to access off range then it should throw an IOException
try {
cacheDataSource = createCacheDataSource(false, false);
cacheDataSource.open(new DataSpec(Uri.EMPTY, TEST_DATA.length, 5, KEY_1));
fail();
} catch (IOException e) {
// success
}
}
use of com.google.android.exoplayer2.upstream.cache.CacheDataSource 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);
}
use of com.google.android.exoplayer2.upstream.cache.CacheDataSource 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);
}
use of com.google.android.exoplayer2.upstream.cache.CacheDataSource in project ExoPlayer by google.
the class SegmentDownloader method remove.
@Override
public final void remove() {
CacheDataSource dataSource = cacheDataSourceFactory.createDataSourceForRemovingDownload();
try {
M manifest = getManifest(dataSource, manifestDataSpec, /* removing= */
true);
List<Segment> segments = getSegments(dataSource, manifest, /* removing= */
true);
for (int i = 0; i < segments.size(); i++) {
cache.removeResource(cacheKeyFactory.buildCacheKey(segments.get(i).dataSpec));
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} catch (Exception e) {
// Ignore exceptions when removing.
} finally {
// Always attempt to remove the manifest.
cache.removeResource(cacheKeyFactory.buildCacheKey(manifestDataSpec));
}
}
use of com.google.android.exoplayer2.upstream.cache.CacheDataSource 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);
}
Aggregations