Use react-player instead of videojs #10
This commit is contained in:
6 files changed
+107
-2125
No files matched your search
Generated
+39
@@ -30,6 +30,7 @@
|
||||
"react-konami-code": "^2.3.0",
|
||||
"react-material-ui-carousel": "^3.4.2",
|
||||
"react-multi-carousel": "^2.8.3",
|
||||
"react-player": "^2.12.0",
|
||||
"react-router-dom": "^6.11.0",
|
||||
"tauri-plugin-store-api": "github:tauri-apps/tauri-plugin-store",
|
||||
"uuid": "^9.0.0",
|
||||
@@ -2151,6 +2152,14 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/deepmerge": {
|
||||
"version": "4.3.1",
|
||||
"resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-4.3.1.tgz",
|
||||
"integrity": "sha512-3sUqbMEc77XqpdNO7FRyRog+eW3ph+GYCbj+rK+uYyRMuwsVy0rMiVtPn+QJlKFvWP/1PYpapqYn0Me2knFn+A==",
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/delayed-stream": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
|
||||
@@ -2616,6 +2625,11 @@
|
||||
"resolved": "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.2.4.tgz",
|
||||
"integrity": "sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg=="
|
||||
},
|
||||
"node_modules/load-script": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/load-script/-/load-script-1.0.0.tgz",
|
||||
"integrity": "sha512-kPEjMFtZvwL9TaZo0uZ2ml+Ye9HUMmPwbYRJ324qF9tqMejwykJ5ggTyvzmrbBeapCAbk98BSbTeovHEEP1uCA=="
|
||||
},
|
||||
"node_modules/loose-envify": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz",
|
||||
@@ -2659,6 +2673,11 @@
|
||||
"npm": ">=5"
|
||||
}
|
||||
},
|
||||
"node_modules/memoize-one": {
|
||||
"version": "5.2.1",
|
||||
"resolved": "https://registry.npmjs.org/memoize-one/-/memoize-one-5.2.1.tgz",
|
||||
"integrity": "sha512-zYiwtZUcYyXKo/np96AGZAckk+FWWsUdJ3cHGGmld7+AhvcWmQyGCYUh1hc4Q/pkOhb65dQR/pqCyK0cOaHz4Q=="
|
||||
},
|
||||
"node_modules/mime-db": {
|
||||
"version": "1.52.0",
|
||||
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
|
||||
@@ -2964,6 +2983,11 @@
|
||||
"react": "^18.2.0"
|
||||
}
|
||||
},
|
||||
"node_modules/react-fast-compare": {
|
||||
"version": "3.2.1",
|
||||
"resolved": "https://registry.npmjs.org/react-fast-compare/-/react-fast-compare-3.2.1.tgz",
|
||||
"integrity": "sha512-xTYf9zFim2pEif/Fw16dBiXpe0hoy5PxcD8+OwBnTtNLfIm3g6WxhKNurY+6OmdH1u6Ta/W/Vl6vjbYP1MFnDg=="
|
||||
},
|
||||
"node_modules/react-is": {
|
||||
"version": "18.2.0",
|
||||
"resolved": "https://registry.npmjs.org/react-is/-/react-is-18.2.0.tgz",
|
||||
@@ -3045,6 +3069,21 @@
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/react-player": {
|
||||
"version": "2.12.0",
|
||||
"resolved": "https://registry.npmjs.org/react-player/-/react-player-2.12.0.tgz",
|
||||
"integrity": "sha512-rymLRz/2GJJD+Wc01S7S+i9pGMFYnNmQibR2gVE3KmHJCBNN8BhPAlOPTGZtn1uKpJ6p4RPLlzPQ1OLreXd8gw==",
|
||||
"dependencies": {
|
||||
"deepmerge": "^4.0.0",
|
||||
"load-script": "^1.0.0",
|
||||
"memoize-one": "^5.1.1",
|
||||
"prop-types": "^15.7.2",
|
||||
"react-fast-compare": "^3.0.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": ">=16.6.0"
|
||||
}
|
||||
},
|
||||
"node_modules/react-refresh": {
|
||||
"version": "0.14.0",
|
||||
"resolved": "https://registry.npmjs.org/react-refresh/-/react-refresh-0.14.0.tgz",
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
"react-konami-code": "^2.3.0",
|
||||
"react-material-ui-carousel": "^3.4.2",
|
||||
"react-multi-carousel": "^2.8.3",
|
||||
"react-player": "^2.12.0",
|
||||
"react-router-dom": "^6.11.0",
|
||||
"tauri-plugin-store-api": "github:tauri-apps/tauri-plugin-store",
|
||||
"uuid": "^9.0.0",
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ import FavouritePage from "./routes/favourite/index.jsx";
|
||||
import Settings from "./routes/settings";
|
||||
import About from "./routes/about";
|
||||
|
||||
import VideoPlayer from "./routes/player/videoPlayer.jsx";
|
||||
import { VideoPlayer } from "./routes/player/videoPlayer.jsx";
|
||||
|
||||
import { SideMenu } from "./components/menu/sidemenu.jsx";
|
||||
import { AppBar } from "./components/appBar/appBar.jsx";
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
/** @format */
|
||||
|
||||
import React from "react";
|
||||
import videojs from "video.js";
|
||||
import "./video.module.scss";
|
||||
|
||||
export const VideoJS = (props) => {
|
||||
const videoRef = React.useRef(null);
|
||||
const playerRef = React.useRef(null);
|
||||
const { options, onReady } = props;
|
||||
|
||||
React.useEffect(() => {
|
||||
// Make sure Video.js player is only initialized once
|
||||
if (!playerRef.current) {
|
||||
// The Video.js player needs to be _inside_ the component el for React 18 Strict Mode.
|
||||
const videoElement = document.createElement("video-js");
|
||||
|
||||
videoElement.classList.add("vjs-big-play-centered");
|
||||
videoRef.current.appendChild(videoElement);
|
||||
|
||||
const player = (playerRef.current = videojs(
|
||||
videoElement,
|
||||
options,
|
||||
() => {
|
||||
videojs.log("player is ready");
|
||||
onReady && onReady(player);
|
||||
},
|
||||
));
|
||||
} else {
|
||||
const player = playerRef.current;
|
||||
|
||||
player.autoplay(options.autoplay);
|
||||
player.src(options.sources);
|
||||
}
|
||||
}, [options, videoRef]);
|
||||
|
||||
// Dispose the Video.js player when the functional component unmounts
|
||||
React.useEffect(() => {
|
||||
const player = playerRef.current;
|
||||
|
||||
return () => {
|
||||
if (player && !player.isDisposed()) {
|
||||
player.dispose();
|
||||
playerRef.current = null;
|
||||
}
|
||||
};
|
||||
}, [playerRef]);
|
||||
|
||||
return (
|
||||
<div data-vjs-player>
|
||||
<div ref={videoRef} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default VideoJS;
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,30 +1,51 @@
|
||||
/** @format */
|
||||
|
||||
import React from "react";
|
||||
|
||||
import videojs from "video.js";
|
||||
|
||||
import { useParams } from "react-router-dom";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { getVideosApi } from "@jellyfin/sdk/lib/utils/api/videos-api";
|
||||
|
||||
import Box from "@mui/material/Box";
|
||||
|
||||
// This imports the functional component from the previous sample.
|
||||
import VideoJS from "../../components/player/video";
|
||||
import { usePlaybackStore } from "../../utils/store/playback";
|
||||
import { appWindow } from "@tauri-apps/api/window";
|
||||
|
||||
import AppBar from "@mui/material/AppBar";
|
||||
import Toolbar from "@mui/material/Toolbar";
|
||||
import Box from "@mui/material/Box";
|
||||
import IconButton from "@mui/material/IconButton";
|
||||
import Typography from "@mui/material/Typography";
|
||||
|
||||
import ReactPlayer from "react-player";
|
||||
|
||||
import { usePlaybackStore } from "../../utils/store/playback";
|
||||
import { MdiArrowLeft } from "../../components/icons/mdiArrowLeft";
|
||||
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { MdiChevronLeft } from "../../components/icons/mdiChevronLeft";
|
||||
|
||||
import { useRef, useState, useCallback } from "react";
|
||||
import { secToTicks, ticksToSec } from "../../utils/date/time";
|
||||
|
||||
import { getPlaystateApi } from "@jellyfin/sdk/lib/utils/api/playstate-api";
|
||||
|
||||
const VideoPlayer = () => {
|
||||
export const VideoPlayer = () => {
|
||||
const navigate = useNavigate();
|
||||
|
||||
const playerRef = useRef();
|
||||
const [isPlaying, setIsPlaying] = useState(true);
|
||||
const [isMuted, setIsMuted] = useState(false);
|
||||
const [isReady, setIsReady] = useState(false);
|
||||
|
||||
const onReady = useCallback(() => {
|
||||
if (!isReady) {
|
||||
const timeToStart = ticksToSec(startPosition);
|
||||
playerRef.current.seekTo(timeToStart, "seconds");
|
||||
setIsReady(true);
|
||||
}
|
||||
}, [isReady]);
|
||||
|
||||
const onProgress = async (e) => {
|
||||
console.log(e);
|
||||
await getPlaystateApi(window.api).reportPlaybackProgress({
|
||||
playbackProgressInfo: {
|
||||
ItemId: itemId,
|
||||
IsMuted: isMuted,
|
||||
PositionTicks: secToTicks(e.playedSeconds),
|
||||
PlaybackStartTimeTicks: startPosition,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const [url, startPosition, itemId, itemName] = usePlaybackStore(
|
||||
(state) => [
|
||||
state.url,
|
||||
@@ -33,57 +54,36 @@ const VideoPlayer = () => {
|
||||
state.itemName,
|
||||
],
|
||||
);
|
||||
|
||||
const navigate = useNavigate();
|
||||
|
||||
const playerRef = React.useRef(null);
|
||||
|
||||
const videoJsOptions = {
|
||||
autoplay: true,
|
||||
controls: true,
|
||||
responsive: true,
|
||||
fill: true,
|
||||
sources: [
|
||||
{
|
||||
src: url,
|
||||
type: "video/mp4",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const handlePlayerReady = (player) => {
|
||||
playerRef.current = player;
|
||||
|
||||
player.on("waiting", () => {
|
||||
videojs.log("player is waiting");
|
||||
});
|
||||
|
||||
player.on("dispose", () => {
|
||||
videojs.log("player will dispose");
|
||||
});
|
||||
|
||||
player.on("progress", async () => {
|
||||
await getPlaystateApi(window.api).reportPlaybackProgress({
|
||||
playbackProgressInfo: {
|
||||
ItemId: itemId,
|
||||
PlaybackStartTimeTicks: startPosition,
|
||||
PositionTicks: secToTicks(player.currentTime()),
|
||||
},
|
||||
});
|
||||
});
|
||||
player.currentTime(ticksToSec(startPosition));
|
||||
};
|
||||
|
||||
return (
|
||||
<Box sx={{ height: "100vh", width: "100vw" }}>
|
||||
<AppBar position="fixed">
|
||||
<IconButton onClick={() => navigate(-1)}>
|
||||
<MdiChevronLeft />
|
||||
</IconButton>
|
||||
<Box sx={{ background: "black" }}>
|
||||
<AppBar
|
||||
position="fixed"
|
||||
elevation={0}
|
||||
sx={{
|
||||
background:
|
||||
"linear-gradient(to bottom, rgb(0 0 0 / 0.75), transparent)",
|
||||
}}
|
||||
>
|
||||
<Toolbar>
|
||||
<IconButton onClick={() => navigate(-1)}>
|
||||
<MdiArrowLeft />
|
||||
</IconButton>
|
||||
<Typography ml={2} variant="h6">
|
||||
{itemName}
|
||||
</Typography>
|
||||
</Toolbar>
|
||||
</AppBar>
|
||||
<VideoJS options={videoJsOptions} onReady={handlePlayerReady} />
|
||||
<ReactPlayer
|
||||
ref={playerRef}
|
||||
width="100vw"
|
||||
height="100vh"
|
||||
playing={true}
|
||||
url={url}
|
||||
controls={true}
|
||||
onProgress={onProgress}
|
||||
onReady={onReady}
|
||||
muted={isMuted}
|
||||
/>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
export default VideoPlayer;
|
||||
Reference in new issue
Block a user