« 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.js14
1 files changed, 13 insertions, 1 deletions
diff --git a/backend.js b/backend.js
index f2c4d59..f2610d0 100644
--- a/backend.js
+++ b/backend.js
@@ -70,6 +70,7 @@ class QueuePlayer extends EventEmitter {
     this.queueGrouplike = {name: 'Queue', isTheQueue: true, items: []}
     this.pauseNextTrack = false
     this.alwaysStartPaused = false
+    this.waitWhenDonePlaying = false
 
     this.playedTrackToEnd = false
     this.timeData = null
@@ -458,7 +459,8 @@ class QueuePlayer extends EventEmitter {
 
     if (playingThisTrack) {
       this.playedTrackToEnd = true
-      if (!this.playNext(item)) {
+      this.emit('done playing', this.playingTrack)
+      if (!this.waitWhenDonePlaying && !this.playNext(item)) {
         this.clearPlayingTrack()
       }
     }
@@ -646,6 +648,7 @@ class Backend extends EventEmitter {
 
     this.queuePlayers = []
     this.alwaysStartPaused = false
+    this.waitWhenDonePlaying = false
 
     this.recordStore = new RecordStore()
     this.throttleMetadata = throttlePromise(10)
@@ -678,12 +681,14 @@ class Backend extends EventEmitter {
     }
 
     queuePlayer.alwaysStartPaused = this.alwaysStartPaused
+    queuePlayer.waitWhenDonePlaying = this.waitWhenDonePlaying
 
     this.queuePlayers.push(queuePlayer)
     this.emit('added queue player', queuePlayer)
 
     for (const event of [
       'playing',
+      'done playing',
       'queue',
       'distribute-queue',
       'unqueue',
@@ -811,6 +816,13 @@ 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()