Search in sources :

Example 31 with Download

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

the class DefaultDownloadIndex method ensureInitialized.

private void ensureInitialized() throws DatabaseIOException {
    synchronized (initializationLock) {
        if (initialized) {
            return;
        }
        try {
            SQLiteDatabase readableDatabase = databaseProvider.getReadableDatabase();
            int version = VersionTable.getVersion(readableDatabase, VersionTable.FEATURE_OFFLINE, name);
            if (version != TABLE_VERSION) {
                SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase();
                writableDatabase.beginTransactionNonExclusive();
                try {
                    VersionTable.setVersion(writableDatabase, VersionTable.FEATURE_OFFLINE, name, TABLE_VERSION);
                    List<Download> upgradedDownloads = version == 2 ? loadDownloadsFromVersion2(writableDatabase) : new ArrayList<>();
                    writableDatabase.execSQL("DROP TABLE IF EXISTS " + tableName);
                    writableDatabase.execSQL("CREATE TABLE " + tableName + " " + TABLE_SCHEMA);
                    for (Download download : upgradedDownloads) {
                        putDownloadInternal(download, writableDatabase);
                    }
                    writableDatabase.setTransactionSuccessful();
                } finally {
                    writableDatabase.endTransaction();
                }
            }
            initialized = true;
        } catch (SQLException e) {
            throw new DatabaseIOException(e);
        }
    }
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLException(android.database.SQLException) DatabaseIOException(com.google.android.exoplayer2.database.DatabaseIOException)

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