MediaPlayer: Fix movement of items in playlist

In Playlist, whenever a move of items occured causing the
currently playing song to change its position, so :
1. Importing files (D&D for example) before its position
2. Removings files before it
3. Moving files before it

was causing the currently playing song to restart because
it was thinking a new entry was asked (it had a different
index number suddently).

Also adjusted the behaviour when you delete the currently
playing track.

Should fix ticket #6689.
This commit is contained in:
Philippe Saint-Pierre 2012-01-07 17:24:37 -05:00
parent 174676503b
commit a5a013ca40
11 changed files with 30 additions and 24 deletions

View File

@ -105,7 +105,7 @@ ControllerView::TogglePlaying()
&& Position() == 1.0) {
// Reached end of playlist and end of last item
// -> start again from the first item.
fPlaylist->SetCurrentItemIndex(0);
fPlaylist->SetCurrentItemIndex(0, true);
} else
fController->TogglePlaying();
}
@ -141,7 +141,7 @@ ControllerView::SkipBackward()
int32 index = fPlaylist->CurrentItemIndex() - 1;
if (index < 0)
index = 0;
fPlaylist->SetCurrentItemIndex(index);
fPlaylist->SetCurrentItemIndex(index, true);
}
@ -152,7 +152,7 @@ ControllerView::SkipForward()
int32 index = fPlaylist->CurrentItemIndex() + 1;
if (index >= fPlaylist->CountItems())
index = fPlaylist->CountItems() - 1;
fPlaylist->SetCurrentItemIndex(index);
fPlaylist->SetCurrentItemIndex(index, true);
}

View File

@ -605,6 +605,10 @@ MainWin::MessageReceived(BMessage* msg)
BAutolock _(fPlaylist);
int32 index;
// if false, the message was meant to only update the GUI
bool play;
if (msg->FindBool("play", &play) < B_OK || !play)
break;
if (msg->FindInt32("index", &index) < B_OK
|| index != fPlaylist->CurrentItemIndex())
break;

View File

@ -107,7 +107,7 @@ CopyPLItemsCommand::Undo()
// take care about currently played item
if (current != NULL)
fPlaylist->SetCurrentItemIndex(fPlaylist->IndexOf(current));
fPlaylist->SetCurrentItemIndex(fPlaylist->IndexOf(current), false);
return B_OK;
}

View File

@ -162,7 +162,7 @@ ImportPLItemsCommand::Undo()
}
// Restore previously playing item
if (fPlaylingIndex >= 0)
fPlaylist->SetCurrentItemIndex(fPlaylingIndex);
fPlaylist->SetCurrentItemIndex(fPlaylingIndex, false);
} else {
// remove new items from playlist
for (int32 i = 0; i < fNewCount; i++) {

View File

@ -134,7 +134,7 @@ MovePLItemsCommand::Perform()
// take care about currently played item
if (current != NULL)
fPlaylist->SetCurrentItemIndex(fPlaylist->IndexOf(current));
fPlaylist->SetCurrentItemIndex(fPlaylist->IndexOf(current), false);
return B_OK;
}
@ -168,7 +168,7 @@ MovePLItemsCommand::Undo()
// take care about currently played item
if (current != NULL)
fPlaylist->SetCurrentItemIndex(fPlaylist->IndexOf(current));
fPlaylist->SetCurrentItemIndex(fPlaylist->IndexOf(current), false);
return B_OK;
}

View File

