Try to use MPD's "elapsed" rather than "time"

This commit is contained in:
Přemysl Eric Janouch 2016-10-02 05:47:50 +02:00
parent a60bbb9e4f
commit 505a2559b8
Signed by: p
GPG Key ID: B715679E3A361BE6
1 changed files with 9 additions and 5 deletions

View File

@ -1490,12 +1490,16 @@ mpd_on_info_response (const struct mpd_response *response,
g_ctx.song_duration = tmp; g_ctx.song_duration = tmp;
// TODO: use "time" as a fallback (no milliseconds there) // TODO: use "time" as a fallback (no milliseconds there)
char *elapsed = str_map_find (&map, "elapsed"); char *period, *elapsed = str_map_find (&map, "elapsed");
if (elapsed && g_ctx.state == PLAYER_PLAYING) if (elapsed && (period = strchr (elapsed, '.')))
{ {
// TODO: parse the "elapsed" value and use it // For some reason this is much more precise
char *period = strchr (elapsed, '.'); *period++ = '\0';
if (period && xstrtoul (&tmp, period + 1, 10)) 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 // TODO: initialize the timer and create a callback
poller_timer_set (&g_ctx.elapsed_event, 1000 - tmp); poller_timer_set (&g_ctx.elapsed_event, 1000 - tmp);