summaryrefslogtreecommitdiffstats
path: root/player
diff options
context:
space:
mode:
authorDavid Vaughan <david@davidv.xyz>2024-02-03 13:44:49 -0800
committerDudemanguy <random342@airmail.cc>2024-02-26 02:03:21 +0000
commit9e162d26046005ca0f58f22a057e1d8393900d50 (patch)
treee4eca589abd63c35cf8f7c84f9e3d546915f2407 /player
parentb71af009dc23edb940aa11f28d261b192f3ea317 (diff)
downloadmpv-9e162d26046005ca0f58f22a057e1d8393900d50.tar.bz2
mpv-9e162d26046005ca0f58f22a057e1d8393900d50.tar.xz
player: add loadfile insert-next commands
This commit adds two new commands (`insert-next` and `insert-next-play`) which mirror the existing commands, `append` and `append-play` in functionality, with the difference that they insert directly after the current playlist entry, rather than at the end of the playlist. This change gives MPV a piece of functionality already found in (for example) Spotify's media player: "play next". Additionally, using the new `insert-next` command, users can trivially write a script to play a new piece of media immediately without otherwise clearing or altering the remainder of the playlist.
Diffstat (limited to 'player')
-rw-r--r--player/command.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/player/command.c b/player/command.c
index 3eecdd3915..3e040bc256 100644
--- a/player/command.c
+++ b/player/command.c
@@ -5527,9 +5527,13 @@ static void cmd_loadfile(void *p)
struct mp_cmd_ctx *cmd = p;
struct MPContext *mpctx = cmd->mpctx;
char *filename = cmd->args[0].v.s;
- int append = cmd->args[1].v.i;
+ int action = cmd->args[1].v.i;
+
+ bool replace = (action == 0);
+ bool insert_next = (action == 3 || action == 4);
+ bool play = (action == 2 || action == 4);
- if (!append)
+ if (replace)
playlist_clear(mpctx->playlist);
struct playlist_entry *entry = playlist_entry_new(filename);
@@ -5538,13 +5542,18 @@ static void cmd_loadfile(void *p)
for (int i = 0; pairs[i] && pairs[i + 1]; i += 2)
playlist_entry_add_param(entry, bstr0(pairs[i]), bstr0(pairs[i + 1]));
}
- playlist_add(mpctx->playlist, entry);
+
+ if (insert_next) {
+ playlist_insert_next(mpctx->playlist, entry, mpctx->playlist->current);
+ } else {
+ playlist_add(mpctx->playlist, entry);
+ }
struct mpv_node *res = &cmd->result;
node_init(res, MPV_FORMAT_NODE_MAP, NULL);
node_map_add_int64(res, "playlist_entry_id", entry->id);
- if (!append || (append == 2 && !mpctx->playlist->current)) {
+ if (replace || (play && !mpctx->playlist->current)) {
if (mpctx->opts->position_save_on_quit) // requested in issue #1148
mp_write_watch_later_conf(mpctx);
mp_set_playlist_entry(mpctx, entry);
@@ -6681,7 +6690,9 @@ const struct mp_cmd_def mp_cmds[] = {
{"flags", OPT_CHOICE(v.i,
{"replace", 0},
{"append", 1},
- {"append-play", 2}),
+ {"append-play", 2},
+ {"insert-next", 3},
+ {"insert-next-play", 4}),
.flags = MP_CMD_OPT_ARG},
{"options", OPT_KEYVALUELIST(v.str_list), .flags = MP_CMD_OPT_ARG},
},