Skip to content

Instantly share code, notes, and snippets.

@prateek54
Last active March 24, 2023 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prateek54/c4507bc75b5dfb8ed30cc356fdd1a801 to your computer and use it in GitHub Desktop.
Save prateek54/c4507bc75b5dfb8ed30cc356fdd1a801 to your computer and use it in GitHub Desktop.
Block of code to start/stop offline download
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