Search in sources :

Example 16 with DatabaseIOException

use of androidx.media3.database.DatabaseIOException in project media by androidx.

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(androidx.media3.test.utils.DownloadBuilder) StreamKey(androidx.media3.common.StreamKey) Test(org.junit.Test)

Example 17 with DatabaseIOException

use of androidx.media3.database.DatabaseIOException in project media by androidx.

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(androidx.media3.test.utils.DownloadBuilder) Test(org.junit.Test)

Example 18 with DatabaseIOException

use of androidx.media3.database.DatabaseIOException in project media by androidx.

the class DefaultDownloadIndexTest method releaseAndRecreateDownloadIndex_returnsTheSameDownload.

@Test
public void releaseAndRecreateDownloadIndex_returnsTheSameDownload() throws DatabaseIOException {
    String id = "id";
    Download download = new DownloadBuilder(id).build();
    downloadIndex.putDownload(download);
    downloadIndex = new DefaultDownloadIndex(databaseProvider);
    Download readDownload = downloadIndex.getDownload(id);
    assertThat(readDownload).isNotNull();
    assertEqual(readDownload, download);
}
Also used : DownloadBuilder(androidx.media3.test.utils.DownloadBuilder) Test(org.junit.Test)

Example 19 with DatabaseIOException

use of androidx.media3.database.DatabaseIOException in project ExoPlayer by google.

the class DefaultDownloadIndex method setStatesToRemoving.

@Override
public void setStatesToRemoving() throws DatabaseIOException {
    ensureInitialized();
    try {
        ContentValues values = new ContentValues();
        values.put(COLUMN_STATE, Download.STATE_REMOVING);
        // Only downloads in STATE_FAILED are allowed a failure reason, so we need to clear it here in
        // case we're moving downloads from STATE_FAILED to STATE_REMOVING.
        values.put(COLUMN_FAILURE_REASON, Download.FAILURE_REASON_NONE);
        SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase();
        writableDatabase.update(tableName, values, /* whereClause= */
        null, /* whereArgs= */
        null);
    } catch (SQLException e) {
        throw new DatabaseIOException(e);
    }
}
Also used : ContentValues(android.content.ContentValues) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLException(android.database.SQLException) DatabaseIOException(com.google.android.exoplayer2.database.DatabaseIOException)

Example 20 with DatabaseIOException

use of androidx.media3.database.DatabaseIOException in project ExoPlayer by google.

the class DefaultDownloadIndex method putDownload.

@Override
public void putDownload(Download download) throws DatabaseIOException {
    ensureInitialized();
    try {
        SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase();
        putDownloadInternal(download, writableDatabase);
    } catch (SQLiteException e) {
        throw new DatabaseIOException(e);
    }
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLiteException(android.database.sqlite.SQLiteException) DatabaseIOException(com.google.android.exoplayer2.database.DatabaseIOException)

Aggregations

SQLiteDatabase (android.database.sqlite.SQLiteDatabase)35 SQLException (android.database.SQLException)33 DatabaseIOException (com.google.android.exoplayer2.database.DatabaseIOException)24 WorkerThread (androidx.annotation.WorkerThread)18 ContentValues (android.content.ContentValues)16 DatabaseIOException (androidx.media3.database.DatabaseIOException)12 DownloadBuilder (androidx.media3.test.utils.DownloadBuilder)7 Test (org.junit.Test)7 Cursor (android.database.Cursor)3 SQLiteException (android.database.sqlite.SQLiteException)3 HashMap (java.util.HashMap)3 StreamKey (androidx.media3.common.StreamKey)1