SHARE
TWEET

Untitled

a guest Jul 19th, 2019 71 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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top