From da2167088018e01c5e15cb1eda6ea370236e6a96 Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 29 Dec 2014 22:08:22 +0100 Subject: player: make --shuffle/--merge-files affect runtime loaded playlists Until now, these options took effect only at program start. This could be confusing when e.g. doing "mpv list.m3u --shuffle". Make them always take effect when a playlist is loaded either via a playlist file, or with the "loadlist" command. --- DOCS/man/options.rst | 4 ---- player/command.c | 10 +++++----- player/core.h | 1 + player/loadfile.c | 20 +++++++++++++++++++- player/main.c | 10 +--------- 5 files changed, 26 insertions(+), 19 deletions(-) diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst index 331d439e7c..adb8128abe 100644 --- a/DOCS/man/options.rst +++ b/DOCS/man/options.rst @@ -360,10 +360,6 @@ Program Behavior file. This uses timeline/EDL support internally. Note that this won't work for ordered chapter files. - This option is interpreted at program start, and doesn't affect for - example files or playlists loaded with the ``loadfile`` or ``loadlist`` - commands. - ``--no-resume-playback`` Do not restore playback position from the ``watch_later`` configuration subdirectory (usually ``~/.config/mpv/watch_later/``). diff --git a/player/command.c b/player/command.c index 63d524ada6..b44d218f52 100644 --- a/player/command.c +++ b/player/command.c @@ -4259,16 +4259,16 @@ int run_command(MPContext *mpctx, mp_cmd_t *cmd) bool append = cmd->args[1].v.i; struct playlist *pl = playlist_parse_file(filename, mpctx->global); if (pl) { + prepare_playlist(mpctx, pl); + struct playlist_entry *new = pl->current; if (!append) playlist_clear(mpctx->playlist); playlist_append_entries(mpctx->playlist, pl); talloc_free(pl); - if (!append && mpctx->playlist->first) { - struct playlist_entry *e = - mp_check_playlist_resume(mpctx, mpctx->playlist); - mp_set_playlist_entry(mpctx, e ? e : mpctx->playlist->first); - } + if (!append && mpctx->playlist->first) + mp_set_playlist_entry(mpctx, new ? new : mpctx->playlist->first); + mp_notify_property(mpctx, "playlist"); } else { MP_ERR(mpctx, "Unable to load playlist %s.\n", filename); diff --git a/player/core.h b/player/core.h index d3fc4195e2..4b45d32e36 100644 --- a/player/core.h +++ b/player/core.h @@ -390,6 +390,7 @@ void mp_set_playlist_entry(struct MPContext *mpctx, struct playlist_entry *e); void mp_play_files(struct MPContext *mpctx); void update_demuxer_properties(struct MPContext *mpctx); void reselect_demux_streams(struct MPContext *mpctx); +void prepare_playlist(struct MPContext *mpctx, struct playlist *pl); // main.c int mpv_main(int argc, char *argv[]); diff --git a/player/loadfile.c b/player/loadfile.c index c19f1d651f..682529feea 100644 --- a/player/loadfile.c +++ b/player/loadfile.c @@ -721,12 +721,30 @@ struct track *mp_add_subtitles(struct MPContext *mpctx, char *filename) STREAM_SUB); } +// Do stuff to a newly loaded playlist. This includes any processing that may +// be required after loading a playlist. +void prepare_playlist(struct MPContext *mpctx, struct playlist *pl) +{ + struct MPOpts *opts = mpctx->opts; + + if (opts->shuffle) + playlist_shuffle(pl); + + if (opts->merge_files) + merge_playlist_files(pl); + + pl->current = mp_check_playlist_resume(mpctx, pl); + if (!pl->current) + pl->current = pl->first; +} + // Replace the current playlist entry with playlist contents. Moves the entries // from the given playlist pl, so the entries don't actually need to be copied. static void transfer_playlist(struct MPContext *mpctx, struct playlist *pl) { if (pl->first) { - struct playlist_entry *new = mp_check_playlist_resume(mpctx, pl); + prepare_playlist(mpctx, pl); + struct playlist_entry *new = pl->current; playlist_transfer_entries(mpctx->playlist, pl); // current entry is replaced if (mpctx->playlist->current) diff --git a/player/main.c b/player/main.c index 6e8755cad7..d3be73c3db 100644 --- a/player/main.c +++ b/player/main.c @@ -457,15 +457,7 @@ int mp_initialize(struct MPContext *mpctx) mpctx->ipc_ctx = mp_init_ipc(mpctx->clients, mpctx->global); #endif - if (opts->shuffle) - playlist_shuffle(mpctx->playlist); - - if (opts->merge_files) - merge_playlist_files(mpctx->playlist); - - mpctx->playlist->current = mp_check_playlist_resume(mpctx, mpctx->playlist); - if (!mpctx->playlist->current) - mpctx->playlist->current = mpctx->playlist->first; + prepare_playlist(mpctx, mpctx->playlist); MP_STATS(mpctx, "end init"); -- cgit v1.2.3