player: don't decrement --loop-file=N and add remaining-file-loops

This stops decreasing numerical values of --loop-file on each iteration
so that loop-file=N loops every playlist entry without having to add
--loop-file to --reset-on-next-file.

The current behavior confuses users as seen in:

https://github.com/mpv-player/mpv/issues/2481
https://github.com/mpv-player/mpv/issues/5943
https://github.com/mpv-player/mpv/issues/11291
https://github.com/mpv-player/mpv/issues/13860
https://www.reddit.com/r/mpv/comments/rcwnrw/looping_each_file_n_times_in_a_playlist/

Also options are supposed to reflect the value configured by the user
and not change on their own.

A remaining-file-loops property is exposed as a replacement to check how
many loops are left.
This commit is contained in:
Guido Cella 2024-06-04 21:51:03 +02:00 committed by Kacper Michajłow
parent 397212ae15
commit f411f3145b
6 changed files with 30 additions and 5 deletions

View File

@ -0,0 +1,2 @@
numerical values of `--loop-file` no longer decrease on each iteration
add `remaining-file-loops` property as a replacement to get the remaining loop count

View File

@ -2142,6 +2142,12 @@ Property list
``playback-time/full``
``playback-time`` with milliseconds.
``remaining-file-loops``
How many more times the current file is going to be looped. This is
initialized from the value of ``--loop-file``. This counts the number of
times it causes the player to seek to the beginning of the file, so it is 0
the last the time is played. -1 corresponds to infinity.
``chapter`` (RW)
Current chapter number. The number of the first chapter is 0.

View File

@ -869,6 +869,13 @@ static int mp_property_playtime_remaining(void *ctx, struct m_property *prop,
return property_time(action, arg, remaining / speed);
}
static int mp_property_remaining_file_loops(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
return m_property_int_ro(action, arg, mpctx->remaining_file_loops);
}
/// Current chapter (RW)
static int mp_property_chapter(void *ctx, struct m_property *prop,
int action, void *arg)
@ -3999,7 +4006,7 @@ static const struct m_property mp_properties_base[] = {
{"audio-pts", mp_property_audio_pts},
{"playtime-remaining", mp_property_playtime_remaining},
M_PROPERTY_ALIAS("playback-time", "time-pos"),
{"chapter", mp_property_chapter},
{"remaining-file-loops", mp_property_remaining_file_loops},
{"edition", mp_property_edition},
{"current-edition", mp_property_current_edition},
{"chapters", mp_property_chapters},
@ -7484,6 +7491,11 @@ void mp_option_change_callback(void *ctx, struct m_config_option *co, int flags,
mpctx->stop_play = PT_CURRENT_ENTRY;
}
if (opt_ptr == &opts->loop_file) {
mpctx->remaining_file_loops = opts->loop_file;
mp_notify_property(mpctx, "remaining-file-loops");
}
if (opt_ptr == &opts->ab_loop[0] || opt_ptr == &opts->ab_loop[1]) {
update_ab_loop_clip(mpctx);
// Update if visible

View File

@ -421,6 +421,8 @@ typedef struct MPContext {
int max_frames;
bool playing_msg_shown;
int remaining_file_loops;
bool paused_for_cache;
bool demux_underrun;
double cache_stop_time;

View File

@ -1633,6 +1633,9 @@ static void play_current_file(struct MPContext *mpctx)
load_per_file_options(mpctx->mconfig, mpctx->playing->params,
mpctx->playing->num_params);
mpctx->remaining_file_loops = mpctx->opts->loop_file;
mp_notify_property(mpctx, "remaining-file-loops");
mpctx->max_frames = opts->play_frames;
handle_force_window(mpctx, false);

View File

@ -901,10 +901,10 @@ static void handle_loop_file(struct MPContext *mpctx)
}
target = ab[0];
prec = MPSEEK_EXACT;
} else if (opts->loop_file) {
if (opts->loop_file > 0) {
opts->loop_file--;
m_config_notify_change_opt_ptr(mpctx->mconfig, &opts->loop_file);
} else if (mpctx->remaining_file_loops) {
if (mpctx->remaining_file_loops > 0) {
mpctx->remaining_file_loops--;
mp_notify_property(mpctx, "remaining-file-loops");
}
target = get_start_time(mpctx, mpctx->play_dir);
}