Update PlayButton #153
This commit is contained in:
4 files changed
+89
-34
No files matched your search
+17
@@ -37,6 +37,7 @@ import DialogTitle from "@mui/material/DialogTitle";
|
|||||||
import Button from "@mui/material/Button";
|
import Button from "@mui/material/Button";
|
||||||
import Slide from "@mui/material/Slide";
|
import Slide from "@mui/material/Slide";
|
||||||
import Box from "@mui/material/Box";
|
import Box from "@mui/material/Box";
|
||||||
|
import LinearProgress from "@mui/material/LinearProgress";
|
||||||
|
|
||||||
// Routes
|
// Routes
|
||||||
import { ServerSetup, ServerList } from "./routes/setup/server";
|
import { ServerSetup, ServerList } from "./routes/setup/server";
|
||||||
@@ -72,6 +73,7 @@ import { delUser, getUser } from "./utils/storage/user.js";
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { useBackdropStore } from "./utils/store/backdrop.js";
|
import { useBackdropStore } from "./utils/store/backdrop.js";
|
||||||
import { useAppLoadingStore } from "./utils/store/appLoading.js";
|
import { useAppLoadingStore } from "./utils/store/appLoading.js";
|
||||||
|
import { usePlaybackDataLoadStore } from "./utils/store/playback.js";
|
||||||
|
|
||||||
const jellyfin = new Jellyfin({
|
const jellyfin = new Jellyfin({
|
||||||
clientInfo: {
|
clientInfo: {
|
||||||
@@ -138,6 +140,9 @@ function App() {
|
|||||||
state.setIsSuccess,
|
state.setIsSuccess,
|
||||||
state.setIsError,
|
state.setIsError,
|
||||||
]);
|
]);
|
||||||
|
const [playbackDataLoading] = usePlaybackDataLoadStore((state) => [
|
||||||
|
state.isLoading,
|
||||||
|
]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const appLoadingStateTimer = setInterval(() => {
|
const appLoadingStateTimer = setInterval(() => {
|
||||||
@@ -315,6 +320,18 @@ function App() {
|
|||||||
return (
|
return (
|
||||||
<SnackbarProvider maxSnack={5}>
|
<SnackbarProvider maxSnack={5}>
|
||||||
<ThemeProvider theme={theme}>
|
<ThemeProvider theme={theme}>
|
||||||
|
{playbackDataLoading && (
|
||||||
|
<LinearProgress
|
||||||
|
sx={{
|
||||||
|
position: "fixed",
|
||||||
|
top: 0,
|
||||||
|
left: 0,
|
||||||
|
right: 0,
|
||||||
|
width: "100vw",
|
||||||
|
zIndex: 100000,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
<Dialog
|
<Dialog
|
||||||
open={easterEgg}
|
open={easterEgg}
|
||||||
onClose={() => setEasterEgg(false)}
|
onClose={() => setEasterEgg(false)}
|
||||||
|
|||||||
@@ -2,22 +2,24 @@
|
|||||||
|
|
||||||
import IconButton from "@mui/material/IconButton";
|
import IconButton from "@mui/material/IconButton";
|
||||||
import { MdiPlayOutline } from "../icons/mdiPlayOutline";
|
import { MdiPlayOutline } from "../icons/mdiPlayOutline";
|
||||||
import { usePlaybackStore } from "../../utils/store/playback";
|
import {
|
||||||
|
usePlaybackDataLoadStore,
|
||||||
|
usePlaybackStore,
|
||||||
|
} from "../../utils/store/playback";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
|
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||||
|
import { getUserLibraryApi } from "@jellyfin/sdk/lib/utils/api/user-library-api";
|
||||||
|
import { getTvShowsApi } from "@jellyfin/sdk/lib/utils/api/tv-shows-api";
|
||||||
|
import { getItemsApi } from "@jellyfin/sdk/lib/utils/api/items-api";
|
||||||
|
import { ItemFields } from "@jellyfin/sdk/lib/generated-client";
|
||||||
|
|
||||||
const PlayButton = ({
|
const PlayButton = ({
|
||||||
itemId,
|
itemId,
|
||||||
mediaSources,
|
userId,
|
||||||
|
itemType,
|
||||||
currentAudioTrack,
|
currentAudioTrack,
|
||||||
currentSubTrack,
|
currentSubTrack,
|
||||||
currentVideoTrack,
|
currentVideoTrack,
|
||||||
itemName,
|
|
||||||
seriesName,
|
|
||||||
itemIndex,
|
|
||||||
itemParentIndex,
|
|
||||||
itemRuntimeTicks,
|
|
||||||
itemPlaybackPositionTicks,
|
|
||||||
itemType,
|
|
||||||
className,
|
className,
|
||||||
sx,
|
sx,
|
||||||
iconProps,
|
iconProps,
|
||||||
@@ -40,22 +42,63 @@ const PlayButton = ({
|
|||||||
state.setSubtitleTracks,
|
state.setSubtitleTracks,
|
||||||
state.setSelectedSubtitleTrack,
|
state.setSelectedSubtitleTrack,
|
||||||
]);
|
]);
|
||||||
const handleClick = (e) => {
|
const setPlaybackDataLoading = usePlaybackDataLoadStore(
|
||||||
e.stopPropagation();
|
(state) => state.setIsLoading,
|
||||||
|
);
|
||||||
|
|
||||||
|
const item = useMutation({
|
||||||
|
mutationKey: ["playButton", itemId, userId],
|
||||||
|
mutationFn: async () => {
|
||||||
|
setPlaybackDataLoading(true);
|
||||||
|
let result;
|
||||||
|
if (itemType == "Series") {
|
||||||
|
result = await getTvShowsApi(window.api).getEpisodes({
|
||||||
|
seriesId: itemId,
|
||||||
|
limit: 1,
|
||||||
|
startIndex: 0,
|
||||||
|
fields: [
|
||||||
|
ItemFields.MediaSources,
|
||||||
|
ItemFields.MediaStreams,
|
||||||
|
],
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
result = await getItemsApi(window.api).getItems({
|
||||||
|
ids: [itemId],
|
||||||
|
userId: userId,
|
||||||
|
fields: [
|
||||||
|
ItemFields.MediaSources,
|
||||||
|
ItemFields.MediaStreams,
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return result.data;
|
||||||
|
},
|
||||||
|
onSuccess: (item) => {
|
||||||
|
console.log(item);
|
||||||
setUrl(
|
setUrl(
|
||||||
`${window.api.basePath}/Videos/${itemId}/stream.${mediaSources[0].Container}?Static=true&mediaSourceId=${itemId}&deviceId=${window.api.deviceInfo.id}&api_key=${window.api.accessToken}&Tag=${mediaSources[0].ETag}&videoStreamIndex=${currentVideoTrack}&audioStreamIndex=${currentAudioTrack}`,
|
`${window.api.basePath}/Videos/${item.Items[0].Id}/stream.
|
||||||
|
${item.Items[0].MediaSources[0].Container}
|
||||||
|
?Static=true&mediaSourceId=${item.Items[0].Id}&deviceId=${window.api.deviceInfo.id}&api_key=${window.api.accessToken}&Tag=${item.Items[0].MediaSources[0].ETag}&videoStreamIndex=${currentVideoTrack}&audioStreamIndex=${currentAudioTrack}`,
|
||||||
);
|
);
|
||||||
setPosition(itemPlaybackPositionTicks);
|
setPosition(item.Items[0].UserData?.PlaybackPositionTicks);
|
||||||
setItemName(
|
setItemName(
|
||||||
itemType == "Episode"
|
item.Items[0].Type == "Episode"
|
||||||
? `${seriesName} S${itemParentIndex}:E${itemIndex} ${itemName}`
|
? `${item.Items[0].SeriesName} S${item.Items[0].ParentIndexNumber}:E${item.Items[0].IndexNumber} ${item.Items[0].Name}`
|
||||||
: itemName,
|
: item.Items[0].Name,
|
||||||
);
|
);
|
||||||
setItemId(itemId);
|
setItemId(item.Items[0].Id);
|
||||||
setDuration(itemRuntimeTicks);
|
setDuration(item.Items[0].RunTimeTicks);
|
||||||
// setSubtitleTracksStore(subtitleTracks);
|
// setSubtitleTracksStore(subtitleTracks);
|
||||||
setSelectedSubtitleTrack(currentSubTrack);
|
setSelectedSubtitleTrack(currentSubTrack);
|
||||||
navigate(`/player`);
|
navigate(`/player`);
|
||||||
|
},
|
||||||
|
onSettled: () => {
|
||||||
|
setPlaybackDataLoading(false);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const handleClick = (e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
item.mutate();
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<IconButton className={className} onClick={handleClick} sx={sx}>
|
<IconButton className={className} onClick={handleClick} sx={sx}>
|
||||||
|
|||||||
@@ -198,25 +198,11 @@ export const Card = ({
|
|||||||
<Box className="card-overlay">
|
<Box className="card-overlay">
|
||||||
<PlayButton
|
<PlayButton
|
||||||
itemId={item.Id}
|
itemId={item.Id}
|
||||||
mediaSources={item.MediaSources}
|
userId={userId}
|
||||||
|
itemType={item.Type}
|
||||||
currentAudioTrack={0}
|
currentAudioTrack={0}
|
||||||
currentSubTrack={0}
|
currentSubTrack={0}
|
||||||
currentVideoTrack={0}
|
currentVideoTrack={0}
|
||||||
itemName={item.Name}
|
|
||||||
seriesName={item.SeriesName}
|
|
||||||
itemIndex={item.IndexNumber}
|
|
||||||
itemParentIndex={
|
|
||||||
item.ParentIndexNumber
|
|
||||||
}
|
|
||||||
itemRuntimeTicks={
|
|
||||||
!!item.MediaSources &&
|
|
||||||
item.MediaSources[0]
|
|
||||||
.RunTimeTicks
|
|
||||||
}
|
|
||||||
itemPlaybackPositionTicks={
|
|
||||||
item.UserData
|
|
||||||
?.PlaybackPositionTicks
|
|
||||||
}
|
|
||||||
className="card-play-button"
|
className="card-play-button"
|
||||||
iconProps={{
|
iconProps={{
|
||||||
sx: { fontSize: "1.5em" },
|
sx: { fontSize: "1.5em" },
|
||||||
|
|||||||
@@ -23,3 +23,12 @@ export const usePlaybackStore = create((set) => ({
|
|||||||
setSelectedSubtitleTrack: (asub) =>
|
setSelectedSubtitleTrack: (asub) =>
|
||||||
set((state) => ({ ...state, selectedSubtitleTrack: asub })),
|
set((state) => ({ ...state, selectedSubtitleTrack: asub })),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
export const usePlaybackDataLoadStore = create((set) => ({
|
||||||
|
isLoading: false,
|
||||||
|
setIsLoading: (loading) =>
|
||||||
|
set((state) => ({
|
||||||
|
...state,
|
||||||
|
isLoading: loading,
|
||||||
|
})),
|
||||||
|
}));
|
||||||
Reference in new issue
Block a user