Last active
March 24, 2023 20:30
-
-
Save prateek54/c4507bc75b5dfb8ed30cc356fdd1a801 to your computer and use it in GitHub Desktop.
Block of code to start/stop offline download
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void toggleDownload( | |
FragmentManager fragmentManager, | |
MediaItem mediaItem, | |
RenderersFactory renderersFactory | |
) { | |
Download download = downloads.get(checkNotNull(mediaItem.localConfiguration).uri); | |
if (download != null && download.state != Download.STATE_FAILED) { | |
DownloadService.sendRemoveDownload( | |
/* context= */ context, | |
/* DownloadService= */ OfflineVideoDownloadService.class, | |
/* id= */ download.request.id, | |
/* foreground= */ false | |
); | |
} else { | |
if (startDownloadDialogHelper != null) { | |
startDownloadDialogHelper.release(); | |
} | |
DownloadHelper helper = | |
DownloadHelper.forMediaItem( | |
context, | |
mediaItem, | |
renderersFactory, | |
dataSourceFactory | |
); | |
startDownloadDialogHelper = | |
new StartDownloadDialogHelper( | |
/* fragmentManager= */fragmentManager, | |
/* downloadHelper= */ helper, | |
/* mediaItem= */mediaItem | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment