From 7c4962de80986af6d434ec4a8a5bcce55406f26e Mon Sep 17 00:00:00 2001 From: Bill Thornton Date: Wed, 9 Oct 2024 13:23:17 -0400 Subject: [PATCH] Skip skipping if skip is short --- .../playback/utils/mediaSegmentManager.ts | 17 ++++++++++++++--- src/constants/time.ts | 8 ++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 src/constants/time.ts diff --git a/src/apps/stable/features/playback/utils/mediaSegmentManager.ts b/src/apps/stable/features/playback/utils/mediaSegmentManager.ts index 8d245cdd925..68e65dd7aba 100644 --- a/src/apps/stable/features/playback/utils/mediaSegmentManager.ts +++ b/src/apps/stable/features/playback/utils/mediaSegmentManager.ts @@ -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'; @@ -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'); @@ -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; } diff --git a/src/constants/time.ts b/src/constants/time.ts new file mode 100644 index 00000000000..4555b91192b --- /dev/null +++ b/src/constants/time.ts @@ -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;