From bd251cbf9f732977b0bc14998e6a16839386054d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 29 Dec 2018 18:33:00 +0100 Subject: [PATCH] module/mpd: only auto-progress 'elapsed' when state is PLAYING --- modules/mpd/mpd.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/modules/mpd/mpd.c b/modules/mpd/mpd.c index 322e393..54ed23a 100644 --- a/modules/mpd/mpd.c +++ b/modules/mpd/mpd.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -108,8 +109,18 @@ content(struct module *mod) mtx_lock(&mod->lock); /* Calculate what 'elapsed' is now */ - uint64_t elapsed = m->elapsed.value + - timespec_diff_milli_seconds(&now, &m->elapsed.when); + uint64_t elapsed = m->elapsed.value; + + if (m->state == STATE_PLAY) { + elapsed += timespec_diff_milli_seconds(&now, &m->elapsed.when); + if (elapsed > m->duration) { + LOG_WARN( + "dynamic update of elapsed overflowed: " + "elapsed=%"PRIu64", duration=%"PRIu64, elapsed, m->duration); + elapsed = m->duration; + } + + } unsigned elapsed_secs = elapsed / 1000; unsigned duration_secs = m->duration / 1000;