use of com.google.android.exoplayer2.offline.DefaultDownloadIndex in project ExoPlayer by google.
the class DefaultDownloadIndexTest method setUp.
@Before
public void setUp() {
databaseProvider = new StandaloneDatabaseProvider(ApplicationProvider.getApplicationContext());
downloadIndex = new DefaultDownloadIndex(databaseProvider);
}
use of com.google.android.exoplayer2.offline.DefaultDownloadIndex 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();
});
}
use of com.google.android.exoplayer2.offline.DefaultDownloadIndex in project ExoPlayer by google.
the class DefaultDownloadIndexTest method downloadIndex_upgradesFromVersion2.
@Test
public void downloadIndex_upgradesFromVersion2() throws IOException {
Context context = ApplicationProvider.getApplicationContext();
File databaseFile = context.getDatabasePath(StandaloneDatabaseProvider.DATABASE_NAME);
try (FileOutputStream output = new FileOutputStream(databaseFile)) {
output.write(TestUtil.getByteArray(context, "media/offline/exoplayer_internal_v2.db"));
}
Download dashDownload = createDownload(/* uri= */
"http://www.test.com/manifest.mpd", /* mimeType= */
MimeTypes.APPLICATION_MPD, ImmutableList.of(), /* customCacheKey= */
null);
Download hlsDownload = createDownload(/* uri= */
"http://www.test.com/manifest.m3u8", /* mimeType= */
MimeTypes.APPLICATION_M3U8, ImmutableList.of(), /* customCacheKey= */
null);
Download ssDownload = createDownload(/* uri= */
"http://www.test.com/video.ism/manifest", /* mimeType= */
MimeTypes.APPLICATION_SS, Arrays.asList(new StreamKey(0, 0), new StreamKey(1, 1)), /* customCacheKey= */
null);
Download progressiveDownload = createDownload(/* uri= */
"http://www.test.com/video.mp4", /* mimeType= */
MimeTypes.VIDEO_UNKNOWN, ImmutableList.of(), /* customCacheKey= */
"customCacheKey");
databaseProvider = new StandaloneDatabaseProvider(context);
downloadIndex = new DefaultDownloadIndex(databaseProvider);
assertEqual(downloadIndex.getDownload("http://www.test.com/manifest.mpd"), dashDownload);
assertEqual(downloadIndex.getDownload("http://www.test.com/manifest.m3u8"), hlsDownload);
assertEqual(downloadIndex.getDownload("http://www.test.com/video.ism/manifest"), ssDownload);
assertEqual(downloadIndex.getDownload("http://www.test.com/video.mp4"), progressiveDownload);
}
use of com.google.android.exoplayer2.offline.DefaultDownloadIndex in project ExoPlayer by google.
the class DefaultDownloadIndexTest method releaseAndRecreateDownloadIndex_returnsTheSameDownload.
@Test
public void releaseAndRecreateDownloadIndex_returnsTheSameDownload() throws DatabaseIOException {
String id = "id";
Download download = new DownloadBuilder(id).build();
downloadIndex.putDownload(download);
downloadIndex = new DefaultDownloadIndex(databaseProvider);
Download readDownload = downloadIndex.getDownload(id);
assertThat(readDownload).isNotNull();
assertEqual(readDownload, download);
}
use of com.google.android.exoplayer2.offline.DefaultDownloadIndex in project ExoPlayer by google.
the class DownloadManagerTest method setupDownloadManager.
private void setupDownloadManager(int maxParallelDownloads) throws Exception {
if (downloadManager != null) {
releaseDownloadManager();
}
try {
runOnMainThread(() -> {
downloadManager = new DownloadManager(ApplicationProvider.getApplicationContext(), new DefaultDownloadIndex(TestUtil.getInMemoryDatabaseProvider()), new FakeDownloaderFactory());
downloadManager.setMaxParallelDownloads(maxParallelDownloads);
downloadManager.setMinRetryCount(MIN_RETRY_COUNT);
downloadManager.setRequirements(new Requirements(0));
downloadManager.resumeDownloads();
downloadManagerListener = new TestDownloadManagerListener(downloadManager);
});
downloadManagerListener.blockUntilInitialized();
} catch (Throwable throwable) {
throw new Exception(throwable);
}
}
Aggregations