Search in sources :

Example 6 with DownloadRequest

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);
}
Also used : DownloadBuilder(com.google.android.exoplayer2.testutil.DownloadBuilder) Test(org.junit.Test)

Example 7 with DownloadRequest

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);
}
Also used : DownloadBuilder(com.google.android.exoplayer2.testutil.DownloadBuilder) Test(org.junit.Test)

Example 8 with DownloadRequest

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);
}
Also used : DownloadRequest(com.google.android.exoplayer2.offline.DownloadRequest) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 9 with DownloadRequest

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));
}
Also used : DownloadRequest(com.google.android.exoplayer2.offline.DownloadRequest)

Example 10 with DownloadRequest

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);
    }
}
Also used : MediaItem(com.google.android.exoplayer2.MediaItem) Nullable(androidx.annotation.Nullable)

Aggregations

Test (org.junit.Test)5 DownloadRequest (com.google.android.exoplayer2.offline.DownloadRequest)4 DownloadBuilder (com.google.android.exoplayer2.testutil.DownloadBuilder)4 Nullable (androidx.annotation.Nullable)3 MediaItem (com.google.android.exoplayer2.MediaItem)2 ArrayList (java.util.ArrayList)2 Intent (android.content.Intent)1 StreamKey (com.google.android.exoplayer2.offline.StreamKey)1 Requirements (com.google.android.exoplayer2.scheduler.Requirements)1 Ignore (org.junit.Ignore)1