SHOW:
|
|
- or go back to the newest paste.
1 | - | suspend fun download(url: String, progressChannel: SendChannel<Int>) = withContext(Dispatchers.IO) { |
1 | + | suspend fun download(url: String) = withContext(Dispatchers.IO) { |
2 | - | while (true) { |
2 | + | |
3 | - | //read bytes |
3 | + | |
4 | - | progressChannel.send(progress++) |
4 | + | |
5 | while (true) { | |
6 | //read bytes | |
7 | progress.send(percent) | |
8 | } | |
9 | progress.close() | |
10 | } | |
11 | ||
12 | return progress | |
13 | } | |
14 | - | download(url, progress) |
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 | } |