Created
September 7, 2020 22:21
-
-
Save Ochornma/024f3029d7ad95e2161b14bbf3a83dd9 to your computer and use it in GitHub Desktop.
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
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