use of androidx.media3.exoplayer.scheduler.Scheduler in project media by androidx.
the class DownloadService method onCreate.
@Override
public void onCreate() {
if (channelId != null) {
NotificationUtil.createNotificationChannel(this, channelId, channelNameResourceId, channelDescriptionResourceId, NotificationUtil.IMPORTANCE_LOW);
}
Class<? extends DownloadService> clazz = getClass();
@Nullable DownloadManagerHelper downloadManagerHelper = downloadManagerHelpers.get(clazz);
if (downloadManagerHelper == null) {
boolean foregroundAllowed = foregroundNotificationUpdater != null;
// See https://developer.android.com/about/versions/12/foreground-services.
boolean canStartForegroundServiceFromBackground = Util.SDK_INT < 31;
@Nullable Scheduler scheduler = foregroundAllowed && canStartForegroundServiceFromBackground ? getScheduler() : null;
DownloadManager downloadManager = getDownloadManager();
downloadManager.resumeDownloads();
downloadManagerHelper = new DownloadManagerHelper(getApplicationContext(), downloadManager, foregroundAllowed, scheduler, clazz);
downloadManagerHelpers.put(clazz, downloadManagerHelper);
}
this.downloadManagerHelper = downloadManagerHelper;
downloadManagerHelper.attachService(this);
}
use of androidx.media3.exoplayer.scheduler.Scheduler in project media by androidx.
the class DownloadServiceDashTest method setUp.
@Before
public void setUp() throws IOException {
testThread = new DummyMainThread();
context = ApplicationProvider.getApplicationContext();
tempFolder = Util.createTempDirectory(context, "ExoPlayerTest");
cache = new SimpleCache(tempFolder, new NoOpCacheEvictor(), TestUtil.getInMemoryDatabaseProvider());
Runnable pauseAction = () -> {
if (pauseDownloadCondition != null) {
try {
pauseDownloadCondition.block();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
};
fakeDataSet = new FakeDataSet().setData(TEST_MPD_URI, TEST_MPD).newData("audio_init_data").appendReadAction(pauseAction).appendReadData(TestUtil.buildTestData(10)).endData().setRandomData("audio_segment_1", 4).setRandomData("audio_segment_2", 5).setRandomData("audio_segment_3", 6).setRandomData("text_segment_1", 1).setRandomData("text_segment_2", 2).setRandomData("text_segment_3", 3);
final DataSource.Factory fakeDataSourceFactory = new FakeDataSource.Factory().setFakeDataSet(fakeDataSet);
fakeStreamKey1 = new StreamKey(0, 0, 0);
fakeStreamKey2 = new StreamKey(0, 1, 0);
testThread.runTestOnMainThread(() -> {
DefaultDownloadIndex downloadIndex = new DefaultDownloadIndex(TestUtil.getInMemoryDatabaseProvider());
DefaultDownloaderFactory downloaderFactory = new DefaultDownloaderFactory(new CacheDataSource.Factory().setCache(cache).setUpstreamDataSourceFactory(fakeDataSourceFactory), /* executor= */
Runnable::run);
final DownloadManager dashDownloadManager = new DownloadManager(ApplicationProvider.getApplicationContext(), downloadIndex, downloaderFactory);
downloadManagerListener = new TestDownloadManagerListener(dashDownloadManager);
dashDownloadManager.resumeDownloads();
dashDownloadService = new DownloadService(DownloadService.FOREGROUND_NOTIFICATION_ID_NONE) {
@Override
protected DownloadManager getDownloadManager() {
return dashDownloadManager;
}
@Override
@Nullable
protected Scheduler getScheduler() {
return null;
}
@Override
protected Notification getForegroundNotification(List<Download> downloads, @Requirements.RequirementFlags int notMetRequirements) {
throw new UnsupportedOperationException();
}
};
dashDownloadService.onCreate();
});
}
Aggregations