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);
}
}
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);
}
}
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);
}
Aggregations