diff --git a/DOCS/interface-changes/preserve-options.txt b/DOCS/interface-changes/preserve-options.txt new file mode 100644 index 0000000000..489f9f3766 --- /dev/null +++ b/DOCS/interface-changes/preserve-options.txt @@ -0,0 +1 @@ +add `preserve-options` flag to `playlist-play-index` diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst index be190cb78c..512e426da9 100644 --- a/DOCS/man/input.rst +++ b/DOCS/man/input.rst @@ -517,7 +517,7 @@ Playlist Manipulation Go to the first of the previous entries on the playlist with a different ``playlist-path``. -``playlist-play-index `` +``playlist-play-index [preserve-options]``] Start (or restart) playback of the given playlist index. In addition to the 0-based playlist entry index, it supports the following values: @@ -531,6 +531,9 @@ Playlist Manipulation Playback is stopped. If idle mode (``--idle``) is enabled, the player will enter idle mode, otherwise it will exit. + Setting ``preserve-options`` (``MPV_FORMAT_FLAG``) will not reset file-local + options when the playback of the current playlist index is restarted. + This command is similar to ``loadfile`` in that it only manipulates the state of what to play next, without waiting until the current file is unloaded, and the next one is loaded. diff --git a/common/playlist.h b/common/playlist.h index 7edb782edc..4b33958a51 100644 --- a/common/playlist.h +++ b/common/playlist.h @@ -53,6 +53,9 @@ struct playlist_entry { bool init_failed : 1; // Entry was removed with playlist_remove (etc.), but not deallocated. bool removed : 1; + // Playback of the entry is restarting without resetting + // file-local options. + bool reloading : 1; // Additional refcount. Normally (reserved==0), the entry is owned by the // playlist, and this can be used to keep the entry alive. int reserved; diff --git a/player/command.c b/player/command.c index b476047be1..13b8424688 100644 --- a/player/command.c +++ b/player/command.c @@ -5987,10 +5987,14 @@ static void cmd_playlist_play_index(void *p) struct MPContext *mpctx = cmd->mpctx; struct playlist *pl = mpctx->playlist; int pos = cmd->args[0].v.i; + bool preserve_options = cmd->num_args >= 2 && cmd->args[1].v.b; if (pos == -2) pos = playlist_entry_to_index(pl, pl->current); + if (preserve_options && pl->current && pos == pl->current->pl_index) + pl->current->reloading = true; + mp_set_playlist_entry(mpctx, playlist_entry_from_index(pl, pos)); if (cmd->on_osd & MP_ON_OSD_MSG) mpctx->add_osd_seek_info |= OSD_SEEK_INFO_CURRENT_FILE; @@ -7256,6 +7260,7 @@ const struct mp_cmd_def mp_cmds[] = { { {"index", OPT_CHOICE(v.i, {"current", -2}, {"none", -1}), M_RANGE(-1, INT_MAX)}, + {"preserve-options", OPT_BOOL(v.b), .flags = MP_CMD_OPT_ARG}, } }, { "playlist-shuffle", cmd_playlist_shuffle, }, diff --git a/player/loadfile.c b/player/loadfile.c index 2dac2c0019..f5079301ee 100644 --- a/player/loadfile.c +++ b/player/loadfile.c @@ -1985,7 +1985,13 @@ terminate_playback: // Possibly stop ongoing async commands. mp_abort_playback_async(mpctx); - m_config_restore_backups(mpctx->mconfig); + struct playlist_entry *current = mpctx->playlist->current; + bool reloading = mpctx->stop_play == PT_CURRENT_ENTRY && + current && current->reloading; + if (current) + current->reloading = false; + if (!reloading) + m_config_restore_backups(mpctx->mconfig); TA_FREEP(&mpctx->filter_root); talloc_free(mpctx->filtered_tags);