Search in sources :

Example 1 with Download

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

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(androidx.media3.database.DatabaseIOException)

Example 2 with Download

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

the class HlsDownloaderTest method createWithDefaultDownloaderFactory.

@Test
public void createWithDefaultDownloaderFactory() {
    CacheDataSource.Factory cacheDataSourceFactory = new CacheDataSource.Factory().setCache(Mockito.mock(Cache.class)).setUpstreamDataSourceFactory(DummyDataSource.FACTORY);
    DownloaderFactory factory = new DefaultDownloaderFactory(cacheDataSourceFactory, /* executor= */
    Runnable::run);
    Downloader downloader = factory.createDownloader(new DownloadRequest.Builder(/* id= */
    "id", Uri.parse("https://www.test.com/download")).setMimeType(MimeTypes.APPLICATION_M3U8).setStreamKeys(Collections.singletonList(new StreamKey(/* groupIndex= */
    0, /* trackIndex= */
    0))).build());
    assertThat(downloader).isInstanceOf(HlsDownloader.class);
}
Also used : CacheDataSource(androidx.media3.datasource.cache.CacheDataSource) DefaultDownloaderFactory(androidx.media3.exoplayer.offline.DefaultDownloaderFactory) DownloaderFactory(androidx.media3.exoplayer.offline.DownloaderFactory) DefaultDownloaderFactory(androidx.media3.exoplayer.offline.DefaultDownloaderFactory) Downloader(androidx.media3.exoplayer.offline.Downloader) DownloaderFactory(androidx.media3.exoplayer.offline.DownloaderFactory) DefaultDownloaderFactory(androidx.media3.exoplayer.offline.DefaultDownloaderFactory) StreamKey(androidx.media3.common.StreamKey) Test(org.junit.Test)

Example 3 with Download

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

the class DownloadManagerTest method mergeRequest_completedWithStopReason_becomesStopped.

@Test
public void mergeRequest_completedWithStopReason_becomesStopped() {
    DownloadRequest downloadRequest = createDownloadRequest(ID1);
    DownloadBuilder downloadBuilder = new DownloadBuilder(downloadRequest).setState(Download.STATE_COMPLETED).setStopReason(/* stopReason= */
    1);
    Download download = downloadBuilder.build();
    Download mergedDownload = DownloadManager.mergeRequest(download, downloadRequest, download.stopReason, NOW_MS);
    Download expectedDownload = downloadBuilder.setStartTimeMs(NOW_MS).setState(Download.STATE_STOPPED).build();
    assertEqualIgnoringUpdateTime(mergedDownload, expectedDownload);
}
Also used : DownloadBuilder(androidx.media3.test.utils.DownloadBuilder) Test(org.junit.Test)

Example 4 with Download

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

the class DownloadManagerTest method mergeRequest_failed_becomesQueued.

@Test
public void mergeRequest_failed_becomesQueued() {
    DownloadRequest downloadRequest = createDownloadRequest(ID1);
    DownloadBuilder downloadBuilder = new DownloadBuilder(downloadRequest).setState(Download.STATE_FAILED).setFailureReason(Download.FAILURE_REASON_UNKNOWN);
    Download download = downloadBuilder.build();
    Download mergedDownload = DownloadManager.mergeRequest(download, downloadRequest, download.stopReason, NOW_MS);
    Download expectedDownload = downloadBuilder.setStartTimeMs(NOW_MS).setState(Download.STATE_QUEUED).setFailureReason(Download.FAILURE_REASON_NONE).build();
    assertEqualIgnoringUpdateTime(mergedDownload, expectedDownload);
}
Also used : DownloadBuilder(androidx.media3.test.utils.DownloadBuilder) Test(org.junit.Test)

Example 5 with Download

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

the class DefaultDownloadIndexTest method setStatesToRemoving_setsStateAndClearsFailureReason.

@Test
public void setStatesToRemoving_setsStateAndClearsFailureReason() throws Exception {
    String id = "id";
    DownloadBuilder downloadBuilder = new DownloadBuilder(id).setState(Download.STATE_FAILED).setFailureReason(FAILURE_REASON_UNKNOWN);
    Download download = downloadBuilder.build();
    downloadIndex.putDownload(download);
    downloadIndex.setStatesToRemoving();
    download = downloadIndex.getDownload(id);
    assertThat(download.state).isEqualTo(Download.STATE_REMOVING);
    assertThat(download.failureReason).isEqualTo(FAILURE_REASON_NONE);
}
Also used : DownloadBuilder(androidx.media3.test.utils.DownloadBuilder) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)22 DownloadBuilder (androidx.media3.test.utils.DownloadBuilder)17 StreamKey (androidx.media3.common.StreamKey)6 CacheDataSource (androidx.media3.datasource.cache.CacheDataSource)5 DefaultDownloaderFactory (androidx.media3.exoplayer.offline.DefaultDownloaderFactory)4 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)3 Downloader (androidx.media3.exoplayer.offline.Downloader)3 DownloaderFactory (androidx.media3.exoplayer.offline.DownloaderFactory)3 Nullable (androidx.annotation.Nullable)2 DatabaseIOException (androidx.media3.database.DatabaseIOException)2 Download (androidx.media3.exoplayer.offline.Download)2 DefaultTrackSelector (androidx.media3.exoplayer.trackselection.DefaultTrackSelector)2 MappedTrackInfo (androidx.media3.exoplayer.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 PriorityTooLowException (androidx.media3.common.PriorityTaskManager.PriorityTooLowException)1 StandaloneDatabaseProvider (androidx.media3.database.StandaloneDatabaseProvider)1