Advertisement
Guest User

Untitled

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