From fc1da6ee8ea604f1f6fcf2d0c82775fc7eeb8e32 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sun, 10 Oct 2021 10:58:36 -0300 Subject: update controls to loop queue on last track --- backend.js | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) (limited to 'backend.js') diff --git a/backend.js b/backend.js index 41107d7..36344be 100644 --- a/backend.js +++ b/backend.js @@ -434,27 +434,19 @@ class QueuePlayer extends EventEmitter { if (playingThisTrack) { this.playedTrackToEnd = true - if (!this.playNext(item)) { - switch (this.queueEndMode) { - case 'loop': - this.playFirst() - break - case 'shuffle': - this.clearPlayingTrack() - this.shuffleQueue() - this.playFirst() - break - case 'end': - default: - this.clearPlayingTrack() - } - } + this.playNext(item) } } playNext(track, automaticallyQueueNextTrack = false) { if (!track) return false + // Auto-queue is nice but it should only happen when the queue hasn't been + // explicitly set to loop. + automaticallyQueueNextTrack = ( + automaticallyQueueNextTrack && + this.queueEndMode === 'end') + const queue = this.queueGrouplike let queueIndex = queue.items.indexOf(track) if (queueIndex === -1) return false @@ -473,7 +465,7 @@ class QueuePlayer extends EventEmitter { this.queue(nextItem) queueIndex = queue.items.length - 1 } else { - return false + return this.playNextAtQueueEnd() } } @@ -519,6 +511,23 @@ class QueuePlayer extends EventEmitter { return false } + playNextAtQueueEnd() { + switch (this.queueEndMode) { + case 'loop': + this.playFirst() + return true + case 'shuffle': + this.clearPlayingTrack() + this.shuffleQueue() + this.playFirst() + return true + case 'end': + default: + this.clearPlayingTrack() + return false + } + } + async playOrSeek(item, time) { if (!isTrack(item)) { // This only makes sense to call with individual tracks! -- cgit 1.3.0-6-gf8a5