From b3424b76383472ac9c7719435dd13ab7b8406a63 Mon Sep 17 00:00:00 2001 From: Florrie Date: Wed, 16 Oct 2019 11:10:00 -0300 Subject: 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. --- backend.js | 14 ++++++++++---- 1 file 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 -- cgit 1.3.0-6-gf8a5