summaryrefslogtreecommitdiffstats
path: root/mpvcore/command.c
diff options
context:
space:
mode:
authorPhilip Sequeira <phsequei@gmail.com>2013-08-13 21:25:50 -0400
committerwm4 <wm4@nowhere>2013-08-17 21:32:52 +0200
commitb018c7d936879dc2ea1bd49b78157a70f9353430 (patch)
tree53221ab06169baa10c007cb46f1c7ee64cb90f5e /mpvcore/command.c
parent8cebec62621cb6e9ed03aab65f5b011393ac588d (diff)
downloadmpv-b018c7d936879dc2ea1bd49b78157a70f9353430.tar.bz2
mpv-b018c7d936879dc2ea1bd49b78157a70f9353430.tar.xz
command: more intuitive chapter seek behavior
If close to chapter start, skipping back goes to previous chapter (no change). If more than <threshold> seconds in, skipping back will now go to the beginning of the current chapter instead. The threshold is set by the new option --chapter-seek-threshold and defaults to 5 seconds. A negative value disables the new functionality.
Diffstat (limited to 'mpvcore/command.c')
-rw-r--r--mpvcore/command.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/mpvcore/command.c b/mpvcore/command.c
index b04c05c9e6..b7aa9dfe6a 100644
--- a/mpvcore/command.c
+++ b/mpvcore/command.c
@@ -390,9 +390,30 @@ static int mp_property_chapter(m_option_t *prop, int action, void *arg,
*(char **) arg = chapter_name;
return M_PROPERTY_OK;
}
+ case M_PROPERTY_SWITCH:
case M_PROPERTY_SET: ;
- int step_all = *(int *)arg - chapter;
+ int step_all;
+ if (action == M_PROPERTY_SWITCH) {
+ struct m_property_switch_arg *sarg = arg;
+ step_all = ROUND(sarg->inc);
+ // Check threshold for relative backward seeks
+ if (mpctx->opts->chapter_seek_threshold >= 0 && step_all < 0) {
+ if (chapter < -1)
+ return M_PROPERTY_UNAVAILABLE;
+ double current_chapter_start =
+ chapter_start_time(mpctx, chapter);
+ // If we are far enough into a chapter, seek back to the
+ // beginning of current chapter instead of previous one
+ if (current_chapter_start >= 0 &&
+ get_current_time(mpctx) - current_chapter_start >
+ mpctx->opts->chapter_seek_threshold)
+ step_all++;
+ }
+ } else // Absolute set
+ step_all = *(int *)arg - chapter;
chapter += step_all;
+ if (chapter < -1)
+ chapter = -1;
if (chapter >= get_chapter_count(mpctx) && step_all > 0) {
mpctx->stop_play = PT_NEXT_ENTRY;
} else {