« 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.js15
1 files changed, 14 insertions, 1 deletions
diff --git a/backend.js b/backend.js
index e75b1a8..0864d09 100644
--- a/backend.js
+++ b/backend.js
@@ -68,6 +68,7 @@ class QueuePlayer extends EventEmitter {
     this.pauseNextTrack = false
     this.queueEndMode = 'end' // end, loop, shuffle
     this.alwaysStartPaused = false
+    this.waitWhenDonePlaying = false
 
     this.playedTrackToEnd = false
     this.timeData = null
@@ -444,7 +445,10 @@ class QueuePlayer extends EventEmitter {
 
     if (playingThisTrack) {
       this.playedTrackToEnd = true
-      this.playNext(item)
+      this.emit('done playing', this.playingTrack)
+      if (!this.waitWhenDonePlaying && !this.playNext(item)) {
+        this.clearPlayingTrack()
+      }
     }
   }
 
@@ -695,6 +699,7 @@ export default class Backend extends EventEmitter {
 
     this.queuePlayers = []
     this.alwaysStartPaused = false
+    this.waitWhenDonePlaying = false
 
     this.recordStore = new RecordStore()
     this.throttleMetadata = throttlePromise(10)
@@ -727,6 +732,7 @@ export default class Backend extends EventEmitter {
     }
 
     queuePlayer.alwaysStartPaused = this.alwaysStartPaused
+    queuePlayer.waitWhenDonePlaying = this.waitWhenDonePlaying
 
     this.queuePlayers.push(queuePlayer)
     this.emit('added queue player', queuePlayer)
@@ -862,6 +868,13 @@ export default class Backend extends EventEmitter {
     }
   }
 
+  setWaitWhenDonePlaying(value) {
+    this.waitWhenDonePlaying = !!value
+    for (const queuePlayer of this.queuePlayers) {
+      queuePlayer.waitWhenDonePlaying = !!value
+    }
+  }
+
   async stopPlayingAll() {
     for (const queuePlayer of this.queuePlayers) {
       await queuePlayer.stopPlaying()