diff --git a/src/core/player.cpp b/src/core/player.cpp index 9a341c1e8..694d5ac62 100644 --- a/src/core/player.cpp +++ b/src/core/player.cpp @@ -129,11 +129,8 @@ void Player::Next() { } void Player::NextInternal(Engine::TrackChangeFlags change) { - if (playlists_->active()->stop_after_current()) { - playlists_->active()->StopAfter(-1); - Stop(); + if (HandleStopAfter()) return; - } if (playlists_->active()->current_item()) { const QUrl url = playlists_->active()->current_item()->Url(); @@ -164,12 +161,26 @@ void Player::NextItem(Engine::TrackChangeFlags change) { PlayAt(i, change, false); } -void Player::TrackEnded() { +bool Player::HandleStopAfter() { if (playlists_->active()->stop_after_current()) { playlists_->active()->StopAfter(-1); + + // Find what the next track would've been, and mark that one as current + // so it plays next time the user presses Play. + const int next_row = playlists_->active()->next_row(); + if (next_row != -1) { + playlists_->active()->set_current_row(next_row); + } + Stop(); - return; + return true; } + return false; +} + +void Player::TrackEnded() { + if (HandleStopAfter()) + return; if (current_item_ && current_item_->IsLocalLibraryItem() && current_item_->Metadata().id() != -1 && diff --git a/src/core/player.h b/src/core/player.h index 7074536d7..c06a53484 100644 --- a/src/core/player.h +++ b/src/core/player.h @@ -163,6 +163,10 @@ public slots: void UrlHandlerDestroyed(QObject* object); void HandleLoadResult(const UrlHandler::LoadResult& result); + private: + // Returns true if we were supposed to stop after this track. + bool HandleStopAfter(); + private: PlaylistManagerInterface* playlists_; LastFMService* lastfm_; diff --git a/src/playlist/playlist.cpp b/src/playlist/playlist.cpp index e8381e166..6c70e2367 100644 --- a/src/playlist/playlist.cpp +++ b/src/playlist/playlist.cpp @@ -53,8 +53,8 @@ #include #include -#include #include +#include using smart_playlists::Generator; using smart_playlists::GeneratorInserter;