Search in sources :

Example 1 with DefaultDownloadIndex

use of androidx.media3.exoplayer.offline.DefaultDownloadIndex in project media by androidx.

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(androidx.media3.database.StandaloneDatabaseProvider) File(java.io.File) StreamKey(androidx.media3.common.StreamKey) Test(org.junit.Test)

Example 2 with DefaultDownloadIndex

use of androidx.media3.exoplayer.offline.DefaultDownloadIndex 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 3 with DefaultDownloadIndex

use of androidx.media3.exoplayer.offline.DefaultDownloadIndex in project media by androidx.

the class DownloadManagerTest method setupDownloadManager.

private void setupDownloadManager(int maxParallelDownloads) throws Exception {
    if (downloadManager != null) {
        releaseDownloadManager();
    }
    try {
        runOnMainThread(() -> {
            downloadManager = new DownloadManager(ApplicationProvider.getApplicationContext(), new DefaultDownloadIndex(TestUtil.getInMemoryDatabaseProvider()), new FakeDownloaderFactory());
            downloadManager.setMaxParallelDownloads(maxParallelDownloads);
            downloadManager.setMinRetryCount(MIN_RETRY_COUNT);
            downloadManager.setRequirements(new Requirements(0));
            downloadManager.resumeDownloads();
            downloadManagerListener = new TestDownloadManagerListener(downloadManager);
        });
        downloadManagerListener.blockUntilInitialized();
    } catch (Throwable throwable) {
        throw new Exception(throwable);
    }
}
Also used : Requirements(androidx.media3.exoplayer.scheduler.Requirements) IOException(java.io.IOException) TestDownloadManagerListener(androidx.media3.test.utils.robolectric.TestDownloadManagerListener)

Example 4 with DefaultDownloadIndex

use of androidx.media3.exoplayer.offline.DefaultDownloadIndex in project media by androidx.

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

Example 5 with DefaultDownloadIndex

use of androidx.media3.exoplayer.offline.DefaultDownloadIndex in project media by androidx.

the class DefaultDownloadIndexTest method setUp.

@Before
public void setUp() {
    databaseProvider = new StandaloneDatabaseProvider(ApplicationProvider.getApplicationContext());
    downloadIndex = new DefaultDownloadIndex(databaseProvider);
}
Also used : StandaloneDatabaseProvider(androidx.media3.database.StandaloneDatabaseProvider) Before(org.junit.Before)

Aggregations

StreamKey (androidx.media3.common.StreamKey)3 Before (org.junit.Before)3 Test (org.junit.Test)3 Context (android.content.Context)2 StandaloneDatabaseProvider (androidx.media3.database.StandaloneDatabaseProvider)2 NoOpCacheEvictor (androidx.media3.datasource.cache.NoOpCacheEvictor)2 SimpleCache (androidx.media3.datasource.cache.SimpleCache)2 DefaultDownloadIndex (androidx.media3.exoplayer.offline.DefaultDownloadIndex)2 DownloadBuilder (androidx.media3.test.utils.DownloadBuilder)2 DummyMainThread (androidx.media3.test.utils.DummyMainThread)2 FakeDataSet (androidx.media3.test.utils.FakeDataSet)2 TestDownloadManagerListener (androidx.media3.test.utils.robolectric.TestDownloadManagerListener)2 File (java.io.File)2 Notification (android.app.Notification)1 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 Nullable (androidx.annotation.Nullable)1 DataSource (androidx.media3.datasource.DataSource)1 CacheDataSource (androidx.media3.datasource.cache.CacheDataSource)1 DefaultDownloaderFactory (androidx.media3.exoplayer.offline.DefaultDownloaderFactory)1 Download (androidx.media3.exoplayer.offline.Download)1