diff options
author | Florrie <towerofnix@gmail.com> | 2018-05-30 18:10:29 -0300 |
---|---|---|
committer | Florrie <towerofnix@gmail.com> | 2018-05-30 18:10:29 -0300 |
commit | 8766d0f6c9fa89c1db9d2df063ffe14603ab5742 (patch) | |
tree | 564cd3ea68aaae50f42e11ce05c0a985bab5974c /ui.js | |
parent | 12ea120dba62d22e27badd4286f2310f0bc5990c (diff) |
Automatically play next track
Diffstat (limited to 'ui.js')
-rw-r--r-- | ui.js | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/ui.js b/ui.js index 8d43db8..bb22074 100644 --- a/ui.js +++ b/ui.js @@ -1,5 +1,6 @@ const { getDownloaderFor } = require('./downloaders') const { getPlayer } = require('./players') +const { parentSymbol } = require('./playlist-utils') const ansi = require('./tui-lib/util/ansi') const Button = require('./tui-lib/ui/form/Button') const FocusElement = require('./tui-lib/ui/form/FocusElement') @@ -70,6 +71,12 @@ class AppElement extends FocusElement { throw new Error('Attempted to play before a player was loaded') } + let playingThisTrack = true + this.emit('playing new track') + this.once('playing new track', () => { + playingThisTrack = false + }) + // TODO: Check if it's an item or a group const downloadFile = await this.downloadGrouplikeItem(item) @@ -80,6 +87,25 @@ class AppElement extends FocusElement { } finally { this.recordStore.getRecord(item).playing = false } + + // playingThisTrack now means whether the track played through to the end + // (true), or was stopped by a different track being started (false). + + if (playingThisTrack) { + this.playNextTrack(item) + } + } + + playNextTrack(track) { + const parent = track[parentSymbol] + if (!parent) { + return + } + const index = parent.items.indexOf(track) + const nextItem = parent.items[index + 1] + if (nextItem) { + this.playGrouplikeItem(nextItem) + } } } |