From 942c36453fc9317056791acade02067f01c1464d Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 16 Feb 2021 20:12:55 -0400 Subject: loop queue --- backend.js | 20 +++++++++++++++++++- ui.js | 7 +++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/backend.js b/backend.js index 69aa815..81726c6 100644 --- a/backend.js +++ b/backend.js @@ -66,6 +66,7 @@ class QueuePlayer extends EventEmitter { this.playingTrack = null this.queueGrouplike = {name: 'Queue', isTheQueue: true, items: []} this.pauseNextTrack = false + this.loopQueueAtEnd = false this.playedTrackToEnd = false this.timeData = null @@ -433,7 +434,11 @@ class QueuePlayer extends EventEmitter { if (playingThisTrack) { this.playedTrackToEnd = true if (!this.playNext(item)) { - this.clearPlayingTrack() + if (this.loopQueueAtEnd) { + this.playFirst() + } else { + this.clearPlayingTrack() + } } } } @@ -496,6 +501,15 @@ class QueuePlayer extends EventEmitter { return true } + playFirst() { + const queue = this.queueGrouplike + if (queue.items.length) { + this.play(queue.items[0]) + return true + } + return false + } + clearPlayingTrack() { if (this.playingTrack !== null) { const oldTrack = this.playingTrack @@ -557,6 +571,10 @@ class QueuePlayer extends EventEmitter { this.pauseNextTrack = !!value } + setLoopQueueAtEnd(value) { + this.loopQueueAtEnd = !!value + } + get remainingTracks() { const index = this.queueGrouplike.items.indexOf(this.playingTrack) const length = this.queueGrouplike.items.length diff --git a/ui.js b/ui.js index c734a74..5a8e0ad 100644 --- a/ui.js +++ b/ui.js @@ -343,6 +343,7 @@ class AppElement extends FocusElement { {divider: true}, playingTrack && {element: this.playingControl}, {element: this.loopingControl}, + {element: this.loopQueueControl}, {element: this.pauseNextControl}, {element: this.autoDJControl}, {element: this.volumeSlider}, @@ -398,6 +399,12 @@ class AppElement extends FocusElement { getEnabled: () => this.config.canControlPlayback }) + this.loopQueueControl = new ToggleControl('Loop queue when it ends?', { + setValue: val => this.SQP.setLoopQueueAtEnd(val), + getValue: () => this.SQP.loopQueueAtEnd, + getEnabled: () => this.config.canControlPlayback + }) + this.volumeSlider = new SliderElement('Volume', { setValue: val => this.SQP.setVolume(val), getValue: () => this.SQP.player.volume, -- cgit 1.3.0-6-gf8a5