Search in sources :

Example 6 with DatabaseProvider

use of com.google.android.exoplayer2.database.DatabaseProvider in project media by androidx.

the class ProgressiveDownloaderTest method createDownloadCache.

@Before
public void createDownloadCache() throws Exception {
    testDir = Util.createTempFile(ApplicationProvider.getApplicationContext(), "ProgressiveDownloaderTest");
    assertThat(testDir.delete()).isTrue();
    assertThat(testDir.mkdirs()).isTrue();
    DatabaseProvider databaseProvider = TestUtil.getInMemoryDatabaseProvider();
    downloadCache = new SimpleCache(testDir, new NoOpCacheEvictor(), databaseProvider);
}
Also used : DatabaseProvider(androidx.media3.database.DatabaseProvider) SimpleCache(androidx.media3.datasource.cache.SimpleCache) NoOpCacheEvictor(androidx.media3.datasource.cache.NoOpCacheEvictor) Before(org.junit.Before)

Example 7 with DatabaseProvider

use of com.google.android.exoplayer2.database.DatabaseProvider in project ExoPlayer by google.

the class DefaultDownloadIndexTest method downloadIndex_upgradesFromVersion2.

@Test
public void downloadIndex_upgradesFromVersion2() throws IOException {
    Context context = ApplicationProvider.getApplicationContext();
    File databaseFile = context.getDatabasePath(StandaloneDatabaseProvider.DATABASE_NAME);
    try (FileOutputStream output = new FileOutputStream(databaseFile)) {
        output.write(TestUtil.getByteArray(context, "media/offline/exoplayer_internal_v2.db"));
    }
    Download dashDownload = createDownload(/* uri= */
    "http://www.test.com/manifest.mpd", /* mimeType= */
    MimeTypes.APPLICATION_MPD, ImmutableList.of(), /* customCacheKey= */
    null);
    Download hlsDownload = createDownload(/* uri= */
    "http://www.test.com/manifest.m3u8", /* mimeType= */
    MimeTypes.APPLICATION_M3U8, ImmutableList.of(), /* customCacheKey= */
    null);
    Download ssDownload = createDownload(/* uri= */
    "http://www.test.com/video.ism/manifest", /* mimeType= */
    MimeTypes.APPLICATION_SS, Arrays.asList(new StreamKey(0, 0), new StreamKey(1, 1)), /* customCacheKey= */
    null);
    Download progressiveDownload = createDownload(/* uri= */
    "http://www.test.com/video.mp4", /* mimeType= */
    MimeTypes.VIDEO_UNKNOWN, ImmutableList.of(), /* customCacheKey= */
    "customCacheKey");
    databaseProvider = new StandaloneDatabaseProvider(context);
    downloadIndex = new DefaultDownloadIndex(databaseProvider);
    assertEqual(downloadIndex.getDownload("http://www.test.com/manifest.mpd"), dashDownload);
    assertEqual(downloadIndex.getDownload("http://www.test.com/manifest.m3u8"), hlsDownload);
    assertEqual(downloadIndex.getDownload("http://www.test.com/video.ism/manifest"), ssDownload);
    assertEqual(downloadIndex.getDownload("http://www.test.com/video.mp4"), progressiveDownload);
}
Also used : Context(android.content.Context) FileOutputStream(java.io.FileOutputStream) StandaloneDatabaseProvider(com.google.android.exoplayer2.database.StandaloneDatabaseProvider) File(java.io.File) Test(org.junit.Test)

Example 8 with DatabaseProvider

use of com.google.android.exoplayer2.database.DatabaseProvider in project ExoPlayer by google.

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(com.google.android.exoplayer2.testutil.DownloadBuilder) Test(org.junit.Test)

Example 9 with DatabaseProvider

use of com.google.android.exoplayer2.database.DatabaseProvider 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)

Example 10 with DatabaseProvider

use of com.google.android.exoplayer2.database.DatabaseProvider in project ExoPlayer by google.

the class CacheFileMetadataIndex method delete.

/**
 * Deletes index data for the specified cache.
 *
 * <p>This method may be slow and shouldn't normally be called on the main thread.
 *
 * @param databaseProvider Provides the database in which the index is stored.
 * @param uid The cache UID.
 * @throws DatabaseIOException If an error occurs deleting the index data.
 */
@WorkerThread
public static void delete(DatabaseProvider databaseProvider, long uid) throws DatabaseIOException {
    String hexUid = Long.toHexString(uid);
    try {
        String tableName = getTableName(hexUid);
        SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase();
        writableDatabase.beginTransactionNonExclusive();
        try {
            VersionTable.removeVersion(writableDatabase, VersionTable.FEATURE_CACHE_FILE_METADATA, hexUid);
            dropTable(writableDatabase, tableName);
            writableDatabase.setTransactionSuccessful();
        } finally {
            writableDatabase.endTransaction();
        }
    } 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) WorkerThread(androidx.annotation.WorkerThread)

Aggregations

SQLiteDatabase (android.database.sqlite.SQLiteDatabase)3 DatabaseProvider (com.google.android.exoplayer2.database.DatabaseProvider)3 SimpleCache (com.google.android.exoplayer2.upstream.cache.SimpleCache)3 File (java.io.File)3 Before (org.junit.Before)3 Test (org.junit.Test)3 SQLException (android.database.SQLException)2 WorkerThread (androidx.annotation.WorkerThread)2 DatabaseIOException (com.google.android.exoplayer2.database.DatabaseIOException)2 ExoDatabaseProvider (com.google.android.exoplayer2.database.ExoDatabaseProvider)2 StandaloneDatabaseProvider (com.google.android.exoplayer2.database.StandaloneDatabaseProvider)2 DownloadBuilder (com.google.android.exoplayer2.testutil.DownloadBuilder)2 LeastRecentlyUsedCacheEvictor (com.google.android.exoplayer2.upstream.cache.LeastRecentlyUsedCacheEvictor)2 Context (android.content.Context)1 DatabaseProvider (androidx.media3.database.DatabaseProvider)1 NoOpCacheEvictor (androidx.media3.datasource.cache.NoOpCacheEvictor)1 SimpleCache (androidx.media3.datasource.cache.SimpleCache)1 NoOpCacheEvictor (com.google.android.exoplayer2.upstream.cache.NoOpCacheEvictor)1 FileOutputStream (java.io.FileOutputStream)1