diff options
author | Florrie <towerofnix@gmail.com> | 2017-08-04 23:40:30 -0300 |
---|---|---|
committer | Florrie <towerofnix@gmail.com> | 2017-08-04 23:40:30 -0300 |
commit | 21848502be0a0e923470f2ce5679fe6759b7b8a1 (patch) | |
tree | 091492df1402b86619b6b1aa1f0c22f9f45c3b48 /src | |
parent | a0c2b302f8a7d2e0aef062fae3ba8badf79c3b9e (diff) |
Ah, progress
Diffstat (limited to 'src')
-rw-r--r-- | src/loop-play.js | 51 | ||||
-rwxr-xr-x | src/play.js | 3 |
2 files changed, 27 insertions, 27 deletions
diff --git a/src/loop-play.js b/src/loop-play.js index 5690f9b..4ea73c7 100644 --- a/src/loop-play.js +++ b/src/loop-play.js @@ -91,43 +91,44 @@ class PlayController { this.playerCommand = null this.currentTrack = null this.process = null + this.downloadProcess = null } async loopPlay() { - let nextFile - // Null would imply there's NO up-next track, but really we just haven't // set it yet. this.nextTrack = undefined - const downloadNext = async () => { - this.nextTrack = this.startNextDownload() - if (this.nextTrack !== null) { - try { - nextFile = await this.downloadController.waitForDownload() - } catch(err) { - console.warn( - "\x1b[31mFailed to download (or convert) track \x1b[1m" + - getItemPathString(this.nextTrack) + "\x1b[0m" - ) - await downloadNext() - } - } else { - nextFile = null + await (this.downloadProcess = this.downlold()) + + while (this.nextTrack) { + this.currentTrack = this.nextTrack + + this.downlold() + + // Maybe Promise.all isn't good here? Rather, wait for play-file then + // downlold? Or - we should have some "downlolder" promise, set by + // downlold. + if (this.nextFile) { + await this.playFile(this.nextFile) } + + await this.downloadProcess } + } - await downloadNext() + async downlold() { + this.nextTrack = this.startNextDownload() - while (this.nextTrack) { - this.currentTrack = this.nextTrack + try { + this.nextFile = await this.downloadController.waitForDownload() + } catch(err) { + console.warn( + "\x1b[31mFailed to download (or convert) track \x1b[1m" + + getItemPathString(this.nextTrack) + "\x1b[0m" + ) - await Promise.all([ - // If the downloader returns false, the file failed to download; that - // means we'll just skip this track and wait for the next. - nextFile !== false ? this.playFile(nextFile) : Promise.resolve(), - downloadNext() - ]) + await (this.downloadProcess = this.downlold()) } } diff --git a/src/play.js b/src/play.js index 35001be..08a33cb 100755 --- a/src/play.js +++ b/src/play.js @@ -409,8 +409,7 @@ async function main(args) { // TODO: It would be nice to have this as a method of // PlayController. // Double TODO: This doesn't actually work!! - downloadController.cancel() - play.startNextDownload() + play.downloadProcess = play.downlold() } if ( |