refactor: rewrite video player
This commit is contained in:
34 files changed
+3766
-3007
No files matched your search
@@ -1,20 +1,24 @@
|
||||
import { useBackdropStore } from "@/utils/store/backdrop";
|
||||
import { AnimatePresence, motion } from "motion/react";
|
||||
import React, { useLayoutEffect, useState } from "react";
|
||||
import { useBackdropStore } from "@/utils/store/backdrop";
|
||||
|
||||
export default function Backdrop() {
|
||||
const [backdropLoading, setBackdropLoading] = useState(true);
|
||||
|
||||
|
||||
const [backdropId, backdropUrl] = useBackdropStore((state) => [
|
||||
state.backdropId,
|
||||
state.backdropUrl,
|
||||
]);
|
||||
|
||||
|
||||
// Reset loading status for backdrop
|
||||
useLayoutEffect(() => {
|
||||
setBackdropLoading(true);
|
||||
}, [backdropId]);
|
||||
|
||||
|
||||
if (!backdropUrl) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="app-backdrop-container">
|
||||
<AnimatePresence>
|
||||
|
||||
@@ -1,11 +1,3 @@
|
||||
import React, { memo, type MouseEvent } from "react"; // Import memo
|
||||
|
||||
import Button, { type ButtonProps } from "@mui/material/Button";
|
||||
import Fab from "@mui/material/Fab";
|
||||
import LinearProgress from "@mui/material/LinearProgress";
|
||||
import Typography from "@mui/material/Typography";
|
||||
|
||||
import { generateAudioStreamUrl, playAudio } from "@/utils/store/audioPlayback";
|
||||
import {
|
||||
type BaseItemDto,
|
||||
type BaseItemDtoQueryResult,
|
||||
@@ -17,31 +9,34 @@ import {
|
||||
type PlaybackInfoResponse,
|
||||
SortOrder,
|
||||
} from "@jellyfin/sdk/lib/generated-client";
|
||||
import { getDisplayPreferencesApi } from "@jellyfin/sdk/lib/utils/api/display-preferences-api";
|
||||
import { getItemsApi } from "@jellyfin/sdk/lib/utils/api/items-api";
|
||||
import { getMediaInfoApi } from "@jellyfin/sdk/lib/utils/api/media-info-api";
|
||||
import { getMediaSegmentsApi } from "@jellyfin/sdk/lib/utils/api/media-segments-api";
|
||||
import { getPlaylistsApi } from "@jellyfin/sdk/lib/utils/api/playlists-api";
|
||||
import { getTvShowsApi } from "@jellyfin/sdk/lib/utils/api/tv-shows-api";
|
||||
import { getUserLibraryApi } from "@jellyfin/sdk/lib/utils/api/user-library-api";
|
||||
import { LoadingButton } from "@mui/lab";
|
||||
import type { SxProps } from "@mui/material";
|
||||
import Button, { type ButtonProps } from "@mui/material/Button";
|
||||
import Fab from "@mui/material/Fab";
|
||||
import LinearProgress from "@mui/material/LinearProgress";
|
||||
import Typography from "@mui/material/Typography";
|
||||
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||
import { useNavigate } from "@tanstack/react-router";
|
||||
import type { AxiosResponse } from "axios";
|
||||
import { useSnackbar } from "notistack";
|
||||
|
||||
import { setQueue } from "@/utils/store/queue";
|
||||
|
||||
import { playItem } from "@/utils/store/playback";
|
||||
|
||||
import React, { type MouseEvent, memo } from "react"; // Import memo
|
||||
import type PlayResult from "@//utils/types/playResult";
|
||||
import { getRuntimeCompact } from "@/utils/date/time";
|
||||
import getSubtitle from "@/utils/methods/getSubtitles";
|
||||
import playbackProfile from "@/utils/playback-profiles";
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import { generateAudioStreamUrl, playAudio } from "@/utils/store/audioPlayback";
|
||||
import { useCentralStore } from "@/utils/store/central";
|
||||
import { usePhotosPlayback } from "@/utils/store/photosPlayback";
|
||||
import { getDisplayPreferencesApi } from "@jellyfin/sdk/lib/utils/api/display-preferences-api";
|
||||
import { getMediaInfoApi } from "@jellyfin/sdk/lib/utils/api/media-info-api";
|
||||
import { getMediaSegmentsApi } from "@jellyfin/sdk/lib/utils/api/media-segments-api";
|
||||
import { getUserLibraryApi } from "@jellyfin/sdk/lib/utils/api/user-library-api";
|
||||
import { LoadingButton } from "@mui/lab";
|
||||
import type { SxProps } from "@mui/material";
|
||||
import type { AxiosResponse } from "axios";
|
||||
import { playItem } from "@/utils/store/playback";
|
||||
import { setQueue } from "@/utils/store/queue";
|
||||
|
||||
type PlayButtonProps = {
|
||||
item: BaseItemDto;
|
||||
@@ -89,7 +84,7 @@ const PlayButton = ({
|
||||
itemType,
|
||||
currentAudioTrack,
|
||||
currentSubTrack,
|
||||
currentVideoTrack,
|
||||
// currentVideoTrack,
|
||||
className,
|
||||
sx,
|
||||
buttonProps,
|
||||
@@ -574,26 +569,46 @@ const PlayButton = ({
|
||||
initVolume = displayPreferences.data.CustomPrefs?.Volume;
|
||||
}
|
||||
|
||||
playItem(
|
||||
itemName,
|
||||
episodeTitle,
|
||||
currentVideoTrack ?? 0,
|
||||
Number(result.mediaSource.MediaSources?.[0].DefaultAudioStreamIndex),
|
||||
result?.mediaSource?.MediaSources?.[0].Container ?? "mkv",
|
||||
playbackUrl,
|
||||
userId ?? "",
|
||||
startPosition,
|
||||
result?.item?.Items?.[episodeIndex].RunTimeTicks,
|
||||
playItemValue ?? item,
|
||||
queue,
|
||||
episodeIndex,
|
||||
result?.mediaSource?.MediaSources?.[0]?.Id,
|
||||
result?.mediaSource?.PlaySessionId,
|
||||
subtitle,
|
||||
result?.mediaSegments,
|
||||
audio,
|
||||
Number(initVolume),
|
||||
);
|
||||
const videoTrack =
|
||||
result.mediaSource.MediaSources?.[0].MediaStreams?.filter(
|
||||
(value) => value.Type === "Video",
|
||||
);
|
||||
|
||||
playItem({
|
||||
metadata: {
|
||||
itemName: itemName ?? "",
|
||||
episodeTitle: episodeTitle,
|
||||
isEpisode: !!item.SeriesId,
|
||||
itemDuration: item.RunTimeTicks ?? 0,
|
||||
item: playItemValue ?? item,
|
||||
mediaSegments: result.mediaSegments,
|
||||
userDataLastPlayedPositionTicks: startPosition ?? 0,
|
||||
},
|
||||
mediaSource: {
|
||||
videoTrack: videoTrack?.[0]?.Index ?? 0,
|
||||
audioTrack: audio.track,
|
||||
container: result.mediaSource.MediaSources?.[0].Container ?? "",
|
||||
id: result.mediaSource.MediaSources?.[0]?.Id,
|
||||
subtitle: {
|
||||
url: subtitle?.url,
|
||||
track: subtitle?.track ?? -1,
|
||||
format: subtitle?.format ?? "nosub",
|
||||
allTracks:
|
||||
result.mediaSource.MediaSources?.[0].MediaStreams?.filter(
|
||||
(value) => value.Type === "Subtitle",
|
||||
),
|
||||
enable: subtitle?.enable ?? false,
|
||||
},
|
||||
audio: audio,
|
||||
},
|
||||
playbackStream: playbackUrl,
|
||||
playsessionId: result.mediaSource.PlaySessionId,
|
||||
userDataPlayedPositionTicks:
|
||||
item.UserData?.PlaybackPositionTicks ?? 0,
|
||||
userId,
|
||||
queueItems: queue ?? [],
|
||||
queueItemIndex: episodeIndex,
|
||||
});
|
||||
navigate({ to: "/player" });
|
||||
}
|
||||
},
|
||||
@@ -686,7 +701,7 @@ const PlayButton = ({
|
||||
position: "relative",
|
||||
}}
|
||||
>
|
||||
<LoadingButton
|
||||
<Button
|
||||
loading={currentEpisode.isPending}
|
||||
className={className ?? "play-button"}
|
||||
variant="contained"
|
||||
@@ -725,7 +740,7 @@ const PlayButton = ({
|
||||
: 0
|
||||
}
|
||||
/>
|
||||
</LoadingButton>
|
||||
</Button>
|
||||
{(currentEpisode.data?.Items?.[0].UserData?.PlaybackPositionTicks ??
|
||||
0) > 0 && (
|
||||
<Typography
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import { CircularProgress } from "@mui/material";
|
||||
import React from "react";
|
||||
import { useShallow } from "zustand/shallow";
|
||||
import { usePlaybackStore } from "@/utils/store/playback";
|
||||
|
||||
const LoadingIndicator = () => {
|
||||
const { isBuffering } = usePlaybackStore(
|
||||
useShallow((state) => ({
|
||||
isBuffering: state.playerState.isBuffering,
|
||||
})),
|
||||
);
|
||||
if (!isBuffering) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
zIndex: 2,
|
||||
position: "absolute",
|
||||
height: "100vh",
|
||||
width: "100vw",
|
||||
top: 0,
|
||||
left: 0,
|
||||
display: "flex",
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
}}
|
||||
>
|
||||
<CircularProgress size={72} thickness={1.4} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
export default LoadingIndicator;
|
||||
@@ -0,0 +1,27 @@
|
||||
import { Typography } from "@mui/material";
|
||||
import React from "react";
|
||||
import { useShallow } from "zustand/shallow";
|
||||
import ticksDisplay from "@/utils/methods/ticksDisplay";
|
||||
import { usePlaybackStore } from "@/utils/store/playback";
|
||||
|
||||
const ProgressDislay = () => {
|
||||
const { currentTime, itemDuration, isUserSeeking, seekValue } =
|
||||
usePlaybackStore(
|
||||
useShallow((state) => ({
|
||||
currentTime: state.playerState.currentTime,
|
||||
itemDuration: state.metadata.itemDuration,
|
||||
isUserSeeking: state.playerState.isUserSeeking,
|
||||
seekValue: state.playerState.seekValue,
|
||||
})),
|
||||
);
|
||||
return (
|
||||
<div className="video-player-osd-controls-timeline-text">
|
||||
<Typography>
|
||||
{ticksDisplay(isUserSeeking ? (seekValue ?? 0) : (currentTime ?? 0))}
|
||||
</Typography>
|
||||
<Typography>{ticksDisplay(itemDuration)}</Typography>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ProgressDislay;
|
||||
@@ -0,0 +1,36 @@
|
||||
import { LinearProgress } from "@mui/material";
|
||||
import { AnimatePresence, motion } from "motion/react";
|
||||
import React from "react";
|
||||
import { useShallow } from "zustand/shallow";
|
||||
import { usePlaybackStore } from "@/utils/store/playback";
|
||||
|
||||
const VolumeChangeOverlay = () => {
|
||||
const { playerVolume, showVolumeIndicator } = usePlaybackStore(
|
||||
useShallow((state) => ({
|
||||
playerVolume: state.playerState.volume,
|
||||
showVolumeIndicator: state.isVolumeInidcatorVisible,
|
||||
})),
|
||||
);
|
||||
return (
|
||||
<AnimatePresence>
|
||||
{showVolumeIndicator && (
|
||||
<motion.div
|
||||
initial={{ opacity: 0 }}
|
||||
animate={{ opacity: 1 }}
|
||||
exit={{ opacity: 0 }}
|
||||
className="video-volume-indicator glass"
|
||||
>
|
||||
<div className="material-symbols-rounded">
|
||||
{playerVolume > 0.7 ? "volume_up" : "volume_down"}
|
||||
</div>
|
||||
<LinearProgress
|
||||
style={{ width: "100%" }}
|
||||
value={playerVolume * 100}
|
||||
variant="determinate"
|
||||
/>
|
||||
</motion.div>
|
||||
)}
|
||||
</AnimatePresence>
|
||||
);
|
||||
};
|
||||
export default VolumeChangeOverlay;
|
||||
+66
-90
@@ -1,46 +1,11 @@
|
||||
import { ticksToMs, ticksToSec } from "@/utils/date/time";
|
||||
import {
|
||||
type VideoPlayerAction,
|
||||
VideoPlayerActionKind,
|
||||
} from "@/utils/reducers/videoPlayerReducer";
|
||||
import type audioPlaybackInfo from "@/utils/types/audioPlaybackInfo";
|
||||
import type subtitlePlaybackInfo from "@/utils/types/subtitlePlaybackInfo";
|
||||
import type { Api } from "@jellyfin/sdk";
|
||||
import type {
|
||||
BaseItemDto,
|
||||
TrickplayInfo,
|
||||
} from "@jellyfin/sdk/lib/generated-client";
|
||||
import type { TrickplayInfo } from "@jellyfin/sdk/lib/generated-client";
|
||||
import { Slider, Tooltip, Typography } from "@mui/material";
|
||||
import type { Instance } from "@popperjs/core";
|
||||
import React, {
|
||||
type RefObject,
|
||||
type ActionDispatch,
|
||||
type MouseEvent,
|
||||
} from "react";
|
||||
import { useRef, useState } from "react";
|
||||
import type ReactPlayer from "react-player";
|
||||
|
||||
type BubbleSliderProps = {
|
||||
itemDuration: number;
|
||||
item: BaseItemDto;
|
||||
mediaSource: {
|
||||
videoTrack: number;
|
||||
audioTrack: number;
|
||||
container: string;
|
||||
id: string | undefined;
|
||||
subtitle: subtitlePlaybackInfo;
|
||||
audio: audioPlaybackInfo;
|
||||
};
|
||||
api: Api;
|
||||
chapterMarks: { value: number }[];
|
||||
sliderState: {
|
||||
isSeeking: boolean;
|
||||
sliderSeek: number;
|
||||
progress: number;
|
||||
};
|
||||
dispatch: ActionDispatch<[action: VideoPlayerAction]>;
|
||||
player: RefObject<ReactPlayer | null>;
|
||||
};
|
||||
import React, { type MouseEvent, useMemo, useRef, useState } from "react";
|
||||
import { useShallow } from "zustand/shallow";
|
||||
import { ticksToMs } from "@/utils/date/time";
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import { usePlaybackStore } from "@/utils/store/playback";
|
||||
|
||||
const ticksDisplay = (ticks: number) => {
|
||||
const time = Math.round(ticks / 10000);
|
||||
@@ -64,16 +29,40 @@ const ticksDisplay = (ticks: number) => {
|
||||
return formatedTime;
|
||||
};
|
||||
|
||||
const BubbleSlider = ({
|
||||
itemDuration,
|
||||
item,
|
||||
mediaSource,
|
||||
api,
|
||||
chapterMarks,
|
||||
sliderState,
|
||||
dispatch,
|
||||
player,
|
||||
}: BubbleSliderProps) => {
|
||||
const BubbleSlider = () => {
|
||||
const api = useApiInContext((state) => state.api);
|
||||
const {
|
||||
seekValue,
|
||||
currentTime,
|
||||
isUserSeeking,
|
||||
// setIsUserSeeking,
|
||||
// setSeekValue,
|
||||
// seekTo,
|
||||
itemDuration,
|
||||
itemChapters,
|
||||
mediaSource,
|
||||
itemTrickplay,
|
||||
itemId,
|
||||
handleStartSeek,
|
||||
handleStopSeek,
|
||||
} = usePlaybackStore(
|
||||
useShallow((state) => ({
|
||||
seekValue: state.playerState.seekValue,
|
||||
currentTime: state.playerState.currentTime,
|
||||
isUserSeeking: state.playerState.isUserSeeking,
|
||||
// setIsUserSeeking: state.setIsUserSeeking,
|
||||
// setSeekValue: state.setSeekValue,
|
||||
// seekTo: state.seekTo,
|
||||
itemDuration: state.metadata.item.RunTimeTicks,
|
||||
itemChapters: state.metadata.item.Chapters,
|
||||
mediaSource: state.mediaSource,
|
||||
itemTrickplay: state.metadata.item.Trickplay,
|
||||
itemId: state.metadata.item.Id,
|
||||
handleStartSeek: state.handleStartSeek,
|
||||
handleStopSeek: state.handleStopSeek,
|
||||
})),
|
||||
);
|
||||
|
||||
const positionRef = useRef<{ x: number; y: number }>({
|
||||
x: 0,
|
||||
y: 0,
|
||||
@@ -89,20 +78,27 @@ const BubbleSlider = ({
|
||||
const width = rect.width;
|
||||
const distX = event.clientX - rect.left;
|
||||
const percentageCovered = distX / width;
|
||||
setHoverProgress(percentageCovered * itemDuration);
|
||||
setHoverProgress(percentageCovered * (itemDuration ?? 0));
|
||||
if (popperRef.current != null) {
|
||||
popperRef.current.update();
|
||||
}
|
||||
};
|
||||
|
||||
const chapterMarks = useMemo(() => {
|
||||
const marks: { value: number }[] = [];
|
||||
itemChapters?.map((val) => {
|
||||
marks.push({ value: val.StartPositionTicks ?? 0 });
|
||||
});
|
||||
return marks;
|
||||
}, [itemChapters]);
|
||||
|
||||
const sliderDisplayFormat = (value: number) => {
|
||||
const currentChapter = item?.Chapters?.filter((chapter, index) => {
|
||||
if (index + 1 === item.Chapters?.length) {
|
||||
const currentChapter = itemChapters?.filter((chapter, index) => {
|
||||
if (index + 1 === itemChapters?.length) {
|
||||
return chapter;
|
||||
}
|
||||
if (
|
||||
(item.Chapters?.[index + 1]?.StartPositionTicks ?? value) - value >=
|
||||
0 &&
|
||||
(itemChapters?.[index + 1]?.StartPositionTicks ?? value) - value >= 0 &&
|
||||
(chapter.StartPositionTicks ?? value) - value < 0
|
||||
) {
|
||||
return chapter;
|
||||
@@ -111,7 +107,7 @@ const BubbleSlider = ({
|
||||
|
||||
let trickplayResolution: TrickplayInfo | undefined;
|
||||
const trickplayResolutions = mediaSource.id
|
||||
? item?.Trickplay?.[mediaSource.id]
|
||||
? itemTrickplay?.[mediaSource.id]
|
||||
: null;
|
||||
if (trickplayResolutions) {
|
||||
let bestWidth: number | undefined;
|
||||
@@ -168,7 +164,7 @@ const BubbleSlider = ({
|
||||
<div
|
||||
className="video-osd-trickplayBubble"
|
||||
style={{
|
||||
background: `url(${api?.basePath}/Videos/${item?.Id}/Trickplay/${trickplayResolution.Width}/${index}.jpg?${imgUrlParams})`,
|
||||
background: `url(${api?.basePath}/Videos/${itemId}/Trickplay/${trickplayResolution.Width}/${index}.jpg?${imgUrlParams})`,
|
||||
backgroundPositionX: `${backgroundOffsetX}px`,
|
||||
backgroundPositionY: `${backgroundOffsetY}px`,
|
||||
width: "100%",
|
||||
@@ -189,7 +185,7 @@ const BubbleSlider = ({
|
||||
<div
|
||||
className="video-osd-trickplayBubble"
|
||||
style={{
|
||||
background: `url(${api?.basePath}/Videos/${item?.Id}/Trickplay/${trickplayResolution.Width}/${index}.jpg?${imgUrlParams})`,
|
||||
background: `url(${api?.basePath}/Videos/${itemId}/Trickplay/${trickplayResolution.Width}/${index}.jpg?${imgUrlParams})`,
|
||||
backgroundPositionX: `${backgroundOffsetX}px`,
|
||||
backgroundPositionY: `${backgroundOffsetY}px`,
|
||||
width: "100%",
|
||||
@@ -259,44 +255,24 @@ const BubbleSlider = ({
|
||||
}}
|
||||
>
|
||||
<Slider
|
||||
value={
|
||||
sliderState.isSeeking ? sliderState.sliderSeek : sliderState.progress
|
||||
}
|
||||
max={itemDuration}
|
||||
value={isUserSeeking ? seekValue : currentTime}
|
||||
max={itemDuration ?? 0}
|
||||
step={1}
|
||||
onChange={(_, newValue) => {
|
||||
dispatch({
|
||||
type: VideoPlayerActionKind.SET_SEEKING,
|
||||
payload: true,
|
||||
});
|
||||
// setIsUserSeeking(true);
|
||||
Array.isArray(newValue)
|
||||
? dispatch({
|
||||
type: VideoPlayerActionKind.SET_SLIDER_SEEK,
|
||||
payload: newValue[0],
|
||||
})
|
||||
: dispatch({
|
||||
type: VideoPlayerActionKind.SET_SLIDER_SEEK,
|
||||
payload: newValue,
|
||||
});
|
||||
? handleStartSeek(newValue[0])
|
||||
: handleStartSeek(newValue);
|
||||
}}
|
||||
onChangeCommitted={(_, newValue) => {
|
||||
dispatch({
|
||||
type: VideoPlayerActionKind.SET_SEEKING,
|
||||
payload: false,
|
||||
});
|
||||
Array.isArray(newValue)
|
||||
? dispatch({
|
||||
type: VideoPlayerActionKind.SET_SLIDER_SEEK,
|
||||
payload: newValue[0],
|
||||
})
|
||||
: dispatch({
|
||||
type: VideoPlayerActionKind.SET_SLIDER_SEEK,
|
||||
payload: newValue,
|
||||
});
|
||||
// setIsUserSeeking(false);
|
||||
// Array.isArray(newValue)
|
||||
// ? setSeekValue(newValue[0])
|
||||
// : setSeekValue(newValue);
|
||||
if (Array.isArray(newValue)) {
|
||||
player.current?.seekTo(ticksToSec(newValue[0]), "seconds");
|
||||
handleStopSeek(newValue[0]);
|
||||
} else {
|
||||
player.current?.seekTo(ticksToSec(newValue), "seconds");
|
||||
handleStopSeek(newValue);
|
||||
}
|
||||
}}
|
||||
sx={{
|
||||
@@ -0,0 +1,25 @@
|
||||
import { IconButton } from "@mui/material";
|
||||
import React, { useTransition } from "react";
|
||||
import { useShallow } from "zustand/shallow";
|
||||
import { toggleSubtitleTrack, usePlaybackStore } from "@/utils/store/playback";
|
||||
|
||||
const CaptionsButton = () => {
|
||||
const { subtitle } = usePlaybackStore(
|
||||
useShallow((state) => ({ subtitle: state.mediaSource.subtitle })),
|
||||
);
|
||||
|
||||
const [subtitleIsChanging, startSubtitleChange] = useTransition();
|
||||
|
||||
return (
|
||||
<IconButton
|
||||
disabled={subtitle?.allTracks?.length === 0 || subtitleIsChanging}
|
||||
onClick={() => startSubtitleChange(toggleSubtitleTrack)}
|
||||
>
|
||||
<span className={"material-symbols-rounded"}>
|
||||
{subtitle?.enable ? "closed_caption" : "closed_caption_disabled"}
|
||||
</span>
|
||||
</IconButton>
|
||||
);
|
||||
};
|
||||
|
||||
export default CaptionsButton;
|
||||
@@ -0,0 +1,58 @@
|
||||
import { IconButton, Menu, MenuItem } from "@mui/material";
|
||||
import React from "react";
|
||||
import { useShallow } from "zustand/shallow";
|
||||
import { ticksToSec } from "@/utils/date/time";
|
||||
import { usePlaybackStore } from "@/utils/store/playback";
|
||||
|
||||
const ChaptersListButton = () => {
|
||||
const { itemChapters, seekTo } = usePlaybackStore(
|
||||
useShallow((state) => ({
|
||||
itemChapters: state.metadata.item?.Chapters,
|
||||
seekTo: state.seekTo,
|
||||
})),
|
||||
);
|
||||
const [showChapterList, setShowChapterList] =
|
||||
React.useState<null | HTMLElement>(null);
|
||||
const handleShowChapterList = (event: React.MouseEvent<HTMLElement>) => {
|
||||
setShowChapterList(event.currentTarget);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<IconButton
|
||||
disabled={itemChapters?.length === 0}
|
||||
onClick={handleShowChapterList}
|
||||
>
|
||||
<span className="material-symbols-rounded">list</span>
|
||||
</IconButton>
|
||||
<Menu
|
||||
open={Boolean(showChapterList)}
|
||||
anchorEl={showChapterList}
|
||||
onClose={() => setShowChapterList(null)}
|
||||
anchorOrigin={{
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
}}
|
||||
transformOrigin={{
|
||||
vertical: "bottom",
|
||||
horizontal: "center",
|
||||
}}
|
||||
>
|
||||
{itemChapters?.length &&
|
||||
itemChapters?.map((chapter) => (
|
||||
<MenuItem
|
||||
key={chapter.Name}
|
||||
onClick={() => {
|
||||
seekTo(ticksToSec(chapter.StartPositionTicks ?? 0));
|
||||
setShowChapterList(null); // Close the chapter list menu
|
||||
}}
|
||||
>
|
||||
{chapter.Name}
|
||||
</MenuItem>
|
||||
))}
|
||||
</Menu>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default ChaptersListButton;
|
||||
@@ -0,0 +1,20 @@
|
||||
import { IconButton } from "@mui/material";
|
||||
import React from "react";
|
||||
import { useShallow } from "zustand/shallow";
|
||||
import { usePlaybackStore } from "@/utils/store/playback";
|
||||
|
||||
const ForwardButton = () => {
|
||||
const { seekForward } = usePlaybackStore(
|
||||
useShallow((state) => ({
|
||||
seekForward: state.seekForward,
|
||||
})),
|
||||
);
|
||||
|
||||
return (
|
||||
<IconButton onClick={() => seekForward(15)}>
|
||||
<span className="material-symbols-rounded fill">fast_forward</span>
|
||||
</IconButton>
|
||||
);
|
||||
};
|
||||
|
||||
export default ForwardButton;
|
||||
@@ -0,0 +1,23 @@
|
||||
import { IconButton } from "@mui/material";
|
||||
import React from "react";
|
||||
import { useShallow } from "zustand/shallow";
|
||||
import { usePlaybackStore } from "@/utils/store/playback";
|
||||
|
||||
const FullscreenButton = () => {
|
||||
const { isPlayerFullscreen, toggleIsPlayerFullscreen } = usePlaybackStore(
|
||||
useShallow((state) => ({
|
||||
isPlayerFullscreen: state.playerState.isPlayerFullscreen,
|
||||
toggleIsPlayerFullscreen: state.toggleIsPlayerFullscreen,
|
||||
})),
|
||||
);
|
||||
|
||||
return (
|
||||
<IconButton onClick={toggleIsPlayerFullscreen}>
|
||||
<span className="material-symbols-rounded fill">
|
||||
{isPlayerFullscreen ? "fullscreen_exit" : "fullscreen"}
|
||||
</span>
|
||||
</IconButton>
|
||||
);
|
||||
};
|
||||
|
||||
export default FullscreenButton;
|
||||
@@ -0,0 +1,19 @@
|
||||
import { IconButton } from "@mui/material";
|
||||
import React from "react";
|
||||
import { useShallow } from "zustand/shallow";
|
||||
import { usePlaybackStore } from "@/utils/store/playback";
|
||||
|
||||
const NextChapterButton = () => {
|
||||
const { seekToNextChapter } = usePlaybackStore(
|
||||
useShallow((state) => ({
|
||||
seekToNextChapter: state.seekToNextChapter,
|
||||
})),
|
||||
);
|
||||
return (
|
||||
<IconButton onClick={() => seekToNextChapter()}>
|
||||
<span className="material-symbols-rounded fill">last_page</span>
|
||||
</IconButton>
|
||||
);
|
||||
};
|
||||
|
||||
export default NextChapterButton;
|
||||
@@ -0,0 +1,22 @@
|
||||
import { IconButton } from "@mui/material";
|
||||
import React from "react";
|
||||
import { useShallow } from "zustand/shallow";
|
||||
import { usePlaybackStore } from "@/utils/store/playback";
|
||||
|
||||
const PlayPauseButton = () => {
|
||||
const { isPlayerPlaying, toggleIsPlaying } = usePlaybackStore(
|
||||
useShallow((state) => ({
|
||||
isPlayerPlaying: state.playerState.isPlayerPlaying,
|
||||
toggleIsPlaying: state.toggleIsPlaying,
|
||||
})),
|
||||
);
|
||||
return (
|
||||
<IconButton onClick={toggleIsPlaying}>
|
||||
<span className="material-symbols-rounded fill">
|
||||
{isPlayerPlaying ? "pause" : "play_arrow"}
|
||||
</span>
|
||||
</IconButton>
|
||||
);
|
||||
};
|
||||
|
||||
export default PlayPauseButton;
|
||||
@@ -0,0 +1,20 @@
|
||||
import { IconButton } from "@mui/material";
|
||||
import React from "react";
|
||||
import { useShallow } from "zustand/shallow";
|
||||
import { usePlaybackStore } from "@/utils/store/playback";
|
||||
|
||||
const PrevChapterButton = () => {
|
||||
const { seekToPrevChapter } = usePlaybackStore(
|
||||
useShallow((state) => ({
|
||||
seekToPrevChapter: state.seekToPrevChapter,
|
||||
})),
|
||||
);
|
||||
|
||||
return (
|
||||
<IconButton onClick={seekToPrevChapter}>
|
||||
<span className="material-symbols-rounded fill">first_page</span>
|
||||
</IconButton>
|
||||
);
|
||||
};
|
||||
|
||||
export default PrevChapterButton;
|
||||
@@ -0,0 +1,23 @@
|
||||
import { IconButton } from "@mui/material";
|
||||
import React from "react";
|
||||
import { useShallow } from "zustand/shallow";
|
||||
import { usePlaybackStore } from "@/utils/store/playback";
|
||||
|
||||
const RewindButton = () => {
|
||||
const { seekBackward } = usePlaybackStore(
|
||||
useShallow((state) => ({
|
||||
seekBackward: state.seekBackward,
|
||||
})),
|
||||
);
|
||||
return (
|
||||
<IconButton
|
||||
onClick={() => {
|
||||
seekBackward(15);
|
||||
}}
|
||||
>
|
||||
<span className="material-symbols-rounded fill">fast_rewind</span>
|
||||
</IconButton>
|
||||
);
|
||||
};
|
||||
|
||||
export default RewindButton;
|
||||
@@ -0,0 +1,41 @@
|
||||
import { Button } from "@mui/material";
|
||||
import React from "react";
|
||||
import { useShallow } from "zustand/shallow";
|
||||
import { usePlaybackStore } from "@/utils/store/playback";
|
||||
|
||||
const SkipSegmentButton = () => {
|
||||
const { mediaSegments, currentSegmentIndex, skipSegment } = usePlaybackStore(
|
||||
useShallow((state) => ({
|
||||
mediaSegments: state.metadata.mediaSegments,
|
||||
currentSegmentIndex: state.nextSegmentIndex - 1,
|
||||
skipSegment: state.skipSegment,
|
||||
})),
|
||||
);
|
||||
|
||||
if (!mediaSegments?.Items?.length || currentSegmentIndex < 0) {
|
||||
return <></>; // No segments to skip
|
||||
}
|
||||
|
||||
console.log("Current Segment Index:", currentSegmentIndex);
|
||||
console.log("Media Segments:", mediaSegments);
|
||||
|
||||
return (
|
||||
<Button
|
||||
variant="outlined"
|
||||
size="large"
|
||||
//@ts-ignore
|
||||
color="white"
|
||||
style={{
|
||||
position: "absolute",
|
||||
bottom: "18vh",
|
||||
right: "2em",
|
||||
zIndex: 10000,
|
||||
}}
|
||||
onClick={skipSegment}
|
||||
>
|
||||
Skip {mediaSegments?.Items?.[currentSegmentIndex].Type}
|
||||
</Button>
|
||||
);
|
||||
};
|
||||
|
||||
export default SkipSegmentButton;
|
||||
@@ -0,0 +1,60 @@
|
||||
.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;
|
||||
cursor: none;
|
||||
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));
|
||||
&.hovering {
|
||||
cursor: default;
|
||||
}
|
||||
&-controls {
|
||||
&-timeline-text {
|
||||
display: flex;
|
||||
align-items: stretch;
|
||||
justify-content: space-between;
|
||||
}
|
||||
&-progress {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.2em;
|
||||
align-items: stretch;
|
||||
justify-content: center;
|
||||
margin-bottom: 0.5em;
|
||||
&-bubble {
|
||||
width: 14em;
|
||||
top: 0;
|
||||
left: 0;
|
||||
transform-origin: bottom center;
|
||||
transform: translate(var(--left, 0), var(--top, 0));
|
||||
position: fixed;
|
||||
}
|
||||
}
|
||||
&-buttons {
|
||||
display: flex;
|
||||
gap: 0.4em;
|
||||
align-items: center;
|
||||
}
|
||||
}
|
||||
.MuiSlider-valueLabel {
|
||||
padding: 0;
|
||||
background: transparent;
|
||||
overflow: hidden;
|
||||
border-radius: $border-radius-default;
|
||||
border: 1.2px solid rgb(255 255 255 / 0.1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,334 @@
|
||||
import { getPlaystateApi } from "@jellyfin/sdk/lib/utils/api/playstate-api";
|
||||
import { IconButton, Typography } from "@mui/material";
|
||||
import { WebviewWindow as appWindow } from "@tauri-apps/api/webviewWindow";
|
||||
import { motion } from "motion/react";
|
||||
import React, {
|
||||
type MouseEvent,
|
||||
useCallback,
|
||||
useEffect,
|
||||
useRef,
|
||||
useState,
|
||||
} from "react";
|
||||
import { useShallow } from "zustand/shallow";
|
||||
import PlayNextButton from "@/components/buttons/playNextButton";
|
||||
import PlayPreviousButton from "@/components/buttons/playPreviousButtom";
|
||||
import QueueButton from "@/components/buttons/queueButton";
|
||||
import BubbleSlider from "@/components/playback/videoPlayer/bubbleSlider";
|
||||
import { endsAt, secToTicks } from "@/utils/date/time";
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import { usePlaybackStore } from "@/utils/store/playback";
|
||||
import CaptionsButton from "./buttons/CaptionsButton";
|
||||
import ChaptersListButton from "./buttons/ChaptersListButton";
|
||||
import ForwardButton from "./buttons/ForwardButton";
|
||||
import FullscreenButton from "./buttons/FullscreenButton";
|
||||
import NextChapterButton from "./buttons/NextChapterButton";
|
||||
import PlayPauseButton from "./buttons/PlayPauseButton";
|
||||
import PrevChapterButton from "./buttons/PrevChapterButton";
|
||||
import RewindButton from "./buttons/RewindButton";
|
||||
import VideoPlayerSettingsMenu from "./settingsMenu";
|
||||
|
||||
import "./controls.scss";
|
||||
import { clearQueue } from "@/utils/store/queue";
|
||||
import ProgressDislay from "./ProgressDisplay";
|
||||
|
||||
/**
|
||||
* Constant for the volume change interval when using the mouse wheel.
|
||||
* This value determines how much the volume will change with each scroll step.
|
||||
*/
|
||||
const VOLUME_SCROLL_INTERVAL = 0.02;
|
||||
|
||||
type VideoPlayerControlsProps = {
|
||||
isVisible: boolean;
|
||||
onHover?: (event: MouseEvent<HTMLDivElement>) => void;
|
||||
onLeave?: (event: MouseEvent<HTMLDivElement>) => void;
|
||||
};
|
||||
|
||||
const VideoPlayerControls = ({
|
||||
isVisible,
|
||||
onHover,
|
||||
onLeave,
|
||||
}: VideoPlayerControlsProps) => {
|
||||
const playerOSDRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
const api = useApiInContext((state) => state.api);
|
||||
const {
|
||||
mediaSourceId,
|
||||
itemId,
|
||||
itemDuration,
|
||||
itemName,
|
||||
episodeTitle,
|
||||
playsessionId,
|
||||
isPlayerPlaying,
|
||||
toggleIsPlaying,
|
||||
toggleIsPlayerFullscreen,
|
||||
isUserSeeking,
|
||||
// seekValue,
|
||||
isPlayerMuted,
|
||||
volume,
|
||||
toggleIsPlayerMuted,
|
||||
increaseVolumeByStep,
|
||||
decreaseVolumeByStep,
|
||||
getCurrentTime,
|
||||
} = usePlaybackStore(
|
||||
useShallow((state) => ({
|
||||
mediaSourceId: state.mediaSource.id,
|
||||
itemChapters: state.metadata.item.Chapters,
|
||||
itemId: state.metadata.item.Id,
|
||||
itemDuration: state.metadata.itemDuration,
|
||||
itemName: state.metadata.itemName,
|
||||
episodeTitle: state.metadata.episodeTitle,
|
||||
// mediaSegments: state.metadata.mediaSegments,
|
||||
isPlayerPlaying: state.playerState.isPlayerPlaying,
|
||||
playsessionId: state.playsessionId,
|
||||
toggleIsPlaying: state.toggleIsPlaying,
|
||||
toggleIsPlayerFullscreen: state.toggleIsPlayerFullscreen,
|
||||
isUserSeeking: state.playerState.isUserSeeking,
|
||||
seekValue: state.playerState.seekValue,
|
||||
isPlayerMuted: state.playerState.isPlayerMuted,
|
||||
volume: state.playerState.volume,
|
||||
toggleIsPlayerMuted: state.toggleIsPlayerMuted,
|
||||
increaseVolumeByStep: state.increaseVolumeByStep,
|
||||
decreaseVolumeByStep: state.decreaseVolumeByStep,
|
||||
getCurrentTime: state.getCurrentTime,
|
||||
})),
|
||||
);
|
||||
|
||||
// Volume control with mouse wheel
|
||||
useEffect(() => {
|
||||
const handleMouseWheel = (event: WheelEvent) => {
|
||||
if (event.deltaY < 0) {
|
||||
increaseVolumeByStep(VOLUME_SCROLL_INTERVAL);
|
||||
} else if (event.deltaY > 0) {
|
||||
decreaseVolumeByStep(VOLUME_SCROLL_INTERVAL);
|
||||
}
|
||||
};
|
||||
|
||||
const currentRef = playerOSDRef.current;
|
||||
// attach the event listener
|
||||
currentRef?.addEventListener("wheel", handleMouseWheel);
|
||||
|
||||
// remove the event listener
|
||||
return () => {
|
||||
currentRef?.removeEventListener("wheel", handleMouseWheel);
|
||||
};
|
||||
}, [increaseVolumeByStep, decreaseVolumeByStep]);
|
||||
|
||||
const [clickTimeout, setClickTimeout] = useState<NodeJS.Timeout | null>(null);
|
||||
|
||||
const [settingsMenuRef, setSettingsMenuRef] =
|
||||
useState<HTMLButtonElement | null>(null);
|
||||
|
||||
// const creditInfo = mediaSegments?.Items?.find(
|
||||
// (segment) => segment.Type === "Outro",
|
||||
// );
|
||||
|
||||
// Credits and Next Episode Card
|
||||
// const [forceShowCredits, setForceShowCredits] = useState(false);
|
||||
// const showUpNextCard = useMemo(() => {
|
||||
// if (queue?.[currentQueueItemIndex]?.Id === queue?.[queue.length - 1]?.Id) {
|
||||
// return false; // Check if the current playing episode is last episode in queue
|
||||
// }
|
||||
// if (creditInfo) {
|
||||
// if (
|
||||
// currentTime >= (creditInfo.StartTicks ?? currentTime + 1) &&
|
||||
// currentTime < (creditInfo.EndTicks ?? 0)
|
||||
// )
|
||||
// return true;
|
||||
// }
|
||||
// if (
|
||||
// Math.ceil(ticksToSec(itemDuration) - ticksToSec(currentTime)) <= 30 &&
|
||||
// Math.ceil(ticksToSec(itemDuration) - ticksToSec(currentTime)) > 0
|
||||
// ) {
|
||||
// return true;
|
||||
// }
|
||||
// return false;
|
||||
// }, [currentTime, creditInfo, itemDuration, queue, currentQueueItemIndex]);
|
||||
|
||||
const handleExitPlayer = useCallback(async () => {
|
||||
appWindow.getCurrent().setFullscreen(false);
|
||||
|
||||
history.back();
|
||||
if (!api) {
|
||||
throw Error("API is not available, cannot report playback stopped.");
|
||||
}
|
||||
// Report Jellyfin server: Playback has ended/stopped
|
||||
getPlaystateApi(api).reportPlaybackStopped({
|
||||
playbackStopInfo: {
|
||||
Failed: false,
|
||||
ItemId: itemId,
|
||||
MediaSourceId: mediaSourceId,
|
||||
PlaySessionId: playsessionId,
|
||||
PositionTicks: secToTicks(getCurrentTime() ?? 0),
|
||||
},
|
||||
});
|
||||
usePlaybackStore.setState(usePlaybackStore.getInitialState());
|
||||
clearQueue();
|
||||
}, [api, mediaSourceId, playsessionId, itemId]);
|
||||
|
||||
return (
|
||||
<motion.div
|
||||
className={
|
||||
isVisible || isUserSeeking || !isPlayerPlaying
|
||||
? "video-player-osd hovering"
|
||||
: "video-player-osd"
|
||||
}
|
||||
onMouseEnter={onHover}
|
||||
onMouseLeave={onLeave}
|
||||
ref={playerOSDRef}
|
||||
initial={{
|
||||
opacity: 0,
|
||||
}}
|
||||
animate={{
|
||||
opacity: isVisible || isUserSeeking || !isPlayerPlaying ? 1 : 0,
|
||||
}}
|
||||
style={{
|
||||
zIndex: 2,
|
||||
}}
|
||||
onClick={(event) => {
|
||||
if (event.currentTarget !== event.target) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.detail === 1) {
|
||||
setClickTimeout(
|
||||
setTimeout(() => {
|
||||
toggleIsPlaying();
|
||||
}, 200),
|
||||
);
|
||||
} else if (event.detail === 2 && clickTimeout) {
|
||||
clearTimeout(clickTimeout);
|
||||
toggleIsPlayerFullscreen();
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div className="video-player-osd-header flex flex-justify-spaced-between flex-align-center">
|
||||
<IconButton onClick={handleExitPlayer}>
|
||||
<span className="material-symbols-rounded">arrow_back</span>
|
||||
</IconButton>
|
||||
<IconButton onClick={(e) => setSettingsMenuRef(e.currentTarget)}>
|
||||
<span className="material-symbols-rounded">settings</span>
|
||||
</IconButton>
|
||||
<VideoPlayerSettingsMenu
|
||||
settingsMenuRef={settingsMenuRef}
|
||||
handleClose={() => setSettingsMenuRef(null)}
|
||||
/>
|
||||
</div>
|
||||
<div className="video-player-osd-info">
|
||||
<div>
|
||||
<Typography variant="h4" fontWeight={500} mb={2}>
|
||||
{String(itemName)}
|
||||
</Typography>
|
||||
{episodeTitle && (
|
||||
<Typography variant="h6" fontWeight={300} mt={1}>
|
||||
{String(episodeTitle)}
|
||||
</Typography>
|
||||
)}
|
||||
</div>
|
||||
<div className="video-player-osd-controls">
|
||||
<div className="video-player-osd-controls-timeline">
|
||||
<BubbleSlider />
|
||||
<ProgressDislay />
|
||||
</div>
|
||||
<div className="flex flex-row flex-justify-spaced-between">
|
||||
<div className="video-player-osd-controls-buttons">
|
||||
<PlayPreviousButton />
|
||||
<RewindButton />
|
||||
<PrevChapterButton />
|
||||
|
||||
<PlayPauseButton />
|
||||
|
||||
<NextChapterButton />
|
||||
|
||||
<ForwardButton />
|
||||
<PlayNextButton />
|
||||
|
||||
<Typography variant="subtitle1">
|
||||
{endsAt(itemDuration)}
|
||||
</Typography>
|
||||
</div>
|
||||
<div className="video-player-osd-controls-buttons">
|
||||
{/* <motion.div
|
||||
style={{
|
||||
width: "13em",
|
||||
padding: "0.5em 1.5em",
|
||||
paddingLeft: "0.8em",
|
||||
gap: "0.4em",
|
||||
background: "black",
|
||||
borderRadius: "100px",
|
||||
display: "grid",
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
gridTemplateColumns: "2em 1fr",
|
||||
opacity: 0,
|
||||
}}
|
||||
animate={{
|
||||
opacity: showVolumeControl ? 1 : 0,
|
||||
}}
|
||||
whileHover={{
|
||||
opacity: 1,
|
||||
}}
|
||||
onMouseLeave={() => setShowVolumeControl(false)}
|
||||
>
|
||||
<Typography textAlign="center">
|
||||
{isPlayerMuted ? 0 : Math.round(playerVolume * 100)}
|
||||
</Typography>
|
||||
<Slider
|
||||
step={0.01}
|
||||
max={1}
|
||||
size="small"
|
||||
value={isPlayerMuted ? 0 : playerVolume}
|
||||
onChange={async (_, newValue) => {
|
||||
if (api && Array.isArray(newValue)) {
|
||||
dispatch({
|
||||
type: VideoPlayerActionKind.SET_PLAYER_VOLUME,
|
||||
payload: newValue[0],
|
||||
});
|
||||
} else {
|
||||
dispatch({
|
||||
type: VideoPlayerActionKind.SET_PLAYER_VOLUME,
|
||||
payload: newValue,
|
||||
});
|
||||
}
|
||||
if (newValue === 0)
|
||||
dispatch({
|
||||
type: VideoPlayerActionKind.SET_PLAYER_MUTED,
|
||||
payload: true,
|
||||
});
|
||||
else
|
||||
dispatch({
|
||||
type: VideoPlayerActionKind.SET_PLAYER_MUTED,
|
||||
payload: true,
|
||||
});
|
||||
}}
|
||||
/>
|
||||
</motion.div> */}
|
||||
{/* TODO: Volume menu */}
|
||||
<IconButton
|
||||
onClick={toggleIsPlayerMuted}
|
||||
// onMouseMoveCapture={() => {
|
||||
// setShowVolumeControl(true);
|
||||
// }}
|
||||
>
|
||||
<span className="material-symbols-rounded">
|
||||
{isPlayerMuted
|
||||
? "volume_off"
|
||||
: volume < 0.4
|
||||
? "volume_down"
|
||||
: "volume_up"}
|
||||
</span>
|
||||
</IconButton>
|
||||
<QueueButton />
|
||||
|
||||
<ChaptersListButton />
|
||||
|
||||
<CaptionsButton />
|
||||
<FullscreenButton />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</motion.div>
|
||||
);
|
||||
};
|
||||
|
||||
export default VideoPlayerControls;
|
||||
@@ -0,0 +1,138 @@
|
||||
import { MenuItem, Popover, TextField } from "@mui/material";
|
||||
import { toNumber } from "lodash";
|
||||
import React, {
|
||||
type ChangeEventHandler,
|
||||
useCallback,
|
||||
useMemo,
|
||||
useTransition,
|
||||
} from "react";
|
||||
import { useShallow } from "zustand/shallow";
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import {
|
||||
changeAudioTrack,
|
||||
changeSubtitleTrack,
|
||||
usePlaybackStore,
|
||||
} from "@/utils/store/playback";
|
||||
|
||||
type VideoPlayerSettingsMenuProps = {
|
||||
settingsMenuRef: HTMLButtonElement | null;
|
||||
handleClose: () => void;
|
||||
};
|
||||
|
||||
const VideoPlayerSettingsMenu = ({
|
||||
settingsMenuRef,
|
||||
handleClose,
|
||||
}: VideoPlayerSettingsMenuProps) => {
|
||||
const settingsMenuOpen = useMemo(() => {
|
||||
return Boolean(settingsMenuRef);
|
||||
}, [settingsMenuRef]);
|
||||
|
||||
const api = useApiInContext((state) => state.api);
|
||||
|
||||
const { mediaSource, setIsBuffering } = usePlaybackStore(
|
||||
useShallow((state) => ({
|
||||
mediaSource: state.mediaSource,
|
||||
setIsBuffering: state.setIsBuffering,
|
||||
})),
|
||||
);
|
||||
|
||||
const [subtitleIsChanging, startSubtitleChange] = useTransition();
|
||||
const handleSubtitleChange: ChangeEventHandler<
|
||||
HTMLInputElement | HTMLTextAreaElement
|
||||
> = useCallback(
|
||||
(e) => {
|
||||
startSubtitleChange(() => {
|
||||
if (mediaSource.subtitle.allTracks) {
|
||||
changeSubtitleTrack(
|
||||
toNumber(e.target.value),
|
||||
mediaSource.subtitle.allTracks,
|
||||
);
|
||||
handleClose();
|
||||
}
|
||||
});
|
||||
},
|
||||
[mediaSource.subtitle?.allTracks],
|
||||
);
|
||||
|
||||
const [audioTackIsChanging, startAudioTrackChange] = useTransition();
|
||||
const handleAudioTrackChange: ChangeEventHandler<
|
||||
HTMLInputElement | HTMLTextAreaElement
|
||||
> = (e) => {
|
||||
// setPlaying(false);
|
||||
startAudioTrackChange(() => {
|
||||
if (api && mediaSource.audio.allTracks) {
|
||||
changeAudioTrack(toNumber(e.target.value), api);
|
||||
handleClose();
|
||||
setIsBuffering(true);
|
||||
}
|
||||
});
|
||||
|
||||
// setPlaying(true);
|
||||
};
|
||||
|
||||
return (
|
||||
<Popover
|
||||
anchorEl={settingsMenuRef}
|
||||
open={settingsMenuOpen}
|
||||
onClose={handleClose}
|
||||
slotProps={{
|
||||
paper: {
|
||||
style: {
|
||||
maxHeight: "20em",
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
gap: "1em",
|
||||
width: "24em",
|
||||
padding: "1em",
|
||||
borderRadius: "12px",
|
||||
},
|
||||
className: "glass",
|
||||
},
|
||||
}}
|
||||
anchorOrigin={{
|
||||
vertical: "bottom",
|
||||
horizontal: "right",
|
||||
}}
|
||||
transformOrigin={{
|
||||
vertical: "top",
|
||||
horizontal: "right",
|
||||
}}
|
||||
>
|
||||
<TextField
|
||||
select
|
||||
label="Audio"
|
||||
variant="outlined"
|
||||
value={mediaSource.audio?.track}
|
||||
onChange={handleAudioTrackChange}
|
||||
fullWidth
|
||||
disabled={audioTackIsChanging}
|
||||
>
|
||||
{mediaSource.audio?.allTracks?.map((sub) => (
|
||||
<MenuItem key={sub.Index} value={sub.Index}>
|
||||
{sub.DisplayTitle}
|
||||
</MenuItem>
|
||||
))}
|
||||
</TextField>
|
||||
<TextField
|
||||
select
|
||||
label="Subtitles"
|
||||
variant="outlined"
|
||||
value={mediaSource.subtitle?.track}
|
||||
onChange={handleSubtitleChange}
|
||||
fullWidth
|
||||
disabled={mediaSource.subtitle?.track === -2 || subtitleIsChanging}
|
||||
>
|
||||
<MenuItem key={-1} value={-1}>
|
||||
No Subtitle
|
||||
</MenuItem>
|
||||
{mediaSource.subtitle?.allTracks?.map((sub) => (
|
||||
<MenuItem key={sub.Index} value={sub.Index}>
|
||||
{sub.DisplayTitle}
|
||||
</MenuItem>
|
||||
))}
|
||||
</TextField>
|
||||
</Popover>
|
||||
);
|
||||
};
|
||||
|
||||
export default VideoPlayerSettingsMenu;
|
||||
@@ -1,76 +1,74 @@
|
||||
import * as generatedClient from "@jellyfin/sdk/lib/generated-client";
|
||||
import {
|
||||
BaseItemKind,
|
||||
type CollectionType,
|
||||
} from "@jellyfin/sdk/lib/generated-client";
|
||||
import React from "react";
|
||||
|
||||
export const getTypeIcon = (
|
||||
icon:
|
||||
| generatedClient.BaseItemKind
|
||||
| generatedClient.CollectionType
|
||||
| "Home"
|
||||
| "User"
|
||||
| "universal",
|
||||
icon: BaseItemKind | CollectionType | "Home" | "User" | "universal",
|
||||
) => {
|
||||
switch (icon) {
|
||||
case "Home":
|
||||
return <div className="material-symbols-rounded">home</div>;
|
||||
case generatedClient.BaseItemKind.Audio:
|
||||
case BaseItemKind.Audio:
|
||||
return <div className="material-symbols-rounded">mic</div>;
|
||||
case generatedClient.BaseItemKind.AudioBook:
|
||||
case BaseItemKind.AudioBook:
|
||||
return <div className="material-symbols-rounded">speech_to_text</div>;
|
||||
case generatedClient.BaseItemKind.Book:
|
||||
case BaseItemKind.Book:
|
||||
return <div className="material-symbols-rounded">book</div>;
|
||||
case "boxsets":
|
||||
case generatedClient.BaseItemKind.BoxSet:
|
||||
case BaseItemKind.BoxSet:
|
||||
return <div className="material-symbols-rounded">video_library</div>;
|
||||
case "livetv":
|
||||
case generatedClient.BaseItemKind.TvProgram:
|
||||
case generatedClient.BaseItemKind.TvChannel:
|
||||
case generatedClient.BaseItemKind.Program:
|
||||
case generatedClient.BaseItemKind.Recording:
|
||||
case generatedClient.BaseItemKind.LiveTvChannel:
|
||||
case generatedClient.BaseItemKind.LiveTvProgram:
|
||||
case generatedClient.BaseItemKind.ChannelFolderItem:
|
||||
case generatedClient.BaseItemKind.Channel:
|
||||
case BaseItemKind.TvProgram:
|
||||
case BaseItemKind.TvChannel:
|
||||
case BaseItemKind.Program:
|
||||
case BaseItemKind.Recording:
|
||||
case BaseItemKind.LiveTvChannel:
|
||||
case BaseItemKind.LiveTvProgram:
|
||||
case BaseItemKind.ChannelFolderItem:
|
||||
case BaseItemKind.Channel:
|
||||
return (
|
||||
<div className="material-symbols-rounded">settings_input_antenna</div>
|
||||
);
|
||||
case "tvshows":
|
||||
case generatedClient.BaseItemKind.Season:
|
||||
case generatedClient.BaseItemKind.Series:
|
||||
case generatedClient.BaseItemKind.Episode:
|
||||
case BaseItemKind.Season:
|
||||
case BaseItemKind.Series:
|
||||
case BaseItemKind.Episode:
|
||||
return <div className="material-symbols-rounded">tv_gen</div>;
|
||||
case "playlists":
|
||||
case generatedClient.BaseItemKind.Playlist:
|
||||
case generatedClient.BaseItemKind.PlaylistsFolder:
|
||||
case generatedClient.BaseItemKind.ManualPlaylistsFolder:
|
||||
case BaseItemKind.Playlist:
|
||||
case BaseItemKind.PlaylistsFolder:
|
||||
case BaseItemKind.ManualPlaylistsFolder:
|
||||
return <div className="material-symbols-rounded">queue_music</div>;
|
||||
case "movies":
|
||||
case generatedClient.BaseItemKind.Movie:
|
||||
case BaseItemKind.Movie:
|
||||
return <div className="material-symbols-rounded">movie</div>;
|
||||
case generatedClient.BaseItemKind.MusicAlbum:
|
||||
case BaseItemKind.MusicAlbum:
|
||||
return <div className="material-symbols-rounded">album</div>;
|
||||
case generatedClient.BaseItemKind.MusicArtist:
|
||||
case BaseItemKind.MusicArtist:
|
||||
return <div className="material-symbols-rounded">artist</div>;
|
||||
case generatedClient.BaseItemKind.Genre:
|
||||
case generatedClient.BaseItemKind.MusicGenre:
|
||||
case BaseItemKind.Genre:
|
||||
case BaseItemKind.MusicGenre:
|
||||
return <div className="material-symbols-rounded">domino_mask</div>;
|
||||
case "musicvideos":
|
||||
case generatedClient.BaseItemKind.MusicVideo:
|
||||
case BaseItemKind.MusicVideo:
|
||||
return <div className="material-symbols-rounded">music_video</div>;
|
||||
case "User":
|
||||
case generatedClient.BaseItemKind.Person:
|
||||
case BaseItemKind.Person:
|
||||
return <div className="material-symbols-rounded">person</div>;
|
||||
case generatedClient.BaseItemKind.Photo:
|
||||
case BaseItemKind.Photo:
|
||||
return <div className="material-symbols-rounded">image</div>;
|
||||
case "photos":
|
||||
case generatedClient.BaseItemKind.PhotoAlbum:
|
||||
case BaseItemKind.PhotoAlbum:
|
||||
return <div className="material-symbols-rounded">photo_library</div>;
|
||||
case "universal":
|
||||
case generatedClient.BaseItemKind.Studio:
|
||||
case BaseItemKind.Studio:
|
||||
return <div className="material-symbols-rounded">category</div>;
|
||||
case "trailers":
|
||||
case generatedClient.BaseItemKind.Trailer:
|
||||
case BaseItemKind.Trailer:
|
||||
return <div className="material-symbols-rounded">smart_display</div>;
|
||||
case generatedClient.BaseItemKind.Video:
|
||||
case BaseItemKind.Video:
|
||||
return <div className="material-symbols-rounded">theaters</div>;
|
||||
case "music":
|
||||
return <div className="material-symbols-rounded">library_music</div>;
|
||||
|
||||
Reference in new issue
Block a user