mirror of
https://github.com/p-stream/p-stream.git
synced 2026-05-12 04:20:52 +00:00
Refactor Native Subtitles feature. Fix playback on ios
This commit is contained in:
parent
0baa20ba7a
commit
ea7caa20d9
3 changed files with 26 additions and 9 deletions
|
|
@ -777,8 +777,8 @@
|
||||||
"refreshing": "Refreshing...",
|
"refreshing": "Refreshing...",
|
||||||
"empty": "There are no provided subtitles for this.",
|
"empty": "There are no provided subtitles for this.",
|
||||||
"notFound": "None of the available options match your query",
|
"notFound": "None of the available options match your query",
|
||||||
"useNativeSubtitles": "Use native video subtitles",
|
"useNativeSubtitles": "Native video subtitles",
|
||||||
"useNativeSubtitlesDescription": "May fix subtitles when casting and in PiP",
|
"useNativeSubtitlesDescription": "Broadcast subtitles for native fullscreen and PiP",
|
||||||
"delayLate": "Heard audio",
|
"delayLate": "Heard audio",
|
||||||
"delayEarly": "Saw caption"
|
"delayEarly": "Saw caption"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import {
|
||||||
} from "@/components/player/utils/captions";
|
} from "@/components/player/utils/captions";
|
||||||
import { Transition } from "@/components/utils/Transition";
|
import { Transition } from "@/components/utils/Transition";
|
||||||
import { usePlayerStore } from "@/stores/player/store";
|
import { usePlayerStore } from "@/stores/player/store";
|
||||||
|
import { usePreferencesStore } from "@/stores/preferences";
|
||||||
import { SubtitleStyling, useSubtitleStore } from "@/stores/subtitles";
|
import { SubtitleStyling, useSubtitleStore } from "@/stores/subtitles";
|
||||||
|
|
||||||
const wordOverrides: Record<string, string> = {
|
const wordOverrides: Record<string, string> = {
|
||||||
|
|
@ -151,12 +152,17 @@ export function SubtitleRenderer() {
|
||||||
|
|
||||||
export function SubtitleView(props: { controlsShown: boolean }) {
|
export function SubtitleView(props: { controlsShown: boolean }) {
|
||||||
const caption = usePlayerStore((s) => s.caption.selected);
|
const caption = usePlayerStore((s) => s.caption.selected);
|
||||||
const captionAsTrack = usePlayerStore((s) => s.caption.asTrack);
|
const source = usePlayerStore((s) => s.source);
|
||||||
const display = usePlayerStore((s) => s.display);
|
const display = usePlayerStore((s) => s.display);
|
||||||
const isCasting = display?.getType() === "casting";
|
const isCasting = display?.getType() === "casting";
|
||||||
const styling = useSubtitleStore((s) => s.styling);
|
const styling = useSubtitleStore((s) => s.styling);
|
||||||
|
const enableNativeSubtitles = usePreferencesStore(
|
||||||
|
(s) => s.enableNativeSubtitles,
|
||||||
|
);
|
||||||
|
|
||||||
if (captionAsTrack || !caption || isCasting) return null;
|
// Hide custom captions when native subtitles are enabled
|
||||||
|
const shouldUseNativeTrack = enableNativeSubtitles && source !== null;
|
||||||
|
if (shouldUseNativeTrack || !caption || isCasting) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Transition animation="slide-up" show>
|
<Transition animation="slide-up" show>
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import { makeVideoElementDisplayInterface } from "@/components/player/display/ba
|
||||||
import { convertSubtitlesToObjectUrl } from "@/components/player/utils/captions";
|
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 { usePreferencesStore } from "@/stores/preferences";
|
||||||
|
|
||||||
import { useInitializeSource } from "../hooks/useInitializePlayer";
|
import { useInitializeSource } from "../hooks/useInitializePlayer";
|
||||||
|
|
||||||
|
|
@ -66,13 +67,19 @@ function VideoElement() {
|
||||||
const trackEl = useRef<HTMLTrackElement>(null);
|
const trackEl = useRef<HTMLTrackElement>(null);
|
||||||
const display = usePlayerStore((s) => s.display);
|
const display = usePlayerStore((s) => s.display);
|
||||||
const srtData = usePlayerStore((s) => s.caption.selected?.srtData);
|
const srtData = usePlayerStore((s) => s.caption.selected?.srtData);
|
||||||
const captionAsTrack = usePlayerStore((s) => s.caption.asTrack);
|
|
||||||
const language = usePlayerStore((s) => s.caption.selected?.language);
|
const language = usePlayerStore((s) => s.caption.selected?.language);
|
||||||
|
const source = usePlayerStore((s) => s.source);
|
||||||
|
const enableNativeSubtitles = usePreferencesStore(
|
||||||
|
(s) => s.enableNativeSubtitles,
|
||||||
|
);
|
||||||
const trackObjectUrl = useObjectUrl(
|
const trackObjectUrl = useObjectUrl(
|
||||||
() => (srtData ? convertSubtitlesToObjectUrl(srtData) : null),
|
() => (srtData ? convertSubtitlesToObjectUrl(srtData) : null),
|
||||||
[srtData],
|
[srtData],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Use native tracks when the setting is enabled
|
||||||
|
const shouldUseNativeTrack = enableNativeSubtitles && source !== null;
|
||||||
|
|
||||||
// report video element to display interface
|
// report video element to display interface
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (display && videoEl.current) {
|
if (display && videoEl.current) {
|
||||||
|
|
@ -80,17 +87,20 @@ function VideoElement() {
|
||||||
}
|
}
|
||||||
}, [display, videoEl]);
|
}, [display, videoEl]);
|
||||||
|
|
||||||
// select track as showing if it exists
|
// Control track visibility based on setting
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (trackEl.current) {
|
if (trackEl.current) {
|
||||||
trackEl.current.track.mode = "showing";
|
trackEl.current.track.mode = shouldUseNativeTrack ? "showing" : "hidden";
|
||||||
}
|
}
|
||||||
}, [trackEl]);
|
}, [shouldUseNativeTrack, trackEl]);
|
||||||
|
|
||||||
|
// Attach track when native subtitles are enabled
|
||||||
|
// SubtitleView handles showing custom captions when native subtitles are disabled
|
||||||
let subtitleTrack: ReactNode = null;
|
let subtitleTrack: ReactNode = null;
|
||||||
if (captionAsTrack && trackObjectUrl && language)
|
if (shouldUseNativeTrack && trackObjectUrl && language) {
|
||||||
subtitleTrack = (
|
subtitleTrack = (
|
||||||
<track
|
<track
|
||||||
|
ref={trackEl}
|
||||||
label="P-Stream Captions"
|
label="P-Stream Captions"
|
||||||
kind="subtitles"
|
kind="subtitles"
|
||||||
srcLang={language}
|
srcLang={language}
|
||||||
|
|
@ -98,6 +108,7 @@ function VideoElement() {
|
||||||
default
|
default
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<video
|
<video
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue