« get me outta code hell

Skip non-playables when determening next/prev item - mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2019-10-16 11:10:00 -0300
committerFlorrie <towerofnix@gmail.com>2019-10-16 11:10:00 -0300
commitb3424b76383472ac9c7719435dd13ab7b8406a63 (patch)
tree190ed0529a554ad84168a17d08643d330ce86020
parent7c3440529c5f51491eac682f137b627cb6b94164 (diff)
Skip non-playables when determening next/prev item
...to play. This is useful when you have non-playables interweaved with
tracks, e.g. a file for each track's art.
-rw-r--r--backend.js14
1 files changed, 10 insertions, 4 deletions
diff --git a/backend.js b/backend.js
index b3e6564..7ee6873 100644
--- a/backend.js
+++ b/backend.js
@@ -446,8 +446,11 @@ class QueuePlayer extends EventEmitter {
       if (automaticallyQueueNextTrack) {
         const parent = track[parentSymbol]
         if (!parent) return false
-        const index = parent.items.indexOf(track)
-        const nextItem = parent.items[index + 1]
+        let index = parent.items.indexOf(track)
+        let nextItem
+        do {
+          nextItem = parent.items[++index]
+        } while (nextItem && !(isTrack(nextItem) || isGroup(nextItem)))
         if (!nextItem) return false
         this.queue(nextItem)
         queueIndex = queue.items.length - 1
@@ -472,8 +475,11 @@ class QueuePlayer extends EventEmitter {
       if (automaticallyQueuePreviousTrack) {
         const parent = track[parentSymbol]
         if (!parent) return false
-        const index = parent.items.indexOf(track)
-        const previousItem = parent.items[index - 1]
+        let index = parent.items.indexOf(track)
+        let previousItem
+        do {
+          previousItem = parent.items[--index]
+        } while (previousItem && !(isTrack(previousItem) || isGroup(previousItem)))
         if (!previousItem) return false
         this.queue(previousItem, 'FRONT')
         queueIndex = 0