From 7e12505e08fcc90b71f2f769ab92040411671c8e Mon Sep 17 00:00:00 2001 From: Bogdan Sinitsyn Date: Wed, 14 Sep 2016 22:27:33 +0300 Subject: [PATCH] Handle radio streams correctly Watch not only on song ID change but on tags change too --- mpd.cpp | 12 ++++++++++-- mpd.h | 6 ++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/mpd.cpp b/mpd.cpp index 180c675..72f6a76 100644 --- a/mpd.cpp +++ b/mpd.cpp @@ -96,19 +96,27 @@ void CMPD::Update() int newsongpos = mpd_status_get_elapsed_time(status); int curplaytime = mpd_stats_get_play_time(stats); + mpd_song *song = mpd_run_current_song(_conn); + Song *song_ = song ? new Song(song) : NULL; + // new song - if(newsongid != _songid) { + if(newsongid != _songid or (song_ and _song != *song_)) { _songid = newsongid; _songpos = newsongpos; _start = curplaytime; - mpd_song *song = mpd_run_current_song(_conn); if(song) { GotNewSong(song); mpd_song_free(song); + song = NULL; } } + if (song) + mpd_song_free(song); + if (song_) + delete song_; + // song playing if(newsongpos != _songpos) { _songpos = newsongpos; diff --git a/mpd.h b/mpd.h index 055b501..e573d89 100644 --- a/mpd.h +++ b/mpd.h @@ -16,6 +16,12 @@ class Song { std::string getTitle() const { return title; } std::string getAlbum() const { return album; } int getDuration() const { return duration; } + + bool operator != (const Song &other) const { + return this->getArtist() != other.getArtist() or + this->getAlbum() != other.getAlbum() or + this->getTitle() != other.getTitle(); + } private: std::string artist, title, album; int duration;