mirror of
https://github.com/p-stream/p-stream.git
synced 2026-05-16 14:22:08 +00:00
Revert "wait untill subtitles are loaded before picking one for reenabling"
This reverts commit 8d8d4659db.
This commit is contained in:
parent
c7e5749384
commit
88faf5bba9
2 changed files with 7 additions and 51 deletions
|
|
@ -24,9 +24,6 @@ export function useCaptions() {
|
||||||
const setIsOpenSubtitles = useSubtitleStore((s) => s.setIsOpenSubtitles);
|
const setIsOpenSubtitles = useSubtitleStore((s) => s.setIsOpenSubtitles);
|
||||||
|
|
||||||
const captionList = usePlayerStore((s) => s.captionList);
|
const captionList = usePlayerStore((s) => s.captionList);
|
||||||
const isLoadingExternalSubtitles = usePlayerStore(
|
|
||||||
(s) => s.isLoadingExternalSubtitles,
|
|
||||||
);
|
|
||||||
const getHlsCaptionList = usePlayerStore((s) => s.display?.getCaptionList);
|
const getHlsCaptionList = usePlayerStore((s) => s.display?.getCaptionList);
|
||||||
const source = usePlayerStore((s) => s.source);
|
const source = usePlayerStore((s) => s.source);
|
||||||
const selectedCaption = usePlayerStore((s) => s.caption.selected);
|
const selectedCaption = usePlayerStore((s) => s.caption.selected);
|
||||||
|
|
@ -188,9 +185,6 @@ export function useCaptions() {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!selectedCaption) return;
|
if (!selectedCaption) return;
|
||||||
|
|
||||||
// Don't clear while external subtitles are still loading - the caption might appear
|
|
||||||
if (isLoadingExternalSubtitles) return;
|
|
||||||
|
|
||||||
// Skip validation for custom/pasted captions that aren't in the caption list
|
// Skip validation for custom/pasted captions that aren't in the caption list
|
||||||
const isCustomCaption =
|
const isCustomCaption =
|
||||||
selectedCaption.id === "custom-caption" ||
|
selectedCaption.id === "custom-caption" ||
|
||||||
|
|
@ -232,7 +226,6 @@ export function useCaptions() {
|
||||||
setCaption,
|
setCaption,
|
||||||
selectCaptionById,
|
selectCaptionById,
|
||||||
currentTranslateTask,
|
currentTranslateTask,
|
||||||
isLoadingExternalSubtitles,
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
import { useCallback, useEffect, useMemo, useRef } from "react";
|
||||||
|
|
||||||
import { usePlayerStore } from "@/stores/player/store";
|
import { usePlayerStore } from "@/stores/player/store";
|
||||||
import { useSubtitleStore } from "@/stores/subtitles";
|
|
||||||
import { useVolumeStore } from "@/stores/volume";
|
import { useVolumeStore } from "@/stores/volume";
|
||||||
|
|
||||||
import { useCaptions } from "./useCaptions";
|
import { useCaptions } from "./useCaptions";
|
||||||
|
|
@ -25,51 +24,15 @@ export function useInitializeSource() {
|
||||||
() => (source ? JSON.stringify(source) : null),
|
() => (source ? JSON.stringify(source) : null),
|
||||||
[source],
|
[source],
|
||||||
);
|
);
|
||||||
const captionList = usePlayerStore((s) => s.captionList);
|
|
||||||
const isLoadingExternalSubtitles = usePlayerStore(
|
|
||||||
(s) => s.isLoadingExternalSubtitles,
|
|
||||||
);
|
|
||||||
const getHlsCaptionList = usePlayerStore((s) => s.display?.getCaptionList);
|
|
||||||
const enabled = useSubtitleStore((s) => s.enabled);
|
|
||||||
const { selectLastUsedLanguageIfEnabled } = useCaptions();
|
const { selectLastUsedLanguageIfEnabled } = useCaptions();
|
||||||
|
|
||||||
// Trigger re-run when HLS tracks may have loaded (they load after manifest)
|
// Only select subtitles on initial load, not when source changes
|
||||||
const [hlsRetryTrigger, setHlsRetryTrigger] = useState(0);
|
const hasInitializedRef = useRef(false);
|
||||||
const hasRetriedForSourceRef = useRef<string | null>(null);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!sourceIdentifier || !enabled) return;
|
if (sourceIdentifier && !hasInitializedRef.current) {
|
||||||
|
hasInitializedRef.current = true;
|
||||||
// Wait for external subtitles to finish loading before selecting
|
selectLastUsedLanguageIfEnabled();
|
||||||
// This ensures we have the full caption list (provider + external) before picking
|
|
||||||
if (isLoadingExternalSubtitles) return;
|
|
||||||
|
|
||||||
const captions =
|
|
||||||
captionList.length > 0 ? captionList : (getHlsCaptionList?.() ?? []);
|
|
||||||
if (captions.length === 0) {
|
|
||||||
// For HLS sources, tracks may load after manifest - retry once per source
|
|
||||||
const alreadyRetried =
|
|
||||||
hasRetriedForSourceRef.current === sourceIdentifier;
|
|
||||||
if (source?.type === "hls" && !alreadyRetried) {
|
|
||||||
hasRetriedForSourceRef.current = sourceIdentifier;
|
|
||||||
const retryTimer = setTimeout(
|
|
||||||
() => setHlsRetryTrigger((n) => n + 1),
|
|
||||||
2000,
|
|
||||||
);
|
|
||||||
return () => clearTimeout(retryTimer);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
}, [sourceIdentifier, selectLastUsedLanguageIfEnabled]);
|
||||||
selectLastUsedLanguageIfEnabled();
|
|
||||||
}, [
|
|
||||||
sourceIdentifier,
|
|
||||||
source?.type,
|
|
||||||
enabled,
|
|
||||||
isLoadingExternalSubtitles,
|
|
||||||
captionList,
|
|
||||||
getHlsCaptionList,
|
|
||||||
selectLastUsedLanguageIfEnabled,
|
|
||||||
hlsRetryTrigger,
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue