feat(player): add jassub to render ASS/SSA subtitles #253
This commit is contained in:
6 files changed
+61
-61
No files matched your search
@@ -31,6 +31,7 @@
|
|||||||
"blurhash": "^2.0.5",
|
"blurhash": "^2.0.5",
|
||||||
"events": "^3.3.0",
|
"events": "^3.3.0",
|
||||||
"framer-motion": "^11.0.6",
|
"framer-motion": "^11.0.6",
|
||||||
|
"jassub": "^1.7.15",
|
||||||
"material-symbols": "^0.15.0",
|
"material-symbols": "^0.15.0",
|
||||||
"million": "^3.0.3",
|
"million": "^3.0.3",
|
||||||
"notistack": "^3.0.1",
|
"notistack": "^3.0.1",
|
||||||
|
|||||||
Generated
+13
@@ -62,6 +62,9 @@ dependencies:
|
|||||||
framer-motion:
|
framer-motion:
|
||||||
specifier: ^11.0.6
|
specifier: ^11.0.6
|
||||||
version: 11.0.6(react-dom@18.2.0)(react@18.2.0)
|
version: 11.0.6(react-dom@18.2.0)(react@18.2.0)
|
||||||
|
jassub:
|
||||||
|
specifier: ^1.7.15
|
||||||
|
version: 1.7.15
|
||||||
material-symbols:
|
material-symbols:
|
||||||
specifier: ^0.15.0
|
specifier: ^0.15.0
|
||||||
version: 0.15.0
|
version: 0.15.0
|
||||||
@@ -3021,6 +3024,12 @@ packages:
|
|||||||
set-function-name: 2.0.2
|
set-function-name: 2.0.2
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/jassub@1.7.15:
|
||||||
|
resolution: {integrity: sha512-8yKAJc++Y1gNfATOPRo3APk0JUhshKl5l7bRkT6WkJ8XP4RvYfVPb6ieH6WDxsMq523exwGzNvjjPEEWT+Z1nQ==}
|
||||||
|
dependencies:
|
||||||
|
rvfc-polyfill: 1.0.7
|
||||||
|
dev: false
|
||||||
|
|
||||||
/js-tokens@4.0.0:
|
/js-tokens@4.0.0:
|
||||||
resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==}
|
resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==}
|
||||||
|
|
||||||
@@ -4123,6 +4132,10 @@ packages:
|
|||||||
queue-microtask: 1.2.3
|
queue-microtask: 1.2.3
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/rvfc-polyfill@1.0.7:
|
||||||
|
resolution: {integrity: sha512-seBl7J1J3/k0LuzW2T9fG6JIOpni5AbU+/87LA+zTYKgTVhsfShmS8K/yOo1eeEjGJHnAdkVAUUM+PEjN9Mpkw==}
|
||||||
|
dev: false
|
||||||
|
|
||||||
/rx-player@4.0.0:
|
/rx-player@4.0.0:
|
||||||
resolution: {integrity: sha512-Ye36kPOvsGY67DIhkuciYLXI1VCc2i+YOLB5KpnQGt+3+E1igxIqQ3zx6UJjy2yNuhXzXjqKWMFxnxdvqf4+Ng==}
|
resolution: {integrity: sha512-Ye36kPOvsGY67DIhkuciYLXI1VCc2i+YOLB5KpnQGt+3+E1igxIqQ3zx6UJjy2yNuhXzXjqKWMFxnxdvqf4+Ng==}
|
||||||
dev: false
|
dev: false
|
||||||
|
|||||||
@@ -224,14 +224,26 @@ const PlayButton = ({
|
|||||||
let episodeTitle = "";
|
let episodeTitle = "";
|
||||||
if (result.Items[0].SeriesId) {
|
if (result.Items[0].SeriesId) {
|
||||||
itemName = result.Items[0].SeriesName;
|
itemName = result.Items[0].SeriesName;
|
||||||
episodeTitle = `S${result?.Items[0].ParentIndexNumber}:E${result?.Items[0].IndexNumber} ${result?.Items[0].Name}`;
|
episodeTitle = `S${result?.Items[0].ParentIndexNumber ?? 0}:E${
|
||||||
|
result?.Items[0].IndexNumber ?? 0
|
||||||
|
} ${result?.Items[0].Name}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let selectedSubtitleTrack: number | undefined = currentSubTrack;
|
||||||
|
if (!currentSubTrack) {
|
||||||
|
const subtitles =
|
||||||
|
result?.Items[0].MediaSources[0].MediaStreams?.filter(
|
||||||
|
(value) => value.Type === "Subtitle",
|
||||||
|
);
|
||||||
|
selectedSubtitleTrack = subtitles[0].Index;
|
||||||
|
}
|
||||||
|
|
||||||
playItem(
|
playItem(
|
||||||
itemName,
|
itemName,
|
||||||
episodeTitle,
|
episodeTitle,
|
||||||
currentVideoTrack,
|
currentVideoTrack,
|
||||||
currentAudioTrack,
|
currentAudioTrack,
|
||||||
currentSubTrack,
|
selectedSubtitleTrack,
|
||||||
result.Items[0].Container,
|
result.Items[0].Container,
|
||||||
true,
|
true,
|
||||||
`${api.basePath}/Videos/${result.Items[0].Id}/stream.${result.Items[0].Container}?Static=true&mediaSourceId=${result.Items[0].Id}&deviceId=${api.deviceInfo.id}&api_key=${api.accessToken}&Tag=${result.Items[0].MediaSources[0].ETag}&videoStreamIndex=${currentVideoTrack}&audioStreamIndex=${currentAudioTrack}`,
|
`${api.basePath}/Videos/${result.Items[0].Id}/stream.${result.Items[0].Container}?Static=true&mediaSourceId=${result.Items[0].Id}&deviceId=${api.deviceInfo.id}&api_key=${api.accessToken}&Tag=${result.Items[0].MediaSources[0].ETag}&videoStreamIndex=${currentVideoTrack}&audioStreamIndex=${currentAudioTrack}`,
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ const TrailerButton = (props: TrailerButtonType) => {
|
|||||||
style={{
|
style={{
|
||||||
aspectRatio: "16/9",
|
aspectRatio: "16/9",
|
||||||
}}
|
}}
|
||||||
|
controls
|
||||||
/>
|
/>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -1,49 +0,0 @@
|
|||||||
import React, { useEffect, useState } from "react";
|
|
||||||
import { useLayoutEffect, useRef } from "react";
|
|
||||||
|
|
||||||
import RxPlayerRaw from "rx-player";
|
|
||||||
|
|
||||||
const RxPlayer = ({ playing, url, onProgress }) => {
|
|
||||||
const videoRef = useRef(null);
|
|
||||||
const [player, setPlayer] = useState<RxPlayerRaw>();
|
|
||||||
useLayoutEffect(() => {
|
|
||||||
console.info("Video tag mounted!");
|
|
||||||
const playerObject = new RxPlayerRaw({
|
|
||||||
videoElement: videoRef.current,
|
|
||||||
});
|
|
||||||
setPlayer(playerObject);
|
|
||||||
playerObject.loadVideo({
|
|
||||||
url: url,
|
|
||||||
transport: "directfile",
|
|
||||||
autoPlay: true,
|
|
||||||
});
|
|
||||||
playerObject.addEventListener("positionUpdate", onProgress());
|
|
||||||
|
|
||||||
// player.pause();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (playing) {
|
|
||||||
player?.play();
|
|
||||||
} else {
|
|
||||||
player?.pause();
|
|
||||||
}
|
|
||||||
}, [playing]);
|
|
||||||
|
|
||||||
return (
|
|
||||||
// biome-ignore lint/a11y/useMediaCaption: <explanation>
|
|
||||||
<video
|
|
||||||
ref={videoRef}
|
|
||||||
style={{
|
|
||||||
width: "100vw",
|
|
||||||
height: "100vh",
|
|
||||||
zIndex: 100,
|
|
||||||
}}
|
|
||||||
className="video-player-element"
|
|
||||||
controls
|
|
||||||
// autoPlay
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default RxPlayer;
|
|
||||||
@@ -37,6 +37,10 @@ import useDebounce from "../../utils/hooks/useDebounce";
|
|||||||
import { useApi } from "../../utils/store/api";
|
import { useApi } from "../../utils/store/api";
|
||||||
import { setBackdrop } from "../../utils/store/backdrop";
|
import { setBackdrop } from "../../utils/store/backdrop";
|
||||||
|
|
||||||
|
import JASSUB from "jassub";
|
||||||
|
import workerUrl from "jassub/dist/jassub-worker.js?url";
|
||||||
|
import wasmUrl from "jassub/dist/jassub-worker.wasm?url";
|
||||||
|
|
||||||
// export const VideoPlayer = () => {
|
// export const VideoPlayer = () => {
|
||||||
// const navigate = useNavigate();
|
// const navigate = useNavigate();
|
||||||
// const [api] = useApi((state) => [state.api]);
|
// const [api] = useApi((state) => [state.api]);
|
||||||
@@ -894,18 +898,27 @@ const ticksDisplay = (ticks: number) => {
|
|||||||
|
|
||||||
const VideoPlayer = () => {
|
const VideoPlayer = () => {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const [api] = useApi((state) => [state.api]);
|
||||||
|
|
||||||
const [hoveringOsd, setHoveringOsd] = useState(false);
|
const [hoveringOsd, setHoveringOsd] = useState(false);
|
||||||
|
|
||||||
const [hlsStream, item, itemName, itemDuration, startPosition, episodeTitle] =
|
const [
|
||||||
usePlaybackStore((state) => [
|
hlsStream,
|
||||||
state.hlsStream,
|
item,
|
||||||
state.item,
|
itemName,
|
||||||
state.itemName,
|
itemDuration,
|
||||||
state.itemDuration,
|
startPosition,
|
||||||
state.startPosition,
|
episodeTitle,
|
||||||
state.episodeTitle,
|
mediaSource,
|
||||||
]);
|
] = usePlaybackStore((state) => [
|
||||||
|
state.hlsStream,
|
||||||
|
state.item,
|
||||||
|
state.itemName,
|
||||||
|
state.itemDuration,
|
||||||
|
state.startPosition,
|
||||||
|
state.episodeTitle,
|
||||||
|
state.mediaSource,
|
||||||
|
]);
|
||||||
|
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
@@ -919,9 +932,18 @@ const VideoPlayer = () => {
|
|||||||
|
|
||||||
useEffect(() => setBackdrop("", ""), []);
|
useEffect(() => setBackdrop("", ""), []);
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`${api.basePath}/Videos/${item.Id}/${item.Id}/Subtitles/${mediaSource.subtitleTrack}/Stream.ass?api_key=${api.accessToken}`,
|
||||||
|
);
|
||||||
const handleReady = async () => {
|
const handleReady = async () => {
|
||||||
if (!isReady) {
|
if (!isReady) {
|
||||||
console.log(startPosition);
|
const subtitleRenderer = new JASSUB({
|
||||||
|
video: player.current.getInternalPlayer(),
|
||||||
|
subUrl: `${api.basePath}/Videos/${item.Id}/${item.Id}/Subtitles/${mediaSource.subtitleTrack}/Stream.ass?api_key=${api.accessToken}`,
|
||||||
|
workerUrl,
|
||||||
|
wasmUrl,
|
||||||
|
});
|
||||||
|
|
||||||
player.current.seekTo(ticksToSec(startPosition), "seconds");
|
player.current.seekTo(ticksToSec(startPosition), "seconds");
|
||||||
setIsReady(true);
|
setIsReady(true);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user