Fix srt selection when switching mode (#508)

This commit is contained in:
Zoe Roux 2024-05-21 01:03:30 +02:00 committed by GitHub
parent aec23ae749
commit 27b0c753bb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 3 deletions

View File

@ -25,7 +25,7 @@ import { percent, px } from "yoshiki/native";
import { Button } from "./button";
import { imageBorderRadius } from "./constants";
import { P } from "./text";
import { ContrastArea, SwitchVariant } from "./themes";
import { SwitchVariant } from "./themes";
import { ts } from "./utils";
export type Snackbar = {

View File

@ -177,7 +177,11 @@ export const Video = memo(function Video({
useEffect(() => {
if (!subtitles) return;
setSubtitle((subtitle) => {
const subRet = subtitle ? subtitles.find((x) => x.language === subtitle.language) : null;
const subRet = subtitle
? subtitles.find(
(x) => x.language === subtitle.language && x.isForced === subtitle.isForced,
)
: null;
if (subRet) return subRet;
if (!defaultSubLanguage) return null;
if (defaultSubLanguage === "default") return subtitles.find((x) => x.isDefault) ?? null;

View File

@ -274,6 +274,7 @@ const useSubtitle = (
) => {
const htmlTrack = useRef<HTMLTrackElement | null>();
const subOcto = useRef<Jassub | null>();
const mode = useAtom(playModeAtom);
useEffect(() => {
if (!player.current) return;
@ -334,7 +335,9 @@ const useSubtitle = (
subOcto.current.setTrackByUrl(value.link);
}
}
}, [player, value, fonts]);
// also include mode because srt get's disabled when the mode change (no idea why)
mode;
}, [player.current, value, fonts, mode]);
useEffect(() => {
return () => {
if (subOcto.current) subOcto.current.destroy();