mirror of
https://github.com/movie-web/movie-web.git
synced 2024-11-11 02:45:09 +01:00
Fix excessive memory usage on chrome+webkit
This commit is contained in:
parent
0ca585f70a
commit
037960f587
@ -81,6 +81,7 @@ export function CaptionsView({ id }: { id: string }) {
|
|||||||
<CaptionOption onClick={() => disableCaption()}>Off</CaptionOption>
|
<CaptionOption onClick={() => disableCaption()}>Off</CaptionOption>
|
||||||
{langs.map((v) => (
|
{langs.map((v) => (
|
||||||
<CaptionOption
|
<CaptionOption
|
||||||
|
key={v.lang}
|
||||||
countryCode={v.lang}
|
countryCode={v.lang}
|
||||||
selected={lang === v.lang}
|
selected={lang === v.lang}
|
||||||
onClick={() => updateCaption()}
|
onClick={() => updateCaption()}
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
import { ReactNode, useEffect, useMemo, useRef } from "react";
|
import { ReactNode, useEffect, useMemo, useRef } from "react";
|
||||||
|
|
||||||
import { makeVideoElementDisplayInterface } from "@/components/player/display/base";
|
import { makeVideoElementDisplayInterface } from "@/components/player/display/base";
|
||||||
import {
|
import { convertSubtitlesToDataurl } from "@/components/player/utils/captions";
|
||||||
convertSubtitlesToVtt,
|
|
||||||
vttToDataurl,
|
|
||||||
} 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";
|
||||||
|
|
||||||
@ -47,10 +44,9 @@ function VideoElement() {
|
|||||||
const captionAsTrack = usePlayerStore((s) => s.caption.asTrack);
|
const captionAsTrack = usePlayerStore((s) => s.caption.asTrack);
|
||||||
const language = usePlayerStore((s) => s.caption.selected?.language);
|
const language = usePlayerStore((s) => s.caption.selected?.language);
|
||||||
|
|
||||||
const trackData = useMemo(
|
const trackData = useMemo(() => {
|
||||||
() => (srtData ? vttToDataurl(convertSubtitlesToVtt(srtData)) : null),
|
return srtData ? convertSubtitlesToDataurl(srtData) : null;
|
||||||
[srtData]
|
}, [srtData]);
|
||||||
);
|
|
||||||
|
|
||||||
// report video element to display interface
|
// report video element to display interface
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -40,8 +40,6 @@ export function parseSubtitles(text: string): CaptionCueType[] {
|
|||||||
return parse(vtt).filter((cue) => cue.type === "caption") as CaptionCueType[];
|
return parse(vtt).filter((cue) => cue.type === "caption") as CaptionCueType[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function vttToDataurl(vtt: string): string {
|
export function convertSubtitlesToDataurl(text: string): string {
|
||||||
const bytes = new TextEncoder().encode(vtt);
|
return `data:text/vtt;${convertSubtitlesToVtt(text)}`;
|
||||||
const encoded = btoa(String.fromCodePoint(...bytes));
|
|
||||||
return `data:text/vtt;base64,${encoded}`;
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user