Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.47 KB | None | 0 0
  1. suspend fun download(url: String, progressChannel: SendChannel<Int>) = withContext(Dispatchers.IO) {
  2.     while (true) {
  3.         //read bytes
  4.         progressChannel.send(progress++)
  5.     }
  6. }
  7.  
  8. fun downloadAudio(url: String) = launch {
  9.     vs.showDownloadProgress()
  10.  
  11.     val progress = Channel<Int>(UNLIMITED)
  12.  
  13.     launch {
  14.         download(url, progress)
  15.     }
  16.  
  17.     for (percent in progress) {
  18.         vs.progress(percent)
  19.     }
  20.  
  21.     vs.hideDownloadProgress()
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement