From 39c331eed61af986e55fbbcf340a946e1af52d52 Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Tue, 21 Apr 2015 22:10:38 +0200 Subject: [PATCH] status: if current song is not yet in playlist, fetch it from the server - part 2 --- src/status.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/status.cpp b/src/status.cpp index 3fda126b..6f60fcf8 100644 --- a/src/status.cpp +++ b/src/status.cpp @@ -78,6 +78,17 @@ unsigned m_playlist_length; unsigned m_total_time; int m_volume; +MPD::Song getCurrentSong() +{ + MPD::Song result = myPlaylist->nowPlayingSong(); + // It may happen that playlist wasn't yet updated + // and current song is not there yet. In such case + // try fetching it from the server. + if (result.empty() && m_player_state != MPD::psUnknown) + result = Mpd.GetCurrentSong(); + return result; +} + void drawTitle(const MPD::Song &np) { assert(!np.empty()); @@ -478,7 +489,7 @@ void Status::Changes::playerState() switch (m_player_state) { case MPD::psPlay: - drawTitle(myPlaylist->nowPlayingSong()); + drawTitle(getCurrentSong()); myPlaylist->reloadRemaining(); break; case MPD::psStop: @@ -578,17 +589,12 @@ void Status::Changes::elapsedTime(bool update_elapsed) *wFooter << NC::XY(0, 1) << NC::TermManip::ClearToEOL; return; } - + + MPD::Song np = getCurrentSong(); std::string ps = playerStateToString(m_player_state); - MPD::Song np = myPlaylist->nowPlayingSong(); - // It may happen that playlist wasn't yet updated - // and current song is not there yet. In such case - // try fetching it from the server. - if (np.empty() && (m_player_state == MPD::psPlay || m_player_state == MPD::psPause)) - np = Mpd.GetCurrentSong(); - drawTitle(np); - std::string tracklength; + + drawTitle(np); switch (Config.design) { case Design::Classic: