summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2016-10-02 05:47:50 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2016-10-02 05:47:50 +0200
commit505a2559b8658c5ec47ae925b4d73f2b34ca7bda (patch)
tree6a3827787e353b91b39a024d31cdbca93ae56882
parenta60bbb9e4feb828a1283cf98b36bb8dfc718b0e6 (diff)
downloadnncmpp-505a2559b8658c5ec47ae925b4d73f2b34ca7bda.tar.gz
nncmpp-505a2559b8658c5ec47ae925b4d73f2b34ca7bda.tar.xz
nncmpp-505a2559b8658c5ec47ae925b4d73f2b34ca7bda.zip
Try to use MPD's "elapsed" rather than "time"
-rw-r--r--nncmpp.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/nncmpp.c b/nncmpp.c
index 1520fd4..eb898dc 100644
--- a/nncmpp.c
+++ b/nncmpp.c
@@ -1490,12 +1490,16 @@ mpd_on_info_response (const struct mpd_response *response,
g_ctx.song_duration = tmp;
// TODO: use "time" as a fallback (no milliseconds there)
- char *elapsed = str_map_find (&map, "elapsed");
- if (elapsed && g_ctx.state == PLAYER_PLAYING)
+ char *period, *elapsed = str_map_find (&map, "elapsed");
+ if (elapsed && (period = strchr (elapsed, '.')))
{
- // TODO: parse the "elapsed" value and use it
- char *period = strchr (elapsed, '.');
- if (period && xstrtoul (&tmp, period + 1, 10))
+ // For some reason this is much more precise
+ *period++ = '\0';
+ if (xstrtoul (&tmp, elapsed, 10))
+ g_ctx.song_elapsed = tmp;
+
+ if (g_ctx.state == PLAYER_PLAYING
+ && xstrtoul (&tmp, period, 10))
{
// TODO: initialize the timer and create a callback
poller_timer_set (&g_ctx.elapsed_event, 1000 - tmp);