diff --git a/include/adapters/mpd.hpp b/include/adapters/mpd.hpp index 5e7dbfa8..03cc2862 100644 --- a/include/adapters/mpd.hpp +++ b/include/adapters/mpd.hpp @@ -140,7 +140,6 @@ namespace mpd { void fetch_data(mpdconnection* conn); void update(int event, mpdconnection* connection); - void update_timer(); bool random() const; bool repeat() const; diff --git a/src/adapters/mpd.cpp b/src/adapters/mpd.cpp index c4e2f731..459551a0 100644 --- a/src/adapters/mpd.cpp +++ b/src/adapters/mpd.cpp @@ -370,6 +370,10 @@ namespace mpd { } void mpdstatus::update(int event, mpdconnection* connection) { + /* + * Only update if either the player state (play, stop, pause, seek, ...), the options (random, repeat, ...), + * or the playlist has been changed + */ if (connection == nullptr || !static_cast(event & (MPD_IDLE_PLAYER | MPD_IDLE_OPTIONS | MPD_IDLE_PLAYLIST))) { return; } @@ -395,14 +399,6 @@ namespace mpd { } } - void mpdstatus::update_timer() { - auto diff = chrono::system_clock::now() - m_updated_at; - auto dur = chrono::duration_cast(diff); - m_elapsed_time_ms += dur.count(); - m_elapsed_time = m_elapsed_time_ms / 1000 + 0.5f; - m_updated_at = chrono::system_clock::now(); - } - bool mpdstatus::random() const { return m_random; } diff --git a/src/modules/mpd.cpp b/src/modules/mpd.cpp index 155663e7..3d67bc3b 100644 --- a/src/modules/mpd.cpp +++ b/src/modules/mpd.cpp @@ -162,13 +162,10 @@ namespace modules { int idle_flags = 0; if ((idle_flags = m_mpd->noidle()) != 0) { + // Update status on every event m_status->update(idle_flags, m_mpd.get()); return true; } - - if (m_status->match_state(mpdstate::PLAYING)) { - m_status->update_timer(); - } } catch (const mpd_exception& err) { m_log.err("%s: %s", name(), err.what()); m_mpd.reset(); @@ -203,6 +200,11 @@ namespace modules { } } + if (m_status->match_state(mpdstate::PLAYING)) { + // Always update the status while playing + m_status->update(-1, m_mpd.get()); + } + string artist; string album; string title;