Skip to content

Commit

Permalink
Merge pull request #1329 from lkiesow/skip-threshold
Browse files Browse the repository at this point in the history
Dynamic skip threshold
  • Loading branch information
lkiesow authored May 7, 2024
2 parents a03c4d0 + d880cf3 commit d8160de
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/redux/videoSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,18 @@ const videoSlice = createSlice({
jumpToPreviousSegment: state => {
let previousSegmentIndex = state.activeSegmentIndex - 1;

// Jump to start of active segment if current time is in interval [start + 3s, end)
if (state.currentlyAt >= state.segments[state.activeSegmentIndex].start + 3000) {
// Calculate the threshold for “being on a cut mark”.
// It is based on the video length, but in between 0.5s and 3.0s.
const threshold = Math.max(Math.min(state.duration / 100, 3000), 500);

// Jump to start of active segment if current time is in interval [start + threshold, end)
if (state.currentlyAt >= state.segments[state.activeSegmentIndex].start + threshold) {
previousSegmentIndex = state.activeSegmentIndex;
}

// Jump to start of first segment if we are anywhere in the first segment
if (state.activeSegmentIndex == 0) {
// Jump to start of first segment
previousSegmentIndex = state.activeSegmentIndex;
previousSegmentIndex = 0;
}

updateCurrentlyAt(state, state.segments[previousSegmentIndex].start);
Expand Down

0 comments on commit d8160de

Please sign in to comment.