mirror of
https://github.com/mpv-player/mpv.git
synced 2026-10-28 23:13:18 +08:00
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.
This commit is contained in:
committed by
Diogo Franco (Kovensky)
parent
2cac69f221
commit
da21670880
@@ -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/``).
|
||||
|
||||
+5
-5
@@ -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);
|
||||
|
||||
@@ -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[]);
|
||||
|
||||
+19
-1
@@ -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)
|
||||
|
||||
+1
-9
@@ -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");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user