Skip to content

Instantly share code, notes, and snippets.

@Ochornma
Created September 7, 2020 22:21
Show Gist options
  • Save Ochornma/024f3029d7ad95e2161b14bbf3a83dd9 to your computer and use it in GitHub Desktop.
Save Ochornma/024f3029d7ad95e2161b14bbf3a83dd9 to your computer and use it in GitHub Desktop.
private fun downloadMedia(){
//the download request
val helper = context?.let { DownloadHelper.forProgressive(it, the URI of the media) }
helper?.prepare(object : DownloadHelper.Callback {
override fun onPrepared(helper: DownloadHelper) {
val json = JSONObject()
//extra data about the download like title, artist e.tc below is an example
json.put("title" "Download like youtube")
json.put("artist" "Promise Ochornma")
val download =
helper.getDownloadRequest(A unique ID for each download, Util.getUtf8Bytes(json.toString()))
//sending the request to the download service
context?.let {
DownloadService.sendAddDownload(
it,
MyDownload::class.java,
download,
true
)
}
}
override fun onPrepareError(helper: DownloadHelper, e: IOException) {
e.printStackTrace()
Toast.makeText(context, e.localizedMessage, Toast.LENGTH_SHORT).show()
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment