diff options
-rw-r--r-- | core/command.c | 2 | ||||
-rw-r--r-- | core/mp_core.h | 1 | ||||
-rw-r--r-- | core/mplayer.c | 30 |
3 files changed, 23 insertions, 10 deletions
diff --git a/core/command.c b/core/command.c index bad1543224..8331278148 100644 --- a/core/command.c +++ b/core/command.c @@ -1871,7 +1871,7 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd) int dir = cmd->id == MP_CMD_PLAYLIST_PREV ? -1 : +1; int force = cmd->args[0].v.i; - struct playlist_entry *e = playlist_get_next(mpctx->playlist, dir); + struct playlist_entry *e = mp_next_file(mpctx, dir); if (!e && !force) break; mpctx->playlist->current = e; diff --git a/core/mp_core.h b/core/mp_core.h index 5a7926dee9..dc541ae55d 100644 --- a/core/mp_core.h +++ b/core/mp_core.h @@ -293,6 +293,7 @@ void mp_switch_track(struct MPContext *mpctx, enum stream_type type, struct track *mp_track_by_tid(struct MPContext *mpctx, enum stream_type type, int tid); bool mp_remove_track(struct MPContext *mpctx, struct track *track); +struct playlist_entry *mp_next_file(struct MPContext *mpctx, int direction); // timeline/tl_matroska.c void build_ordered_chapter_timeline(struct MPContext *mpctx); diff --git a/core/mplayer.c b/core/mplayer.c index 51eef24d20..a7761b4da5 100644 --- a/core/mplayer.c +++ b/core/mplayer.c @@ -4191,6 +4191,26 @@ terminate_playback: // don't jump here after ao/vo/getch initialization! #endif } +// Determine the next file to play. Note that if this function returns non-NULL, +// it can have side-effects and mutate mpctx. +struct playlist_entry *mp_next_file(struct MPContext *mpctx, int direction) +{ + struct playlist_entry *next = playlist_get_next(mpctx->playlist, direction); + if (!next && mpctx->opts.loop_times >= 0) { + if (direction > 0) { + next = mpctx->playlist->first; + if (next && mpctx->opts.loop_times > 0) { + mpctx->opts.loop_times--; + if (mpctx->opts.loop_times == 0) + mpctx->opts.loop_times = -1; + } + } else { + next = mpctx->playlist->last; + } + } + return next; +} + // Play all entries on the playlist, starting from the current entry. // Return if all done. static void play_files(struct MPContext *mpctx) @@ -4210,15 +4230,7 @@ static void play_files(struct MPContext *mpctx) struct playlist_entry *new_entry = NULL; if (mpctx->stop_play == PT_NEXT_ENTRY) { - new_entry = playlist_get_next(mpctx->playlist, +1); - if (!new_entry && mpctx->opts.loop_times >= 0) { - new_entry = mpctx->playlist->first; - if (mpctx->opts.loop_times > 0) { - mpctx->opts.loop_times--; - if (mpctx->opts.loop_times == 0) - mpctx->opts.loop_times = -1; - } - } + new_entry = mp_next_file(mpctx, +1); } else if (mpctx->stop_play == PT_CURRENT_ENTRY) { new_entry = mpctx->playlist->current; } else if (mpctx->stop_play == PT_RESTART) { |