Skip to content

Commit

Permalink
Merge pull request #52 from ninov/master
Browse files Browse the repository at this point in the history
detect repeating a song
  • Loading branch information
hrkfdn authored Sep 30, 2018
2 parents 76165ed + fefebb5 commit c8ba5f1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions mpd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,8 @@ void CMPD::Update()
int newsongid = mpd_status_get_song_id(status);
int newsongpos = mpd_status_get_elapsed_time(status);
int curplaytime = mpd_stats_get_play_time(stats);

// new song
if(newsongid != _songid) {
// new song (or the same song but from the beginning after it has been played long enough before)
if(newsongid != _songid || (_song.getDuration() != -1 && _songpos > (_song.getDuration()/2) && newsongpos < _songpos && newsongpos < 10)) {
_songid = newsongid;
_songpos = newsongpos;
_start = curplaytime;
Expand All @@ -107,6 +106,8 @@ void CMPD::Update()
if(song) {
GotNewSong(song);
mpd_song_free(song);
} else {
_song = Song();
}
}

Expand Down
2 changes: 1 addition & 1 deletion mpd.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Song {
int getDuration() const { return duration; }
private:
std::string albumartist, artist, title, album;
int duration;
int duration = -1;
};

class CMPD
Expand Down

0 comments on commit c8ba5f1

Please sign in to comment.