mirror of https://github.com/mpv-player/mpv
player: handle chapter range like --start/--end
Instead of comparing the current chapter every time, set the playback end timestamp to the chapter end. Likewise, don't execute an extra seek for the start chapter. Maybe we could also use the timeline facility to restrict playback to the given chapter range, but this would be strange when using --chapter=N to start playback at a given chapter. Then you couldn't seek back, which is possibly not what the user wants.
This commit is contained in:
parent
c19c777061
commit
6c2cd08aff
|
@ -1335,17 +1335,17 @@ goto_reopen_demuxer: ;
|
||||||
if (startpos == -1 && mpctx->resolve_result &&
|
if (startpos == -1 && mpctx->resolve_result &&
|
||||||
mpctx->resolve_result->start_time > 0)
|
mpctx->resolve_result->start_time > 0)
|
||||||
startpos = mpctx->resolve_result->start_time;
|
startpos = mpctx->resolve_result->start_time;
|
||||||
|
if (startpos == -1 && opts->chapterrange[0] > 0) {
|
||||||
|
double start = chapter_start_time(mpctx, opts->chapterrange[0] - 1);
|
||||||
|
if (start != MP_NOPTS_VALUE)
|
||||||
|
startpos = start;
|
||||||
|
}
|
||||||
if (startpos == -1 && mpctx->timeline)
|
if (startpos == -1 && mpctx->timeline)
|
||||||
startpos = 0;
|
startpos = 0;
|
||||||
if (startpos != -1) {
|
if (startpos != -1) {
|
||||||
queue_seek(mpctx, MPSEEK_ABSOLUTE, startpos, 0, true);
|
queue_seek(mpctx, MPSEEK_ABSOLUTE, startpos, 0, true);
|
||||||
execute_queued_seek(mpctx);
|
execute_queued_seek(mpctx);
|
||||||
}
|
}
|
||||||
if (opts->chapterrange[0] > 0) {
|
|
||||||
if (mp_seek_chapter(mpctx, opts->chapterrange[0] - 1))
|
|
||||||
execute_queued_seek(mpctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
get_relative_time(mpctx); // reset current delta
|
get_relative_time(mpctx); // reset current delta
|
||||||
|
|
||||||
if (mpctx->opts->pause)
|
if (mpctx->opts->pause)
|
||||||
|
|
|
@ -947,9 +947,9 @@ void run_playloop(struct MPContext *mpctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts->chapterrange[1] > 0) {
|
if (opts->chapterrange[1] > 0) {
|
||||||
int cur_chapter = get_current_chapter(mpctx);
|
double end = chapter_start_time(mpctx, opts->chapterrange[1]);
|
||||||
if (cur_chapter != -1 && cur_chapter + 1 > opts->chapterrange[1])
|
if (end != MP_NOPTS_VALUE && (endpts == MP_NOPTS_VALUE || end < endpts))
|
||||||
mpctx->stop_play = PT_NEXT_ENTRY;
|
endpts = end;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mpctx->d_audio && !mpctx->restart_playback && !ao_untimed(mpctx->ao)) {
|
if (mpctx->d_audio && !mpctx->restart_playback && !ao_untimed(mpctx->ao)) {
|
||||||
|
|
Loading…
Reference in New Issue