From 6618e5d69ab2f1eef70769e46f4129d13bd7ff29 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. --- player/command.c | 10 +++++----- player/core.h | 1 + player/loadfile.c | 20 +++++++++++++++++++- player/main.c | 10 +--------- 4 files changed, 26 insertions(+), 15 deletions(-) (limited to 'player') diff --git a/player/command.c b/player/command.c index dbf9167fff..4e5fdc6509 100644 --- a/player/command.c +++ b/player/command.c @@ -4343,16 +4343,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 bb310e0975..8184b133ce 100644 --- a/player/core.h +++ b/player/core.h @@ -395,6 +395,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 624f6beebc..2f75a5bea9 100644 --- a/player/loadfile.c +++ b/player/loadfile.c @@ -737,12 +737,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 700dbfa48f..41a57981e4 100644 --- a/player/main.c +++ b/player/main.c @@ -467,15 +467,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