1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-26 17:12:36 +00:00

command: allow seek to "chapter -1"

This will seek to the start of the file regardless of whether the first real
chapter starts there or not.
This commit is contained in:
Philip Sequeira 2013-08-15 15:49:06 -04:00 committed by wm4
parent ab81af477c
commit 8cebec6262
2 changed files with 8 additions and 3 deletions

View File

@ -1721,7 +1721,7 @@ static const m_option_t mp_properties[] = {
M_OPT_MIN, 0, 0, NULL }, M_OPT_MIN, 0, 0, NULL },
{ "time-remaining", mp_property_remaining, CONF_TYPE_TIME }, { "time-remaining", mp_property_remaining, CONF_TYPE_TIME },
{ "chapter", mp_property_chapter, CONF_TYPE_INT, { "chapter", mp_property_chapter, CONF_TYPE_INT,
M_OPT_MIN, 0, 0, NULL }, M_OPT_MIN, -1, 0, NULL },
M_OPTION_PROPERTY_CUSTOM("edition", mp_property_edition), M_OPTION_PROPERTY_CUSTOM("edition", mp_property_edition),
M_OPTION_PROPERTY_CUSTOM("quvi-format", mp_property_quvi_format), M_OPTION_PROPERTY_CUSTOM("quvi-format", mp_property_quvi_format),
{ "titles", mp_property_titles, CONF_TYPE_INT, { "titles", mp_property_titles, CONF_TYPE_INT,

View File

@ -3229,6 +3229,8 @@ char *chapter_name(struct MPContext *mpctx, int chapter)
// returns the start of the chapter in seconds (-1 if unavailable) // returns the start of the chapter in seconds (-1 if unavailable)
double chapter_start_time(struct MPContext *mpctx, int chapter) double chapter_start_time(struct MPContext *mpctx, int chapter)
{ {
if (chapter == -1)
return get_start_time(mpctx);
if (mpctx->chapters) if (mpctx->chapters)
return mpctx->chapters[chapter].start; return mpctx->chapters[chapter].start;
if (mpctx->master_demuxer) if (mpctx->master_demuxer)
@ -3252,13 +3254,16 @@ bool mp_seek_chapter(struct MPContext *mpctx, int chapter)
int num = get_chapter_count(mpctx); int num = get_chapter_count(mpctx);
if (num == 0) if (num == 0)
return false; return false;
if (chapter < 0 || chapter >= num) if (chapter < -1 || chapter >= num)
return false; return false;
mpctx->last_chapter_seek = -2; mpctx->last_chapter_seek = -2;
double pts; double pts;
if (mpctx->chapters) { if (chapter == -1) {
pts = get_start_time(mpctx);
goto do_seek;
} else if (mpctx->chapters) {
pts = mpctx->chapters[chapter].start; pts = mpctx->chapters[chapter].start;
goto do_seek; goto do_seek;
} else if (mpctx->master_demuxer) { } else if (mpctx->master_demuxer) {