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/loadfile.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'player/loadfile.c') 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) -- cgit v1.2.3