From b5f22a7f7832b533fcb0370361e93e6469b69c61 Mon Sep 17 00:00:00 2001 From: Philippe Saint-Pierre Date: Sun, 2 Sep 2012 16:05:35 -0400 Subject: [PATCH] MediaPlayer: Deletion of playlist entries Several scenarios of misbehaviour found and fixed, examples : * Deleting an item sitting before the currently playing item had the effect of starting the playback of the item before the delete item. (now it just updates the indexes - setting it to fCurrentIndex - 1 - without altering playback). * Deleting the last item of the list had for effect of starting the playback of the entry newingly being the last entry, regardless if the last entry was the active one or not. Should fix #6689. --- src/apps/mediaplayer/playlist/Playlist.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/apps/mediaplayer/playlist/Playlist.cpp b/src/apps/mediaplayer/playlist/Playlist.cpp index 9707423574..35fabad63d 100644 --- a/src/apps/mediaplayer/playlist/Playlist.cpp +++ b/src/apps/mediaplayer/playlist/Playlist.cpp @@ -325,10 +325,15 @@ Playlist::RemoveItem(int32 index, bool careAboutCurrentIndex) _NotifyItemRemoved(index); if (careAboutCurrentIndex) { - if (index >= CountItems()) - SetCurrentItemIndex(CountItems() - 1); - else if (index <= fCurrentIndex) - SetCurrentItemIndex(index - 1); + // fCurrentIndex isn't in sync yet, so might be one too large (if the + // removed item was above the currently playing item). + if (index < fCurrentIndex) + SetCurrentItemIndex(fCurrentIndex - 1, false); + else if (index == fCurrentIndex) { + if (fCurrentIndex == CountItems()) + fCurrentIndex--; + SetCurrentItemIndex(fCurrentIndex, true); + } } return item;