Skip to content

Commit

Permalink
Skip skipping if skip is short
Browse files Browse the repository at this point in the history
  • Loading branch information
thornbill committed Oct 9, 2024
1 parent 9aeb64e commit 7c4962d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/apps/stable/features/playback/utils/mediaSegmentManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { MediaSegmentsApi } from '@jellyfin/sdk/lib/generated-client/api/media-s

import type { PlaybackManager } from 'components/playback/playbackmanager';
import ServerConnections from 'components/ServerConnections';
import { TICKS_PER_MILLISECOND, TICKS_PER_SECOND } from 'constants/time';
import { currentSettings as userSettings } from 'scripts/settings/userSettings';
import type { PlayerState } from 'types/playbackStopInfo';
import type { Event } from 'utils/events';
Expand Down Expand Up @@ -44,7 +45,13 @@ class MediaSegmentManager extends PlaybackSubscriber {
if (action === MediaSegmentAction.Skip) {
// Perform skip
if (mediaSegment.EndTicks) {
console.debug('[MediaSegmentManager] skipping to %s ms', mediaSegment.EndTicks / 10000);
// Do not skip if duration < 1s to avoid slow stream changes
if (mediaSegment.StartTicks && mediaSegment.EndTicks - mediaSegment.StartTicks < TICKS_PER_SECOND) {
console.info('[MediaSegmentManager] ignoring skipping segment with duration <1s', mediaSegment);
return;
}

console.debug('[MediaSegmentManager] skipping to %s ms', mediaSegment.EndTicks / TICKS_PER_MILLISECOND);
this.playbackManager.seek(mediaSegment.EndTicks, this.player);
} else {
console.debug('[MediaSegmentManager] skipping to next item in queue');
Expand Down Expand Up @@ -88,10 +95,14 @@ class MediaSegmentManager extends PlaybackSubscriber {

onPlayerTimeUpdate() {
if (this.hasSegments && this.mediaSegments.length) {
const time = this.playbackManager.currentTime(this.player) * 10000;
const time = this.playbackManager.currentTime(this.player) * TICKS_PER_MILLISECOND;
const currentSegmentDetails = findCurrentSegment(this.mediaSegments, time, this.lastIndex);
if (currentSegmentDetails) {
console.debug('[MediaSegmentManager] found %s segment at %s ms', currentSegmentDetails.segment.Type, time / 10000, currentSegmentDetails);
console.debug(
'[MediaSegmentManager] found %s segment at %s ms',
currentSegmentDetails.segment.Type,
time / TICKS_PER_MILLISECOND,
currentSegmentDetails);
this.performAction(currentSegmentDetails.segment);
this.lastIndex = currentSegmentDetails.index;
}
Expand Down
8 changes: 8 additions & 0 deletions src/constants/time.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** The number of ticks per millisecond */
export const TICKS_PER_MILLISECOND = 10_000;

/** The number of ticks per second */
export const TICKS_PER_SECOND = 1_000 * TICKS_PER_MILLISECOND;

/** The number of ticks per minute */
export const TICKS_PER_MINUTE = 60 * TICKS_PER_SECOND;

0 comments on commit 7c4962d

Please sign in to comment.