Skip to content

Commit

Permalink
playloop: use MPMIN when chapter-seeking backwards
Browse files Browse the repository at this point in the history
Also added a check to avoid using chapter index -1 if nothing
comes before the first chapter.
  • Loading branch information
myQwil committed Sep 25, 2023
1 parent 9cd2a9f commit 482ebc7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions player/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -906,8 +906,8 @@ static int mp_property_chapter(void *ctx, struct m_property *prop,
} else // Absolute set
step_all = *(int *)arg - chapter;
chapter += step_all;
if (chapter < -1)
chapter = -1;
if (chapter < 0) // avoid using -1 if first chapter starts at 0
chapter = (chapter_start_time(mpctx, 0) <= 0) ? 0 : -1;
if (chapter >= num && step_all > 0) {
if (mpctx->opts->keep_open) {
seek_to_last_frame(mpctx);
Expand Down
5 changes: 5 additions & 0 deletions player/playloop.c
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,11 @@ int get_current_chapter(struct MPContext *mpctx)
for (i = 0; i < mpctx->num_chapters; i++)
if (current_pts < mpctx->chapters[i].pts)
break;
if (mpctx->last_chapter_pts < current_pts &&
mpctx->last_chapter_seek > -2)
{
return MPMIN(mpctx->last_chapter_seek, i - 1);
}
return MPMAX(mpctx->last_chapter_seek, i - 1);
}

Expand Down

0 comments on commit 482ebc7

Please sign in to comment.