Search in sources :

Example 1 with DownloadCursor

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

the class DownloadTracker method loadDownloads.

private void loadDownloads() {
    try (DownloadCursor loadedDownloads = downloadIndex.getDownloads()) {
        while (loadedDownloads.moveToNext()) {
            Download download = loadedDownloads.getDownload();
            downloads.put(download.request.uri, download);
        }
    } catch (IOException e) {
        Log.w(TAG, "Failed to query downloads", e);
    }
}
Also used : DownloadCursor(com.google.android.exoplayer2.offline.DownloadCursor) IOException(java.io.IOException) Download(com.google.android.exoplayer2.offline.Download)

Example 2 with DownloadCursor

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

the class DefaultDownloadIndexTest method getDownloads_withStates_returnsAllDownloadStatusWithTheSameStates.

@Test
public void getDownloads_withStates_returnsAllDownloadStatusWithTheSameStates() throws DatabaseIOException {
    Download download1 = new DownloadBuilder("id1").setStartTimeMs(0).setState(Download.STATE_REMOVING).build();
    downloadIndex.putDownload(download1);
    Download download2 = new DownloadBuilder("id2").setStartTimeMs(1).setState(STATE_STOPPED).build();
    downloadIndex.putDownload(download2);
    Download download3 = new DownloadBuilder("id3").setStartTimeMs(2).setState(Download.STATE_COMPLETED).build();
    downloadIndex.putDownload(download3);
    try (DownloadCursor cursor = downloadIndex.getDownloads(Download.STATE_REMOVING, Download.STATE_COMPLETED)) {
        assertThat(cursor.getCount()).isEqualTo(2);
        cursor.moveToNext();
        assertEqual(cursor.getDownload(), download1);
        cursor.moveToNext();
        assertEqual(cursor.getDownload(), download3);
    }
}
Also used : DownloadBuilder(com.google.android.exoplayer2.testutil.DownloadBuilder) Test(org.junit.Test)

Example 3 with DownloadCursor

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

DownloadBuilder (com.google.android.exoplayer2.testutil.DownloadBuilder)2 Test (org.junit.Test)2 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 Download (com.google.android.exoplayer2.offline.Download)1 DownloadCursor (com.google.android.exoplayer2.offline.DownloadCursor)1 IOException (java.io.IOException)1