« get me outta code hell

mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
path: root/backend.js
diff options
context:
space:
mode:
Diffstat (limited to 'backend.js')
-rw-r--r--backend.js18
1 files changed, 13 insertions, 5 deletions
diff --git a/backend.js b/backend.js
index e38fe2f..41107d7 100644
--- a/backend.js
+++ b/backend.js
@@ -66,7 +66,7 @@ class QueuePlayer extends EventEmitter {
     this.playingTrack = null
     this.queueGrouplike = {name: 'Queue', isTheQueue: true, items: []}
     this.pauseNextTrack = false
-    this.loopQueueAtEnd = false
+    this.queueEndMode = 'end' // end, loop, shuffle
     this.playedTrackToEnd = false
     this.timeData = null
 
@@ -435,10 +435,18 @@ class QueuePlayer extends EventEmitter {
     if (playingThisTrack) {
       this.playedTrackToEnd = true
       if (!this.playNext(item)) {
-        if (this.loopQueueAtEnd) {
-          this.playFirst()
-        } else {
-          this.clearPlayingTrack()
+        switch (this.queueEndMode) {
+          case 'loop':
+            this.playFirst()
+            break
+          case 'shuffle':
+            this.clearPlayingTrack()
+            this.shuffleQueue()
+            this.playFirst()
+            break
+          case 'end':
+          default:
+            this.clearPlayingTrack()
         }
       }
     }