Start adding video player #10
This commit is contained in:
13 files changed
+2659
-115
No files matched your search
@@ -50,6 +50,8 @@ 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 { SideMenu } from "./components/menu/sidemenu.jsx";
|
||||
import { AppBar } from "./components/appBar/appBar.jsx";
|
||||
|
||||
@@ -393,6 +395,10 @@ function App() {
|
||||
path="/about"
|
||||
element={<About />}
|
||||
/>
|
||||
<Route
|
||||
path="/player"
|
||||
element={<VideoPlayer />}
|
||||
/>
|
||||
|
||||
<Route
|
||||
path="/login"
|
||||
|
||||
@@ -63,6 +63,7 @@ export const AppBar = () => {
|
||||
if (
|
||||
location.pathname.includes("login") ||
|
||||
location.pathname.includes("setup") ||
|
||||
location.pathname.includes("player") ||
|
||||
location.pathname === "/"
|
||||
) {
|
||||
setDisplay(false);
|
||||
|
||||
@@ -37,6 +37,7 @@ export const ArtistAlbum = ({ user, album, boxProps }) => {
|
||||
});
|
||||
return result.data;
|
||||
},
|
||||
networkMode: "always",
|
||||
});
|
||||
|
||||
const handleLikingTrack = async (track) => {
|
||||
|
||||
@@ -93,6 +93,7 @@ export const SideMenu = ({}) => {
|
||||
if (
|
||||
location.pathname.includes("login") ||
|
||||
location.pathname.includes("setup") ||
|
||||
location.pathname.includes("player") ||
|
||||
location.pathname === "/"
|
||||
) {
|
||||
setDisplay(false);
|
||||
@@ -275,8 +276,3 @@ export const SideMenu = ({}) => {
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
// SideMenu.propTypes = {
|
||||
// skeleton: PropTypes.bool.isRequired,
|
||||
// data: PropTypes.array.isRequired,
|
||||
// };
|
||||
@@ -0,0 +1,56 @@
|
||||
/** @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
@@ -65,6 +65,7 @@ import { EpisodeCardsSkeleton } from "../../components/skeleton/episodeCards";
|
||||
import { ErrorNotice } from "../../components/notices/errorNotice/errorNotice";
|
||||
import { ArtistAlbum } from "../../components/layouts/artist/artistAlbum";
|
||||
import { MdiMusic } from "../../components/icons/mdiMusic";
|
||||
import { usePlaybackStore } from "../../utils/store/playback";
|
||||
function TabPanel(props) {
|
||||
const { children, value, index, ...other } = props;
|
||||
|
||||
@@ -217,6 +218,7 @@ const ItemDetail = () => {
|
||||
return result.data;
|
||||
},
|
||||
enabled: item.isSuccess && item.data.Type == BaseItemKind.Episode,
|
||||
networkMode: "always",
|
||||
});
|
||||
|
||||
const personMovies = useQuery({
|
||||
@@ -508,6 +510,11 @@ const ItemDetail = () => {
|
||||
}
|
||||
}, [item.isSuccess]);
|
||||
|
||||
const [url, setUrl] = usePlaybackStore((state) => [
|
||||
state.url,
|
||||
state.setUrl,
|
||||
]);
|
||||
|
||||
if (item.isLoading || similarItems.isLoading) {
|
||||
return (
|
||||
<Box
|
||||
@@ -583,7 +590,8 @@ const ItemDetail = () => {
|
||||
mb={2}
|
||||
paddingTop={
|
||||
item.data.Type.includes("Music") ||
|
||||
item.data.Type === BaseItemKind.Episode
|
||||
item.data.Type === BaseItemKind.Episode ||
|
||||
!!item.data.PrimaryImageAspectRatio
|
||||
? 10
|
||||
: 0
|
||||
}
|
||||
@@ -683,7 +691,13 @@ const ItemDetail = () => {
|
||||
<Box
|
||||
className={`item-detail-image-container ${item.data.Type}`}
|
||||
sx={{
|
||||
aspectRatio: `${item.data.PrimaryImageAspectRatio}`,
|
||||
aspectRatio: `${
|
||||
!!item.data
|
||||
.PrimaryImageAspectRatio
|
||||
? item.data
|
||||
.PrimaryImageAspectRatio
|
||||
: 1
|
||||
}`,
|
||||
}}
|
||||
>
|
||||
<Chip
|
||||
@@ -735,9 +749,13 @@ const ItemDetail = () => {
|
||||
resolutionX={12}
|
||||
resolutionY={8}
|
||||
style={{
|
||||
aspectRatio:
|
||||
item.data
|
||||
.PrimaryImageAspectRatio,
|
||||
aspectRatio: `${
|
||||
!!item.data
|
||||
.PrimaryImageAspectRatio
|
||||
? item.data
|
||||
.PrimaryImageAspectRatio
|
||||
: 1
|
||||
}`,
|
||||
}}
|
||||
className="item-detail-image-blurhash"
|
||||
/>
|
||||
@@ -978,7 +996,20 @@ const ItemDetail = () => {
|
||||
overflow:
|
||||
"hidden",
|
||||
}}
|
||||
disabled
|
||||
onClick={() => {
|
||||
if (
|
||||
!!item
|
||||
.data
|
||||
.VideoType
|
||||
) {
|
||||
setUrl(
|
||||
`${window.api.basePath}/Videos/${item.data.Id}/stream.${item.data.MediaSources[0].Container}?Static=true&mediaSourceId=${item.data.Id}&deviceId=${window.api.deviceInfo.id}&api_key=${window.api.accessToken}&Tag=${item.data.MediaSources[0].ETag}`,
|
||||
);
|
||||
}
|
||||
navigate(
|
||||
`/player`,
|
||||
);
|
||||
}}
|
||||
>
|
||||
{!!item.data
|
||||
.UserData
|
||||
@@ -1230,6 +1261,55 @@ const ItemDetail = () => {
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
{item.data.Studios.length != 0 && (
|
||||
<TableRow
|
||||
sx={{
|
||||
"& td, & th": {
|
||||
border: 0,
|
||||
},
|
||||
}}
|
||||
>
|
||||
<TableCell
|
||||
sx={{
|
||||
paddingLeft: 0,
|
||||
width: "5%",
|
||||
}}
|
||||
>
|
||||
<Typography
|
||||
className="item-detail-heading"
|
||||
variant="h5"
|
||||
mr={2}
|
||||
>
|
||||
Studios
|
||||
</Typography>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Stack
|
||||
direction="row"
|
||||
gap={1}
|
||||
>
|
||||
{item.data.Genres.map(
|
||||
(
|
||||
genre,
|
||||
index,
|
||||
) => {
|
||||
return (
|
||||
<Chip
|
||||
key={
|
||||
index
|
||||
}
|
||||
variant="filled"
|
||||
label={
|
||||
genre
|
||||
}
|
||||
/>
|
||||
);
|
||||
},
|
||||
)}
|
||||
</Stack>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
|
||||
{!!item.data.MediaStreams &&
|
||||
item.data.MediaStreams.length !=
|
||||
@@ -2674,7 +2754,7 @@ const ItemDetail = () => {
|
||||
return (
|
||||
<TableRow
|
||||
component={
|
||||
motion.row
|
||||
motion.div
|
||||
}
|
||||
key={
|
||||
mindex
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/** @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 AppBar from "@mui/material/AppBar";
|
||||
import IconButton from "@mui/material/IconButton";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { MdiChevronLeft } from "../../components/icons/mdiChevronLeft";
|
||||
|
||||
const VideoPlayer = () => {
|
||||
const url = usePlaybackStore((state) => state.url);
|
||||
|
||||
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;
|
||||
|
||||
// You can handle player events here, for example:
|
||||
player.on("waiting", () => {
|
||||
videojs.log("player is waiting");
|
||||
});
|
||||
|
||||
player.on("dispose", () => {
|
||||
videojs.log("player will dispose");
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Box sx={{ height: "100vh", width: "100vw" }}>
|
||||
<AppBar position="fixed">
|
||||
<IconButton onClick={() => navigate(-1)}>
|
||||
<MdiChevronLeft />
|
||||
</IconButton>
|
||||
</AppBar>
|
||||
<VideoJS options={videoJsOptions} onReady={handlePlayerReady} />
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
export default VideoPlayer;
|
||||
@@ -0,0 +1,8 @@
|
||||
/** @format */
|
||||
|
||||
import { create } from "zustand";
|
||||
|
||||
export const usePlaybackStore = create((set) => ({
|
||||
url: "",
|
||||
setUrl: (aurl) => set(() => ({ url: aurl })),
|
||||
}));
|
||||
Reference in new issue
Block a user