From 8d414e2fe7f79f1bbf9158e8aa034e9ac9cf2222 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 16 Oct 2015 16:16:10 +0200 Subject: command: make time properties unavailable if timestamp is unknown Let's hope this doesn't confuse client API users too much. It's still the best solution to get rid of corner cases where it actually return the wrong timestamp on start, and then suddenly jump. --- player/osd.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'player/osd.c') diff --git a/player/osd.c b/player/osd.c index 8a000862eb..65747bc7cf 100644 --- a/player/osd.c +++ b/player/osd.c @@ -54,6 +54,14 @@ static void sadd_hhmmssff(char **buf, double time, bool fractions) talloc_free(s); } +// If time unknown (MP_NOPTS_VALUE), use 0 instead. +static void sadd_hhmmssff_u(char **buf, double time, bool fractions) +{ + if (time == MP_NOPTS_VALUE) + time = 0; + sadd_hhmmssff(buf, time, fractions); +} + static void sadd_percentage(char **buf, int percent) { if (percent >= 0) *buf = talloc_asprintf_append(*buf, " (%d%%)", percent); @@ -191,7 +199,7 @@ static void print_status(struct MPContext *mpctx) saddf(&line, ": "); // Playback position - sadd_hhmmssff(&line, get_playback_time(mpctx), mpctx->opts->osd_fractions); + sadd_hhmmssff_u(&line, get_playback_time(mpctx), mpctx->opts->osd_fractions); double len = get_time_length(mpctx); if (len >= 0) { @@ -429,7 +437,7 @@ static void sadd_osd_status(char **buffer, struct MPContext *mpctx, int level) *buffer = talloc_strdup_append(*buffer, text); talloc_free(text); } else { - sadd_hhmmssff(buffer, get_playback_time(mpctx), fractions); + sadd_hhmmssff_u(buffer, get_playback_time(mpctx), fractions); if (level == 3) { double len = get_time_length(mpctx); if (len >= 0) { -- cgit v1.2.3