use of com.google.android.exoplayer2.upstream.cache.CacheDataSource in project ExoPlayer by google.
the class CacheWriterTest method cacheUnknownLength.
@Test
public void cacheUnknownLength() throws Exception {
FakeDataSet fakeDataSet = new FakeDataSet().newData("test_data").setSimulateUnknownLength(true).appendReadData(TestUtil.buildTestData(100)).endData();
FakeDataSource dataSource = new FakeDataSource(fakeDataSet);
DataSpec dataSpec = new DataSpec(Uri.parse("test_data"));
CachingCounters counters = new CachingCounters();
CacheWriter cacheWriter = new CacheWriter(new CacheDataSource(cache, dataSource), dataSpec, /* temporaryBuffer= */
null, counters);
cacheWriter.cache();
counters.assertValues(0, 100, 100);
assertCachedData(cache, fakeDataSet);
}
use of com.google.android.exoplayer2.upstream.cache.CacheDataSource in project ExoPlayer by google.
the class CacheWriterTest method cacheSetOffsetAndLength.
@Test
public void cacheSetOffsetAndLength() throws Exception {
FakeDataSet fakeDataSet = new FakeDataSet().setRandomData("test_data", 100);
FakeDataSource dataSource = new FakeDataSource(fakeDataSet);
Uri testUri = Uri.parse("test_data");
DataSpec dataSpec = new DataSpec(testUri, /* position= */
10, /* length= */
20);
CachingCounters counters = new CachingCounters();
CacheWriter cacheWriter = new CacheWriter(new CacheDataSource(cache, dataSource), dataSpec, /* temporaryBuffer= */
null, counters);
cacheWriter.cache();
counters.assertValues(0, 20, 20);
counters.reset();
cacheWriter = new CacheWriter(new CacheDataSource(cache, dataSource), new DataSpec(testUri), /* temporaryBuffer= */
null, counters);
cacheWriter.cache();
counters.assertValues(20, 80, 100);
assertCachedData(cache, fakeDataSet);
}
use of com.google.android.exoplayer2.upstream.cache.CacheDataSource in project ExoPlayer by google.
the class CacheWriterTest method cache.
@Test
public void cache() throws Exception {
FakeDataSet fakeDataSet = new FakeDataSet().setRandomData("test_data", 100);
FakeDataSource dataSource = new FakeDataSource(fakeDataSet);
CachingCounters counters = new CachingCounters();
CacheWriter cacheWriter = new CacheWriter(new CacheDataSource(cache, dataSource), new DataSpec(Uri.parse("test_data")), /* temporaryBuffer= */
null, counters);
cacheWriter.cache();
counters.assertValues(0, 100, 100);
assertCachedData(cache, fakeDataSet);
}
use of com.google.android.exoplayer2.upstream.cache.CacheDataSource in project ExoPlayer by google.
the class CacheWriterTest method cachePolling.
@Test
public void cachePolling() throws Exception {
final CachingCounters counters = new CachingCounters();
FakeDataSet fakeDataSet = new FakeDataSet().newData("test_data").appendReadData(TestUtil.buildTestData(100)).appendReadAction(() -> counters.assertValues(0, 100, 300)).appendReadData(TestUtil.buildTestData(100)).appendReadAction(() -> counters.assertValues(0, 200, 300)).appendReadData(TestUtil.buildTestData(100)).endData();
FakeDataSource dataSource = new FakeDataSource(fakeDataSet);
CacheWriter cacheWriter = new CacheWriter(new CacheDataSource(cache, dataSource), new DataSpec(Uri.parse("test_data")), /* temporaryBuffer= */
null, counters);
cacheWriter.cache();
counters.assertValues(0, 300, 300);
assertCachedData(cache, fakeDataSet);
}
use of com.google.android.exoplayer2.upstream.cache.CacheDataSource 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);
}
Aggregations