From 1ec3eab0dc312e505dc725119cbbd8c784ed6d9d Mon Sep 17 00:00:00 2001 From: Calvin Montgomery Date: Thu, 1 Aug 2019 19:57:32 -0700 Subject: [PATCH] Preserve current playing item when shuffling (#812) --- src/channel/playlist.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/channel/playlist.js b/src/channel/playlist.js index 1f8c14df..ca42964e 100644 --- a/src/channel/playlist.js +++ b/src/channel/playlist.js @@ -748,6 +748,8 @@ PlaylistModule.prototype.handleShuffle = function (user) { this.channel.logger.log("[playlist] " + user.getName() + " shuffled the playlist"); var pl = this.items.toArray(false); + let currentUid = this.current ? this.current.uid : null; + let currentTime = this.current ? this.current.media.currentTime : undefined; this.items.clear(); this.semaphore.reset(); while (pl.length > 0) { @@ -758,7 +760,12 @@ PlaylistModule.prototype.handleShuffle = function (user) { queueby: pl[i].queueby }); - this.items.append(item); + if (pl[i].uid === currentUid) { + this.items.prepend(item); + } else { + this.items.append(item); + } + pl.splice(i, 1); } this._listDirty = true; @@ -772,7 +779,7 @@ PlaylistModule.prototype.handleShuffle = function (user) { u.socket.emit("playlist", pl); } }); - this.startPlayback(); + this.startPlayback(currentTime); }; /**