From 8cebec62621cb6e9ed03aab65f5b011393ac588d Mon Sep 17 00:00:00 2001 From: Philip Sequeira Date: Thu, 15 Aug 2013 15:49:06 -0400 Subject: 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. --- mpvcore/command.c | 2 +- mpvcore/mplayer.c | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/mpvcore/command.c b/mpvcore/command.c index d1513bd998..b04c05c9e6 100644 --- a/mpvcore/command.c +++ b/mpvcore/command.c @@ -1721,7 +1721,7 @@ static const m_option_t mp_properties[] = { M_OPT_MIN, 0, 0, NULL }, { "time-remaining", mp_property_remaining, CONF_TYPE_TIME }, { "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("quvi-format", mp_property_quvi_format), { "titles", mp_property_titles, CONF_TYPE_INT, diff --git a/mpvcore/mplayer.c b/mpvcore/mplayer.c index e7c21cc272..88804939c1 100644 --- a/mpvcore/mplayer.c +++ b/mpvcore/mplayer.c @@ -3229,6 +3229,8 @@ char *chapter_name(struct MPContext *mpctx, int chapter) // returns the start of the chapter in seconds (-1 if unavailable) double chapter_start_time(struct MPContext *mpctx, int chapter) { + if (chapter == -1) + return get_start_time(mpctx); if (mpctx->chapters) return mpctx->chapters[chapter].start; if (mpctx->master_demuxer) @@ -3252,13 +3254,16 @@ bool mp_seek_chapter(struct MPContext *mpctx, int chapter) int num = get_chapter_count(mpctx); if (num == 0) return false; - if (chapter < 0 || chapter >= num) + if (chapter < -1 || chapter >= num) return false; mpctx->last_chapter_seek = -2; 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; goto do_seek; } else if (mpctx->master_demuxer) { -- cgit v1.2.3