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