use of com.google.android.exoplayer2.upstream.cache.NoOpCacheEvictor in project ExoPlayer by google.
the class DemoUtil method getDownloadCache.
private static synchronized Cache getDownloadCache(Context context) {
if (downloadCache == null) {
File downloadContentDirectory = new File(getDownloadDirectory(context), DOWNLOAD_CONTENT_DIRECTORY);
downloadCache = new SimpleCache(downloadContentDirectory, new NoOpCacheEvictor(), getDatabaseProvider(context));
}
return downloadCache;
}
use of com.google.android.exoplayer2.upstream.cache.NoOpCacheEvictor in project ExoPlayer by google.
the class ProgressiveDownloaderTest method createDownloadCache.
@Before
public void createDownloadCache() throws Exception {
testDir = Util.createTempFile(ApplicationProvider.getApplicationContext(), "ProgressiveDownloaderTest");
assertThat(testDir.delete()).isTrue();
assertThat(testDir.mkdirs()).isTrue();
DatabaseProvider databaseProvider = TestUtil.getInMemoryDatabaseProvider();
downloadCache = new SimpleCache(testDir, new NoOpCacheEvictor(), databaseProvider);
}
use of com.google.android.exoplayer2.upstream.cache.NoOpCacheEvictor 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);
}
use of com.google.android.exoplayer2.upstream.cache.NoOpCacheEvictor in project ExoPlayer by google.
the class CacheDataSourceTest method setUp.
@Before
public void setUp() throws Exception {
testDataUri = Uri.parse("https://www.test.com/data");
httpRequestHeaders = new HashMap<>();
httpRequestHeaders.put("Test-key", "Test-val");
unboundedDataSpec = buildDataSpec(/* unbounded= */
true, /* key= */
null);
boundedDataSpec = buildDataSpec(/* unbounded= */
false, /* key= */
null);
unboundedDataSpecWithKey = buildDataSpec(/* unbounded= */
true, DATASPEC_KEY);
boundedDataSpecWithKey = buildDataSpec(/* unbounded= */
false, DATASPEC_KEY);
defaultCacheKey = CacheKeyFactory.DEFAULT.buildCacheKey(unboundedDataSpec);
customCacheKey = "customKey." + defaultCacheKey;
cacheKeyFactory = dataSpec -> customCacheKey;
tempFolder = Util.createTempDirectory(ApplicationProvider.getApplicationContext(), "ExoPlayerTest");
cache = new SimpleCache(tempFolder, new NoOpCacheEvictor(), TestUtil.getInMemoryDatabaseProvider());
upstreamDataSource = new FakeDataSource();
}
use of com.google.android.exoplayer2.upstream.cache.NoOpCacheEvictor in project ExoPlayer by google.
the class DownloadServiceDashTest method setUp.
@Before
public void setUp() throws IOException {
testThread = new DummyMainThread();
context = ApplicationProvider.getApplicationContext();
tempFolder = Util.createTempDirectory(context, "ExoPlayerTest");
cache = new SimpleCache(tempFolder, new NoOpCacheEvictor(), TestUtil.getInMemoryDatabaseProvider());
Runnable pauseAction = () -> {
if (pauseDownloadCondition != null) {
try {
pauseDownloadCondition.block();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
};
fakeDataSet = new FakeDataSet().setData(TEST_MPD_URI, TEST_MPD).newData("audio_init_data").appendReadAction(pauseAction).appendReadData(TestUtil.buildTestData(10)).endData().setRandomData("audio_segment_1", 4).setRandomData("audio_segment_2", 5).setRandomData("audio_segment_3", 6).setRandomData("text_segment_1", 1).setRandomData("text_segment_2", 2).setRandomData("text_segment_3", 3);
final DataSource.Factory fakeDataSourceFactory = new FakeDataSource.Factory().setFakeDataSet(fakeDataSet);
fakeStreamKey1 = new StreamKey(0, 0, 0);
fakeStreamKey2 = new StreamKey(0, 1, 0);
testThread.runTestOnMainThread(() -> {
DefaultDownloadIndex downloadIndex = new DefaultDownloadIndex(TestUtil.getInMemoryDatabaseProvider());
DefaultDownloaderFactory downloaderFactory = new DefaultDownloaderFactory(new CacheDataSource.Factory().setCache(cache).setUpstreamDataSourceFactory(fakeDataSourceFactory), /* executor= */
Runnable::run);
final DownloadManager dashDownloadManager = new DownloadManager(ApplicationProvider.getApplicationContext(), downloadIndex, downloaderFactory);
downloadManagerListener = new TestDownloadManagerListener(dashDownloadManager);
dashDownloadManager.resumeDownloads();
dashDownloadService = new DownloadService(DownloadService.FOREGROUND_NOTIFICATION_ID_NONE) {
@Override
protected DownloadManager getDownloadManager() {
return dashDownloadManager;
}
@Override
@Nullable
protected Scheduler getScheduler() {
return null;
}
@Override
protected Notification getForegroundNotification(List<Download> downloads, @Requirements.RequirementFlags int notMetRequirements) {
throw new UnsupportedOperationException();
}
};
dashDownloadService.onCreate();
});
}
Aggregations