refactor: migrate to react-player v3, fixing multiple instance of video player being created
This commit is contained in:
9 files changed
+1016
-2233
No files matched your search
+1
-1
@@ -4,7 +4,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<script src="http://localhost:8097"></script>
|
<!-- <script src="http://localhost:8097"></script> -->
|
||||||
<title>Blink</title>
|
<title>Blink</title>
|
||||||
<style>
|
<style>
|
||||||
.app-loading {
|
.app-loading {
|
||||||
|
|||||||
+26
-28
@@ -18,34 +18,33 @@
|
|||||||
"@dnd-kit/sortable": "^10.0.0",
|
"@dnd-kit/sortable": "^10.0.0",
|
||||||
"@dnd-kit/utilities": "^3.2.2",
|
"@dnd-kit/utilities": "^3.2.2",
|
||||||
"@emotion/react": "^11.14.0",
|
"@emotion/react": "^11.14.0",
|
||||||
"@emotion/styled": "^11.14.0",
|
"@emotion/styled": "^11.14.1",
|
||||||
"@fontsource-variable/jetbrains-mono": "^5.2.6",
|
"@fontsource-variable/jetbrains-mono": "^5.2.6",
|
||||||
"@fontsource-variable/noto-sans": "^5.2.7",
|
"@fontsource-variable/noto-sans": "^5.2.7",
|
||||||
"@fontsource-variable/plus-jakarta-sans": "^5.2.6",
|
"@fontsource-variable/plus-jakarta-sans": "^5.2.6",
|
||||||
"@fontsource-variable/space-grotesk": "^5.2.8",
|
"@fontsource-variable/space-grotesk": "^5.2.8",
|
||||||
"@jellyfin/sdk": "0.11.0",
|
"@jellyfin/sdk": "0.11.0",
|
||||||
"@million/lint": "^1.0.14",
|
|
||||||
"@mui/lab": "7.0.0-beta.14",
|
"@mui/lab": "7.0.0-beta.14",
|
||||||
"@mui/material": "7.1.2",
|
"@mui/material": "7.2.0",
|
||||||
"@popperjs/core": "^2.11.8",
|
"@popperjs/core": "^2.11.8",
|
||||||
"@react-spring/web": "^10.0.1",
|
"@react-spring/web": "^10.0.1",
|
||||||
"@tanem/react-nprogress": "^5.0.55",
|
"@tanem/react-nprogress": "^5.0.55",
|
||||||
"@tanstack/react-form": "^1.12.3",
|
"@tanstack/react-form": "^1.12.4",
|
||||||
"@tanstack/react-query": "^5.81.2",
|
"@tanstack/react-query": "^5.81.5",
|
||||||
"@tanstack/react-query-devtools": "^5.81.2",
|
"@tanstack/react-query-devtools": "^5.81.5",
|
||||||
"@tanstack/react-router": "^1.121.34",
|
"@tanstack/react-router": "^1.123.2",
|
||||||
"@tanstack/react-router-devtools": "^1.121.34",
|
"@tanstack/react-router-devtools": "^1.123.2",
|
||||||
"@tanstack/react-virtual": "^3.13.11",
|
"@tanstack/react-virtual": "^3.13.12",
|
||||||
"@tauri-apps/api": "2.6.0",
|
"@tauri-apps/api": "2.6.0",
|
||||||
"@tauri-apps/plugin-clipboard-manager": "2.2.3",
|
"@tauri-apps/plugin-clipboard-manager": "2.3.0",
|
||||||
"@tauri-apps/plugin-dialog": "2.2.2",
|
"@tauri-apps/plugin-dialog": "2.3.0",
|
||||||
"@tauri-apps/plugin-notification": "2.2.3",
|
"@tauri-apps/plugin-notification": "2.3.0",
|
||||||
"@tauri-apps/plugin-process": "2.2.2",
|
"@tauri-apps/plugin-process": "2.3.0",
|
||||||
"@tauri-apps/plugin-store": "github:tauri-apps/tauri-plugin-store#v2",
|
"@tauri-apps/plugin-store": "github:tauri-apps/tauri-plugin-store#v2",
|
||||||
"@tauri-apps/plugin-updater": "2.8.1",
|
"@tauri-apps/plugin-updater": "2.9.0",
|
||||||
"@tauri-apps/plugin-upload": "2.2.2",
|
"@tauri-apps/plugin-upload": "2.3.0",
|
||||||
"@tauri-apps/plugin-window-state": "~2.2.3",
|
"@tauri-apps/plugin-window-state": "~2.3.0",
|
||||||
"@types/node": "^24.0.4",
|
"@types/node": "^24.0.8",
|
||||||
"@types/react": "^19.1.8",
|
"@types/react": "^19.1.8",
|
||||||
"@types/react-dom": "^19.1.6",
|
"@types/react-dom": "^19.1.6",
|
||||||
"axios": "^1.10.0",
|
"axios": "^1.10.0",
|
||||||
@@ -56,8 +55,7 @@
|
|||||||
"libpgs": "^0.8.1",
|
"libpgs": "^0.8.1",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"material-symbols": "^0.31.9",
|
"material-symbols": "^0.31.9",
|
||||||
"million": "^3.1.11",
|
"motion": "^12.22.0",
|
||||||
"motion": "^12.19.1",
|
|
||||||
"notistack": "^3.0.2",
|
"notistack": "^3.0.2",
|
||||||
"react": "^19.1.0",
|
"react": "^19.1.0",
|
||||||
"react-blurhash": "^0.3.0",
|
"react-blurhash": "^0.3.0",
|
||||||
@@ -68,21 +66,21 @@
|
|||||||
"react-intersection-observer": "^9.16.0",
|
"react-intersection-observer": "^9.16.0",
|
||||||
"react-markdown": "^10.1.0",
|
"react-markdown": "^10.1.0",
|
||||||
"react-multi-carousel": "^2.8.6",
|
"react-multi-carousel": "^2.8.6",
|
||||||
"react-player": "^2.16.0",
|
"react-player": "^3.0.0",
|
||||||
"remark-gfm": "^4.0.1",
|
"remark-gfm": "^4.0.1",
|
||||||
"typescript": "^5.8.3",
|
"typescript": "^5.8.3",
|
||||||
"vite-plugin-svgr": "^4.3.0",
|
"vite-plugin-svgr": "^4.3.0",
|
||||||
"wavesurfer.js": "^7.9.8",
|
"wavesurfer.js": "^7.9.9",
|
||||||
"zustand": "5.0.5"
|
"zustand": "5.0.6"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/plugin-proposal-optional-chaining-assign": "^7.27.1",
|
"@babel/plugin-proposal-optional-chaining-assign": "^7.27.1",
|
||||||
"@biomejs/biome": "^2.0.5",
|
"@biomejs/biome": "^2.0.6",
|
||||||
"@tanstack/router-cli": "^1.121.34",
|
"@tanstack/router-cli": "^1.123.2",
|
||||||
"@tanstack/router-devtools": "^1.121.34",
|
"@tanstack/router-devtools": "^1.123.2",
|
||||||
"@tanstack/router-vite-plugin": "^1.121.34",
|
"@tanstack/router-vite-plugin": "^1.123.2",
|
||||||
"@tauri-apps/cli": "2.6.0",
|
"@tauri-apps/cli": "2.6.2",
|
||||||
"@types/lodash": "^4.17.18",
|
"@types/lodash": "^4.17.19",
|
||||||
"@vitejs/plugin-react": "^4.6.0",
|
"@vitejs/plugin-react": "^4.6.0",
|
||||||
"babel-plugin-react-compiler": "19.1.0-rc.2",
|
"babel-plugin-react-compiler": "19.1.0-rc.2",
|
||||||
"eslint-plugin-react-hooks": "6.0.0-rc1",
|
"eslint-plugin-react-hooks": "6.0.0-rc1",
|
||||||
|
|||||||
Generated
+870
-2045
File diff suppressed because it is too large.
Load diff
@@ -4,21 +4,27 @@ import { useShallow } from "zustand/shallow";
|
|||||||
import { usePlaybackStore } from "@/utils/store/playback";
|
import { usePlaybackStore } from "@/utils/store/playback";
|
||||||
|
|
||||||
const SkipSegmentButton = () => {
|
const SkipSegmentButton = () => {
|
||||||
const { mediaSegments, currentSegmentIndex, skipSegment } = usePlaybackStore(
|
const { mediaSegments, currentSegmentIndex, skipSegment, activeSegmentId } =
|
||||||
|
usePlaybackStore(
|
||||||
useShallow((state) => ({
|
useShallow((state) => ({
|
||||||
mediaSegments: state.metadata.mediaSegments,
|
mediaSegments: state.metadata.mediaSegments,
|
||||||
currentSegmentIndex: state.nextSegmentIndex - 1,
|
currentSegmentIndex: state.nextSegmentIndex - 1,
|
||||||
skipSegment: state.skipSegment,
|
skipSegment: state.skipSegment,
|
||||||
|
activeSegmentId: state.activeSegmentId,
|
||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!mediaSegments?.Items?.length || currentSegmentIndex < 0) {
|
console.info("Active segment ID:", activeSegmentId);
|
||||||
|
console.info("Current segment index:", currentSegmentIndex);
|
||||||
|
console.info("Media segments:", mediaSegments?.Items);
|
||||||
|
if (
|
||||||
|
!mediaSegments?.Items?.length ||
|
||||||
|
currentSegmentIndex < 0 ||
|
||||||
|
!activeSegmentId
|
||||||
|
) {
|
||||||
return <></>; // No segments to skip
|
return <></>; // No segments to skip
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("Current Segment Index:", currentSegmentIndex);
|
|
||||||
console.log("Media Segments:", mediaSegments);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
@@ -38,4 +44,6 @@ const SkipSegmentButton = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default SkipSegmentButton;
|
const SkipSegmentButtonMemo = React.memo(SkipSegmentButton);
|
||||||
|
|
||||||
|
export default SkipSegmentButtonMemo;
|
||||||
+11
-15
@@ -1,12 +1,9 @@
|
|||||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||||
import { RouterProvider, createRouter } from "@tanstack/react-router";
|
import { createRouter, RouterProvider } from "@tanstack/react-router";
|
||||||
import React, { Suspense, useEffect } from "react";
|
import React from "react";
|
||||||
import ReactDOM from "react-dom/client";
|
import ReactDOM from "react-dom/client";
|
||||||
// Import the generated route tree
|
// Import the generated route tree
|
||||||
import { routeTree } from "./routeTree.gen";
|
import { routeTree } from "./routeTree.gen";
|
||||||
|
|
||||||
import { ErrorBoundary } from "react-error-boundary";
|
|
||||||
import { ErrorNotice } from "./components/notices/errorNotice/errorNotice";
|
|
||||||
import { ApiProvider, useApiInContext } from "./utils/store/api";
|
import { ApiProvider, useApiInContext } from "./utils/store/api";
|
||||||
import { CentralProvider, useCentralStore } from "./utils/store/central";
|
import { CentralProvider, useCentralStore } from "./utils/store/central";
|
||||||
|
|
||||||
@@ -54,7 +51,6 @@ declare module "@tanstack/react-router" {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// biome-ignore lint/nursery/useComponentExportOnlyModules : This is a valid use case for a component export
|
|
||||||
function ProviderWrapper() {
|
function ProviderWrapper() {
|
||||||
const [api, createApi, jellyfinSDK] = useApiInContext((s) => [
|
const [api, createApi, jellyfinSDK] = useApiInContext((s) => [
|
||||||
s.api,
|
s.api,
|
||||||
@@ -68,15 +64,15 @@ function ProviderWrapper() {
|
|||||||
if (api?.accessToken && !user?.Id) {
|
if (api?.accessToken && !user?.Id) {
|
||||||
fetchCurrentUser(api);
|
fetchCurrentUser(api);
|
||||||
}
|
}
|
||||||
useEffect(() => {
|
// useEffect(() => {
|
||||||
if (api) {
|
// if (api) {
|
||||||
console.log(`API is set - Route ${window.location.pathname}`);
|
// console.log(`API is set - Route ${window.location.pathname}`);
|
||||||
console.log(api);
|
// console.log(api);
|
||||||
} else {
|
// } else {
|
||||||
console.log(`API is not set - Route ${window.location.pathname}`);
|
// console.log(`API is not set - Route ${window.location.pathname}`);
|
||||||
}
|
// }
|
||||||
router.invalidate(); // This is a hack to force the router to re-evaluate the routes and re-run the beforeLoad functions
|
// router.invalidate(); // This is a hack to force the router to re-evaluate the routes and re-run the beforeLoad functions
|
||||||
}, [api]);
|
// }, [api]);
|
||||||
return (
|
return (
|
||||||
<RouterProvider
|
<RouterProvider
|
||||||
router={router}
|
router={router}
|
||||||
|
|||||||
+12
-11
@@ -1,12 +1,12 @@
|
|||||||
import { AppBar } from "@/components/appBar/appBar";
|
|
||||||
import NProgress from "@/components/nProgress";
|
|
||||||
import AudioPlayer from "@/components/playback/audioPlayer";
|
|
||||||
import Settings from "@/components/settings";
|
|
||||||
// import { EasterEgg } from "@/components/utils/easterEgg";
|
// import { EasterEgg } from "@/components/utils/easterEgg";
|
||||||
import { CssBaseline, ThemeProvider } from "@mui/material";
|
import { CssBaseline, ThemeProvider } from "@mui/material";
|
||||||
import { Outlet, createRootRouteWithContext } from "@tanstack/react-router";
|
import { createRootRouteWithContext, Outlet } from "@tanstack/react-router";
|
||||||
import { SnackbarProvider } from "notistack";
|
import { SnackbarProvider } from "notistack";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
import { AppBar } from "@/components/appBar/appBar";
|
||||||
|
// import NProgress from "@/components/nProgress";
|
||||||
|
import AudioPlayer from "@/components/playback/audioPlayer";
|
||||||
|
import Settings from "@/components/settings";
|
||||||
|
|
||||||
import "../styles/global.scss";
|
import "../styles/global.scss";
|
||||||
import { theme } from "@/theme";
|
import { theme } from "@/theme";
|
||||||
@@ -17,17 +17,18 @@ import "@fontsource-variable/noto-sans";
|
|||||||
import "@fontsource-variable/plus-jakarta-sans";
|
import "@fontsource-variable/plus-jakarta-sans";
|
||||||
|
|
||||||
import "material-symbols/rounded.scss";
|
import "material-symbols/rounded.scss";
|
||||||
import Backdrop from "@/components/backdrop";
|
|
||||||
import { ErrorNotice } from "@/components/notices/errorNotice/errorNotice";
|
|
||||||
import RouterLoading from "@/components/routerLoading";
|
|
||||||
import Updater from "@/components/updater";
|
|
||||||
import type { Api, Jellyfin } from "@jellyfin/sdk";
|
import type { Api, Jellyfin } from "@jellyfin/sdk";
|
||||||
import type { UserDto } from "@jellyfin/sdk/lib/generated-client";
|
import type { UserDto } from "@jellyfin/sdk/lib/generated-client";
|
||||||
import type { QueryClient } from "@tanstack/react-query";
|
import type { QueryClient } from "@tanstack/react-query";
|
||||||
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
|
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
|
||||||
import { TanStackRouterDevtools } from "@tanstack/react-router-devtools";
|
// import { TanStackRouterDevtools } from "@tanstack/react-router-devtools";
|
||||||
import { DndProvider } from "react-dnd";
|
import { DndProvider } from "react-dnd";
|
||||||
import { HTML5Backend } from "react-dnd-html5-backend";
|
import { HTML5Backend } from "react-dnd-html5-backend";
|
||||||
|
import Backdrop from "@/components/backdrop";
|
||||||
|
import { ErrorNotice } from "@/components/notices/errorNotice/errorNotice";
|
||||||
|
import RouterLoading from "@/components/routerLoading";
|
||||||
|
import Updater from "@/components/updater";
|
||||||
|
import { EasterEgg } from "@/components/utils/easterEgg";
|
||||||
|
|
||||||
type ApiContext = {
|
type ApiContext = {
|
||||||
api: Api | undefined;
|
api: Api | undefined;
|
||||||
@@ -46,7 +47,7 @@ export const Route = createRootRouteWithContext<ApiContext>()({
|
|||||||
<SnackbarProvider maxSnack={5}>
|
<SnackbarProvider maxSnack={5}>
|
||||||
<CssBaseline />
|
<CssBaseline />
|
||||||
<Settings />
|
<Settings />
|
||||||
{/* <EasterEgg /> */}
|
<EasterEgg />
|
||||||
{/* <NProgress /> */}
|
{/* <NProgress /> */}
|
||||||
|
|
||||||
<RouterLoading />
|
<RouterLoading />
|
||||||
|
|||||||
@@ -1,15 +1,8 @@
|
|||||||
import { getPlaystateApi } from "@jellyfin/sdk/lib/utils/api/playstate-api";
|
import { getPlaystateApi } from "@jellyfin/sdk/lib/utils/api/playstate-api";
|
||||||
import CircularProgress from "@mui/material/CircularProgress";
|
import CircularProgress from "@mui/material/CircularProgress";
|
||||||
import { WebviewWindow as appWindow } from "@tauri-apps/api/webviewWindow";
|
import { WebviewWindow as appWindow } from "@tauri-apps/api/webviewWindow";
|
||||||
import React, {
|
import React, { useCallback, useEffect, useRef, useState } from "react";
|
||||||
useCallback,
|
import ReactPlayer from "react-player";
|
||||||
useEffect,
|
|
||||||
// useLayoutEffect,
|
|
||||||
useMemo,
|
|
||||||
useRef,
|
|
||||||
useState,
|
|
||||||
} from "react";
|
|
||||||
import ReactPlayer from "react-player/lazy";
|
|
||||||
import { secToTicks, ticksToSec } from "@/utils/date/time";
|
import { secToTicks, ticksToSec } from "@/utils/date/time";
|
||||||
import { playItemFromQueue, usePlaybackStore } from "@/utils/store/playback";
|
import { playItemFromQueue, usePlaybackStore } from "@/utils/store/playback";
|
||||||
|
|
||||||
@@ -25,7 +18,7 @@ import wasmUrl from "jassub/dist/jassub-worker.wasm?url";
|
|||||||
import { PgsRenderer } from "libpgs";
|
import { PgsRenderer } from "libpgs";
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
import pgsWorkerUrl from "libpgs/dist/libpgs.worker.js?url";
|
import pgsWorkerUrl from "libpgs/dist/libpgs.worker.js?url";
|
||||||
import type { OnProgressProps } from "react-player/base";
|
// import type { OnProgressProps } from "react-player";
|
||||||
import { useShallow } from "zustand/shallow";
|
import { useShallow } from "zustand/shallow";
|
||||||
import SkipSegmentButton from "@/components/playback/videoPlayer/buttons/SkipSegmentButton";
|
import SkipSegmentButton from "@/components/playback/videoPlayer/buttons/SkipSegmentButton";
|
||||||
import VideoPlayerControls from "@/components/playback/videoPlayer/controls";
|
import VideoPlayerControls from "@/components/playback/videoPlayer/controls";
|
||||||
@@ -88,14 +81,14 @@ function addSubtitleTrackToReactPlayer(
|
|||||||
export function VideoPlayer() {
|
export function VideoPlayer() {
|
||||||
const api = useApiInContext((s) => s.api);
|
const api = useApiInContext((s) => s.api);
|
||||||
const { history } = useRouter();
|
const { history } = useRouter();
|
||||||
const player = useRef<ReactPlayer | null>(null);
|
const player = useRef<HTMLVideoElement | null>(null);
|
||||||
|
|
||||||
const user = useCentralStore((s) => s.currentUser);
|
const user = useCentralStore((s) => s.currentUser);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
itemId,
|
itemId,
|
||||||
userDataLastPlayedPositionTicks,
|
userDataLastPlayedPositionTicks,
|
||||||
mediaSegments,
|
// mediaSegments,
|
||||||
setCurrentTime,
|
setCurrentTime,
|
||||||
volume,
|
volume,
|
||||||
isPlayerPlaying,
|
isPlayerPlaying,
|
||||||
@@ -106,10 +99,10 @@ export function VideoPlayer() {
|
|||||||
playsessionId,
|
playsessionId,
|
||||||
toggleIsPlaying,
|
toggleIsPlaying,
|
||||||
toggleIsPlayerMuted,
|
toggleIsPlayerMuted,
|
||||||
nextSegmentIndex,
|
// nextSegmentIndex,
|
||||||
activeSegmentId,
|
// activeSegmentId,
|
||||||
clearActiveSegment,
|
// clearActiveSegment,
|
||||||
setActiveSegment,
|
// setActiveSegment,
|
||||||
playbackStream,
|
playbackStream,
|
||||||
setIsBuffering,
|
setIsBuffering,
|
||||||
registerPlayerActions,
|
registerPlayerActions,
|
||||||
@@ -119,7 +112,7 @@ export function VideoPlayer() {
|
|||||||
itemId: state.metadata.item?.Id,
|
itemId: state.metadata.item?.Id,
|
||||||
userDataLastPlayedPositionTicks:
|
userDataLastPlayedPositionTicks:
|
||||||
state.metadata.userDataLastPlayedPositionTicks,
|
state.metadata.userDataLastPlayedPositionTicks,
|
||||||
mediaSegments: state.metadata.mediaSegments,
|
// mediaSegments: state.metadata.mediaSegments,
|
||||||
setCurrentTime: state.setCurrentTime,
|
setCurrentTime: state.setCurrentTime,
|
||||||
volume: state.playerState.volume,
|
volume: state.playerState.volume,
|
||||||
isPlayerPlaying: state.playerState.isPlayerPlaying,
|
isPlayerPlaying: state.playerState.isPlayerPlaying,
|
||||||
@@ -132,10 +125,10 @@ export function VideoPlayer() {
|
|||||||
toggleIsPlaying: state.toggleIsPlaying,
|
toggleIsPlaying: state.toggleIsPlaying,
|
||||||
toggleIsPlayerMuted: state.toggleIsPlayerMuted,
|
toggleIsPlayerMuted: state.toggleIsPlayerMuted,
|
||||||
toggleIsPlayerFullscreen: state.toggleIsPlayerFullscreen,
|
toggleIsPlayerFullscreen: state.toggleIsPlayerFullscreen,
|
||||||
nextSegmentIndex: state.nextSegmentIndex,
|
// nextSegmentIndex: state.nextSegmentIndex,
|
||||||
activeSegmentId: state.activeSegmentId,
|
// activeSegmentId: state.activeSegmentId,
|
||||||
clearActiveSegment: state.clearActiveSegment,
|
// clearActiveSegment: state.clearActiveSegment,
|
||||||
setActiveSegment: state.setActiveSegment,
|
// setActiveSegment: state.setActiveSegment,
|
||||||
playbackStream: state.playbackStream,
|
playbackStream: state.playbackStream,
|
||||||
setIsBuffering: state.setIsBuffering,
|
setIsBuffering: state.setIsBuffering,
|
||||||
registerPlayerActions: state.registerPlayerActions,
|
registerPlayerActions: state.registerPlayerActions,
|
||||||
@@ -152,26 +145,23 @@ export function VideoPlayer() {
|
|||||||
|
|
||||||
const handleReady = async () => {
|
const handleReady = async () => {
|
||||||
if (api && !isPlayerReady && player.current) {
|
if (api && !isPlayerReady && player.current) {
|
||||||
player.current.seekTo(
|
player.current.fastSeek(ticksToSec(userDataLastPlayedPositionTicks ?? 0));
|
||||||
ticksToSec(userDataLastPlayedPositionTicks ?? 0),
|
|
||||||
"seconds",
|
|
||||||
);
|
|
||||||
registerPlayerActions({
|
registerPlayerActions({
|
||||||
seekTo: (seconds: number) => {
|
seekTo: (seconds: number) => {
|
||||||
const internalPlayer = player.current;
|
const internalPlayer = player.current;
|
||||||
internalPlayer?.seekTo(seconds, "seconds");
|
if (internalPlayer) {
|
||||||
|
internalPlayer.currentTime = seconds;
|
||||||
console.log("Seeking to", seconds, "seconds");
|
console.log("Seeking to", seconds, "seconds");
|
||||||
|
}
|
||||||
|
console.warn("ReactPlayer is not ready yet");
|
||||||
// If you want to report the seek action
|
// If you want to report the seek action
|
||||||
// if (internalPlayer && typeof internalPlayer.seekTo === "function") {
|
// if (internalPlayer && typeof internalPlayer.seekTo === "function") {
|
||||||
// }
|
// }
|
||||||
},
|
},
|
||||||
getCurrentTime: () => {
|
getCurrentTime: () => {
|
||||||
const internalPlayer = player.current;
|
const internalPlayer = player.current;
|
||||||
if (
|
if (internalPlayer) {
|
||||||
internalPlayer &&
|
return internalPlayer.currentTime;
|
||||||
typeof internalPlayer.getCurrentTime === "function"
|
|
||||||
) {
|
|
||||||
return internalPlayer.getCurrentTime();
|
|
||||||
}
|
}
|
||||||
console.warn("ReactPlayer is not ready yet");
|
console.warn("ReactPlayer is not ready yet");
|
||||||
return 0;
|
return 0;
|
||||||
@@ -199,29 +189,10 @@ export function VideoPlayer() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleProgress = useCallback(
|
const handleTimeUpdate = useCallback(async () => {
|
||||||
async (event: OnProgressProps) => {
|
const ticks = secToTicks(player.current?.currentTime ?? 0);
|
||||||
const ticks = secToTicks(event.playedSeconds);
|
|
||||||
|
|
||||||
if (activeSegmentId) {
|
setCurrentTime(ticks);
|
||||||
const activeSegment = mediaSegments?.Items?.find(
|
|
||||||
(s) => s.Id === activeSegmentId,
|
|
||||||
);
|
|
||||||
// If the current time is past the active segment's end time, clear it.
|
|
||||||
if (activeSegment && ticks > (activeSegment.EndTicks ?? ticks)) {
|
|
||||||
clearActiveSegment();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nextSegmentIndex !== -1) {
|
|
||||||
const nextSegment = mediaSegments?.Items?.[nextSegmentIndex];
|
|
||||||
if (nextSegment && ticks >= (nextSegment.StartTicks ?? ticks)) {
|
|
||||||
clearActiveSegment();
|
|
||||||
setActiveSegment(nextSegmentIndex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setCurrentTime(secToTicks(event.playedSeconds));
|
|
||||||
if (!api) {
|
if (!api) {
|
||||||
console.warn("API is not available, cannot report playback progress.");
|
console.warn("API is not available, cannot report playback progress.");
|
||||||
return;
|
return;
|
||||||
@@ -233,20 +204,18 @@ export function VideoPlayer() {
|
|||||||
AudioStreamIndex: mediaSource.audioTrack,
|
AudioStreamIndex: mediaSource.audioTrack,
|
||||||
CanSeek: true,
|
CanSeek: true,
|
||||||
IsMuted: isPlayerMuted,
|
IsMuted: isPlayerMuted,
|
||||||
IsPaused: player.current?.getInternalPlayer()?.paused,
|
IsPaused: player.current?.paused,
|
||||||
ItemId: itemId,
|
ItemId: itemId,
|
||||||
MediaSourceId: mediaSource.id,
|
MediaSourceId: mediaSource.id,
|
||||||
PlayMethod: PlayMethod.DirectPlay,
|
PlayMethod: PlayMethod.DirectPlay,
|
||||||
PlaySessionId: playsessionId,
|
PlaySessionId: playsessionId,
|
||||||
PlaybackStartTimeTicks: userDataLastPlayedPositionTicks,
|
PlaybackStartTimeTicks: userDataLastPlayedPositionTicks,
|
||||||
PositionTicks: secToTicks(event.playedSeconds),
|
PositionTicks: ticks,
|
||||||
RepeatMode: RepeatMode.RepeatNone,
|
RepeatMode: RepeatMode.RepeatNone,
|
||||||
VolumeLevel: Math.floor(volume * 100),
|
VolumeLevel: Math.floor(volume * 100),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
}, [setCurrentTime]);
|
||||||
[setCurrentTime],
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleExitPlayer = useCallback(async () => {
|
const handleExitPlayer = useCallback(async () => {
|
||||||
appWindow.getCurrent().setFullscreen(false);
|
appWindow.getCurrent().setFullscreen(false);
|
||||||
@@ -256,29 +225,28 @@ export function VideoPlayer() {
|
|||||||
throw Error("API is not available, cannot report playback stopped.");
|
throw Error("API is not available, cannot report playback stopped.");
|
||||||
}
|
}
|
||||||
// Report Jellyfin server: Playback has ended/stopped
|
// Report Jellyfin server: Playback has ended/stopped
|
||||||
/* getPlaystateApi(api).reportPlaybackStopped({
|
getPlaystateApi(api).reportPlaybackStopped({
|
||||||
playbackStopInfo: {
|
playbackStopInfo: {
|
||||||
Failed: false,
|
Failed: false,
|
||||||
ItemId: itemId,
|
ItemId: itemId,
|
||||||
MediaSourceId: mediaSource.id,
|
MediaSourceId: mediaSource.id,
|
||||||
PlaySessionId: playsessionId,
|
PlaySessionId: playsessionId,
|
||||||
PositionTicks: secToTicks(player.current?.getCurrentTime() ?? 0),
|
PositionTicks: secToTicks(player.current?.currentTime ?? 0),
|
||||||
},
|
},
|
||||||
}); */
|
});
|
||||||
usePlaybackStore.setState(usePlaybackStore.getInitialState());
|
usePlaybackStore.setState(usePlaybackStore.getInitialState());
|
||||||
clearQueue();
|
clearQueue();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleKeyPress = useCallback(
|
const handleKeyPress = useCallback((event: KeyboardEvent) => {
|
||||||
(event: KeyboardEvent) => {
|
|
||||||
if (player.current) {
|
if (player.current) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
switch (event.key) {
|
switch (event.key) {
|
||||||
case "ArrowRight":
|
case "ArrowRight":
|
||||||
player.current.seekTo(player.current.getCurrentTime() + 10);
|
player.current.currentTime = player.current.currentTime + 10;
|
||||||
break;
|
break;
|
||||||
case "ArrowLeft":
|
case "ArrowLeft":
|
||||||
player.current.seekTo(player.current.getCurrentTime() - 10);
|
player.current.currentTime = player.current.currentTime - 10;
|
||||||
break;
|
break;
|
||||||
case "F8":
|
case "F8":
|
||||||
case " ":
|
case " ":
|
||||||
@@ -312,9 +280,7 @@ export function VideoPlayer() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}, []);
|
||||||
[player.current?.seekTo],
|
|
||||||
);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// attach the event listener
|
// attach the event listener
|
||||||
@@ -328,7 +294,7 @@ export function VideoPlayer() {
|
|||||||
|
|
||||||
// Manage Subtitle playback
|
// Manage Subtitle playback
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (player.current?.getInternalPlayer() && mediaSource.subtitle.enable) {
|
if (player.current && mediaSource.subtitle.enable) {
|
||||||
let jassubRenderer: JASSUB | undefined;
|
let jassubRenderer: JASSUB | undefined;
|
||||||
let pgsRenderer: PgsRenderer | undefined;
|
let pgsRenderer: PgsRenderer | undefined;
|
||||||
if (
|
if (
|
||||||
@@ -337,7 +303,7 @@ export function VideoPlayer() {
|
|||||||
) {
|
) {
|
||||||
jassubRenderer = new JASSUB({
|
jassubRenderer = new JASSUB({
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
video: player.current?.getInternalPlayer(),
|
video: player.current,
|
||||||
workerUrl,
|
workerUrl,
|
||||||
wasmUrl,
|
wasmUrl,
|
||||||
subUrl: `${api?.basePath}${mediaSource.subtitle.url}`,
|
subUrl: `${api?.basePath}${mediaSource.subtitle.url}`,
|
||||||
@@ -349,14 +315,14 @@ export function VideoPlayer() {
|
|||||||
mediaSource.subtitle.format === "vtt"
|
mediaSource.subtitle.format === "vtt"
|
||||||
) {
|
) {
|
||||||
addSubtitleTrackToReactPlayer(
|
addSubtitleTrackToReactPlayer(
|
||||||
player.current.getInternalPlayer() as HTMLMediaElement,
|
player.current as HTMLMediaElement,
|
||||||
mediaSource.subtitle,
|
mediaSource.subtitle,
|
||||||
api?.basePath ?? "",
|
api?.basePath ?? "",
|
||||||
);
|
);
|
||||||
} else if (mediaSource.subtitle.format === "PGSSUB") {
|
} else if (mediaSource.subtitle.format === "PGSSUB") {
|
||||||
pgsRenderer = new PgsRenderer({
|
pgsRenderer = new PgsRenderer({
|
||||||
workerUrl: pgsWorkerUrl,
|
workerUrl: pgsWorkerUrl,
|
||||||
video: player.current?.getInternalPlayer() as any,
|
video: player.current as any,
|
||||||
subUrl: `${api?.basePath}${mediaSource.subtitle.url}`,
|
subUrl: `${api?.basePath}${mediaSource.subtitle.url}`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -369,27 +335,15 @@ export function VideoPlayer() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (
|
if (player.current && mediaSource.subtitle.enable === false) {
|
||||||
player.current?.getInternalPlayer() &&
|
|
||||||
mediaSource.subtitle.enable === false
|
|
||||||
) {
|
|
||||||
// @ts-ignore internalPlayer here provides the HTML video player element
|
// @ts-ignore internalPlayer here provides the HTML video player element
|
||||||
const videoElem: HTMLMediaElement =
|
const videoElem: HTMLMediaElement = player.current as HTMLMediaElement;
|
||||||
player.current.getInternalPlayer() as HTMLMediaElement;
|
|
||||||
for (const i of videoElem.textTracks) {
|
for (const i of videoElem.textTracks) {
|
||||||
i.mode = "hidden";
|
i.mode = "hidden";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [mediaSource.subtitle?.track, mediaSource.subtitle?.enable]);
|
}, [mediaSource.subtitle?.track, mediaSource.subtitle?.enable]);
|
||||||
|
|
||||||
// const chapterMarks = useMemo(() => {
|
|
||||||
// const marks: { value: number }[] = [];
|
|
||||||
// item?.Chapters?.map((val) => {
|
|
||||||
// marks.push({ value: val.StartPositionTicks ?? 0 });
|
|
||||||
// });
|
|
||||||
// return marks;
|
|
||||||
// }, [item?.Chapters]);
|
|
||||||
|
|
||||||
const handlePlaybackEnded = useCallback(() => {
|
const handlePlaybackEnded = useCallback(() => {
|
||||||
if (queue?.length !== currentQueueItemIndex + 1) {
|
if (queue?.length !== currentQueueItemIndex + 1) {
|
||||||
playItemFromQueue("next", user?.Id, api);
|
playItemFromQueue("next", user?.Id, api);
|
||||||
@@ -451,19 +405,6 @@ export function VideoPlayer() {
|
|||||||
setAreControlsVisible(false);
|
setAreControlsVisible(false);
|
||||||
}, [clearIdleTimer]);
|
}, [clearIdleTimer]);
|
||||||
|
|
||||||
const playerConfig = useMemo(
|
|
||||||
() => ({
|
|
||||||
file: {
|
|
||||||
attributes: {
|
|
||||||
crossOrigin: "anonymous",
|
|
||||||
preload: "metadata",
|
|
||||||
},
|
|
||||||
tracks: [],
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
[],
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleOnBuffer = useCallback(() => {
|
const handleOnBuffer = useCallback(() => {
|
||||||
setIsBuffering(true);
|
setIsBuffering(true);
|
||||||
}, [setIsBuffering]);
|
}, [setIsBuffering]);
|
||||||
@@ -471,16 +412,6 @@ export function VideoPlayer() {
|
|||||||
setIsBuffering(false);
|
setIsBuffering(false);
|
||||||
}, [setIsBuffering]);
|
}, [setIsBuffering]);
|
||||||
|
|
||||||
const handleError = useCallback(
|
|
||||||
(error: any, data: any, hls: any, hlsG: any) => {
|
|
||||||
console.error(error.target.error);
|
|
||||||
console.error(data);
|
|
||||||
console.error(hls);
|
|
||||||
console.error(hlsG);
|
|
||||||
},
|
|
||||||
[],
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!playbackStream) {
|
if (!playbackStream) {
|
||||||
return (
|
return (
|
||||||
<div className="video-player">
|
<div className="video-player">
|
||||||
@@ -516,11 +447,11 @@ export function VideoPlayer() {
|
|||||||
<ReactPlayer
|
<ReactPlayer
|
||||||
key={playsessionId}
|
key={playsessionId}
|
||||||
playing={isPlayerPlaying}
|
playing={isPlayerPlaying}
|
||||||
url={playbackStream}
|
src={playbackStream}
|
||||||
ref={player}
|
ref={player}
|
||||||
onReady={handleReady}
|
onReady={handleReady}
|
||||||
onProgress={handleProgress}
|
onTimeUpdate={handleTimeUpdate}
|
||||||
onError={handleError}
|
// onError={handleError}
|
||||||
onEnded={handlePlaybackEnded}
|
onEnded={handlePlaybackEnded}
|
||||||
width="100vw"
|
width="100vw"
|
||||||
height="100vh"
|
height="100vh"
|
||||||
@@ -529,10 +460,9 @@ export function VideoPlayer() {
|
|||||||
zIndex: 1,
|
zIndex: 1,
|
||||||
}}
|
}}
|
||||||
volume={isPlayerMuted ? 0 : volume}
|
volume={isPlayerMuted ? 0 : volume}
|
||||||
onBuffer={handleOnBuffer}
|
onWaiting={handleOnBuffer}
|
||||||
onBufferEnd={handleOnBufferEnd}
|
onPlaying={handleOnBufferEnd}
|
||||||
playsinline
|
playsInline
|
||||||
config={playerConfig}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -339,10 +339,38 @@ export const usePlaybackStore = create<
|
|||||||
set((state) => {
|
set((state) => {
|
||||||
state.playerState.isBuffering = isBuffering;
|
state.playerState.isBuffering = isBuffering;
|
||||||
}),
|
}),
|
||||||
setCurrentTime: (currentTime) =>
|
setCurrentTime: (ticks) => {
|
||||||
|
const { nextSegmentIndex, activeSegmentId, metadata } = get();
|
||||||
|
if (activeSegmentId) {
|
||||||
|
const activeSegment = metadata.mediaSegments?.Items?.find(
|
||||||
|
(s) => s.Id === activeSegmentId,
|
||||||
|
);
|
||||||
|
if (activeSegment && ticks > (activeSegment.EndTicks ?? ticks)) {
|
||||||
|
// If the current time is past the active segment's end time, clear it.
|
||||||
set((state) => {
|
set((state) => {
|
||||||
state.playerState.currentTime = currentTime;
|
state.activeSegmentId = null;
|
||||||
}),
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nextSegmentIndex !== -1) {
|
||||||
|
const nextSegment = metadata.mediaSegments?.Items?.[nextSegmentIndex];
|
||||||
|
console.info("Next segment:", nextSegment);
|
||||||
|
if (nextSegment && ticks >= (nextSegment.StartTicks ?? ticks + 1)) {
|
||||||
|
// If the current time is past the next segment's start time, set it as active.
|
||||||
|
// clearActiveSegment();
|
||||||
|
set((state) => {
|
||||||
|
state.activeSegmentId = null;
|
||||||
|
state.nextSegmentIndex = nextSegmentIndex + 1;
|
||||||
|
state.activeSegmentId = nextSegment?.Id ?? null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
set((state) => {
|
||||||
|
state.playerState.currentTime = ticks;
|
||||||
|
});
|
||||||
|
},
|
||||||
setPlayerReady: (isPlayerReady) =>
|
setPlayerReady: (isPlayerReady) =>
|
||||||
set((state) => {
|
set((state) => {
|
||||||
state.playerState.isPlayerReady = isPlayerReady;
|
state.playerState.isPlayerReady = isPlayerReady;
|
||||||
@@ -533,7 +561,8 @@ export const usePlaybackStore = create<
|
|||||||
console.warn("No segment to skip");
|
console.warn("No segment to skip");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
get()._playerActions.seekTo(activeSegment.EndTicks ?? 0);
|
console.info("Skipping segment:", activeSegment);
|
||||||
|
get()._playerActions.seekTo(ticksToSec(activeSegment.EndTicks ?? 0));
|
||||||
},
|
},
|
||||||
handleStartSeek: (ticks) => {
|
handleStartSeek: (ticks) => {
|
||||||
set((state) => {
|
set((state) => {
|
||||||
@@ -547,7 +576,7 @@ export const usePlaybackStore = create<
|
|||||||
// Update current time to the new seek value
|
// Update current time to the new seek value
|
||||||
set((state) => {
|
set((state) => {
|
||||||
state.playerState.isUserSeeking = false;
|
state.playerState.isUserSeeking = false;
|
||||||
state.playerState.currentTime = ticks;
|
// state.playerState.currentTime = ticks;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
})),
|
})),
|
||||||
|
|||||||
+2
-6
@@ -2,7 +2,7 @@ import { defineConfig } from "vite";
|
|||||||
import react from "@vitejs/plugin-react";
|
import react from "@vitejs/plugin-react";
|
||||||
import svgr from "vite-plugin-svgr";
|
import svgr from "vite-plugin-svgr";
|
||||||
import { tanstackRouter } from '@tanstack/router-vite-plugin'
|
import { tanstackRouter } from '@tanstack/router-vite-plugin'
|
||||||
import MillionLint from "@million/lint";
|
// import MillionLint from "@million/lint";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
|
||||||
// const ReactCompilerConfig = {compilationMode: "annotation"}
|
// const ReactCompilerConfig = {compilationMode: "annotation"}
|
||||||
@@ -20,11 +20,7 @@ const plugins = [react({
|
|||||||
}],
|
}],
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
}), svgr(), tanstackRouter(), MillionLint.vite({
|
}), svgr(), tanstackRouter()];
|
||||||
// Enable Million's linting capabilities
|
|
||||||
enabled: true,
|
|
||||||
|
|
||||||
})];
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: plugins,
|
plugins: plugins,
|
||||||
css: {
|
css: {
|
||||||
|
|||||||
Reference in new issue
Block a user