fix(segments): backport segment-skip fixes from chromecast refactor

Reconcile segment-skip with the diverged-but-ahead version on the
chromecast refactor branch:
- useSegmentSkipper: track auto-skip by segment identity instead of a
  bool, so it no longer re-triggers on pause/unpause; guard skipMode
  "none"; use a finite totalDuration check for Outro.
- Controls: playingRef avoids a stale-closure resume after a seek; only
  resume playback if it was actually playing; skipCredit noop fallback.
- segments: drop the dead try/catch around Promise.allSettled.
- Remove the obsolete useIntroSkipper / useCreditSkipper hooks (177 dead
  lines, superseded by useSegmentSkipper).
This commit is contained in:
Uruk
2026-05-22 01:44:03 +02:00
parent 63ed386369
commit 0990e479d2
5 changed files with 50 additions and 217 deletions

View File

@@ -124,6 +124,12 @@ export const Controls: FC<Props> = ({
// Ref to track pending play timeout for cleanup and cancellation
const playTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
// Mutable ref tracking isPlaying to avoid stale closures in seekMs timeout
const playingRef = useRef(isPlaying);
useEffect(() => {
playingRef.current = isPlaying;
}, [isPlaying]);
// Clean up timeout on unmount
useEffect(() => {
return () => {
@@ -346,8 +352,11 @@ export const Controls: FC<Props> = ({
seek(timeInSeconds * 1000);
// Brief delay ensures the seek operation completes before resuming playback
// Without this, playback may resume from the old position
// Read latest isPlaying from ref to avoid stale closure
playTimeoutRef.current = setTimeout(() => {
play();
if (playingRef.current) {
play();
}
playTimeoutRef.current = null;
}, 200);
},
@@ -427,7 +436,7 @@ export const Controls: FC<Props> = ({
);
const skipIntro = activeSegment?.skipSegment || noop;
const showSkipCreditButton = activeSegment?.type === "Outro";
const skipCredit = outroSkipper.skipSegment;
const skipCredit = outroSkipper.skipSegment || noop;
const hasContentAfterCredits =
outroSkipper.currentSegment && maxSeconds
? outroSkipper.currentSegment.endTime < maxSeconds