refactor(player): start rewrite for videoPlayer component
This commit is contained in:
15 files changed
+1512
-1120
No files matched your search
@@ -44,6 +44,8 @@
|
||||
"react-router-dom": "^6.22.1",
|
||||
"react-use-konami": "^1.1.0",
|
||||
"remark-gfm": "^4.0.0",
|
||||
"rx-player": "^4.0.0",
|
||||
"shaka-player": "^4.7.11",
|
||||
"tauri-plugin-log-api": "github:tauri-apps/tauri-plugin-log#v1",
|
||||
"tauri-plugin-store-api": "github:tauri-apps/tauri-plugin-store",
|
||||
"typescript": "^5.3.3",
|
||||
|
||||
Generated
+21
@@ -101,6 +101,12 @@ dependencies:
|
||||
remark-gfm:
|
||||
specifier: ^4.0.0
|
||||
version: 4.0.0
|
||||
rx-player:
|
||||
specifier: ^4.0.0
|
||||
version: 4.0.0
|
||||
shaka-player:
|
||||
specifier: ^4.7.11
|
||||
version: 4.7.11
|
||||
tauri-plugin-log-api:
|
||||
specifier: github:tauri-apps/tauri-plugin-log#v1
|
||||
version: github.com/tauri-apps/tauri-plugin-log/19f5dcc0425e9127d2c591780e5047b83e77a7c2
|
||||
@@ -2098,6 +2104,10 @@ packages:
|
||||
/electron-to-chromium@1.4.681:
|
||||
resolution: {integrity: sha512-1PpuqJUFWoXZ1E54m8bsLPVYwIVCRzvaL+n5cjigGga4z854abDnFRc+cTa2th4S79kyGqya/1xoR7h+Y5G5lg==}
|
||||
|
||||
/eme-encryption-scheme-polyfill@2.1.1:
|
||||
resolution: {integrity: sha512-njD17wcUrbqCj0ArpLu5zWXtaiupHb/2fIUQGdInf83GlI+Q6mmqaPGLdrke4savKAu15J/z1Tg/ivDgl14g0g==}
|
||||
dev: false
|
||||
|
||||
/entities@4.5.0:
|
||||
resolution: {integrity: sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==}
|
||||
engines: {node: '>=0.12'}
|
||||
@@ -4060,6 +4070,10 @@ packages:
|
||||
queue-microtask: 1.2.3
|
||||
dev: true
|
||||
|
||||
/rx-player@4.0.0:
|
||||
resolution: {integrity: sha512-Ye36kPOvsGY67DIhkuciYLXI1VCc2i+YOLB5KpnQGt+3+E1igxIqQ3zx6UJjy2yNuhXzXjqKWMFxnxdvqf4+Ng==}
|
||||
dev: false
|
||||
|
||||
/safe-array-concat@1.1.0:
|
||||
resolution: {integrity: sha512-ZdQ0Jeb9Ofti4hbt5lX3T2JcAamT9hfzYU1MNB+z/jaEbB6wfFfPIR/zEORmZqobkCCJhSjodobH6WHNmJ97dg==}
|
||||
engines: {node: '>=0.4'}
|
||||
@@ -4120,6 +4134,13 @@ packages:
|
||||
has-property-descriptors: 1.0.2
|
||||
dev: true
|
||||
|
||||
/shaka-player@4.7.11:
|
||||
resolution: {integrity: sha512-zHyuL/cph3xKbci/Ovba/Swyni6g3cj79cN+84BCCrD3tWR9WEBwc8svcqPIXNQX/7VYb3uwaOa+85eBQKPkMg==}
|
||||
engines: {node: '>=14'}
|
||||
dependencies:
|
||||
eme-encryption-scheme-polyfill: 2.1.1
|
||||
dev: false
|
||||
|
||||
/shebang-command@2.0.0:
|
||||
resolution: {integrity: sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==}
|
||||
engines: {node: '>=8'}
|
||||
|
||||
@@ -18,7 +18,7 @@ tauri-build = { version = "1.5.1", features = [] }
|
||||
log = "^0.4.20"
|
||||
serde_json = "1.0"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
tauri = { version = "1.6.0", features = [ "updater", "http-all", "process-exit", "process-relaunch", "shell-all", "window-set-fullscreen", "http-all"] }
|
||||
tauri = { version = "1.6.0", features = [ "window-all", "updater", "http-all", "process-exit", "process-relaunch", "shell-all", "http-all"] }
|
||||
tauri-plugin-store = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" }
|
||||
tauri-plugin-localhost = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" }
|
||||
tauri-plugin-log = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1", features = ["colored"] }
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
"relaunchDangerousAllowSymlinkMacos": false
|
||||
},
|
||||
"window": {
|
||||
"all": true,
|
||||
"setFullscreen": true
|
||||
},
|
||||
"shell": {
|
||||
@@ -46,7 +47,7 @@
|
||||
"icons/icon.ico"
|
||||
],
|
||||
"identifier": "com.jellyplayer.prayag17",
|
||||
"longDescription": "A Modern Jellyfin Client for Jellyfin",
|
||||
"longDescription": "A modern desktop client for Jellyfin",
|
||||
"macOS": {
|
||||
"entitlements": null,
|
||||
"exceptionDomain": "",
|
||||
@@ -55,7 +56,7 @@
|
||||
"signingIdentity": null
|
||||
},
|
||||
"resources": [],
|
||||
"shortDescription": "A Modern Jellyfin Client for Jellyfin",
|
||||
"shortDescription": "JellyPlayer",
|
||||
"targets": ["deb", "appimage", "nsis", "app", "dmg", "updater"],
|
||||
"windows": {
|
||||
"certificateThumbprint": null,
|
||||
@@ -107,7 +108,8 @@
|
||||
"title": "JellyPlayer",
|
||||
"visible": true,
|
||||
"center": true,
|
||||
"label": "main"
|
||||
"label": "main",
|
||||
"decorations": false
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
+24
-9
@@ -56,7 +56,7 @@ import {
|
||||
UserLoginManual,
|
||||
} from "./routes/login";
|
||||
import PersonTitlePage from "./routes/person/index.jsx";
|
||||
import { VideoPlayer } from "./routes/player/videoPlayer.jsx";
|
||||
import VideoPlayer from "./routes/player/videoPlayer";
|
||||
import PlaylistTitlePage from "./routes/playlist/index.jsx";
|
||||
import SearchPage from "./routes/search";
|
||||
import SeriesTitlePage from "./routes/series/index.jsx";
|
||||
@@ -107,6 +107,7 @@ import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
|
||||
import { useSnackbar } from "notistack";
|
||||
import { ErrorBoundary } from "react-error-boundary";
|
||||
|
||||
import { getSystemApi } from "@jellyfin/sdk/lib/utils/api/system-api";
|
||||
import {
|
||||
useIsFetching,
|
||||
useIsMutating,
|
||||
@@ -124,7 +125,7 @@ import {
|
||||
setDefaultServer,
|
||||
} from "./utils/storage/servers";
|
||||
import { UserStore, delUser, getUser } from "./utils/storage/user";
|
||||
import { createApi, useApi } from "./utils/store/api";
|
||||
import { axiosClient, createApi, useApi } from "./utils/store/api";
|
||||
|
||||
const handleAuthError = async () => {
|
||||
await delUser();
|
||||
@@ -164,6 +165,15 @@ const init = async () => {
|
||||
|
||||
const userOnDisk = await getUser();
|
||||
createApi(defaultServerInfo.address, "");
|
||||
try {
|
||||
const api = useApi.getState();
|
||||
const ping = await getSystemApi(api.api).getPingSystem();
|
||||
// const ping = await fetch("http://192.168.29.60:8096/System/Ping");
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
setInitialRoute("/error");
|
||||
return;
|
||||
}
|
||||
|
||||
if (userOnDisk) {
|
||||
try {
|
||||
@@ -287,10 +297,7 @@ function AppReady() {
|
||||
<SnackbarProvider maxSnack={5}>
|
||||
<ThemeProvider theme={theme}>
|
||||
<CssBaseline />
|
||||
<NProgress
|
||||
isAnimating={isQueryFetching || isMutating}
|
||||
key={isQueryFetching || isMutating ? "fetching" : "notFetching"}
|
||||
/>
|
||||
<NProgress isAnimating={isQueryFetching || isMutating} />
|
||||
<Dialog
|
||||
open={updateDialog}
|
||||
fullWidth
|
||||
@@ -462,10 +469,18 @@ function AppReady() {
|
||||
</DialogContentText>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<Button onClick={() => navigate("/servers/list")}>
|
||||
<Button
|
||||
color="secondary"
|
||||
variant="contained"
|
||||
onClick={() => navigate("/servers/list")}
|
||||
>
|
||||
Change Server
|
||||
</Button>
|
||||
<Button variant="outlined" onClick={handleRelaunch}>
|
||||
<Button
|
||||
variant="contained"
|
||||
color="primary"
|
||||
onClick={handleRelaunch}
|
||||
>
|
||||
Restart JellyPlayer
|
||||
</Button>
|
||||
</DialogActions>
|
||||
@@ -504,7 +519,7 @@ function AppReady() {
|
||||
</ErrorBoundary>
|
||||
</div>
|
||||
|
||||
<ReactQueryDevtools buttonPosition="bottom-right" position="left" />
|
||||
<ReactQueryDevtools buttonPosition="top-right" position="left" />
|
||||
</ThemeProvider>
|
||||
</SnackbarProvider>
|
||||
);
|
||||
|
||||
@@ -11,6 +11,7 @@ import Typography from "@mui/material/Typography";
|
||||
|
||||
import {
|
||||
BaseItemDto,
|
||||
BaseItemDtoQueryResult,
|
||||
BaseItemKind,
|
||||
ItemFields,
|
||||
SortOrder,
|
||||
@@ -28,6 +29,7 @@ import { useAudioPlayback } from "../../utils/store/audioPlayback";
|
||||
import useQueue, { setQueue } from "../../utils/store/queue";
|
||||
|
||||
import {
|
||||
playItem,
|
||||
setItem,
|
||||
usePlaybackDataLoadStore,
|
||||
usePlaybackStore,
|
||||
@@ -75,35 +77,35 @@ const PlayButton = ({
|
||||
const [api] = useApi((state) => [state.api]);
|
||||
|
||||
const navigate = useNavigate();
|
||||
const [
|
||||
setUrl,
|
||||
setPosition,
|
||||
setDuration,
|
||||
setItemId,
|
||||
setItemName,
|
||||
setAudioStreamIndex,
|
||||
setVideoStreamIndex,
|
||||
setSubtitleStreamIndex,
|
||||
setMediaSourceId,
|
||||
setUserId,
|
||||
setMediaContainer,
|
||||
setSeriesId,
|
||||
setEpisodeIndex,
|
||||
] = usePlaybackStore((state) => [
|
||||
state.setUrl,
|
||||
state.setPosition,
|
||||
state.setDuration,
|
||||
state.setItemId,
|
||||
state.setItemName,
|
||||
state.setAudioStreamIndex,
|
||||
state.setVideoStreamIndex,
|
||||
state.setSubtitleStreamIndex,
|
||||
state.setMediaSourceId,
|
||||
state.setUserId,
|
||||
state.setMediaContainer,
|
||||
state.setSeriesId,
|
||||
state.setEpisodeIndex,
|
||||
]);
|
||||
// const [
|
||||
// setUrl,
|
||||
// setPosition,
|
||||
// setDuration,
|
||||
// setItemId,
|
||||
// setItemName,
|
||||
// setAudioStreamIndex,
|
||||
// setVideoStreamIndex,
|
||||
// setSubtitleStreamIndex,
|
||||
// setMediaSourceId,
|
||||
// setUserId,
|
||||
// setMediaContainer,
|
||||
// setSeriesId,
|
||||
// setEpisodeIndex,
|
||||
// ] = usePlaybackStore((state) => [
|
||||
// state.setUrl,
|
||||
// state.setPosition,
|
||||
// state.setDuration,
|
||||
// state.setItemId,
|
||||
// state.setItemName,
|
||||
// state.setAudioStreamIndex,
|
||||
// state.setVideoStreamIndex,
|
||||
// state.setSubtitleStreamIndex,
|
||||
// state.setMediaSourceId,
|
||||
// state.setUserId,
|
||||
// state.setMediaContainer,
|
||||
// state.setSeriesId,
|
||||
// state.setEpisodeIndex,
|
||||
// ]);
|
||||
const [
|
||||
setAudioUrl,
|
||||
setAudioDisplay,
|
||||
@@ -194,8 +196,7 @@ const PlayButton = ({
|
||||
}
|
||||
return result.data;
|
||||
},
|
||||
onSuccess: (result) => {
|
||||
console.log(result.Items[0].MediaSources);
|
||||
onSuccess: (result: BaseItemDtoQueryResult | null) => {
|
||||
if (trackIndex) {
|
||||
setPlaylistItemId(playlistItemId);
|
||||
// setCurrentTrack(trackIndex);
|
||||
@@ -216,98 +217,31 @@ const PlayButton = ({
|
||||
setAudioDisplay(true);
|
||||
setQueue(result.Items, 0);
|
||||
} else {
|
||||
setUserId(userId);
|
||||
setItemId(result.Items[0].Id);
|
||||
setDuration(result.Items[0].RunTimeTicks);
|
||||
// Movie / Series Playback
|
||||
const queue = result.Items;
|
||||
|
||||
if (result.Items[0].Type === BaseItemKind.Episode) {
|
||||
setSeriesId(result.Items[0].SeriesId);
|
||||
// setEpisodeIndex(result.Ite)
|
||||
let itemName = result.Items[0].Name;
|
||||
let episodeTitle = "";
|
||||
if (result.Items[0].SeriesId) {
|
||||
itemName = result.Items[0].SeriesName;
|
||||
episodeTitle = `S${result?.Items[0].ParentIndexNumber}:E${result?.Items[0].IndexNumber} ${result?.Items[0].Name}`;
|
||||
}
|
||||
|
||||
setMediaContainer(result.Items[0].MediaSources[0].Container);
|
||||
// Set all required stream index
|
||||
setAudioStreamIndex(currentAudioTrack);
|
||||
setVideoStreamIndex(currentVideoTrack);
|
||||
setSubtitleStreamIndex(currentSubTrack);
|
||||
|
||||
setMediaSourceId(result.Items[0].Id);
|
||||
setItem(result.Items[0]);
|
||||
|
||||
switch (result.Items[0].Type) {
|
||||
case BaseItemKind.Movie:
|
||||
if (result.Items[0].ImageBlurHashes.Logo) {
|
||||
setItemName(
|
||||
<div className="video-osd-name">
|
||||
<img
|
||||
alt={result.Items[0].Name}
|
||||
src={`${api.basePath}/Items/${result.Items[0].Id}/Images/Logo`}
|
||||
className="video-osd-name-logo"
|
||||
onLoad={(e) => {
|
||||
e.target.style.opacity = 1;
|
||||
}}
|
||||
/>
|
||||
</div>,
|
||||
);
|
||||
} else {
|
||||
setItemName(
|
||||
<div className="video-osd-name">
|
||||
<Typography variant="h6">{result.Items[0].Name}</Typography>
|
||||
</div>,
|
||||
);
|
||||
}
|
||||
break;
|
||||
case BaseItemKind.Episode:
|
||||
if (result.Items[0].ImageBlurHashes.Logo) {
|
||||
setItemName(
|
||||
<div className="video-osd-name">
|
||||
<img
|
||||
alt={result.Items[0].SeriesName}
|
||||
src={`${api.basePath}/Items/${result.Items[0].SeriesId}/Images/Logo`}
|
||||
className="video-osd-name-logo"
|
||||
onLoad={(e) => {
|
||||
e.target.style.opacity = 1;
|
||||
}}
|
||||
/>
|
||||
<Typography variant="subtitle1">
|
||||
S{result.Items[0].ParentIndexNumber}
|
||||
:E
|
||||
{result.Items[0].IndexNumber} {result.Items[0].Name}
|
||||
</Typography>
|
||||
</div>,
|
||||
);
|
||||
} else {
|
||||
setItemName(
|
||||
<div className="video-osd-name">
|
||||
<Typography variant="h6">
|
||||
{result.Items[0].SeriesName}
|
||||
</Typography>
|
||||
<Typography variant="subtitle1">
|
||||
S{result.Items[0].ParentIndexNumber}
|
||||
:E
|
||||
{result.Items[0].IndexNumber} {result.Items[0].Name}
|
||||
</Typography>
|
||||
</div>,
|
||||
);
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
setItemName(
|
||||
<div className="video-osd-name">
|
||||
<Typography variant="h6">{result.Items[0].Name}</Typography>
|
||||
</div>,
|
||||
);
|
||||
break;
|
||||
}
|
||||
setPosition(result.Items[0].UserData?.PlaybackPositionTicks);
|
||||
|
||||
setUrl(
|
||||
`${api.basePath}/Videos/${result.Items[0].Id}/stream.
|
||||
${result.Items[0].MediaSources[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}`,
|
||||
playItem(
|
||||
itemName,
|
||||
episodeTitle,
|
||||
currentVideoTrack,
|
||||
currentAudioTrack,
|
||||
currentSubTrack,
|
||||
result.Items[0].Container,
|
||||
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}`,
|
||||
userId,
|
||||
result?.Items[0].UserData?.PlaybackPositionTicks,
|
||||
result.Items[0].RunTimeTicks,
|
||||
result.Items[0],
|
||||
queue,
|
||||
0,
|
||||
);
|
||||
|
||||
navigate("/player");
|
||||
}
|
||||
},
|
||||
|
||||
@@ -26,8 +26,7 @@
|
||||
position: relative;
|
||||
width: 100%;
|
||||
box-shadow: 0 4px 8px rgb(0 0 0 / 0.2);
|
||||
border-radius: 5px;
|
||||
border: 1px solid rgb(255 255 255 / 0.1);
|
||||
border-radius: $border-radius-default;
|
||||
overflow: hidden;
|
||||
height: auto;
|
||||
z-index: 0;
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
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;
|
||||
@@ -117,7 +117,7 @@ export const LoginWithImage = () => {
|
||||
);
|
||||
return auth;
|
||||
} catch (error) {
|
||||
if (error.response.status === 500) {
|
||||
if (error.response?.status === 500) {
|
||||
enqueueSnackbar(
|
||||
"Unable to connect to server. Please try again after some time.",
|
||||
{ variant: "error" },
|
||||
|
||||
@@ -1,880 +0,0 @@
|
||||
import { appWindow } from "@tauri-apps/api/window";
|
||||
import React from "react";
|
||||
|
||||
import Backdrop from "@mui/material/Backdrop";
|
||||
import Box from "@mui/material/Box";
|
||||
import CircularProgress from "@mui/material/CircularProgress";
|
||||
import IconButton from "@mui/material/IconButton";
|
||||
import LinearProgress from "@mui/material/LinearProgress";
|
||||
import Menu from "@mui/material/Menu";
|
||||
import MenuItem from "@mui/material/MenuItem";
|
||||
import Slider from "@mui/material/Slider";
|
||||
import Stack from "@mui/material/Stack";
|
||||
import Typography from "@mui/material/Typography";
|
||||
|
||||
import ReactPlayer from "react-player";
|
||||
|
||||
import { usePlaybackStore } from "../../utils/store/playback";
|
||||
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
import { Navigate, useNavigate } from "react-router-dom";
|
||||
import { secToTicks, ticksToSec } from "../../utils/date/time";
|
||||
|
||||
import { getMediaInfoApi } from "@jellyfin/sdk/lib/utils/api/media-info-api";
|
||||
import { getPlaystateApi } from "@jellyfin/sdk/lib/utils/api/playstate-api";
|
||||
import { getTvShowsApi } from "@jellyfin/sdk/lib/utils/api/tv-shows-api";
|
||||
|
||||
import "./videoPlayer.module.scss";
|
||||
|
||||
import { endsAt } from "../../utils/date/time";
|
||||
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
import { ItemFields, LocationType } from "@jellyfin/sdk/lib/generated-client";
|
||||
import { AnimatePresence, motion } from "framer-motion";
|
||||
|
||||
import { useApi } from "../../utils/store/api";
|
||||
|
||||
export const VideoPlayer = () => {
|
||||
const navigate = useNavigate();
|
||||
const [api] = useApi((state) => [state.api]);
|
||||
|
||||
const [settingsMenuEl, setSettingsMenuEl] = useState(null);
|
||||
const settingsMenuState = Boolean(settingsMenuEl);
|
||||
|
||||
const [speedMenuEl, setSpeedMenuEl] = useState(null);
|
||||
const [speed, setSpeed] = useState(3);
|
||||
const speedMenuState = Boolean(speedMenuEl);
|
||||
const availableSpeeds = [0.25, 0.5, 0.75, 1, 1.25, 1.5, 1.75, 2];
|
||||
|
||||
const [
|
||||
url,
|
||||
startPosition,
|
||||
itemDuration,
|
||||
itemId,
|
||||
itemName,
|
||||
audioStreamIndex,
|
||||
subtitleStreamIndex,
|
||||
userId,
|
||||
seriesId,
|
||||
setUrl,
|
||||
setPosition,
|
||||
setDurationStore,
|
||||
setItemId,
|
||||
setItemName,
|
||||
setAudioStreamIndex,
|
||||
setVideoStreamIndex,
|
||||
setSubtitleStreamIndex,
|
||||
setMediaSourceId,
|
||||
setUserId,
|
||||
setSeriesId,
|
||||
item,
|
||||
] = usePlaybackStore((state) => [
|
||||
state.url,
|
||||
state.startPosition,
|
||||
state.duration,
|
||||
state.itemId,
|
||||
state.itemName,
|
||||
state.audioStreamIndex,
|
||||
state.subtitleStreamIndex,
|
||||
state.userId,
|
||||
state.seriesId,
|
||||
state.setUrl,
|
||||
state.setPosition,
|
||||
state.setDuration,
|
||||
state.setItemId,
|
||||
state.setItemName,
|
||||
state.setAudioStreamIndex,
|
||||
state.setVideoStreamIndex,
|
||||
state.setSubtitleStreamIndex,
|
||||
state.setMediaSourceId,
|
||||
state.setUserId,
|
||||
state.setSeriesId,
|
||||
state.item,
|
||||
]);
|
||||
|
||||
const mediaInfo = useQuery({
|
||||
queryKey: ["videoPlayer", itemId, "mediaInfo"],
|
||||
queryFn: async () => {
|
||||
const result = await getMediaInfoApi(api).getPlaybackInfo({
|
||||
itemId: itemId,
|
||||
userId: userId,
|
||||
});
|
||||
return result.data;
|
||||
},
|
||||
});
|
||||
|
||||
const episodes = useQuery({
|
||||
queryKey: ["videoPlayer", itemId, "episodes"],
|
||||
queryFn: async () => {
|
||||
const result = await getTvShowsApi(api).getEpisodes({
|
||||
userId: userId,
|
||||
seriesId: seriesId,
|
||||
fields: [ItemFields.MediaSources],
|
||||
excludeLocationTypes: [LocationType.Virtual],
|
||||
});
|
||||
return result.data;
|
||||
},
|
||||
});
|
||||
|
||||
const currentEpisodeIndex = episodes.data?.Items?.findIndex(
|
||||
(item) => item.Id === itemId,
|
||||
);
|
||||
|
||||
const [currentSubtrack] = useState(subtitleStreamIndex);
|
||||
|
||||
const [showControls, setShowControls] = useState(false);
|
||||
|
||||
const playerRef = useRef();
|
||||
const [isSeeking, setIsSeeking] = useState(false);
|
||||
const [isBuffering, setIsBuffering] = useState(true);
|
||||
const [isPlaying, setIsPlaying] = useState(true);
|
||||
const [isMuted, setIsMuted] = useState(false);
|
||||
const [isReady, setIsReady] = useState(false);
|
||||
const [isPIP, setIsPIP] = useState(false);
|
||||
const [volume, setVolume] = useState(0.8);
|
||||
|
||||
const [progress, setProgress] = useState(0);
|
||||
const [currentTime, setCurrentTime] = useState(startPosition);
|
||||
|
||||
const onReady = useCallback(async () => {
|
||||
if (!isReady) {
|
||||
const timeToStart = ticksToSec(startPosition);
|
||||
await getPlaystateApi(api).reportPlaybackStart({
|
||||
playbackStartInfo: {
|
||||
PlayMethod: mediaInfo.data?.MediaSources[0].SupportsDirectPlay
|
||||
? "DirectPlay"
|
||||
: mediaInfo.data?.MediaSources[0].SupportsDirectStream
|
||||
? "DirectStream"
|
||||
: "Transcode",
|
||||
AudioStreamIndex: audioStreamIndex,
|
||||
SubtitleStreamIndex: subtitleStreamIndex,
|
||||
userId: userId,
|
||||
CanSeek: true,
|
||||
ItemId: itemId,
|
||||
MediaSourceId: mediaInfo.data?.MediaSources[0].Id,
|
||||
PlaySessionId: mediaInfo.data?.PlaySessionId,
|
||||
},
|
||||
});
|
||||
|
||||
playerRef.current.seekTo(timeToStart, "seconds");
|
||||
setIsReady(true);
|
||||
}
|
||||
});
|
||||
|
||||
const handleDisplayCurrentTime = () => {
|
||||
let time = ticksToSec(progress * itemDuration);
|
||||
const hr = Math.floor(time / 3600);
|
||||
time -= hr * 3600;
|
||||
const min = Math.floor(time / 60);
|
||||
time -= min * 60;
|
||||
return `${hr.toLocaleString([], {
|
||||
minimumIntegerDigits: 2,
|
||||
maximumFractionDigits: 0,
|
||||
})}:${min.toLocaleString([], {
|
||||
minimumIntegerDigits: 2,
|
||||
maximumFractionDigits: 0,
|
||||
})}:${time.toLocaleString([], {
|
||||
minimumIntegerDigits: 2,
|
||||
maximumFractionDigits: 0,
|
||||
})}`;
|
||||
};
|
||||
|
||||
const handleDisplayTime = (ticks) => {
|
||||
let time = ticksToSec(ticks);
|
||||
const hr = Math.floor(time / 3600);
|
||||
time -= hr * 3600;
|
||||
const min = Math.floor(time / 60);
|
||||
time -= min * 60;
|
||||
return `${hr.toLocaleString([], {
|
||||
minimumIntegerDigits: 2,
|
||||
maximumFractionDigits: 0,
|
||||
})}:${min.toLocaleString([], {
|
||||
minimumIntegerDigits: 2,
|
||||
maximumFractionDigits: 0,
|
||||
})}:${time.toLocaleString([], {
|
||||
minimumIntegerDigits: 2,
|
||||
maximumFractionDigits: 0,
|
||||
})}`;
|
||||
};
|
||||
|
||||
const handlePlayNextEpisode = () => {
|
||||
// Reset Player time state
|
||||
setProgress(0);
|
||||
setCurrentTime(0);
|
||||
setIsPlaying(true);
|
||||
|
||||
setUserId(userId);
|
||||
|
||||
// Set all required stream index
|
||||
setAudioStreamIndex(0);
|
||||
setVideoStreamIndex(0);
|
||||
setSubtitleStreamIndex(0);
|
||||
|
||||
setMediaSourceId(episodes.data.Items[currentEpisodeIndex + 1].Id);
|
||||
|
||||
setUrl(
|
||||
`${api.basePath}/Videos/${episodes.data.Items[currentEpisodeIndex + 1].Id}/stream.
|
||||
${
|
||||
episodes.data.Items[currentEpisodeIndex + 1].MediaSources[0]
|
||||
.Container
|
||||
}
|
||||
?Static=true&mediaSourceId=${
|
||||
episodes.data.Items[currentEpisodeIndex + 1].Id
|
||||
}&deviceId=${api.deviceInfo.id}&api_key=${api.accessToken}&Tag=${
|
||||
episodes.data.Items[currentEpisodeIndex + 1].MediaSources[0].ETag
|
||||
}&videoStreamIndex=${0}&audioStreamIndex=${0}`,
|
||||
);
|
||||
setPosition(
|
||||
episodes.data.Items[currentEpisodeIndex + 1].UserData
|
||||
?.PlaybackPositionTicks,
|
||||
);
|
||||
|
||||
setSeriesId(episodes.data.Items[currentEpisodeIndex + 1].SeriesId);
|
||||
if (episodes.data.Items[currentEpisodeIndex + 1].ImageBlurHashes.Logo) {
|
||||
setItemName(
|
||||
<div className="video-osd-name">
|
||||
<img
|
||||
alt="Series Logo"
|
||||
src={`${api.basePath}/Items/${
|
||||
episodes.data.Items[currentEpisodeIndex + 1].SeriesId
|
||||
}/Images/Logo`}
|
||||
className="video-osd-name-logo"
|
||||
onLoad={(e) => {
|
||||
e.target.style.opacity = 1;
|
||||
}}
|
||||
/>
|
||||
<Typography variant="subtitle1">
|
||||
S{episodes.data.Items[currentEpisodeIndex + 1].ParentIndexNumber}
|
||||
:E
|
||||
{episodes.data.Items[currentEpisodeIndex + 1].IndexNumber}{" "}
|
||||
{episodes.data.Items[currentEpisodeIndex + 1].Name}
|
||||
</Typography>
|
||||
</div>,
|
||||
);
|
||||
} else {
|
||||
setItemName(
|
||||
<div className="video-osd-name">
|
||||
<Typography variant="h6">
|
||||
{episodes.data.Items[currentEpisodeIndex + 1].SeriesName}
|
||||
</Typography>
|
||||
<Typography variant="subtitle1">
|
||||
S{episodes.data.Items[currentEpisodeIndex + 1].ParentIndexNumber}
|
||||
:E
|
||||
{episodes.data.Items[currentEpisodeIndex + 1].IndexNumber}{" "}
|
||||
{episodes.data.Items[currentEpisodeIndex + 1].Name}
|
||||
</Typography>
|
||||
</div>,
|
||||
);
|
||||
}
|
||||
|
||||
setItemId(episodes.data.Items[currentEpisodeIndex + 1].Id);
|
||||
setDurationStore(episodes.data.Items[currentEpisodeIndex + 1].RunTimeTicks);
|
||||
};
|
||||
const handlePlayPrevEpisode = () => {
|
||||
// Reset video player state
|
||||
setProgress(0);
|
||||
setCurrentTime(0);
|
||||
setIsPlaying(true);
|
||||
|
||||
setUserId(userId);
|
||||
|
||||
// Set all required stream index
|
||||
setAudioStreamIndex(0);
|
||||
setVideoStreamIndex(0);
|
||||
setSubtitleStreamIndex(0);
|
||||
|
||||
setMediaSourceId(episodes.data.Items[currentEpisodeIndex - 1].Id);
|
||||
|
||||
setUrl(
|
||||
`${api.basePath}/Videos/${episodes.data.Items[currentEpisodeIndex - 1].Id}/stream.
|
||||
${
|
||||
episodes.data.Items[currentEpisodeIndex - 1].MediaSources[0]
|
||||
.Container
|
||||
}
|
||||
?Static=true&mediaSourceId=${
|
||||
episodes.data.Items[currentEpisodeIndex - 1].Id
|
||||
}&deviceId=${api.deviceInfo.id}&api_key=${api.accessToken}&Tag=${
|
||||
episodes.data.Items[currentEpisodeIndex - 1].MediaSources[0].ETag
|
||||
}&videoStreamIndex=${0}&audioStreamIndex=${0}`,
|
||||
);
|
||||
setPosition(
|
||||
episodes.data.Items[currentEpisodeIndex - 1].UserData
|
||||
?.PlaybackPositionTicks,
|
||||
);
|
||||
|
||||
setSeriesId(episodes.data.Items[currentEpisodeIndex - 1].SeriesId);
|
||||
if (episodes.data.Items[currentEpisodeIndex - 1].ImageBlurHashes.Logo) {
|
||||
setItemName(
|
||||
<div className="video-osd-name">
|
||||
<img
|
||||
alt="Series Logo"
|
||||
src={`${api.basePath}/Items/${
|
||||
episodes.data.Items[currentEpisodeIndex - 1].SeriesId
|
||||
}/Images/Logo`}
|
||||
className="video-osd-name-logo"
|
||||
onLoad={(e) => {
|
||||
e.target.style.opacity = 1;
|
||||
}}
|
||||
/>
|
||||
<Typography variant="subtitle1">
|
||||
S{episodes.data.Items[currentEpisodeIndex - 1].ParentIndexNumber}
|
||||
:E
|
||||
{episodes.data.Items[currentEpisodeIndex - 1].IndexNumber}{" "}
|
||||
{episodes.data.Items[currentEpisodeIndex - 1].Name}
|
||||
</Typography>
|
||||
</div>,
|
||||
);
|
||||
} else {
|
||||
setItemName(
|
||||
<div className="video-osd-name">
|
||||
<Typography variant="h6">
|
||||
{episodes.data.Items[currentEpisodeIndex - 1].SeriesName}
|
||||
</Typography>
|
||||
<Typography variant="subtitle1">
|
||||
S{episodes.data.Items[currentEpisodeIndex - 1].ParentIndexNumber}
|
||||
:E
|
||||
{episodes.data.Items[currentEpisodeIndex - 1].IndexNumber}{" "}
|
||||
{episodes.data.Items[currentEpisodeIndex - 1].Name}
|
||||
</Typography>
|
||||
</div>,
|
||||
);
|
||||
}
|
||||
|
||||
setItemId(episodes.data.Items[currentEpisodeIndex - 1].Id);
|
||||
setDurationStore(episodes.data.Items[currentEpisodeIndex - 1].RunTimeTicks);
|
||||
};
|
||||
|
||||
const [appFullscreen, setAppFullScreen] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (showControls) {
|
||||
const timeout = setTimeout(() => {
|
||||
setShowControls(false);
|
||||
}, 5000);
|
||||
return () => {
|
||||
clearTimeout(timeout);
|
||||
};
|
||||
}
|
||||
}, [showControls]);
|
||||
|
||||
const handleKeyPress = useCallback((event) => {
|
||||
switch (event.key) {
|
||||
case "ArrowRight":
|
||||
playerRef.current.seekTo(playerRef.current.getCurrentTime() + 15);
|
||||
break;
|
||||
case "ArrowLeft":
|
||||
playerRef.current.seekTo(playerRef.current.getCurrentTime() - 15);
|
||||
break;
|
||||
case " ":
|
||||
setIsPlaying((state) => !state);
|
||||
break;
|
||||
case "ArrowUp":
|
||||
setVolume((state) => (state <= 0.9 ? state + 0.1 : state));
|
||||
break;
|
||||
case "ArrowDown":
|
||||
setVolume((state) => (state >= 0.1 ? state - 0.1 : state));
|
||||
break;
|
||||
case "F":
|
||||
case "f":
|
||||
setAppFullScreen((state) => !state);
|
||||
break;
|
||||
case "P":
|
||||
case "p":
|
||||
setIsPIP((state) => !state);
|
||||
break;
|
||||
case "M":
|
||||
case "m":
|
||||
setIsMuted((state) => !state);
|
||||
break;
|
||||
default:
|
||||
console.log(event.key);
|
||||
break;
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
appWindow.setFullscreen(appFullscreen);
|
||||
}, [appFullscreen]);
|
||||
|
||||
useEffect(() => {
|
||||
// attach the event listener
|
||||
document.addEventListener("keydown", handleKeyPress);
|
||||
|
||||
// remove the event listener
|
||||
return () => {
|
||||
document.removeEventListener("keydown", handleKeyPress);
|
||||
};
|
||||
}, [handleKeyPress]);
|
||||
|
||||
const [showVolume, setShowVolume] = useState(false);
|
||||
|
||||
// Show/Hide volume Indicator
|
||||
useEffect(() => {
|
||||
setShowVolume(true);
|
||||
const timeout = setTimeout(() => {
|
||||
setShowVolume(false);
|
||||
}, 5000);
|
||||
return () => {
|
||||
clearTimeout(timeout);
|
||||
};
|
||||
}, []);
|
||||
|
||||
const handleExit = async () => {
|
||||
// Remove app from fullscreen
|
||||
await appWindow.setFullscreen(false);
|
||||
// Send playback end report
|
||||
await getPlaystateApi(api).reportPlaybackStopped({
|
||||
playbackStopInfo: {
|
||||
Failed: false,
|
||||
Item: item,
|
||||
ItemId: itemId,
|
||||
MediaSourceId: mediaInfo.data?.MediaSources[0].Id,
|
||||
PlaySessionId: mediaInfo.data?.PlaySessionId,
|
||||
PositionTicks: currentTime,
|
||||
},
|
||||
});
|
||||
|
||||
navigate(-1);
|
||||
|
||||
// Reset playback store
|
||||
setUrl("");
|
||||
setPosition(0);
|
||||
setDurationStore(0);
|
||||
setItemId("");
|
||||
setItemName("");
|
||||
setAudioStreamIndex(0);
|
||||
setVideoStreamIndex(0);
|
||||
setSubtitleStreamIndex(0);
|
||||
setMediaSourceId("");
|
||||
setUserId("");
|
||||
setSeriesId("");
|
||||
};
|
||||
|
||||
const handleOnEnd = () => {
|
||||
if (seriesId) {
|
||||
if (episodes.isSuccess && episodes.data.TotalRecordCount > 0) {
|
||||
handlePlayNextEpisode();
|
||||
}
|
||||
} else {
|
||||
handleExit();
|
||||
}
|
||||
};
|
||||
|
||||
const onProgress = async (e) => {
|
||||
if (!isSeeking) {
|
||||
setProgress(e.played);
|
||||
setCurrentTime(secToTicks(e.playedSeconds));
|
||||
}
|
||||
await getPlaystateApi(api).reportPlaybackProgress({
|
||||
playbackProgressInfo: {
|
||||
PlayMethod: mediaInfo.data?.MediaSources[0].SupportsDirectPlay
|
||||
? "DirectPlay"
|
||||
: mediaInfo.data?.MediaSources[0].SupportsDirectStream
|
||||
? "DirectStream"
|
||||
: "Transcode",
|
||||
ItemId: itemId,
|
||||
IsMuted: isMuted,
|
||||
PositionTicks: secToTicks(e.playedSeconds),
|
||||
PlaybackStartTimeTicks: startPosition,
|
||||
VolumeLevel: volume * 100,
|
||||
IsPaused: !isPlaying,
|
||||
AudioStreamIndex: audioStreamIndex,
|
||||
Brightness: 100,
|
||||
CanSeek: true,
|
||||
MediaSourceId: mediaInfo.data?.MediaSources[0].Id,
|
||||
SubtitleStreamIndex: subtitleStreamIndex,
|
||||
PlaySessionId: mediaInfo.data?.PlaySessionId,
|
||||
},
|
||||
});
|
||||
if (Math.round(e.playedSeconds) === ticksToSec(itemDuration)) {
|
||||
handleOnEnd();
|
||||
}
|
||||
};
|
||||
|
||||
if (!itemId) {
|
||||
return (
|
||||
<>
|
||||
<Navigate to="/library/index" />;
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
className="video-player-container"
|
||||
style={{ background: "black" }}
|
||||
onMouseMove={() => {
|
||||
setShowControls(true);
|
||||
}}
|
||||
key={itemId}
|
||||
>
|
||||
<AnimatePresence>
|
||||
{showVolume && (
|
||||
<motion.div
|
||||
initial={{ opacity: 0 }}
|
||||
animate={{ opacity: 1 }}
|
||||
exit={{ opacity: 0 }}
|
||||
style={{
|
||||
position: "absolute",
|
||||
top: "4em",
|
||||
right: "4em",
|
||||
background: "rgb(0 0 0/ 0.5)",
|
||||
backdropFilter: "blur(10px)",
|
||||
width: "10em",
|
||||
height: "10em",
|
||||
padding: "1em",
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
flexDirection: "column",
|
||||
borderRadius: "10px",
|
||||
border: "2px solid rgb(255 255 255 / 0.2)",
|
||||
gap: "2em",
|
||||
}}
|
||||
>
|
||||
<div
|
||||
className="material-symbols-rounded"
|
||||
style={{ fontSize: "2.8em" }}
|
||||
>
|
||||
{isMuted ? "volume_mute" : "volume_up"}
|
||||
</div>
|
||||
<LinearProgress
|
||||
variant="determinate"
|
||||
value={volume * 100}
|
||||
style={{
|
||||
width: "8em",
|
||||
margin: "0 1em",
|
||||
}}
|
||||
/>
|
||||
</motion.div>
|
||||
)}
|
||||
</AnimatePresence>
|
||||
<div
|
||||
style={{
|
||||
position: "absolute",
|
||||
inset: 0,
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
opacity: isBuffering ? 1 : 0,
|
||||
transition: "opacity 250ms",
|
||||
}}
|
||||
>
|
||||
<CircularProgress />
|
||||
</div>
|
||||
<Backdrop
|
||||
className={showControls ? "video-osd video-osd-visible" : "video-osd"}
|
||||
sx={{
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
zIndex: 1000,
|
||||
justifyContent: "space-between",
|
||||
background: "transparent",
|
||||
}}
|
||||
open={showControls}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
background:
|
||||
"linear-gradient(to bottom, rgb(0 0 0 / 0.75), transparent)",
|
||||
width: "100vw",
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
padding: "0.85em 1.2em",
|
||||
}}
|
||||
>
|
||||
<IconButton onClick={handleExit}>
|
||||
<span className="material-symbols-rounded">arrow_back</span>
|
||||
</IconButton>
|
||||
|
||||
{itemName}
|
||||
</div>
|
||||
<Stack
|
||||
direction="column"
|
||||
padding={2}
|
||||
width="100%"
|
||||
sx={{
|
||||
background:
|
||||
"linear-gradient(to top, rgb(0 0 0 / 0.75), transparent)",
|
||||
}}
|
||||
>
|
||||
<Stack
|
||||
width="100%"
|
||||
direction="row"
|
||||
alignItems="center"
|
||||
justifyContent="center"
|
||||
gap={2}
|
||||
>
|
||||
<Typography variant="h6">{handleDisplayCurrentTime()}</Typography>
|
||||
<Slider
|
||||
value={currentTime ? currentTime : 0}
|
||||
step={0.01}
|
||||
max={itemDuration}
|
||||
onChange={(e, newVal) => {
|
||||
setIsSeeking(true);
|
||||
setCurrentTime(newVal);
|
||||
}}
|
||||
onChangeCommitted={(e, newVal) => {
|
||||
playerRef.current.seekTo(ticksToSec(newVal));
|
||||
setCurrentTime(newVal);
|
||||
setIsSeeking(false);
|
||||
}}
|
||||
valueLabelDisplay="auto"
|
||||
valueLabelFormat={(value) => handleDisplayTime(value)}
|
||||
// size="medium"
|
||||
sx={{
|
||||
"& .MuiSlider-valueLabel": {
|
||||
lineHeight: 1.2,
|
||||
fontSize: 24,
|
||||
background: "rgb(0 0 0 / 0.5)",
|
||||
backdropFilter: "blur(5px)",
|
||||
padding: 1,
|
||||
borderRadius: "10px",
|
||||
border: "1px solid rgb(255 255 255 / 0.15)",
|
||||
boxShadow: "0 0 10px rgb(0 0 0 / 0.4) ",
|
||||
transform: "translatey(-120%) scale(0)",
|
||||
"&:before": { display: "none" },
|
||||
"&.MuiSlider-valueLabelOpen": {
|
||||
transform: "translateY(-120%) scale(1)",
|
||||
},
|
||||
"& > *": {
|
||||
transform: "rotate(0deg)",
|
||||
},
|
||||
},
|
||||
}}
|
||||
/>
|
||||
<Typography variant="h6">
|
||||
{handleDisplayTime(itemDuration)}
|
||||
</Typography>
|
||||
</Stack>
|
||||
<Stack
|
||||
direction="row"
|
||||
justifyContent="space-between"
|
||||
alignItems="center"
|
||||
>
|
||||
<Stack
|
||||
direction="row"
|
||||
gap={1}
|
||||
justifyContent="center"
|
||||
alignItems="center"
|
||||
>
|
||||
<IconButton
|
||||
onClick={handlePlayPrevEpisode}
|
||||
disabled={
|
||||
seriesId
|
||||
? episodes.isPending || currentEpisodeIndex === 0
|
||||
: true
|
||||
}
|
||||
>
|
||||
<div className="material-symbols-rounded">skip_previous</div>
|
||||
</IconButton>
|
||||
<IconButton
|
||||
onClick={() =>
|
||||
playerRef.current.seekTo(
|
||||
playerRef.current.getCurrentTime() - 15,
|
||||
)
|
||||
}
|
||||
>
|
||||
<div className="material-symbols-rounded">fast_rewind</div>
|
||||
</IconButton>
|
||||
<IconButton onClick={() => setIsPlaying((state) => !state)}>
|
||||
<div className="material-symbols-rounded">
|
||||
{isPlaying ? "pause" : "play_arrow"}
|
||||
</div>
|
||||
</IconButton>
|
||||
<IconButton
|
||||
onClick={() =>
|
||||
playerRef.current.seekTo(
|
||||
playerRef.current.getCurrentTime() + 15,
|
||||
)
|
||||
}
|
||||
>
|
||||
<div className="material-symbols-rounded">fast_forward</div>
|
||||
</IconButton>
|
||||
<IconButton
|
||||
onClick={handlePlayNextEpisode}
|
||||
disabled={
|
||||
seriesId
|
||||
? episodes.isPending ||
|
||||
episodes.data?.TotalRecordCount ===
|
||||
currentEpisodeIndex + 1
|
||||
: true
|
||||
}
|
||||
>
|
||||
<div className="material-symbols-rounded">skip_next</div>
|
||||
</IconButton>
|
||||
<Typography variant="subtitle1">
|
||||
{endsAt(itemDuration - currentTime)}
|
||||
</Typography>
|
||||
</Stack>
|
||||
<Stack
|
||||
direction="row"
|
||||
gap={1}
|
||||
alignItems="center"
|
||||
justifyContent="center"
|
||||
>
|
||||
<Box>
|
||||
<Menu
|
||||
anchorEl={speedMenuEl}
|
||||
open={speedMenuState}
|
||||
onClose={() => setSpeedMenuEl(null)}
|
||||
MenuListProps={{
|
||||
"aria-labelledby": "lock-button",
|
||||
role: "listbox",
|
||||
}}
|
||||
anchorOrigin={{
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
}}
|
||||
transformOrigin={{
|
||||
vertical: "bottom",
|
||||
horizontal: "center",
|
||||
}}
|
||||
sx={{
|
||||
mb: 20,
|
||||
}}
|
||||
>
|
||||
{availableSpeeds.map((sspeed, index) => {
|
||||
return (
|
||||
<MenuItem
|
||||
key={sspeed}
|
||||
selected={index === speed}
|
||||
onClick={() => {
|
||||
setSpeed(index);
|
||||
setSpeedMenuEl(null);
|
||||
}}
|
||||
sx={{
|
||||
width: 160,
|
||||
}}
|
||||
>
|
||||
{sspeed}x
|
||||
</MenuItem>
|
||||
);
|
||||
})}
|
||||
</Menu>
|
||||
<IconButton onClick={(e) => setSpeedMenuEl(e.currentTarget)}>
|
||||
<div className="material-symbols-rounded">pace</div>
|
||||
</IconButton>
|
||||
</Box>
|
||||
<IconButton
|
||||
sx={{
|
||||
ml: 0.1,
|
||||
}}
|
||||
onClick={() => setIsMuted((state) => !state)}
|
||||
>
|
||||
<div className="material-symbols-rounded">
|
||||
{isMuted ? "volume_mute" : "volume_up"}
|
||||
</div>
|
||||
</IconButton>
|
||||
<Slider
|
||||
value={isMuted ? 0 : volume * 100}
|
||||
step={1}
|
||||
max={100}
|
||||
onChange={(e, newVal) => setVolume(newVal / 100)}
|
||||
valueLabelDisplay="auto"
|
||||
valueLabelFormat={(value) => Math.floor(value)}
|
||||
size="small"
|
||||
sx={{
|
||||
mr: 1,
|
||||
ml: 1,
|
||||
width: "8em",
|
||||
"& .MuiSlider-valueLabel": {
|
||||
lineHeight: 1.2,
|
||||
fontSize: 24,
|
||||
background: "rgb(0 0 0 / 0.5)",
|
||||
backdropFilter: "blur(5px)",
|
||||
padding: 1,
|
||||
borderRadius: "10px",
|
||||
border: "1px solid rgb(255 255 255 / 0.15)",
|
||||
boxShadow: "0 0 10px rgb(0 0 0 / 0.4) ",
|
||||
transform: "translatey(-120%) scale(0)",
|
||||
"&:before": {
|
||||
display: "none",
|
||||
},
|
||||
"&.MuiSlider-valueLabelOpen": {
|
||||
transform: "translateY(-120%) scale(1)",
|
||||
},
|
||||
"& > *": {
|
||||
transform: "rotate(0deg)",
|
||||
},
|
||||
},
|
||||
}}
|
||||
/>
|
||||
<Box>
|
||||
<Menu
|
||||
anchorEl={settingsMenuEl}
|
||||
onClose={() => {
|
||||
setSettingsMenuEl(null);
|
||||
}}
|
||||
open={settingsMenuState}
|
||||
sx={{ padding: 2 }}
|
||||
>
|
||||
<Stack direction="row">
|
||||
<Typography variant="h6">Subtitle</Typography>
|
||||
</Stack>
|
||||
</Menu>
|
||||
<IconButton
|
||||
onClick={(e) => setSettingsMenuEl(e.currentTarget)}
|
||||
disabled
|
||||
>
|
||||
<div className="material-symbols-rounded">settings</div>
|
||||
</IconButton>
|
||||
</Box>
|
||||
<IconButton
|
||||
onClick={() => {
|
||||
setIsPIP(!isPIP);
|
||||
}}
|
||||
>
|
||||
<div className="material-symbols-rounded">
|
||||
picture_in_picture_alt
|
||||
</div>
|
||||
</IconButton>
|
||||
<IconButton
|
||||
onClick={async () => {
|
||||
const fstate = await appWindow.isFullscreen();
|
||||
setAppFullScreen(!fstate);
|
||||
}}
|
||||
>
|
||||
<div className="material-symbols-rounded">
|
||||
{appFullscreen ? "fullscreen_exit" : "fullscreen"}
|
||||
</div>
|
||||
</IconButton>
|
||||
</Stack>
|
||||
</Stack>
|
||||
</Stack>
|
||||
</Backdrop>
|
||||
<ReactPlayer
|
||||
ref={playerRef}
|
||||
width="100vw"
|
||||
height="100vh"
|
||||
playing={isPlaying}
|
||||
url={url}
|
||||
onProgress={onProgress}
|
||||
onReady={onReady}
|
||||
muted={isMuted}
|
||||
pip={isPIP}
|
||||
volume={volume}
|
||||
onBuffer={() => setIsBuffering(true)}
|
||||
onBufferEnd={() => setIsBuffering(false)}
|
||||
config={{
|
||||
file: {
|
||||
attributes: {
|
||||
crossOrigin: "true",
|
||||
},
|
||||
tracks: [
|
||||
{
|
||||
kind: "subtitles",
|
||||
src: `${api.basePath}/Videos/${itemId}/${itemId}/Subtitles/${currentSubtrack}/Stream.vtt?api_key=${api.accessToken}`,
|
||||
srcLang: "",
|
||||
default: true,
|
||||
mode: "showing",
|
||||
},
|
||||
],
|
||||
},
|
||||
}}
|
||||
playbackRate={availableSpeeds[speed]}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -46,3 +46,45 @@ video {
|
||||
text-shadow: 0 2px 10px rgb(0 0 0 / 0.8);
|
||||
}
|
||||
}
|
||||
|
||||
.video-player {
|
||||
background: black;
|
||||
position: absolute;
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
top: 0;
|
||||
left: 0;
|
||||
&-osd{
|
||||
position: absolute;
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
top: 0;
|
||||
left: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-self: stretch;
|
||||
justify-content: space-between;
|
||||
padding: 1em 2em;
|
||||
background: linear-gradient(to top, rgb(0 0 0 / 0.7) 5vh, transparent 26vh 90vh, rgb(0 0 0 / 0.7));
|
||||
&-controls{
|
||||
&-progress{
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.2em;
|
||||
align-items: stretch;
|
||||
justify-content: center;
|
||||
&-text{
|
||||
display: flex;
|
||||
align-items: stretch;
|
||||
justify-content: space-between;
|
||||
}
|
||||
margin-bottom: 0.5em;
|
||||
}
|
||||
&-buttons {
|
||||
display: flex;
|
||||
gap: 0.4em;
|
||||
align-items: center;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -152,7 +152,7 @@ h1 {
|
||||
--wght: 300;
|
||||
--grad: 25;
|
||||
--opsz: 40;
|
||||
|
||||
|
||||
font-variation-settings: "FILL" var(--fill, 0), "wght" var(--wght, 300), "GRAD" var(--grad, 25), "opsz" var(--opsz, 40);
|
||||
font-size: 1.1em;
|
||||
transition: all $transition-time-default;
|
||||
@@ -239,6 +239,12 @@ h1 {
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
&-align-center {
|
||||
align-items: center;
|
||||
}
|
||||
&-justify-spaced-between {
|
||||
justify-content: space-between;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes pulse {
|
||||
|
||||
+164
-94
@@ -1,106 +1,176 @@
|
||||
import { BaseItemDto } from "@jellyfin/sdk/lib/generated-client";
|
||||
import { create } from "zustand";
|
||||
import { setQueue, setTrackIndex } from "./queue";
|
||||
|
||||
export interface PlaybackState {
|
||||
url: string;
|
||||
startPosition: number;
|
||||
duration: number;
|
||||
itemId: string;
|
||||
itemName: string | Element;
|
||||
subtitleTracks: unknown[];
|
||||
selectedSubtitleTrack: number;
|
||||
mediaSourceId: string;
|
||||
audioStreamIndex: number;
|
||||
videoStreamIndex: number;
|
||||
subtitleStreamIndex: number;
|
||||
// export interface PlaybackState {
|
||||
// url: string;
|
||||
// startPosition: number;
|
||||
// duration: number;
|
||||
// itemId: string;
|
||||
// itemName: string | Element;
|
||||
// subtitleTracks: unknown[];
|
||||
// selectedSubtitleTrack: number;
|
||||
// mediaSourceId: string;
|
||||
// audioStreamIndex: number;
|
||||
// videoStreamIndex: number;
|
||||
// subtitleStreamIndex: number;
|
||||
// userId: string;
|
||||
// mediaContainer: string;
|
||||
// seriesId: string;
|
||||
// queue: unknown[];
|
||||
// episodeIndex: number;
|
||||
// item: BaseItemDto;
|
||||
// setUrl: (aurl: string) => void;
|
||||
// setPosition: (apos: number) => void;
|
||||
// setDuration: (adur: number) => void;
|
||||
// setItemId: (aid: string) => void;
|
||||
// setItemName: (anm: string | Element) => void;
|
||||
// setUserId: (anm: string) => void;
|
||||
// setSeriesId: (anm: string) => void;
|
||||
// setMediaContainer: (anm: string) => void;
|
||||
// setMediaSourceId: (anm: string) => void;
|
||||
// setAudioStreamIndex: (anm: number) => void;
|
||||
// setVideoStreamIndex: (anm: number) => void;
|
||||
// setSubtitleStreamIndex: (anm: number) => void;
|
||||
// setSubtitleTracks: (asub: unknown[]) => void;
|
||||
// setSelectedSubtitleTrack: (asub: number) => void;
|
||||
// setQueue: (qitem: unknown[]) => void;
|
||||
// setEpisodeIndex: (aitem: number) => void;
|
||||
// }
|
||||
|
||||
// export const usePlaybackStore = create<PlaybackState>((set) => ({
|
||||
// url: "",
|
||||
// startPosition: 0,
|
||||
// duration: 0,
|
||||
// itemId: "",
|
||||
// itemName: "",
|
||||
// subtitleTracks: [],
|
||||
// selectedSubtitleTrack: 0,
|
||||
// mediaSourceId: "",
|
||||
// audioStreamIndex: 0,
|
||||
// videoStreamIndex: 0,
|
||||
// subtitleStreamIndex: 0,
|
||||
// userId: "",
|
||||
// mediaContainer: "",
|
||||
// seriesId: "",
|
||||
// queue: [],
|
||||
// episodeIndex: 0,
|
||||
|
||||
// item: {} as BaseItemDto,
|
||||
// setUrl: (aurl: string) =>
|
||||
// set((state: PlaybackState) => ({ ...state, url: aurl })),
|
||||
// setPosition: (apos: number) =>
|
||||
// set((state: PlaybackState) => ({ ...state, startPosition: apos })),
|
||||
// setDuration: (adur: number) =>
|
||||
// set((state: PlaybackState) => ({ ...state, duration: adur })),
|
||||
// setItemId: (aid: string) =>
|
||||
// set((state: PlaybackState) => ({ ...state, itemId: aid })),
|
||||
// setItemName: (anm: string | Element) =>
|
||||
// set((state: PlaybackState) => ({ ...state, itemName: anm })),
|
||||
// setUserId: (anm: string) =>
|
||||
// set((state: PlaybackState) => ({ ...state, userId: anm })),
|
||||
// setSeriesId: (anm: string) =>
|
||||
// set((state: PlaybackState) => ({ ...state, seriesId: anm })),
|
||||
// setMediaContainer: (anm: string) =>
|
||||
// set((state: PlaybackState) => ({ ...state, mediaContainer: anm })),
|
||||
// setMediaSourceId: (anm: string) =>
|
||||
// set((state: PlaybackState) => ({ ...state, mediaSourceId: anm })),
|
||||
// setAudioStreamIndex: (anm: number) =>
|
||||
// set((state: PlaybackState) => ({ ...state, audioStreamIndex: anm })),
|
||||
// setVideoStreamIndex: (anm: number) =>
|
||||
// set((state: PlaybackState) => ({ ...state, videoStreamIndex: anm })),
|
||||
// setSubtitleStreamIndex: (anm: number) =>
|
||||
// set((state: PlaybackState) => ({ ...state, subtitleStreamIndex: anm })),
|
||||
// setSubtitleTracks: (asub: unknown[]) =>
|
||||
// set((state: PlaybackState) => ({
|
||||
// ...state,
|
||||
// subtitleTracks: asub,
|
||||
// })),
|
||||
// setSelectedSubtitleTrack: (asub: number) =>
|
||||
// set((state: PlaybackState) => ({
|
||||
// ...state,
|
||||
// selectedSubtitleTrack: asub,
|
||||
// })),
|
||||
// setQueue: (qitem: unknown[]) =>
|
||||
// set((state: PlaybackState) => ({ ...state, queue: qitem })),
|
||||
// setEpisodeIndex: (aitem: number) =>
|
||||
// set((state: PlaybackState) => ({ ...state, episodeIndex: aitem })),
|
||||
// }));
|
||||
|
||||
// export const setItem = (item: BaseItemDto) =>
|
||||
// usePlaybackStore.setState((state: PlaybackState) => ({
|
||||
// ...state,
|
||||
// item: item,
|
||||
// }));
|
||||
|
||||
type PlaybackStore = {
|
||||
itemName: string | React.Component;
|
||||
episodeTitle: string | React.Component;
|
||||
mediaSource: {
|
||||
videoTrack: number;
|
||||
audioTrack: number;
|
||||
subtitleTrack: number;
|
||||
container: string;
|
||||
};
|
||||
enableSubtitle: boolean;
|
||||
hlsStream: string;
|
||||
userId: string;
|
||||
mediaContainer: string;
|
||||
seriesId: string;
|
||||
queue: unknown[];
|
||||
episodeIndex: number;
|
||||
item: BaseItemDto;
|
||||
setUrl: (aurl: string) => void;
|
||||
setPosition: (apos: number) => void;
|
||||
setDuration: (adur: number) => void;
|
||||
setItemId: (aid: string) => void;
|
||||
setItemName: (anm: string | Element) => void;
|
||||
setUserId: (anm: string) => void;
|
||||
setSeriesId: (anm: string) => void;
|
||||
setMediaContainer: (anm: string) => void;
|
||||
setMediaSourceId: (anm: string) => void;
|
||||
setAudioStreamIndex: (anm: number) => void;
|
||||
setVideoStreamIndex: (anm: number) => void;
|
||||
setSubtitleStreamIndex: (anm: number) => void;
|
||||
setSubtitleTracks: (asub: unknown[]) => void;
|
||||
setSelectedSubtitleTrack: (asub: number) => void;
|
||||
setQueue: (qitem: unknown[]) => void;
|
||||
setEpisodeIndex: (aitem: number) => void;
|
||||
}
|
||||
startPosition: number;
|
||||
itemDuration: number;
|
||||
item: BaseItemDto | null;
|
||||
};
|
||||
|
||||
export const usePlaybackStore = create<PlaybackState>((set) => ({
|
||||
url: "",
|
||||
startPosition: 0,
|
||||
duration: 0,
|
||||
itemId: "",
|
||||
export const usePlaybackStore = create<PlaybackStore>(() => ({
|
||||
itemName: "",
|
||||
subtitleTracks: [],
|
||||
selectedSubtitleTrack: 0,
|
||||
mediaSourceId: "",
|
||||
audioStreamIndex: 0,
|
||||
videoStreamIndex: 0,
|
||||
subtitleStreamIndex: 0,
|
||||
episodeTitle: "",
|
||||
mediaSource: {
|
||||
videoTrack: 0,
|
||||
audioTrack: 0,
|
||||
subtitleTrack: 0,
|
||||
container: "",
|
||||
},
|
||||
enableSubtitle: true,
|
||||
hlsStream: "",
|
||||
userId: "",
|
||||
mediaContainer: "",
|
||||
seriesId: "",
|
||||
queue: [],
|
||||
episodeIndex: 0,
|
||||
|
||||
item: {} as BaseItemDto,
|
||||
setUrl: (aurl: string) =>
|
||||
set((state: PlaybackState) => ({ ...state, url: aurl })),
|
||||
setPosition: (apos: number) =>
|
||||
set((state: PlaybackState) => ({ ...state, startPosition: apos })),
|
||||
setDuration: (adur: number) =>
|
||||
set((state: PlaybackState) => ({ ...state, duration: adur })),
|
||||
setItemId: (aid: string) =>
|
||||
set((state: PlaybackState) => ({ ...state, itemId: aid })),
|
||||
setItemName: (anm: string | Element) =>
|
||||
set((state: PlaybackState) => ({ ...state, itemName: anm })),
|
||||
setUserId: (anm: string) =>
|
||||
set((state: PlaybackState) => ({ ...state, userId: anm })),
|
||||
setSeriesId: (anm: string) =>
|
||||
set((state: PlaybackState) => ({ ...state, seriesId: anm })),
|
||||
setMediaContainer: (anm: string) =>
|
||||
set((state: PlaybackState) => ({ ...state, mediaContainer: anm })),
|
||||
setMediaSourceId: (anm: string) =>
|
||||
set((state: PlaybackState) => ({ ...state, mediaSourceId: anm })),
|
||||
setAudioStreamIndex: (anm: number) =>
|
||||
set((state: PlaybackState) => ({ ...state, audioStreamIndex: anm })),
|
||||
setVideoStreamIndex: (anm: number) =>
|
||||
set((state: PlaybackState) => ({ ...state, videoStreamIndex: anm })),
|
||||
setSubtitleStreamIndex: (anm: number) =>
|
||||
set((state: PlaybackState) => ({ ...state, subtitleStreamIndex: anm })),
|
||||
setSubtitleTracks: (asub: unknown[]) =>
|
||||
set((state: PlaybackState) => ({
|
||||
...state,
|
||||
subtitleTracks: asub,
|
||||
})),
|
||||
setSelectedSubtitleTrack: (asub: number) =>
|
||||
set((state: PlaybackState) => ({
|
||||
...state,
|
||||
selectedSubtitleTrack: asub,
|
||||
})),
|
||||
setQueue: (qitem: unknown[]) =>
|
||||
set((state: PlaybackState) => ({ ...state, queue: qitem })),
|
||||
setEpisodeIndex: (aitem: number) =>
|
||||
set((state: PlaybackState) => ({ ...state, episodeIndex: aitem })),
|
||||
startPosition: 0,
|
||||
itemDuration: 0,
|
||||
item: null,
|
||||
}));
|
||||
|
||||
export const setItem = (item: BaseItemDto) =>
|
||||
usePlaybackStore.setState((state: PlaybackState) => ({
|
||||
...state,
|
||||
item: item,
|
||||
}));
|
||||
export const playItem = (
|
||||
itemName,
|
||||
episodeTitle,
|
||||
videoTrack,
|
||||
audioTrack,
|
||||
subtitleTrack,
|
||||
container,
|
||||
enableSubtitle,
|
||||
hlsStream,
|
||||
userId,
|
||||
startPosition,
|
||||
itemDuration,
|
||||
item,
|
||||
queue,
|
||||
queueItemIndex,
|
||||
) => {
|
||||
usePlaybackStore.setState({
|
||||
itemName,
|
||||
episodeTitle,
|
||||
mediaSource: {
|
||||
videoTrack,
|
||||
audioTrack,
|
||||
subtitleTrack,
|
||||
container,
|
||||
},
|
||||
enableSubtitle,
|
||||
hlsStream,
|
||||
userId,
|
||||
startPosition,
|
||||
itemDuration,
|
||||
item,
|
||||
});
|
||||
setQueue(queue, queueItemIndex);
|
||||
};
|
||||
|
||||
interface PlaybackDataLoadState {
|
||||
isPending: boolean;
|
||||
|
||||
+1
-9
@@ -5,15 +5,7 @@ import million from "million/compiler";
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
react(),
|
||||
svgr(),
|
||||
// million.vite({
|
||||
// auto: {
|
||||
// skip: [/ReactQueryDevtools/g],
|
||||
// },
|
||||
// }),
|
||||
],
|
||||
plugins: [react(), svgr()],
|
||||
css: {
|
||||
modules: {
|
||||
scopeBehaviour: "global",
|
||||
|
||||
Reference in new issue
Block a user