mirror of
https://github.com/movie-web/movie-web.git
synced 2025-01-13 13:39:07 +01:00
Re-add auto captions
Co-authored-by: mrjvs <mistrjvs@gmail.com>
This commit is contained in:
parent
6862255de9
commit
179bdb07dd
@ -46,10 +46,15 @@ export function useCaptions() {
|
|||||||
else await selectLastUsedLanguage();
|
else await selectLastUsedLanguage();
|
||||||
}, [selectLastUsedLanguage, disable, enabled]);
|
}, [selectLastUsedLanguage, disable, enabled]);
|
||||||
|
|
||||||
|
const selectLastUsedLanguageIfEnabled = useCallback(async () => {
|
||||||
|
if (enabled) await selectLastUsedLanguage();
|
||||||
|
}, [selectLastUsedLanguage, enabled]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
selectLanguage,
|
selectLanguage,
|
||||||
disable,
|
disable,
|
||||||
selectLastUsedLanguage,
|
selectLastUsedLanguage,
|
||||||
toggleLastUsed,
|
toggleLastUsed,
|
||||||
|
selectLastUsedLanguageIfEnabled,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
import { useCallback } from "react";
|
import { useCallback, useEffect, useMemo, useRef } from "react";
|
||||||
|
|
||||||
import { usePlayerStore } from "@/stores/player/store";
|
import { usePlayerStore } from "@/stores/player/store";
|
||||||
import { useVolumeStore } from "@/stores/volume";
|
import { useVolumeStore } from "@/stores/volume";
|
||||||
|
|
||||||
|
import { useCaptions } from "./useCaptions";
|
||||||
|
|
||||||
export function useInitializePlayer() {
|
export function useInitializePlayer() {
|
||||||
const display = usePlayerStore((s) => s.display);
|
const display = usePlayerStore((s) => s.display);
|
||||||
const volume = useVolumeStore((s) => s.volume);
|
const volume = useVolumeStore((s) => s.volume);
|
||||||
@ -15,3 +17,21 @@ export function useInitializePlayer() {
|
|||||||
init,
|
init,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function useInitializeSource() {
|
||||||
|
const source = usePlayerStore((s) => s.source);
|
||||||
|
const sourceIdentifier = useMemo(
|
||||||
|
() => (source ? JSON.stringify(source) : null),
|
||||||
|
[source]
|
||||||
|
);
|
||||||
|
const { selectLastUsedLanguageIfEnabled } = useCaptions();
|
||||||
|
|
||||||
|
const funRef = useRef(selectLastUsedLanguageIfEnabled);
|
||||||
|
useEffect(() => {
|
||||||
|
funRef.current = selectLastUsedLanguageIfEnabled;
|
||||||
|
}, [selectLastUsedLanguageIfEnabled]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (sourceIdentifier) funRef.current();
|
||||||
|
}, [sourceIdentifier]);
|
||||||
|
}
|
||||||
|
@ -5,6 +5,8 @@ import { convertSubtitlesToObjectUrl } from "@/components/player/utils/captions"
|
|||||||
import { playerStatus } from "@/stores/player/slices/source";
|
import { playerStatus } from "@/stores/player/slices/source";
|
||||||
import { usePlayerStore } from "@/stores/player/store";
|
import { usePlayerStore } from "@/stores/player/store";
|
||||||
|
|
||||||
|
import { useInitializeSource } from "../hooks/useInitializePlayer";
|
||||||
|
|
||||||
// initialize display interface
|
// initialize display interface
|
||||||
function useDisplayInterface() {
|
function useDisplayInterface() {
|
||||||
const display = usePlayerStore((s) => s.display);
|
const display = usePlayerStore((s) => s.display);
|
||||||
@ -112,6 +114,7 @@ function VideoElement() {
|
|||||||
export function VideoContainer() {
|
export function VideoContainer() {
|
||||||
const show = useShouldShowVideoElement();
|
const show = useShouldShowVideoElement();
|
||||||
useDisplayInterface();
|
useDisplayInterface();
|
||||||
|
useInitializeSource();
|
||||||
|
|
||||||
if (!show) return null;
|
if (!show) return null;
|
||||||
return <VideoElement />;
|
return <VideoElement />;
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
import { RunOutput } from "@movie-web/providers";
|
import { RunOutput } from "@movie-web/providers";
|
||||||
import { useCallback, useEffect, useState } from "react";
|
import { useCallback, useEffect, useState } from "react";
|
||||||
import { useHistory, useParams } from "react-router-dom";
|
import { useHistory, useParams } from "react-router-dom";
|
||||||
import { useEffectOnce } from "react-use";
|
|
||||||
|
|
||||||
import { useCaptions } from "@/components/player/hooks/useCaptions";
|
|
||||||
import { usePlayer } from "@/components/player/hooks/usePlayer";
|
import { usePlayer } from "@/components/player/hooks/usePlayer";
|
||||||
import { usePlayerMeta } from "@/components/player/hooks/usePlayerMeta";
|
import { usePlayerMeta } from "@/components/player/hooks/usePlayerMeta";
|
||||||
import { convertProviderCaption } from "@/components/player/utils/captions";
|
import { convertProviderCaption } from "@/components/player/utils/captions";
|
||||||
@ -41,7 +39,6 @@ export function PlayerView() {
|
|||||||
} = usePlayer();
|
} = usePlayer();
|
||||||
const { setPlayerMeta, scrapeMedia } = usePlayerMeta();
|
const { setPlayerMeta, scrapeMedia } = usePlayerMeta();
|
||||||
const backUrl = useLastNonPlayerLink();
|
const backUrl = useLastNonPlayerLink();
|
||||||
const { disable } = useCaptions();
|
|
||||||
|
|
||||||
const paramsData = JSON.stringify({
|
const paramsData = JSON.stringify({
|
||||||
media: params.media,
|
media: params.media,
|
||||||
@ -86,10 +83,6 @@ export function PlayerView() {
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffectOnce(() => {
|
|
||||||
disable();
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PlayerPart backUrl={backUrl} onMetaChange={metaChange}>
|
<PlayerPart backUrl={backUrl} onMetaChange={metaChange}>
|
||||||
{status === playerStatus.IDLE ? (
|
{status === playerStatus.IDLE ? (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user