From 602105dbdae5b35dfcd7c060349b42a990bd25a8 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 22 Aug 2015 22:08:17 +0200 Subject: player: add --playlist-pos option Oddly often requested. --- DOCS/interface-changes.rst | 1 + DOCS/man/options.rst | 11 +++++++++++ options/options.c | 3 +++ options/options.h | 1 + player/loadfile.c | 9 ++++++++- 5 files changed, 24 insertions(+), 1 deletion(-) diff --git a/DOCS/interface-changes.rst b/DOCS/interface-changes.rst index e74296c557..9d1390c808 100644 --- a/DOCS/interface-changes.rst +++ b/DOCS/interface-changes.rst @@ -20,6 +20,7 @@ Interface changes :: --- mpv 0.10.0 will be released --- + - add --playlist-pos option - add --video-sync* options "display-sync-active" property "vo-missed-frame-count" property diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst index afa3eb55a8..c8b2460879 100644 --- a/DOCS/man/options.rst +++ b/DOCS/man/options.rst @@ -129,6 +129,17 @@ Playback Control Specify which chapter to start playing at. Optionally specify which chapter to end playing at. Also see ``--start``. +``--playlist-pos=`` + Set which file on the internal playlist to start playback with. The index + is an integer, with 0 meaning the first file. The value ``no`` means that + the selection of the entry to play is left to the playback resume mechanism + (default). If an entry with the given index doesn't exist, the behavior is + unspecified and might change in future mpv versions. The same applies if + the playlist contains further playlists (don't expect any reasonable + behavior). Passing a playlist file to mpv should work with this option, + though. E.g. ``mpv playlist.m3u --playlist-pos=123`` will work as expected, + as long as ``playlist.m3u`` does not link to further playlists. + ``--playlist=`` Play files according to a playlist file (Supports some common formats. If no format is detected, it will be treated as list of files, separated by diff --git a/options/options.c b/options/options.c index c393536af0..2a62ef69c8 100644 --- a/options/options.c +++ b/options/options.c @@ -200,6 +200,8 @@ const m_option_t mp_opts[] = { OPT_TIME("ab-loop-a", ab_loop[0], 0, .min = MP_NOPTS_VALUE), OPT_TIME("ab-loop-b", ab_loop[1], 0, .min = MP_NOPTS_VALUE), + OPT_CHOICE_OR_INT("playlist-pos", playlist_pos, 0, 0, INT_MAX, ({"no", -1})), + OPT_FLAG("pause", pause, M_OPT_FIXED), OPT_CHOICE("keep-open", keep_open, 0, ({"no", 0}, @@ -754,6 +756,7 @@ const struct MPOpts mp_default_opts = { .term_osd = 2, .term_osd_bar_chars = "[-+-]", .consolecontrols = 1, + .playlist_pos = -1, .play_frames = -1, .keep_open = 0, .stream_id = { { [STREAM_AUDIO] = -1, diff --git a/options/options.h b/options/options.h index 1b65b4af4d..b3d6bb18c2 100644 --- a/options/options.h +++ b/options/options.h @@ -167,6 +167,7 @@ typedef struct MPOpts { float heartbeat_interval; int player_idle_mode; int consolecontrols; + int playlist_pos; struct m_rel_time play_start; struct m_rel_time play_end; struct m_rel_time play_length; diff --git a/player/loadfile.c b/player/loadfile.c index 9857d8a1a8..2115c72058 100644 --- a/player/loadfile.c +++ b/player/loadfile.c @@ -804,13 +804,20 @@ void prepare_playlist(struct MPContext *mpctx, struct playlist *pl) { struct MPOpts *opts = mpctx->opts; + pl->current = NULL; + + if (opts->playlist_pos >= 0) + pl->current = playlist_entry_from_index(pl, opts->playlist_pos); + 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 = mp_check_playlist_resume(mpctx, pl); + if (!pl->current) pl->current = pl->first; } -- cgit v1.2.3