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:
wm4 2014-03-25 02:27:22 +01:00
parent c19c777061
commit 6c2cd08aff
2 changed files with 8 additions and 8 deletions

View File

@ -1335,17 +1335,17 @@ goto_reopen_demuxer: ;
if (startpos == -1 && mpctx->resolve_result &&
mpctx->resolve_result->start_time > 0)
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)
startpos = 0;
if (startpos != -1) {
queue_seek(mpctx, MPSEEK_ABSOLUTE, startpos, 0, true);
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
if (mpctx->opts->pause)

View File

@ -947,9 +947,9 @@ void run_playloop(struct MPContext *mpctx)
}
if (opts->chapterrange[1] > 0) {
int cur_chapter = get_current_chapter(mpctx);
if (cur_chapter != -1 && cur_chapter + 1 > opts->chapterrange[1])
mpctx->stop_play = PT_NEXT_ENTRY;
double end = chapter_start_time(mpctx, opts->chapterrange[1]);
if (end != MP_NOPTS_VALUE && (endpts == MP_NOPTS_VALUE || end < endpts))
endpts = end;
}
if (mpctx->d_audio && !mpctx->restart_playback && !ao_untimed(mpctx->ao)) {