@ -55,7 +55,7 @@ Playlist::Listener::~Listener() {}
void Playlist::Listener::ItemAdded(PlaylistItem* item, int32 index) {}
void Playlist::Listener::ItemRemoved(int32 index) {}
void Playlist::Listener::ItemsSorted() {}
void Playlist::Listener::CurrentItemChanged(int32 newIndex) {}
void Playlist::Listener::CurrentItemChanged(int32 newIndex, bool play) {}
void Playlist::Listener::ImportFailed() {}
@ -277,7 +277,7 @@ Playlist::AddItem(PlaylistItem* item, int32 index)
return false;
if (index <= fCurrentIndex)
SetCurrentItemIndex(fCurrentIndex + 1);
SetCurrentItemIndex(fCurrentIndex + 1, false);
_NotifyItemAdded(item, index);
@ -325,10 +325,10 @@ Playlist::RemoveItem(int32 index, bool careAboutCurrentIndex)
_NotifyItemRemoved(index);
if (careAboutCurrentIndex) {
if (index == fCurrentIndex && index >= CountItems())
if (index >= CountItems())
SetCurrentItemIndex(CountItems() - 1);
else if (index < fCurrentIndex)
SetCurrentItemIndex(fCurrentIndex - 1);
else if (index <= fCurrentIndex)
SetCurrentItemIndex(index - 1);
}
return item;
@ -360,7 +360,7 @@ Playlist::ItemAtFast(int32 index) const
bool
Playlist::SetCurrentItemIndex(int32 index, bool forceNotify)
Playlist::SetCurrentItemIndex(int32 index, bool notify)
{
bool result = true;
if (index >= CountItems()) {
@ -371,11 +371,11 @@ Playlist::SetCurrentItemIndex(int32 index, bool forceNotify)
index = -1;
result = false;
}
if (index == fCurrentIndex && !forceNotify)
if (index == fCurrentIndex && !notify)
return result;
fCurrentIndex = index;
_NotifyCurrentItemChanged(fCurrentIndex);
_NotifyCurrentItemChanged(fCurrentIndex, notify);
return result;
}
@ -804,13 +804,13 @@ Playlist::_NotifyItemsSorted() const
void
Playlist::_NotifyCurrentItemChanged(int32 newIndex) const
Playlist::_NotifyCurrentItemChanged(int32 newIndex, bool play) const
{
BList listeners(fListeners);
int32 count = listeners.CountItems();
for (int32 i = 0; i < count; i++) {
Listener* listener = (Listener*)listeners.ItemAtFast(i);
listener->CurrentItemChanged(newIndex);
listener->CurrentItemChanged(newIndex, play);
}
}

View File

@ -55,7 +55,7 @@ public:
virtual void ItemsSorted();
virtual void CurrentItemChanged(int32 newIndex);
virtual void CurrentItemChanged(int32 newIndex, bool play);
virtual void ImportFailed();
};
@ -92,7 +92,7 @@ public:
// navigating current ref
bool SetCurrentItemIndex(int32 index,
bool forceNotify = false);
bool notify = true);
int32 CurrentItemIndex() const;
void GetSkipInfo(bool* canSkipPrevious,
@ -137,7 +137,8 @@ private:
int32 index) const;
void _NotifyItemRemoved(int32 index) const;
void _NotifyItemsSorted() const;
void _NotifyCurrentItemChanged(int32 newIndex) const;
void _NotifyCurrentItemChanged(int32 newIndex,
bool play) const;
void _NotifyImportFailed() const;
private:

View File

@ -53,10 +53,11 @@ PlaylistObserver::ItemsSorted()
void
PlaylistObserver::CurrentItemChanged(int32 newIndex)
PlaylistObserver::CurrentItemChanged(int32 newIndex, bool play)
{
BMessage message(MSG_PLAYLIST_CURRENT_ITEM_CHANGED);
message.AddInt32("index", newIndex);
message.AddBool("play", play);
DeliverMessage(message);
}

View File

@ -26,7 +26,7 @@ public:
virtual void ItemsSorted();
virtual void CurrentItemChanged(int32 newIndex);
virtual void CurrentItemChanged(int32 newIndex, bool play);
virtual void ImportFailed();
};

View File

@ -135,7 +135,7 @@ RandomizePLItemsCommand::_Sort(bool random)
// take care about currently played item
if (current != NULL)
fPlaylist->SetCurrentItemIndex(fPlaylist->IndexOf(current));
fPlaylist->SetCurrentItemIndex(fPlaylist->IndexOf(current), false);
return B_OK;
}

View File

@ -157,7 +157,7 @@ RemovePLItemsCommand::Undo()
// take care about currently played ref
if (current != NULL)
fPlaylist->SetCurrentItemIndex(fPlaylist->IndexOf(current));
fPlaylist->SetCurrentItemIndex(fPlaylist->IndexOf(current), false);
return B_OK;
}