Search in sources :

Example 6 with DownloadManager

use of com.google.android.exoplayer2.offline.DownloadManager in project ExoPlayer by google.

the class DemoDownloadService method getDownloadManager.

@Override
protected DownloadManager getDownloadManager() {
    // This will only happen once, because getDownloadManager is guaranteed to be called only once
    // in the life cycle of the process.
    DownloadManager downloadManager = DemoUtil.getDownloadManager(/* context= */
    this);
    DownloadNotificationHelper downloadNotificationHelper = DemoUtil.getDownloadNotificationHelper(/* context= */
    this);
    downloadManager.addListener(new TerminalStateNotificationHelper(this, downloadNotificationHelper, FOREGROUND_NOTIFICATION_ID + 1));
    return downloadManager;
}
Also used : DownloadNotificationHelper(com.google.android.exoplayer2.ui.DownloadNotificationHelper) DownloadManager(com.google.android.exoplayer2.offline.DownloadManager)

Example 7 with DownloadManager

use of com.google.android.exoplayer2.offline.DownloadManager in project ExoPlayer by google.

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);
}
Also used : Scheduler(com.google.android.exoplayer2.scheduler.Scheduler) Nullable(androidx.annotation.Nullable)

Aggregations

DownloadManager (com.google.android.exoplayer2.offline.DownloadManager)4 Nullable (androidx.annotation.Nullable)3 TestDownloadManagerListener (com.google.android.exoplayer2.robolectric.TestDownloadManagerListener)3 Requirements (com.google.android.exoplayer2.scheduler.Requirements)3 DefaultDownloaderFactory (com.google.android.exoplayer2.offline.DefaultDownloaderFactory)2 Scheduler (com.google.android.exoplayer2.scheduler.Scheduler)2 FakeDataSource (com.google.android.exoplayer2.testutil.FakeDataSource)2 CacheDataSource (com.google.android.exoplayer2.upstream.cache.CacheDataSource)2 Notification (android.app.Notification)1 DefaultDownloadIndex (com.google.android.exoplayer2.offline.DefaultDownloadIndex)1 Download (com.google.android.exoplayer2.offline.Download)1 DownloadService (com.google.android.exoplayer2.offline.DownloadService)1 StreamKey (com.google.android.exoplayer2.offline.StreamKey)1 DummyMainThread (com.google.android.exoplayer2.testutil.DummyMainThread)1 TestRunnable (com.google.android.exoplayer2.testutil.DummyMainThread.TestRunnable)1 FakeDataSet (com.google.android.exoplayer2.testutil.FakeDataSet)1 DownloadNotificationHelper (com.google.android.exoplayer2.ui.DownloadNotificationHelper)1 DataSource (com.google.android.exoplayer2.upstream.DataSource)1 Factory (com.google.android.exoplayer2.upstream.DataSource.Factory)1 NoOpCacheEvictor (com.google.android.exoplayer2.upstream.cache.NoOpCacheEvictor)1