From 6f51debddeb0edc2651113b8938808240d3d18b5 Mon Sep 17 00:00:00 2001 From: casey langen Date: Sat, 21 Jan 2017 22:28:43 -0800 Subject: [PATCH] Fixed bug where deleting the currently playing item from the play queue would cause the second, instead of first, track in the queue to start playing. --- src/core/audio/PlaybackService.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/core/audio/PlaybackService.cpp b/src/core/audio/PlaybackService.cpp index 7a8583ef8..ea648b85a 100755 --- a/src/core/audio/PlaybackService.cpp +++ b/src/core/audio/PlaybackService.cpp @@ -59,6 +59,7 @@ using musik::core::audio::ITransport; using Editor = PlaybackService::Editor; #define NO_POSITION (size_t) -1 +#define START_OVER (size_t) -2 #define URI_AT_INDEX(x) this->playlist.Get(x)->Uri() @@ -172,8 +173,18 @@ void PlaybackService::PrepareNextTrack() { this->transport.PrepareNextTrack(URI_AT_INDEX(this->index)); } else { + /* annoying and confusing special case -- the user edited the + playlist and deleted the currently playing item. let's start + again from the top... */ + if (this->index == START_OVER) { + if (this->playlist.Count() > 0) { + this->index = NO_POSITION; + this->nextIndex = 0; + this->transport.PrepareNextTrack(URI_AT_INDEX(nextIndex)); + } + } /* normal case, just move forward */ - if (this->playlist.Count() > this->index + 1) { + else if (this->playlist.Count() > this->index + 1) { if (this->nextIndex != this->index + 1) { this->nextIndex = this->index + 1; this->transport.PrepareNextTrack(URI_AT_INDEX(nextIndex)); @@ -605,7 +616,7 @@ bool PlaybackService::Editor::Delete(size_t index) { this->playIndex = NO_POSITION; } if (index == this->playIndex) { - this->playIndex = 0; + this->playIndex = START_OVER; } else if (index < this->playIndex) { --this->playIndex;