status: if current song is not yet in playlist, fetch it from the server - part 2

This commit is contained in:
Andrzej Rybczak
2015-04-21 22:10:38 +02:00
parent 9e85f38865
commit 39c331eed6

View File

@@ -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:
@@ -579,16 +590,11 @@ void Status::Changes::elapsedTime(bool update_elapsed)
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: