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 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'backend.js') 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 -- cgit 1.3.0-6-gf8a5