diff options
author | wm4 <wm4@nowhere> | 2014-12-20 17:31:58 +0100 |
---|---|---|
committer | Alessandro Ghedini <alessandro@ghedini.me> | 2015-01-14 16:18:17 +0100 |
commit | 3a6572d206f211f4cbd6651f72fdf0ac7919ad13 (patch) | |
tree | 4be2313e219a075ba4954bfef373c353f47d0ec7 | |
parent | 8ab8fa8960a2ea8642c006cfd10057b93835600b (diff) | |
download | mpv-3a6572d206f211f4cbd6651f72fdf0ac7919ad13.tar.bz2 mpv-3a6572d206f211f4cbd6651f72fdf0ac7919ad13.tar.xz |
player: don't show "0%" percentage in infinite streams
-rw-r--r-- | player/command.c | 8 | ||||
-rw-r--r-- | player/playloop.c | 5 |
2 files changed, 9 insertions, 4 deletions
diff --git a/player/command.c b/player/command.c index cec28491d4..63d524ada6 100644 --- a/player/command.c +++ b/player/command.c @@ -568,10 +568,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 190bc3f98c..678ee6986d 100644 --- a/player/playloop.c +++ b/player/playloop.c @@ -427,10 +427,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 |