From 7d43a7ea840e752221c0da5cd99e11cf8b3fd834 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 20 Dec 2014 17:31:58 +0100 Subject: player: don't show "0%" percentage in infinite streams --- player/command.c | 8 ++++++-- player/playloop.c | 5 +++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/player/command.c b/player/command.c index 52eebe12ec..b4e691c053 100644 --- a/player/command.c +++ b/player/command.c @@ -576,10 +576,14 @@ static int mp_property_percent_pos(void *ctx, struct m_property *prop, .max = 100, }; return M_PROPERTY_OK; - case M_PROPERTY_PRINT: - *(char **)arg = talloc_asprintf(NULL, "%d", get_percent_pos(mpctx)); + case M_PROPERTY_PRINT: { + int pos = get_percent_pos(mpctx); + if (pos < 0) + return M_PROPERTY_UNAVAILABLE; + *(char **)arg = talloc_asprintf(NULL, "%d", pos); return M_PROPERTY_OK; } + } return M_PROPERTY_NOT_IMPLEMENTED; } diff --git a/player/playloop.c b/player/playloop.c index 597d1094a2..25ab5ae0f9 100644 --- a/player/playloop.c +++ b/player/playloop.c @@ -422,10 +422,11 @@ double get_current_pos_ratio(struct MPContext *mpctx, bool use_range) return ans; } +// 0-100, -1 if unknown int get_percent_pos(struct MPContext *mpctx) { - int pos = get_current_pos_ratio(mpctx, false) * 100; - return MPCLAMP(pos, 0, 100); + double pos = get_current_pos_ratio(mpctx, false); + return pos < 0 ? -1 : pos * 100; } // -2 is no chapters, -1 is before first chapter -- cgit v1.2.3