Search in sources :

Example 21 with Download

use of com.google.android.exoplayer2.offline.Download in project ExoPlayer by google.

the class DefaultDownloadIndexTest method addAndGetDownload_existingId_returnsUpdatedDownload.

@Test
public void addAndGetDownload_existingId_returnsUpdatedDownload() throws DatabaseIOException {
    String id = "id";
    DownloadBuilder downloadBuilder = new DownloadBuilder(id);
    downloadIndex.putDownload(downloadBuilder.build());
    Download download = downloadBuilder.setUri("different uri").setMimeType(MimeTypes.APPLICATION_MP4).setCacheKey("different cacheKey").setState(Download.STATE_FAILED).setPercentDownloaded(50).setBytesDownloaded(200).setContentLength(400).setFailureReason(FAILURE_REASON_UNKNOWN).setStopReason(0x12345678).setStartTimeMs(10).setUpdateTimeMs(20).setStreamKeys(new StreamKey(/* periodIndex= */
    0, /* groupIndex= */
    1, /* trackIndex= */
    2), new StreamKey(/* periodIndex= */
    3, /* groupIndex= */
    4, /* trackIndex= */
    5)).setCustomMetadata(new byte[] { 0, 1, 2, 3, 7, 8, 9, 10 }).setKeySetId(new byte[] { 0, 1, 2, 3 }).build();
    downloadIndex.putDownload(download);
    Download readDownload = downloadIndex.getDownload(id);
    assertThat(readDownload).isNotNull();
    assertEqual(readDownload, download);
}
Also used : DownloadBuilder(com.google.android.exoplayer2.testutil.DownloadBuilder) Test(org.junit.Test)

Example 22 with Download

use of com.google.android.exoplayer2.offline.Download 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 23 with Download

use of com.google.android.exoplayer2.offline.Download 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 24 with Download

use of com.google.android.exoplayer2.offline.Download in project ExoPlayer by google.

the class DefaultDownloadIndexTest method setSingleDownloadStopReason_setReason.

@Test
public void setSingleDownloadStopReason_setReason() throws Exception {
    String id = "id";
    DownloadBuilder downloadBuilder = new DownloadBuilder(id).setState(Download.STATE_FAILED).setFailureReason(FAILURE_REASON_UNKNOWN);
    Download download = downloadBuilder.build();
    downloadIndex.putDownload(download);
    int stopReason = 0x12345678;
    downloadIndex.setStopReason(id, stopReason);
    Download readDownload = downloadIndex.getDownload(id);
    Download expectedDownload = downloadBuilder.setStopReason(stopReason).build();
    assertEqual(readDownload, expectedDownload);
}
Also used : DownloadBuilder(com.google.android.exoplayer2.testutil.DownloadBuilder) Test(org.junit.Test)

Example 25 with Download

use of com.google.android.exoplayer2.offline.Download in project ExoPlayer by google.

the class DefaultDownloadIndexTest method downloadIndex_versionDowngradeWipesData.

@Test
public void downloadIndex_versionDowngradeWipesData() throws DatabaseIOException {
    Download download1 = new DownloadBuilder("id1").build();
    downloadIndex.putDownload(download1);
    DownloadCursor cursor = downloadIndex.getDownloads();
    assertThat(cursor.getCount()).isEqualTo(1);
    cursor.close();
    SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase();
    VersionTable.setVersion(writableDatabase, VersionTable.FEATURE_OFFLINE, EMPTY_NAME, Integer.MAX_VALUE);
    downloadIndex = new DefaultDownloadIndex(databaseProvider);
    cursor = downloadIndex.getDownloads();
    assertThat(cursor.getCount()).isEqualTo(0);
    cursor.close();
    assertThat(VersionTable.getVersion(writableDatabase, VersionTable.FEATURE_OFFLINE, EMPTY_NAME)).isEqualTo(DefaultDownloadIndex.TABLE_VERSION);
}
Also used : DownloadBuilder(com.google.android.exoplayer2.testutil.DownloadBuilder) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)22 DownloadBuilder (com.google.android.exoplayer2.testutil.DownloadBuilder)17 CacheDataSource (com.google.android.exoplayer2.upstream.cache.CacheDataSource)5 DefaultDownloaderFactory (com.google.android.exoplayer2.offline.DefaultDownloaderFactory)4 StreamKey (com.google.android.exoplayer2.offline.StreamKey)4 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)3 Download (com.google.android.exoplayer2.offline.Download)3 Downloader (com.google.android.exoplayer2.offline.Downloader)3 DownloaderFactory (com.google.android.exoplayer2.offline.DownloaderFactory)3 Nullable (androidx.annotation.Nullable)2 DatabaseIOException (com.google.android.exoplayer2.database.DatabaseIOException)2 DefaultTrackSelector (com.google.android.exoplayer2.trackselection.DefaultTrackSelector)2 MappedTrackInfo (com.google.android.exoplayer2.trackselection.MappingTrackSelector.MappedTrackInfo)2 IOException (java.io.IOException)2 Notification (android.app.Notification)1 Context (android.content.Context)1 SQLException (android.database.SQLException)1 SQLiteException (android.database.sqlite.SQLiteException)1 Format (com.google.android.exoplayer2.Format)1 StandaloneDatabaseProvider (com.google.android.exoplayer2.database.StandaloneDatabaseProvider)1