use of com.google.android.exoplayer2.offline.DownloadRequest in project ExoPlayer by google.
the class DownloadManagerTest method mergeRequest_stopped_staysStopped.
@Test
public void mergeRequest_stopped_staysStopped() {
DownloadRequest downloadRequest = createDownloadRequest(ID1);
DownloadBuilder downloadBuilder = new DownloadBuilder(downloadRequest).setState(Download.STATE_STOPPED).setStopReason(/* stopReason= */
1);
Download download = downloadBuilder.build();
Download mergedDownload = DownloadManager.mergeRequest(download, downloadRequest, download.stopReason, NOW_MS);
assertEqualIgnoringUpdateTime(mergedDownload, download);
}
use of com.google.android.exoplayer2.offline.DownloadRequest in project ExoPlayer by google.
the class DownloadManagerTest method mergeRequest_removing_becomesRestarting.
@Test
public void mergeRequest_removing_becomesRestarting() {
DownloadRequest downloadRequest = createDownloadRequest(ID1);
DownloadBuilder downloadBuilder = new DownloadBuilder(downloadRequest).setState(Download.STATE_REMOVING);
Download download = downloadBuilder.build();
Download mergedDownload = DownloadManager.mergeRequest(download, downloadRequest, download.stopReason, NOW_MS);
Download expectedDownload = downloadBuilder.setStartTimeMs(NOW_MS).setState(Download.STATE_RESTARTING).build();
assertEqualIgnoringUpdateTime(mergedDownload, expectedDownload);
}
use of com.google.android.exoplayer2.offline.DownloadRequest in project ExoPlayer by google.
the class DownloadManagerDashTest method saveAndLoadActionFile.
@Ignore("Disabled due to flakiness")
@Test
public void saveAndLoadActionFile() throws Throwable {
// Configure fakeDataSet to block until interrupted when TEST_MPD is read.
fakeDataSet.newData(TEST_MPD_URI).appendReadAction(() -> {
try {
// Wait until interrupted.
while (true) {
Thread.sleep(100000);
}
} catch (InterruptedException ignored) {
Thread.currentThread().interrupt();
}
}).appendReadData(TEST_MPD).endData();
// Run DM accessing code on UI/main thread as it should be. Also not to block handling of loaded
// actions.
runOnMainThread(() -> {
// Setup an Action and immediately release the DM.
DownloadRequest request = getDownloadRequest(fakeStreamKey1, fakeStreamKey2);
downloadManager.addDownload(request);
downloadManager.release();
});
assertCacheEmpty(cache);
// Revert fakeDataSet to normal.
fakeDataSet.setData(TEST_MPD_URI, TEST_MPD);
testThread.runOnMainThread(this::createDownloadManager);
// Block on the test thread.
downloadManagerListener.blockUntilIdleAndThrowAnyFailure();
assertCachedData(cache, fakeDataSet);
}
use of com.google.android.exoplayer2.offline.DownloadRequest in project ExoPlayer by google.
the class DownloadManagerDashTest method handleDownloadRequest.
private void handleDownloadRequest(StreamKey... keys) {
DownloadRequest request = getDownloadRequest(keys);
runOnMainThread(() -> downloadManager.addDownload(request));
}
use of com.google.android.exoplayer2.offline.DownloadRequest in project ExoPlayer by google.
the class DefaultDownloaderFactory method createDownloader.
private Downloader createDownloader(DownloadRequest request, @C.ContentType int contentType) {
@Nullable Constructor<? extends Downloader> constructor = CONSTRUCTORS.get(contentType);
if (constructor == null) {
throw new IllegalStateException("Module missing for content type " + contentType);
}
MediaItem mediaItem = new MediaItem.Builder().setUri(request.uri).setStreamKeys(request.streamKeys).setCustomCacheKey(request.customCacheKey).build();
try {
return constructor.newInstance(mediaItem, cacheDataSourceFactory, executor);
} catch (Exception e) {
throw new IllegalStateException("Failed to instantiate downloader for content type " + contentType);
}
}
Aggregations