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