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:
@@ -105,7 +105,7 @@ ControllerView::TogglePlaying()
|
|||||||
&& Position() == 1.0) {
|
&& Position() == 1.0) {
|
||||||
// Reached end of playlist and end of last item
|
// Reached end of playlist and end of last item
|
||||||
// -> start again from the first item.
|
// -> start again from the first item.
|
||||||
fPlaylist->SetCurrentItemIndex(0);
|
fPlaylist->SetCurrentItemIndex(0, true);
|
||||||
} else
|
} else
|
||||||
fController->TogglePlaying();
|
fController->TogglePlaying();
|
||||||
}
|
}
|
||||||
@@ -141,7 +141,7 @@ ControllerView::SkipBackward()
|
|||||||
int32 index = fPlaylist->CurrentItemIndex() - 1;
|
int32 index = fPlaylist->CurrentItemIndex() - 1;
|
||||||
if (index < 0)
|
if (index < 0)
|
||||||
index = 0;
|
index = 0;
|
||||||
fPlaylist->SetCurrentItemIndex(index);
|
fPlaylist->SetCurrentItemIndex(index, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -152,7 +152,7 @@ ControllerView::SkipForward()
|
|||||||
int32 index = fPlaylist->CurrentItemIndex() + 1;
|
int32 index = fPlaylist->CurrentItemIndex() + 1;
|
||||||
if (index >= fPlaylist->CountItems())
|
if (index >= fPlaylist->CountItems())
|
||||||
index = fPlaylist->CountItems() - 1;
|
index = fPlaylist->CountItems() - 1;
|
||||||
fPlaylist->SetCurrentItemIndex(index);
|
fPlaylist->SetCurrentItemIndex(index, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -605,6 +605,10 @@ MainWin::MessageReceived(BMessage* msg)
|
|||||||
BAutolock _(fPlaylist);
|
BAutolock _(fPlaylist);
|
||||||
|
|
||||||
int32 index;
|
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
|
if (msg->FindInt32("index", &index) < B_OK
|
||||||
|| index != fPlaylist->CurrentItemIndex())
|
|| index != fPlaylist->CurrentItemIndex())
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ CopyPLItemsCommand::Undo()
|
|||||||
|
|
||||||
// take care about currently played item
|
// take care about currently played item
|
||||||
if (current != NULL)
|
if (current != NULL)
|
||||||
fPlaylist->SetCurrentItemIndex(fPlaylist->IndexOf(current));
|
fPlaylist->SetCurrentItemIndex(fPlaylist->IndexOf(current), false);
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ ImportPLItemsCommand::Undo()
|
|||||||
}
|
}
|
||||||
// Restore previously playing item
|
// Restore previously playing item
|
||||||
if (fPlaylingIndex >= 0)
|
if (fPlaylingIndex >= 0)
|
||||||
fPlaylist->SetCurrentItemIndex(fPlaylingIndex);
|
fPlaylist->SetCurrentItemIndex(fPlaylingIndex, false);
|
||||||
} else {
|
} else {
|
||||||
// remove new items from playlist
|
// remove new items from playlist
|
||||||
for (int32 i = 0; i < fNewCount; i++) {
|
for (int32 i = 0; i < fNewCount; i++) {
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ MovePLItemsCommand::Perform()
|
|||||||
|
|
||||||
// take care about currently played item
|
// take care about currently played item
|
||||||
if (current != NULL)
|
if (current != NULL)
|
||||||
fPlaylist->SetCurrentItemIndex(fPlaylist->IndexOf(current));
|
fPlaylist->SetCurrentItemIndex(fPlaylist->IndexOf(current), false);
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -168,7 +168,7 @@ MovePLItemsCommand::Undo()
|
|||||||
|
|
||||||
// take care about currently played item
|
// take care about currently played item
|
||||||
if (current != NULL)
|
if (current != NULL)
|
||||||
fPlaylist->SetCurrentItemIndex(fPlaylist->IndexOf(current));
|
fPlaylist->SetCurrentItemIndex(fPlaylist->IndexOf(current), false);
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ Playlist::Listener::~Listener() {}
|
|||||||
void Playlist::Listener::ItemAdded(PlaylistItem* item, int32 index) {}
|
void Playlist::Listener::ItemAdded(PlaylistItem* item, int32 index) {}
|
||||||
void Playlist::Listener::ItemRemoved(int32 index) {}
|
void Playlist::Listener::ItemRemoved(int32 index) {}
|
||||||
void Playlist::Listener::ItemsSorted() {}
|
void Playlist::Listener::ItemsSorted() {}
|
||||||
void Playlist::Listener::CurrentItemChanged(int32 newIndex) {}
|
void Playlist::Listener::CurrentItemChanged(int32 newIndex, bool play) {}
|
||||||
void Playlist::Listener::ImportFailed() {}
|
void Playlist::Listener::ImportFailed() {}
|
||||||
|
|
||||||
|
|
||||||
@@ -277,7 +277,7 @@ Playlist::AddItem(PlaylistItem* item, int32 index)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (index <= fCurrentIndex)
|
if (index <= fCurrentIndex)
|
||||||
SetCurrentItemIndex(fCurrentIndex + 1);
|
SetCurrentItemIndex(fCurrentIndex + 1, false);
|
||||||
|
|
||||||
_NotifyItemAdded(item, index);
|
_NotifyItemAdded(item, index);
|
||||||
|
|
||||||
@@ -325,10 +325,10 @@ Playlist::RemoveItem(int32 index, bool careAboutCurrentIndex)
|
|||||||
_NotifyItemRemoved(index);
|
_NotifyItemRemoved(index);
|
||||||
|
|
||||||
if (careAboutCurrentIndex) {
|
if (careAboutCurrentIndex) {
|
||||||
if (index == fCurrentIndex && index >= CountItems())
|
if (index >= CountItems())
|
||||||
SetCurrentItemIndex(CountItems() - 1);
|
SetCurrentItemIndex(CountItems() - 1);
|
||||||
else if (index < fCurrentIndex)
|
else if (index <= fCurrentIndex)
|
||||||
SetCurrentItemIndex(fCurrentIndex - 1);
|
SetCurrentItemIndex(index - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
@@ -360,7 +360,7 @@ Playlist::ItemAtFast(int32 index) const
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Playlist::SetCurrentItemIndex(int32 index, bool forceNotify)
|
Playlist::SetCurrentItemIndex(int32 index, bool notify)
|
||||||
{
|
{
|
||||||
bool result = true;
|
bool result = true;
|
||||||
if (index >= CountItems()) {
|
if (index >= CountItems()) {
|
||||||
@@ -371,11 +371,11 @@ Playlist::SetCurrentItemIndex(int32 index, bool forceNotify)
|
|||||||
index = -1;
|
index = -1;
|
||||||
result = false;
|
result = false;
|
||||||
}
|
}
|
||||||
if (index == fCurrentIndex && !forceNotify)
|
if (index == fCurrentIndex && !notify)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
fCurrentIndex = index;
|
fCurrentIndex = index;
|
||||||
_NotifyCurrentItemChanged(fCurrentIndex);
|
_NotifyCurrentItemChanged(fCurrentIndex, notify);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -804,13 +804,13 @@ Playlist::_NotifyItemsSorted() const
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Playlist::_NotifyCurrentItemChanged(int32 newIndex) const
|
Playlist::_NotifyCurrentItemChanged(int32 newIndex, bool play) const
|
||||||
{
|
{
|
||||||
BList listeners(fListeners);
|
BList listeners(fListeners);
|
||||||
int32 count = listeners.CountItems();
|
int32 count = listeners.CountItems();
|
||||||
for (int32 i = 0; i < count; i++) {
|
for (int32 i = 0; i < count; i++) {
|
||||||
Listener* listener = (Listener*)listeners.ItemAtFast(i);
|
Listener* listener = (Listener*)listeners.ItemAtFast(i);
|
||||||
listener->CurrentItemChanged(newIndex);
|
listener->CurrentItemChanged(newIndex, play);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ public:
|
|||||||
|
|
||||||
virtual void ItemsSorted();
|
virtual void ItemsSorted();
|
||||||
|
|
||||||
virtual void CurrentItemChanged(int32 newIndex);
|
virtual void CurrentItemChanged(int32 newIndex, bool play);
|
||||||
|
|
||||||
virtual void ImportFailed();
|
virtual void ImportFailed();
|
||||||
};
|
};
|
||||||
@@ -92,7 +92,7 @@ public:
|
|||||||
|
|
||||||
// navigating current ref
|
// navigating current ref
|
||||||
bool SetCurrentItemIndex(int32 index,
|
bool SetCurrentItemIndex(int32 index,
|
||||||
bool forceNotify = false);
|
bool notify = true);
|
||||||
int32 CurrentItemIndex() const;
|
int32 CurrentItemIndex() const;
|
||||||
|
|
||||||
void GetSkipInfo(bool* canSkipPrevious,
|
void GetSkipInfo(bool* canSkipPrevious,
|
||||||
@@ -137,7 +137,8 @@ private:
|
|||||||
int32 index) const;
|
int32 index) const;
|
||||||
void _NotifyItemRemoved(int32 index) const;
|
void _NotifyItemRemoved(int32 index) const;
|
||||||
void _NotifyItemsSorted() const;
|
void _NotifyItemsSorted() const;
|
||||||
void _NotifyCurrentItemChanged(int32 newIndex) const;
|
void _NotifyCurrentItemChanged(int32 newIndex,
|
||||||
|
bool play) const;
|
||||||
void _NotifyImportFailed() const;
|
void _NotifyImportFailed() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -53,10 +53,11 @@ PlaylistObserver::ItemsSorted()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PlaylistObserver::CurrentItemChanged(int32 newIndex)
|
PlaylistObserver::CurrentItemChanged(int32 newIndex, bool play)
|
||||||
{
|
{
|
||||||
BMessage message(MSG_PLAYLIST_CURRENT_ITEM_CHANGED);
|
BMessage message(MSG_PLAYLIST_CURRENT_ITEM_CHANGED);
|
||||||
message.AddInt32("index", newIndex);
|
message.AddInt32("index", newIndex);
|
||||||
|
message.AddBool("play", play);
|
||||||
|
|
||||||
DeliverMessage(message);
|
DeliverMessage(message);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ public:
|
|||||||
|
|
||||||
virtual void ItemsSorted();
|
virtual void ItemsSorted();
|
||||||
|
|
||||||
virtual void CurrentItemChanged(int32 newIndex);
|
virtual void CurrentItemChanged(int32 newIndex, bool play);
|
||||||
|
|
||||||
virtual void ImportFailed();
|
virtual void ImportFailed();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ RandomizePLItemsCommand::_Sort(bool random)
|
|||||||
|
|
||||||
// take care about currently played item
|
// take care about currently played item
|
||||||
if (current != NULL)
|
if (current != NULL)
|
||||||
fPlaylist->SetCurrentItemIndex(fPlaylist->IndexOf(current));
|
fPlaylist->SetCurrentItemIndex(fPlaylist->IndexOf(current), false);
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -157,7 +157,7 @@ RemovePLItemsCommand::Undo()
|
|||||||
|
|
||||||
// take care about currently played ref
|
// take care about currently played ref
|
||||||
if (current != NULL)
|
if (current != NULL)
|
||||||
fPlaylist->SetCurrentItemIndex(fPlaylist->IndexOf(current));
|
fPlaylist->SetCurrentItemIndex(fPlaylist->IndexOf(current), false);
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user