Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- suspend fun download(url: String, progressChannel: SendChannel<Int>) = withContext(Dispatchers.IO) {
- while (true) {
- //read bytes
- progressChannel.send(progress++)
- }
- }
- fun downloadAudio(url: String) = launch {
- vs.showDownloadProgress()
- val progress = Channel<Int>(UNLIMITED)
- launch {
- download(url, progress)
- }
- for (percent in progress) {
- vs.progress(percent)
- }
- vs.hideDownloadProgress()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement