History

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.

Guido Cella committed 2 years ago

Commit f411f311 parent 397212a6 files · +30 −5Browse files

Unified · Split

6 files
  1. DOCS/interface-changes/loop.txt +2 −0
  2. DOCS/man/input.rst +6 −0
  3. player/command.c +13 −1
  4. player/core.h +2 −0
  5. player/loadfile.c +3 −0
  6. player/playloop.c +4 −4
DOCS/interface-changes/loop.txt+2−0
@@ -0,0 +1,2 @@
1+numerical values of `--loop-file` no longer decrease on each iteration
2+add `remaining-file-loops` property as a replacement to get the remaining loop count
DOCS/man/input.rst+6−0
@@ -2142,6 +2142,12 @@ Property list · 2141 unmodified lines
21422142 ``playback-time/full``
21432143 ``playback-time`` with milliseconds.
21442144
2145+``remaining-file-loops``
2146+ How many more times the current file is going to be looped. This is
2147+ initialized from the value of ``--loop-file``. This counts the number of
2148+ times it causes the player to seek to the beginning of the file, so it is 0
2149+ the last the time is played. -1 corresponds to infinity.
2150+
21452151 ``chapter`` (RW)
21462152 Current chapter number. The number of the first chapter is 0.
21472153
player/command.c+13−1
@@ -869,6 +869,13 @@ static int mp_property_playtime_remaining(void *ctx, struct m_property *prop, · 868 unmodified lines
869869 return property_time(action, arg, remaining / speed);
870870 }
871871
872+static int mp_property_remaining_file_loops(void *ctx, struct m_property *prop,
873+ int action, void *arg)
874+{
875+ MPContext *mpctx = ctx;
876+ return m_property_int_ro(action, arg, mpctx->remaining_file_loops);
877+}
878+
872879 /// Current chapter (RW)
873880 static int mp_property_chapter(void *ctx, struct m_property *prop,
874881 int action, void *arg)
@@ -3999,7 +4006,7 @@ static const struct m_property mp_properties_base[] = { · 3124 unmodified lines
39994006 {"audio-pts", mp_property_audio_pts},
40004007 {"playtime-remaining", mp_property_playtime_remaining},
40014008 M_PROPERTY_ALIAS("playback-time", "time-pos"),
4002− {"chapter", mp_property_chapter},
4009+ {"remaining-file-loops", mp_property_remaining_file_loops},
40034010 {"edition", mp_property_edition},
40044011 {"current-edition", mp_property_current_edition},
40054012 {"chapters", mp_property_chapters},
@@ -7484,6 +7491,11 @@ void mp_option_change_callback(void *ctx, struct m_config_option *co, int flags, · 3478 unmodified lines
74847491 mpctx->stop_play = PT_CURRENT_ENTRY;
74857492 }
74867493
7494+ if (opt_ptr == &opts->loop_file) {
7495+ mpctx->remaining_file_loops = opts->loop_file;
7496+ mp_notify_property(mpctx, "remaining-file-loops");
7497+ }
7498+
74877499 if (opt_ptr == &opts->ab_loop[0] || opt_ptr == &opts->ab_loop[1]) {
74887500 update_ab_loop_clip(mpctx);
74897501 // Update if visible
player/core.h+2−0
@@ -421,6 +421,8 @@ typedef struct MPContext { · 420 unmodified lines
421421 int max_frames;
422422 bool playing_msg_shown;
423423
424+ int remaining_file_loops;
425+
424426 bool paused_for_cache;
425427 bool demux_underrun;
426428 double cache_stop_time;
player/loadfile.c+3−0
@@ -1633,6 +1633,9 @@ static void play_current_file(struct MPContext *mpctx) · 1632 unmodified lines
16331633 load_per_file_options(mpctx->mconfig, mpctx->playing->params,
16341634 mpctx->playing->num_params);
16351635
1636+ mpctx->remaining_file_loops = mpctx->opts->loop_file;
1637+ mp_notify_property(mpctx, "remaining-file-loops");
1638+
16361639 mpctx->max_frames = opts->play_frames;
16371640
16381641 handle_force_window(mpctx, false);
player/playloop.c+4−4
@@ -901,10 +901,10 @@ static void handle_loop_file(struct MPContext *mpctx) · 900 unmodified lines
901901 }
902902 target = ab[0];
903903 prec = MPSEEK_EXACT;
904− } else if (opts->loop_file) {
905− if (opts->loop_file > 0) {
906− opts->loop_file--;
907− m_config_notify_change_opt_ptr(mpctx->mconfig, &opts->loop_file);
904+ } else if (mpctx->remaining_file_loops) {
905+ if (mpctx->remaining_file_loops > 0) {
906+ mpctx->remaining_file_loops--;
907+ mp_notify_property(mpctx, "remaining-file-loops");
908908 }
909909 target = get_start_time(mpctx, mpctx->play_dir);
910910 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t