From 8766d0f6c9fa89c1db9d2df063ffe14603ab5742 Mon Sep 17 00:00:00 2001 From: Florrie Date: Wed, 30 May 2018 18:10:29 -0300 Subject: Automatically play next track --- ui.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'ui.js') 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) + } } } -- cgit 1.3.0-6-gf8a5