0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 03:52:22 +02:00

player: add a --loop=force mode

Requested. See manpage additions.

This also makes the magical loop_times constants slightly saner, but
shouldn't change the semantics of any existing --loop option values.

(cherry picked from commit aee0978d50)
This commit is contained in:
wm4 2015-02-12 22:41:45 +01:00 committed by Diogo Franco (Kovensky)
parent 4387919753
commit e4eb9c5469
4 changed files with 17 additions and 13 deletions

View File

@ -107,12 +107,17 @@ Playback Control
If ``--audio-pitch-correction`` is used, playing with a speed higher than
normal automatically inserts the ``scaletempo`` audio filter.
``--loop=<N|inf|no>``
``--loop=<N|inf|force|no>``
Loops playback ``N`` times. A value of ``1`` plays it one time (default),
``2`` two times, etc. ``inf`` means forever. ``no`` is the same as ``1`` and
disables looping. If several files are specified on command line, the
entire playlist is looped.
The ``force`` mode is like ``inf``, but does not skip playlist entries
which have been marked as failing. This means the player might waste CPU
time trying to loop a file that doesn't exist. But it might be useful for
playing webradios under very bad network conditions.
``--pause``
Start the player in paused state.

View File

@ -500,9 +500,10 @@ const m_option_t mp_opts[] = {
OPT_FLAG("stop-playback-on-init-failure", stop_playback_on_init_failure, 0),
OPT_CHOICE_OR_INT("loop", loop_times, M_OPT_GLOBAL, 2, 10000,
({"no", -1}, {"1", -1},
{"inf", 0})),
OPT_CHOICE_OR_INT("loop", loop_times, M_OPT_GLOBAL, 1, 10000,
({"no", 1},
{"inf", -1},
{"force", -2})),
OPT_CHOICE_OR_INT("loop-file", loop_file, M_OPT_OPTIONAL_PARAM, 0, 10000,
({"yes", -1}, {"", -1}, {"no", 0}, // compat
{"inf", -1})),
@ -712,7 +713,7 @@ const struct MPOpts mp_default_opts = {
.lua_ytdl_format = NULL,
#endif
.auto_load_scripts = 1,
.loop_times = -1,
.loop_times = 1,
.ordered_chapters = 1,
.chapter_merge_threshold = 100,
.chapter_seek_threshold = 5.0,

View File

@ -1317,26 +1317,24 @@ struct playlist_entry *mp_next_file(struct MPContext *mpctx, int direction,
while (next && next->playback_short)
next = next->prev;
// Always allow jumping to first file
if (!next && mpctx->opts->loop_times < 0)
if (!next && mpctx->opts->loop_times == 1)
next = mpctx->playlist->first;
}
if (!next && mpctx->opts->loop_times >= 0) {
if (!next && mpctx->opts->loop_times != 1) {
if (direction > 0) {
if (mpctx->opts->shuffle)
playlist_shuffle(mpctx->playlist);
next = mpctx->playlist->first;
if (next && mpctx->opts->loop_times > 1) {
if (next && mpctx->opts->loop_times > 1)
mpctx->opts->loop_times--;
if (mpctx->opts->loop_times == 1)
mpctx->opts->loop_times = -1;
}
} else {
next = mpctx->playlist->last;
// Don't jump to files that would immediately go to next file anyway
while (next && next->playback_short)
next = next->prev;
}
if (!force && next && next->init_failed) {
bool ignore_failures = mpctx->opts->loop_times == -2;
if (!force && next && next->init_failed && !ignore_failures) {
// Don't endless loop if no file in playlist is playable
bool all_failed = true;
struct playlist_entry *cur;

View File

@ -813,7 +813,7 @@ static void handle_keep_open(struct MPContext *mpctx)
struct MPOpts *opts = mpctx->opts;
if (opts->keep_open && mpctx->stop_play == AT_END_OF_FILE &&
(opts->keep_open == 2 || !playlist_get_next(mpctx->playlist, 1)) &&
opts->loop_times < 0)
opts->loop_times == 1)
{
mpctx->stop_play = KEEP_PLAYING;
if (mpctx->d_video) {