mirror of
https://github.com/mpv-player/mpv.git
synced 2024-09-20 03:52:22 +02:00
player: minor fix/simplification of OSD time/duration handling
Always display the duration as "unknown" if the duration is known. Also fix that at least demux_lavf reported unknown duration as 0 (fix by setting the default to unknown in demux.c). Remove the dumb _u formatter function, and use a different approach to avoiding displaying "unknown" as playback time on playback start (set last_seek_pts for that).
This commit is contained in:
parent
274cc06aaf
commit
efbb919997
@ -1937,6 +1937,7 @@ static struct demuxer *open_given_type(struct mpv_global *global,
|
||||
.is_network = stream->is_network,
|
||||
.access_references = opts->access_references,
|
||||
.events = DEMUX_EVENT_ALL,
|
||||
.duration = -1,
|
||||
};
|
||||
demuxer->seekable = stream->seekable;
|
||||
if (demuxer->stream->underlying && !demuxer->stream->underlying->seekable)
|
||||
|
@ -837,7 +837,7 @@ static bool time_remaining(MPContext *mpctx, double *remaining)
|
||||
double len = get_time_length(mpctx);
|
||||
double playback = get_playback_time(mpctx);
|
||||
|
||||
if (playback == MP_NOPTS_VALUE)
|
||||
if (playback == MP_NOPTS_VALUE || len <= 0)
|
||||
return false;
|
||||
|
||||
*remaining = len - playback;
|
||||
|
@ -1163,6 +1163,9 @@ static void play_current_file(struct MPContext *mpctx)
|
||||
|
||||
reset_playback_state(mpctx);
|
||||
|
||||
// let get_current_time() show 0 as start time (before playback_pts is set)
|
||||
mpctx->last_seek_pts = 0.0;
|
||||
|
||||
mpctx->playing = mpctx->playlist->current;
|
||||
if (!mpctx->playing || !mpctx->playing->filename)
|
||||
goto terminate_playback;
|
||||
|
27
player/osd.c
27
player/osd.c
@ -57,14 +57,6 @@ 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);
|
||||
@ -207,13 +199,9 @@ static void term_osd_print_status_lazy(struct MPContext *mpctx)
|
||||
saddf(&line, ": ");
|
||||
|
||||
// Playback position
|
||||
sadd_hhmmssff_u(&line, get_playback_time(mpctx), mpctx->opts->osd_fractions);
|
||||
|
||||
double len = get_time_length(mpctx);
|
||||
if (len >= 0) {
|
||||
saddf(&line, " / ");
|
||||
sadd_hhmmssff(&line, len, mpctx->opts->osd_fractions);
|
||||
}
|
||||
sadd_hhmmssff(&line, get_playback_time(mpctx), mpctx->opts->osd_fractions);
|
||||
saddf(&line, " / ");
|
||||
sadd_hhmmssff(&line, get_time_length(mpctx), mpctx->opts->osd_fractions);
|
||||
|
||||
sadd_percentage(&line, get_percent_pos(mpctx));
|
||||
|
||||
@ -442,15 +430,12 @@ static void sadd_osd_status(char **buffer, struct MPContext *mpctx, int level)
|
||||
*buffer = talloc_strdup_append(*buffer, text);
|
||||
talloc_free(text);
|
||||
} else {
|
||||
sadd_hhmmssff_u(buffer, get_playback_time(mpctx), fractions);
|
||||
sadd_hhmmssff(buffer, get_playback_time(mpctx), fractions);
|
||||
#if HAVE_GPL
|
||||
// Potentially GPL due to 8d190244d21a4d40bb9e8f7d51aa09ca1888de09.
|
||||
if (level == 3) {
|
||||
double len = get_time_length(mpctx);
|
||||
if (len >= 0) {
|
||||
saddf(buffer, " / ");
|
||||
sadd_hhmmssff(buffer, len, fractions);
|
||||
}
|
||||
saddf(buffer, " / ");
|
||||
sadd_hhmmssff(buffer, get_time_length(mpctx), fractions);
|
||||
sadd_percentage(buffer, get_percent_pos(mpctx));
|
||||
}
|
||||
#endif
|
||||
|
@ -438,11 +438,11 @@ void execute_queued_seek(struct MPContext *mpctx)
|
||||
}
|
||||
}
|
||||
|
||||
// -1 if unknown
|
||||
// NOPTS (i.e. <0) if unknown
|
||||
double get_time_length(struct MPContext *mpctx)
|
||||
{
|
||||
struct demuxer *demuxer = mpctx->demuxer;
|
||||
return demuxer ? demuxer->duration : -1;
|
||||
return demuxer && demuxer->duration >= 0 ? demuxer->duration : MP_NOPTS_VALUE;
|
||||
}
|
||||
|
||||
double get_current_time(struct MPContext *mpctx)
|
||||
|
Loading…
Reference in New Issue
Block a user