feat: revamp the entire audio player with a refreshed look and cleanup audioPlayer code
This commit is contained in:
16 files changed
+1571
-755
No files matched your search
@@ -43,7 +43,10 @@ export const AppBar = () => {
|
|||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
|
|
||||||
const display = !HIDDEN_PATHS.some(
|
const display = !HIDDEN_PATHS.some(
|
||||||
(path) => location.pathname.startsWith(path) || location.pathname === "/",
|
(path) =>
|
||||||
|
(location.pathname.startsWith(path) &&
|
||||||
|
location.pathname !== "/player/audio") ||
|
||||||
|
location.pathname === "/",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,15 +2,39 @@ $image-size: 4em;
|
|||||||
|
|
||||||
.audio-player {
|
.audio-player {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
bottom: 0;
|
bottom: 1rem;
|
||||||
right: 0;
|
left: 50%;
|
||||||
z-index: 10;
|
transform: translateX(-50%);
|
||||||
|
width: 95%;
|
||||||
|
max-width: 1200px;
|
||||||
|
z-index: 100;
|
||||||
display: grid;
|
display: grid;
|
||||||
padding: 0.5em 1.5em;
|
padding: 0.75em 1.5em;
|
||||||
gap: 1em;
|
gap: 1.5em;
|
||||||
box-shadow: 0 0 20px rgb(0 0 0 / 0.25);
|
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
|
||||||
grid-template-columns: 30% 1fr 30%;
|
grid-template-columns: 25% 1fr 25%;
|
||||||
background: rgb(0 0 0 / 0.8) !important;
|
background: rgba(18, 18, 18, 0.85) !important;
|
||||||
|
backdrop-filter: blur(12px);
|
||||||
|
-webkit-backdrop-filter: blur(12px);
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||||
|
border-radius: 1rem;
|
||||||
|
align-items: center;
|
||||||
|
|
||||||
|
@media (max-width: 900px) {
|
||||||
|
grid-template-columns: 1fr auto;
|
||||||
|
padding: 0.5em 1em;
|
||||||
|
bottom: 0;
|
||||||
|
width: 100%;
|
||||||
|
border-radius: 0;
|
||||||
|
border-bottom: none;
|
||||||
|
border-left: none;
|
||||||
|
border-right: none;
|
||||||
|
|
||||||
|
.audio-player-controls {
|
||||||
|
display: none; // Hide controls on mobile for now or adjust
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#waveform {
|
#waveform {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
transform: scaleY(0);
|
transform: scaleY(0);
|
||||||
@@ -36,6 +60,13 @@ $image-size: 4em;
|
|||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
|
||||||
|
&-text {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
overflow: hidden;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
&-image {
|
&-image {
|
||||||
width: $image-size;
|
width: $image-size;
|
||||||
|
|||||||
@@ -0,0 +1,104 @@
|
|||||||
|
import type { Api } from "@jellyfin/sdk";
|
||||||
|
import type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client";
|
||||||
|
import { getLyricsApi } from "@jellyfin/sdk/lib/utils/api/lyrics-api";
|
||||||
|
import { Typography } from "@mui/material";
|
||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import React, { useEffect, useRef, useState } from "react";
|
||||||
|
import { secToTicks } from "@/utils/date/time";
|
||||||
|
|
||||||
|
interface LyricsPanelProps {
|
||||||
|
item: BaseItemDto | undefined | null;
|
||||||
|
api: Api | undefined;
|
||||||
|
currentTime: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
const LyricsPanel = ({ item, api, currentTime }: LyricsPanelProps) => {
|
||||||
|
const lyricsContainer = useRef<HTMLDivElement | null>(null);
|
||||||
|
|
||||||
|
const lyrics = useQuery({
|
||||||
|
queryKey: ["player", "audio", item?.Id, "lyrics"],
|
||||||
|
queryFn: async () => {
|
||||||
|
if (!item?.Id || !api) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const response = await getLyricsApi(api).getLyrics({
|
||||||
|
itemId: item?.Id,
|
||||||
|
});
|
||||||
|
return response.data;
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Failed to fetch lyrics", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
enabled: Boolean(item?.Id) && Boolean(api),
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (lyrics.data && lyricsContainer.current) {
|
||||||
|
const currentLyric = lyricsContainer.current.querySelector(
|
||||||
|
"[data-active-lyric='true']",
|
||||||
|
);
|
||||||
|
if (currentLyric) {
|
||||||
|
currentLyric.scrollIntoView({
|
||||||
|
block: "center",
|
||||||
|
inline: "nearest",
|
||||||
|
behavior: "smooth",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [currentTime, lyrics.data]);
|
||||||
|
|
||||||
|
if (lyrics.isLoading) {
|
||||||
|
return (
|
||||||
|
<div className="audio-lyrics-status">
|
||||||
|
<Typography>Loading lyrics...</Typography>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lyrics.isError || !lyrics.data || !lyrics.data.Lyrics?.length) {
|
||||||
|
return (
|
||||||
|
<div className="audio-lyrics-status">
|
||||||
|
<Typography>No lyrics available</Typography>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const hasSyncedLyrics = (lyrics.data.Lyrics[0].Start ?? -1) >= 0;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="audio-lyrics" data-has-synced-lyrics={hasSyncedLyrics}>
|
||||||
|
<div className="audio-lyrics-container" ref={lyricsContainer}>
|
||||||
|
{lyrics.data.Lyrics.map((lyric, index) => {
|
||||||
|
const isActive =
|
||||||
|
hasSyncedLyrics &&
|
||||||
|
secToTicks(currentTime) >= (lyric.Start ?? 0) &&
|
||||||
|
secToTicks(currentTime) <
|
||||||
|
(lyrics.data?.Lyrics?.[index + 1]?.Start ??
|
||||||
|
Number.POSITIVE_INFINITY);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Typography
|
||||||
|
variant="body1"
|
||||||
|
component="p"
|
||||||
|
className={`audio-lyrics-line ${isActive ? "active" : ""}`}
|
||||||
|
key={`${lyric.Text}-${index}`}
|
||||||
|
data-active-lyric={isActive}
|
||||||
|
>
|
||||||
|
{lyric.Text}
|
||||||
|
</Typography>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
{!hasSyncedLyrics && (
|
||||||
|
<div className="audio-lyrics-unsynced-notice">
|
||||||
|
<span className="material-symbols-rounded">info</span>
|
||||||
|
<Typography variant="caption">Synced lyrics not available</Typography>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default React.memo(LyricsPanel);
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
import IconButton from "@mui/material/IconButton";
|
||||||
|
import type { ReactNode } from "react";
|
||||||
|
import React from "react";
|
||||||
|
import QueueButton from "@/components/buttons/queueButton";
|
||||||
|
|
||||||
|
interface PlayerActionsProps {
|
||||||
|
onNavigate: () => void;
|
||||||
|
onClose: () => void;
|
||||||
|
children?: ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
const PlayerActions = ({
|
||||||
|
onNavigate,
|
||||||
|
onClose,
|
||||||
|
children,
|
||||||
|
}: PlayerActionsProps) => {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "flex-end",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IconButton onClick={onNavigate}>
|
||||||
|
<span className="material-symbols-rounded">info</span>
|
||||||
|
</IconButton>
|
||||||
|
<QueueButton />
|
||||||
|
{children}
|
||||||
|
<IconButton onClick={onClose}>
|
||||||
|
<div className="material-symbols-rounded">close</div>
|
||||||
|
</IconButton>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default PlayerActions;
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
import Fab from "@mui/material/Fab";
|
||||||
|
import IconButton from "@mui/material/IconButton";
|
||||||
|
import React from "react";
|
||||||
|
import PlayNextButton from "@/components/buttons/playNextButton";
|
||||||
|
import PlayPreviousButton from "@/components/buttons/playPreviousButtom";
|
||||||
|
|
||||||
|
interface PlayerControlsProps {
|
||||||
|
playing: boolean;
|
||||||
|
onPlayPause: () => void;
|
||||||
|
size?: "small" | "medium" | "large";
|
||||||
|
onRewind?: () => void;
|
||||||
|
onForward?: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const PlayerControls = ({
|
||||||
|
playing,
|
||||||
|
onPlayPause,
|
||||||
|
size = "small",
|
||||||
|
onRewind,
|
||||||
|
onForward,
|
||||||
|
}: PlayerControlsProps) => {
|
||||||
|
return (
|
||||||
|
<div style={{ display: "flex", gap: "1em", alignItems: "center" }}>
|
||||||
|
<PlayPreviousButton />
|
||||||
|
{onRewind && (
|
||||||
|
<IconButton onClick={onRewind}>
|
||||||
|
<span className="material-symbols-rounded">fast_rewind</span>
|
||||||
|
</IconButton>
|
||||||
|
)}
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: "inline-flex",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "center",
|
||||||
|
position: "relative",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Fab size={size} onClick={onPlayPause}>
|
||||||
|
<div
|
||||||
|
className="material-symbols-rounded"
|
||||||
|
style={{
|
||||||
|
fontSize: size === "large" ? "2.4em" : "2em",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{playing ? "pause" : "play_arrow"}
|
||||||
|
</div>
|
||||||
|
</Fab>
|
||||||
|
</div>
|
||||||
|
{onForward && (
|
||||||
|
<IconButton onClick={onForward}>
|
||||||
|
<span className="material-symbols-rounded">fast_forward</span>
|
||||||
|
</IconButton>
|
||||||
|
)}
|
||||||
|
<PlayNextButton />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default React.memo(PlayerControls);
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
import type { Api } from "@jellyfin/sdk";
|
||||||
|
import type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client";
|
||||||
|
import Typography from "@mui/material/Typography";
|
||||||
|
import React from "react";
|
||||||
|
import getImageUrlsApi from "@/utils/methods/getImageUrlsApi";
|
||||||
|
|
||||||
|
interface PlayerInfoProps {
|
||||||
|
item: BaseItemDto | undefined | null;
|
||||||
|
api: Api | undefined;
|
||||||
|
trackName?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const PlayerInfo = ({ item, api, trackName }: PlayerInfoProps) => {
|
||||||
|
if (!api || !item) return null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="audio-player-info">
|
||||||
|
<div className="audio-player-image-container">
|
||||||
|
<img
|
||||||
|
alt={trackName ?? "track"}
|
||||||
|
className="audio-player-image"
|
||||||
|
src={getImageUrlsApi(api).getItemImageUrlById(
|
||||||
|
(!item?.ImageTags?.Primary ? item?.AlbumId : item.Id) ?? "",
|
||||||
|
"Primary",
|
||||||
|
{
|
||||||
|
quality: 85,
|
||||||
|
fillHeight: 462,
|
||||||
|
fillWidth: 462,
|
||||||
|
},
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<span className="material-symbols-rounded audio-player-image-icon">
|
||||||
|
music_note
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div className="audio-player-info-text">
|
||||||
|
<Typography
|
||||||
|
variant="subtitle2"
|
||||||
|
style={{
|
||||||
|
width: "100%",
|
||||||
|
}}
|
||||||
|
noWrap
|
||||||
|
>
|
||||||
|
{item?.Name}
|
||||||
|
</Typography>
|
||||||
|
<Typography
|
||||||
|
variant="caption"
|
||||||
|
style={{
|
||||||
|
opacity: 0.5,
|
||||||
|
}}
|
||||||
|
noWrap
|
||||||
|
>
|
||||||
|
by {item?.Artists?.map((artist) => artist).join(",")}
|
||||||
|
</Typography>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default PlayerInfo;
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
import Slider from "@mui/material/Slider";
|
||||||
|
import Typography from "@mui/material/Typography";
|
||||||
|
import React, { useEffect, useState } from "react";
|
||||||
|
import { getRuntimeMusic } from "@/utils/date/time";
|
||||||
|
|
||||||
|
interface PlayerProgressProps {
|
||||||
|
progress: number;
|
||||||
|
duration: number;
|
||||||
|
onSeek: (value: number) => void;
|
||||||
|
onSeekCommit: (value: number) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const PlayerProgress = ({
|
||||||
|
progress,
|
||||||
|
duration,
|
||||||
|
onSeek,
|
||||||
|
onSeekCommit,
|
||||||
|
}: PlayerProgressProps) => {
|
||||||
|
const [isScrubbing, setIsScrubbing] = useState(false);
|
||||||
|
const [sliderValue, setSliderValue] = useState(progress);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isScrubbing) {
|
||||||
|
setSliderValue(progress);
|
||||||
|
}
|
||||||
|
}, [progress, isScrubbing]);
|
||||||
|
|
||||||
|
const handleChange = (_: Event, value: number | number[]) => {
|
||||||
|
setIsScrubbing(true);
|
||||||
|
const newValue = Array.isArray(value) ? value[0] : value;
|
||||||
|
setSliderValue(newValue);
|
||||||
|
onSeek(newValue);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleChangeCommitted = (_: unknown, value: number | number[]) => {
|
||||||
|
setIsScrubbing(false);
|
||||||
|
const newValue = Array.isArray(value) ? value[0] : value;
|
||||||
|
onSeekCommit(newValue);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
width: "100%",
|
||||||
|
display: "flex",
|
||||||
|
gap: "1em",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "center",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Typography
|
||||||
|
variant="subtitle2"
|
||||||
|
fontWeight={300}
|
||||||
|
style={{
|
||||||
|
opacity: 0.8,
|
||||||
|
minWidth: "3.5em",
|
||||||
|
textAlign: "right",
|
||||||
|
fontVariantNumeric: "tabular-nums",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{getRuntimeMusic(sliderValue)}
|
||||||
|
</Typography>
|
||||||
|
<Slider
|
||||||
|
value={sliderValue}
|
||||||
|
step={1}
|
||||||
|
size="small"
|
||||||
|
max={duration}
|
||||||
|
onChange={handleChange}
|
||||||
|
onChangeCommitted={handleChangeCommitted}
|
||||||
|
/>
|
||||||
|
<Typography
|
||||||
|
variant="subtitle2"
|
||||||
|
fontWeight={300}
|
||||||
|
style={{
|
||||||
|
opacity: 0.8,
|
||||||
|
minWidth: "3.5em",
|
||||||
|
textAlign: "left",
|
||||||
|
fontVariantNumeric: "tabular-nums",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{getRuntimeMusic(duration)}
|
||||||
|
</Typography>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default PlayerProgress;
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
import IconButton from "@mui/material/IconButton";
|
||||||
|
import Slider from "@mui/material/Slider";
|
||||||
|
import React from "react";
|
||||||
|
|
||||||
|
interface PlayerVolumeProps {
|
||||||
|
volume: number;
|
||||||
|
isMuted: boolean;
|
||||||
|
onVolumeChange: (value: number) => void;
|
||||||
|
onMuteToggle: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const PlayerVolume = ({
|
||||||
|
volume,
|
||||||
|
isMuted,
|
||||||
|
onVolumeChange,
|
||||||
|
onMuteToggle,
|
||||||
|
}: PlayerVolumeProps) => {
|
||||||
|
const [localVolume, setLocalVolume] = React.useState(volume * 100);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
setLocalVolume(volume * 100);
|
||||||
|
}, [volume]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<IconButton onClick={onMuteToggle}>
|
||||||
|
<div className="material-symbols-rounded">
|
||||||
|
{isMuted ? "volume_mute" : "volume_up"}
|
||||||
|
</div>
|
||||||
|
</IconButton>
|
||||||
|
<Slider
|
||||||
|
value={isMuted ? 0 : localVolume}
|
||||||
|
step={1}
|
||||||
|
max={100}
|
||||||
|
onChange={(_, newVal) => {
|
||||||
|
const newVolume = Array.isArray(newVal) ? newVal[0] : newVal;
|
||||||
|
setLocalVolume(newVolume);
|
||||||
|
onVolumeChange(newVolume / 100);
|
||||||
|
}}
|
||||||
|
valueLabelDisplay="auto"
|
||||||
|
valueLabelFormat={(value) => Math.floor(value)}
|
||||||
|
size="small"
|
||||||
|
sx={{
|
||||||
|
mr: 1,
|
||||||
|
ml: 1,
|
||||||
|
width: "10em",
|
||||||
|
"& .MuiSlider-valueLabel": {
|
||||||
|
lineHeight: 1.2,
|
||||||
|
fontSize: 24,
|
||||||
|
background: "rgb(0 0 0 / 0.5)",
|
||||||
|
backdropFilter: "blur(5px)",
|
||||||
|
padding: 1,
|
||||||
|
borderRadius: "10px",
|
||||||
|
border: "1px solid rgb(255 255 255 / 0.15)",
|
||||||
|
boxShadow: "0 0 10px rgb(0 0 0 / 0.4) ",
|
||||||
|
transform: "translatey(-120%) scale(0)",
|
||||||
|
"&:before": {
|
||||||
|
display: "none",
|
||||||
|
},
|
||||||
|
"&.MuiSlider-valueLabelOpen": {
|
||||||
|
transform: "translateY(-120%) scale(1)",
|
||||||
|
},
|
||||||
|
"& > *": {
|
||||||
|
transform: "rotate(0deg)",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default PlayerVolume;
|
||||||
@@ -0,0 +1,297 @@
|
|||||||
|
import {
|
||||||
|
closestCenter,
|
||||||
|
DndContext,
|
||||||
|
type DragEndEvent,
|
||||||
|
DragOverlay,
|
||||||
|
type DragStartEvent,
|
||||||
|
type DropAnimation,
|
||||||
|
defaultDropAnimationSideEffects,
|
||||||
|
KeyboardSensor,
|
||||||
|
PointerSensor,
|
||||||
|
useSensor,
|
||||||
|
useSensors,
|
||||||
|
} from "@dnd-kit/core";
|
||||||
|
import {
|
||||||
|
restrictToVerticalAxis,
|
||||||
|
restrictToWindowEdges,
|
||||||
|
} from "@dnd-kit/modifiers";
|
||||||
|
import {
|
||||||
|
arrayMove,
|
||||||
|
SortableContext,
|
||||||
|
sortableKeyboardCoordinates,
|
||||||
|
useSortable,
|
||||||
|
verticalListSortingStrategy,
|
||||||
|
} from "@dnd-kit/sortable";
|
||||||
|
import { CSS } from "@dnd-kit/utilities";
|
||||||
|
import type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client";
|
||||||
|
import {
|
||||||
|
Box,
|
||||||
|
IconButton,
|
||||||
|
Menu,
|
||||||
|
MenuItem,
|
||||||
|
Tooltip,
|
||||||
|
Typography,
|
||||||
|
} from "@mui/material";
|
||||||
|
import React, { useMemo, useState } from "react";
|
||||||
|
import QueueListItem from "@/components/queueListItem";
|
||||||
|
import { stopPlayback } from "@/utils/store/audioPlayback";
|
||||||
|
import useQueue, {
|
||||||
|
clearQueue,
|
||||||
|
removeFromQueue,
|
||||||
|
setQueue,
|
||||||
|
shuffleUpcoming,
|
||||||
|
} from "@/utils/store/queue";
|
||||||
|
|
||||||
|
interface QueuePanelProps {
|
||||||
|
queue: BaseItemDto[];
|
||||||
|
currentTrackIndex: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
const dropAnimation: DropAnimation = {
|
||||||
|
sideEffects: defaultDropAnimationSideEffects({
|
||||||
|
styles: {
|
||||||
|
active: {
|
||||||
|
opacity: "0.5",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
|
||||||
|
function SortableQueueItem({
|
||||||
|
item,
|
||||||
|
onDelete,
|
||||||
|
index,
|
||||||
|
isActive,
|
||||||
|
}: {
|
||||||
|
item: BaseItemDto;
|
||||||
|
onDelete: () => void;
|
||||||
|
index: number;
|
||||||
|
isActive: boolean;
|
||||||
|
}) {
|
||||||
|
const {
|
||||||
|
attributes,
|
||||||
|
listeners,
|
||||||
|
setNodeRef,
|
||||||
|
transform,
|
||||||
|
transition,
|
||||||
|
isDragging,
|
||||||
|
} = useSortable({ id: item.Id || "" });
|
||||||
|
|
||||||
|
const style = {
|
||||||
|
transform: CSS.Translate.toString(transform),
|
||||||
|
transition,
|
||||||
|
opacity: isDragging ? 0.3 : 1,
|
||||||
|
position: "relative" as const,
|
||||||
|
zIndex: isDragging ? 999 : "auto",
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div ref={setNodeRef} style={style} className="sortable-queue-item">
|
||||||
|
<QueueListItem
|
||||||
|
queueItem={item}
|
||||||
|
onDelete={onDelete}
|
||||||
|
dragHandleProps={{ ...attributes, ...listeners }}
|
||||||
|
isEpisode={item.Type === "Episode"}
|
||||||
|
index={index}
|
||||||
|
className={isActive ? "active" : ""}
|
||||||
|
sx={{
|
||||||
|
bgcolor: isActive
|
||||||
|
? "rgba(255, 255, 255, 0.1) !important"
|
||||||
|
: "transparent",
|
||||||
|
borderRadius: 2,
|
||||||
|
mb: 1,
|
||||||
|
transition: "background-color 0.2s",
|
||||||
|
"&:hover": {
|
||||||
|
bgcolor: "rgba(255, 255, 255, 0.05)",
|
||||||
|
},
|
||||||
|
".MuiListItemText-primary": {
|
||||||
|
color: isActive ? "var(--primary-color, #90caf9)" : "inherit",
|
||||||
|
fontWeight: isActive ? 600 : 500,
|
||||||
|
fontSize: "1rem",
|
||||||
|
},
|
||||||
|
".MuiListItemText-secondary": {
|
||||||
|
fontSize: "0.85rem",
|
||||||
|
opacity: 0.7,
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const QueuePanel = ({ queue, currentTrackIndex }: QueuePanelProps) => {
|
||||||
|
const [activeId, setActiveId] = useState<string | null>(null);
|
||||||
|
|
||||||
|
const sensors = useSensors(
|
||||||
|
useSensor(PointerSensor, {
|
||||||
|
activationConstraint: {
|
||||||
|
distance: 8,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
useSensor(KeyboardSensor, {
|
||||||
|
coordinateGetter: sortableKeyboardCoordinates,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
const activeItem = useMemo(
|
||||||
|
() => queue.find((item) => item.Id === activeId),
|
||||||
|
[queue, activeId],
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleDragStart = (event: DragStartEvent) => {
|
||||||
|
setActiveId(String(event.active.id));
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDragEnd = (event: DragEndEvent) => {
|
||||||
|
const { active, over } = event;
|
||||||
|
setActiveId(null);
|
||||||
|
|
||||||
|
if (active.id !== over?.id) {
|
||||||
|
const oldIndex = queue.map((item) => item.Id).indexOf(String(active.id));
|
||||||
|
const newIndex = queue.map((item) => item.Id).indexOf(String(over?.id));
|
||||||
|
|
||||||
|
if (oldIndex !== -1 && newIndex !== -1) {
|
||||||
|
const newQueue = arrayMove(queue, oldIndex, newIndex);
|
||||||
|
const currentTrackId = queue[currentTrackIndex]?.Id;
|
||||||
|
const newCurrentTrackIndex = newQueue.findIndex(
|
||||||
|
(item) => item.Id === currentTrackId,
|
||||||
|
);
|
||||||
|
|
||||||
|
setQueue(
|
||||||
|
newQueue,
|
||||||
|
newCurrentTrackIndex !== -1 ? newCurrentTrackIndex : 0,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
|
||||||
|
const open = Boolean(anchorEl);
|
||||||
|
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
|
||||||
|
setAnchorEl(event.currentTarget);
|
||||||
|
};
|
||||||
|
const handleClose = () => {
|
||||||
|
setAnchorEl(null);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleClearQueue = () => {
|
||||||
|
stopPlayback();
|
||||||
|
clearQueue();
|
||||||
|
handleClose();
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DndContext
|
||||||
|
sensors={sensors}
|
||||||
|
collisionDetection={closestCenter}
|
||||||
|
onDragStart={handleDragStart}
|
||||||
|
onDragEnd={handleDragEnd}
|
||||||
|
modifiers={[restrictToVerticalAxis, restrictToWindowEdges]}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="audio-queue-container"
|
||||||
|
style={{
|
||||||
|
width: "100%",
|
||||||
|
height: "100%",
|
||||||
|
display: "flex",
|
||||||
|
flexDirection: "column",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
display: "flex",
|
||||||
|
justifyContent: "space-between",
|
||||||
|
alignItems: "center",
|
||||||
|
mb: 2,
|
||||||
|
px: 1,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Typography variant="h6" fontWeight={700}>
|
||||||
|
Queue
|
||||||
|
</Typography>
|
||||||
|
<Box sx={{ display: "flex", gap: 1 }}>
|
||||||
|
<Tooltip title="Shuffle Upcoming">
|
||||||
|
<IconButton onClick={() => shuffleUpcoming()} size="small">
|
||||||
|
<span className="material-symbols-rounded">shuffle</span>
|
||||||
|
</IconButton>
|
||||||
|
</Tooltip>
|
||||||
|
<IconButton onClick={handleClick} size="small">
|
||||||
|
<span className="material-symbols-rounded">more_vert</span>
|
||||||
|
</IconButton>
|
||||||
|
</Box>
|
||||||
|
<Menu
|
||||||
|
anchorEl={anchorEl}
|
||||||
|
open={open}
|
||||||
|
onClose={handleClose}
|
||||||
|
transformOrigin={{ horizontal: "right", vertical: "top" }}
|
||||||
|
anchorOrigin={{ horizontal: "right", vertical: "bottom" }}
|
||||||
|
>
|
||||||
|
<MenuItem onClick={handleClearQueue}>
|
||||||
|
<span
|
||||||
|
className="material-symbols-rounded"
|
||||||
|
style={{ marginRight: "0.5em", fontSize: "1.2em" }}
|
||||||
|
>
|
||||||
|
clear_all
|
||||||
|
</span>
|
||||||
|
Clear Queue
|
||||||
|
</MenuItem>
|
||||||
|
</Menu>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
<SortableContext
|
||||||
|
items={queue.map((track) => track.Id ?? "")}
|
||||||
|
strategy={verticalListSortingStrategy}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="audio-queue"
|
||||||
|
style={{ display: "flex", flexDirection: "column", gap: "0px" }}
|
||||||
|
>
|
||||||
|
{queue.map((track, index) => (
|
||||||
|
<SortableQueueItem
|
||||||
|
key={track.Id}
|
||||||
|
item={track}
|
||||||
|
index={index}
|
||||||
|
onDelete={() => removeFromQueue(index)}
|
||||||
|
isActive={currentTrackIndex === index}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</SortableContext>
|
||||||
|
|
||||||
|
<DragOverlay
|
||||||
|
dropAnimation={dropAnimation}
|
||||||
|
style={{
|
||||||
|
left: "1.5rem",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{activeItem ? (
|
||||||
|
<QueueListItem
|
||||||
|
queueItem={activeItem}
|
||||||
|
isEpisode={activeItem.Type === "Episode"}
|
||||||
|
dragHandleProps={{}} // Pass empty object to render handle
|
||||||
|
onDelete={() => {}} // Pass empty function to render delete button space
|
||||||
|
sx={{
|
||||||
|
bgcolor: "rgba(40, 40, 40, 0.9)",
|
||||||
|
backdropFilter: "blur(10px)",
|
||||||
|
borderRadius: 2,
|
||||||
|
boxShadow: "0 8px 32px rgba(0,0,0,0.5)",
|
||||||
|
outline: "1px solid rgba(255, 255, 255, 0.1)",
|
||||||
|
mb: 1,
|
||||||
|
".MuiListItemText-primary": {
|
||||||
|
fontWeight: 500,
|
||||||
|
fontSize: "1rem",
|
||||||
|
},
|
||||||
|
".MuiListItemText-secondary": {
|
||||||
|
fontSize: "0.85rem",
|
||||||
|
opacity: 0.7,
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
</DragOverlay>
|
||||||
|
</div>
|
||||||
|
</DndContext>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default React.memo(QueuePanel);
|
||||||
@@ -0,0 +1,149 @@
|
|||||||
|
import type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client";
|
||||||
|
import { Box, Paper, Typography } from "@mui/material";
|
||||||
|
import React, { useEffect, useState } from "react";
|
||||||
|
|
||||||
|
interface StatsPanelProps {
|
||||||
|
item: BaseItemDto | undefined | null;
|
||||||
|
audioRef: React.RefObject<HTMLAudioElement> | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const StatRow = ({
|
||||||
|
label,
|
||||||
|
value,
|
||||||
|
}: {
|
||||||
|
label: string;
|
||||||
|
value: string | number | undefined | null;
|
||||||
|
}) => (
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
display: "flex",
|
||||||
|
justifyContent: "space-between",
|
||||||
|
mb: 1,
|
||||||
|
borderBottom: "1px solid rgba(255,255,255,0.1)",
|
||||||
|
pb: 0.5,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Typography variant="body2" sx={{ opacity: 0.7, fontFamily: "monospace" }}>
|
||||||
|
{label}
|
||||||
|
</Typography>
|
||||||
|
<Typography
|
||||||
|
variant="body2"
|
||||||
|
sx={{ fontFamily: "monospace", fontWeight: 600 }}
|
||||||
|
>
|
||||||
|
{value || "-"}
|
||||||
|
</Typography>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
|
||||||
|
const StatsPanel: React.FC<StatsPanelProps> = ({ item, audioRef }) => {
|
||||||
|
const [buffered, setBuffered] = useState<string>("0%");
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const player = audioRef?.current;
|
||||||
|
if (!player) return;
|
||||||
|
|
||||||
|
const updateStats = () => {
|
||||||
|
if (player.buffered.length > 0) {
|
||||||
|
const bufferedEnd = player.buffered.end(player.buffered.length - 1);
|
||||||
|
const duration = player.duration;
|
||||||
|
if (duration > 0) {
|
||||||
|
setBuffered(`${Math.round((bufferedEnd / duration) * 100)}%`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const interval = setInterval(updateStats, 1000);
|
||||||
|
return () => clearInterval(interval);
|
||||||
|
}, [audioRef]);
|
||||||
|
|
||||||
|
const mediaSource = item?.MediaSources?.[0];
|
||||||
|
const mediaStream = mediaSource?.MediaStreams?.find(
|
||||||
|
(s) => s.Type === "Audio",
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box sx={{ p: 2 }}>
|
||||||
|
<Typography variant="h6" sx={{ mb: 2 }}>
|
||||||
|
Stats for Nerds
|
||||||
|
</Typography>
|
||||||
|
|
||||||
|
<Paper
|
||||||
|
sx={{
|
||||||
|
p: 2,
|
||||||
|
background: "rgba(0,0,0,0.2)",
|
||||||
|
backdropFilter: "blur(10px)",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Typography
|
||||||
|
variant="subtitle2"
|
||||||
|
sx={{ mb: 1, opacity: 0.5, textTransform: "uppercase" }}
|
||||||
|
>
|
||||||
|
Media Source
|
||||||
|
</Typography>
|
||||||
|
<StatRow label="Container" value={mediaSource?.Container} />
|
||||||
|
<StatRow
|
||||||
|
label="Bitrate"
|
||||||
|
value={
|
||||||
|
mediaSource?.Bitrate
|
||||||
|
? `${Math.round(mediaSource.Bitrate / 1000)} kbps`
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<StatRow
|
||||||
|
label="Size"
|
||||||
|
value={
|
||||||
|
mediaSource?.Size
|
||||||
|
? `${(mediaSource.Size / 1024 / 1024).toFixed(2)} MB`
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<StatRow label="Path" value={mediaSource?.Path} />
|
||||||
|
|
||||||
|
<Box sx={{ mt: 3 }}>
|
||||||
|
<Typography
|
||||||
|
variant="subtitle2"
|
||||||
|
sx={{ mb: 1, opacity: 0.5, textTransform: "uppercase" }}
|
||||||
|
>
|
||||||
|
Audio Stream
|
||||||
|
</Typography>
|
||||||
|
<StatRow label="Codec" value={mediaStream?.Codec} />
|
||||||
|
<StatRow label="Channels" value={mediaStream?.Channels} />
|
||||||
|
<StatRow
|
||||||
|
label="Sample Rate"
|
||||||
|
value={
|
||||||
|
mediaStream?.SampleRate
|
||||||
|
? `${mediaStream.SampleRate} Hz`
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<StatRow label="Bit Depth" value={mediaStream?.BitDepth} />
|
||||||
|
<StatRow label="Language" value={mediaStream?.Language} />
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
<Box sx={{ mt: 3 }}>
|
||||||
|
<Typography
|
||||||
|
variant="subtitle2"
|
||||||
|
sx={{ mb: 1, opacity: 0.5, textTransform: "uppercase" }}
|
||||||
|
>
|
||||||
|
Player
|
||||||
|
</Typography>
|
||||||
|
<StatRow label="Buffered" value={buffered} />
|
||||||
|
<StatRow
|
||||||
|
label="Volume"
|
||||||
|
value={
|
||||||
|
audioRef?.current
|
||||||
|
? `${Math.round(audioRef.current.volume * 100)}%`
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<StatRow
|
||||||
|
label="Playback Rate"
|
||||||
|
value={audioRef?.current?.playbackRate}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
</Paper>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default React.memo(StatsPanel);
|
||||||
@@ -1,37 +1,39 @@
|
|||||||
import React, { useEffect, useMemo, useRef, useState } from "react";
|
import { useLocation, useNavigate } from "@tanstack/react-router";
|
||||||
|
import { AnimatePresence, motion } from "motion/react";
|
||||||
import { motion } from "motion/react";
|
import React, { type SyntheticEvent, useEffect, useRef, useState } from "react";
|
||||||
|
import { secToTicks, ticksToSec } from "@/utils/date/time";
|
||||||
import Fab from "@mui/material/Fab";
|
|
||||||
import IconButton from "@mui/material/IconButton";
|
|
||||||
import Slider from "@mui/material/Slider";
|
|
||||||
import Typography from "@mui/material/Typography";
|
|
||||||
|
|
||||||
import { setAudioRef, useAudioPlayback } from "@/utils/store/audioPlayback";
|
|
||||||
import useQueue from "@/utils/store/queue";
|
|
||||||
|
|
||||||
import { AnimatePresence } from "motion/react";
|
|
||||||
import "./audioPlayer.scss";
|
|
||||||
|
|
||||||
import { getRuntimeMusic, secToTicks, ticksToSec } from "@/utils/date/time";
|
|
||||||
|
|
||||||
import PlayNextButton from "@/components/buttons/playNextButton";
|
|
||||||
import PlayPreviousButton from "@/components/buttons/playPreviousButtom";
|
|
||||||
import QueueButton from "@/components/buttons/queueButton";
|
|
||||||
import getImageUrlsApi from "@/utils/methods/getImageUrlsApi";
|
import getImageUrlsApi from "@/utils/methods/getImageUrlsApi";
|
||||||
import { useApiInContext } from "@/utils/store/api";
|
import { useApiInContext } from "@/utils/store/api";
|
||||||
|
import {
|
||||||
|
setAudioRef,
|
||||||
|
setIsMuted,
|
||||||
|
setVolume,
|
||||||
|
useAudioPlayback,
|
||||||
|
} from "@/utils/store/audioPlayback";
|
||||||
import { useCentralStore } from "@/utils/store/central";
|
import { useCentralStore } from "@/utils/store/central";
|
||||||
import { playItemFromQueue } from "@/utils/store/playback";
|
import { playItemFromQueue } from "@/utils/store/playback";
|
||||||
import { useNavigate } from "@tanstack/react-router";
|
import useQueue from "@/utils/store/queue";
|
||||||
|
import PlayerActions from "./components/PlayerActions";
|
||||||
|
import PlayerControls from "./components/PlayerControls";
|
||||||
|
import PlayerInfo from "./components/PlayerInfo";
|
||||||
|
import PlayerProgress from "./components/PlayerProgress";
|
||||||
|
import PlayerVolume from "./components/PlayerVolume";
|
||||||
|
|
||||||
|
import "./audioPlayer.scss";
|
||||||
|
|
||||||
const AudioPlayer = () => {
|
const AudioPlayer = () => {
|
||||||
const api = useApiInContext((s) => s.api);
|
const api = useApiInContext((s) => s.api);
|
||||||
|
const user = useCentralStore((s) => s.currentUser);
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const location = useLocation();
|
||||||
|
|
||||||
const audioRef = useRef<HTMLAudioElement | null>(null);
|
const audioRef = useRef<HTMLAudioElement | null>(null);
|
||||||
const [url, display, item] = useAudioPlayback((state) => [
|
const [url, display, item, volume, isMuted] = useAudioPlayback((state) => [
|
||||||
state.url,
|
state.url,
|
||||||
state.display,
|
state.display,
|
||||||
state.item,
|
state.item,
|
||||||
|
state.player.volume,
|
||||||
|
state.player.isMuted,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const [tracks, currentTrack] = useQueue((state) => [
|
const [tracks, currentTrack] = useQueue((state) => [
|
||||||
@@ -39,327 +41,213 @@ const AudioPlayer = () => {
|
|||||||
state.currentItemIndex,
|
state.currentItemIndex,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const user = useCentralStore((s) => s.currentUser);
|
const [playing, setPlaying] = useState(false);
|
||||||
|
|
||||||
const playing = useMemo(() => {
|
|
||||||
if (audioRef.current?.paused) return false;
|
|
||||||
return true;
|
|
||||||
}, [audioRef.current?.paused]);
|
|
||||||
const [volume, setVolume] = useState(0.8);
|
|
||||||
const [isMuted, setIsMuted] = useState(false);
|
|
||||||
const [progress, setProgress] = useState(0);
|
const [progress, setProgress] = useState(0);
|
||||||
const [isScrubbing, setIsScrubbing] = useState(false);
|
|
||||||
const [sliderProgress, setSliderProgress] = useState(0);
|
|
||||||
|
|
||||||
|
// Sync volume and ref
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (display) {
|
if (display) {
|
||||||
// const audioUrlRequest = new Request(audioRef.current?.dataset.src, {
|
|
||||||
// method: "GET",
|
|
||||||
// headers: {
|
|
||||||
// Authorization: api.authorizationHeader,
|
|
||||||
// },
|
|
||||||
// });
|
|
||||||
// fetch(audioUrlRequest)
|
|
||||||
// .then((res) => res)
|
|
||||||
// .then(async (result) => {
|
|
||||||
// const blob = await result.blob();
|
|
||||||
// const blobUrl = URL.createObjectURL(blob);
|
|
||||||
// audioRef.current.src = blobUrl;
|
|
||||||
// await audioRef.current.play();
|
|
||||||
// setLoading(false);
|
|
||||||
// });
|
|
||||||
|
|
||||||
// Set the audio ref in the store to allow for global control
|
|
||||||
setAudioRef(audioRef);
|
setAudioRef(audioRef);
|
||||||
|
if (audioRef.current) {
|
||||||
|
audioRef.current.volume = isMuted ? 0 : volume;
|
||||||
}
|
}
|
||||||
}, [url, tracks?.[currentTrack]?.Id]);
|
}
|
||||||
|
}, [display, url, tracks?.[currentTrack]?.Id]);
|
||||||
|
|
||||||
const navigate = useNavigate();
|
// Update volume when state changes
|
||||||
|
useEffect(() => {
|
||||||
|
if (audioRef.current) {
|
||||||
|
audioRef.current.volume = isMuted ? 0 : volume;
|
||||||
|
}
|
||||||
|
}, [volume, isMuted]);
|
||||||
|
|
||||||
const info = useMemo(
|
// Media Session Metadata
|
||||||
() =>
|
useEffect(() => {
|
||||||
api && (
|
if ("mediaSession" in navigator && item) {
|
||||||
<div
|
const imageUrl = item.ImageTags?.Primary
|
||||||
// initial={{
|
? api &&
|
||||||
// filter: "opacity(0)",
|
getImageUrlsApi(api).getItemImageUrlById(item.Id ?? "", "Primary", {
|
||||||
// }}
|
tag: item.ImageTags.Primary,
|
||||||
// animate={{
|
})
|
||||||
// filter: "opacity(1)",
|
: undefined;
|
||||||
// }}
|
|
||||||
// exit={{
|
navigator.mediaSession.metadata = new MediaMetadata({
|
||||||
// filter: "opacity(0)",
|
title: item.Name ?? "Unknown Title",
|
||||||
// }}
|
artist: item.Artists?.join(", ") ?? "Unknown Artist",
|
||||||
className="audio-player-info"
|
album: item.Album ?? "Unknown Album",
|
||||||
>
|
artwork: imageUrl
|
||||||
<div className="audio-player-image-container">
|
? [
|
||||||
<img
|
|
||||||
alt={tracks?.[currentTrack]?.Name ?? "track"}
|
|
||||||
className="audio-player-image"
|
|
||||||
src={getImageUrlsApi(api).getItemImageUrlById(
|
|
||||||
(!item?.ImageTags?.Primary ? item?.AlbumId : item.Id) ?? "",
|
|
||||||
"Primary",
|
|
||||||
{
|
{
|
||||||
quality: 85,
|
src: imageUrl,
|
||||||
fillHeight: 462,
|
sizes: "512x512",
|
||||||
fillWidth: 462,
|
type: "image/jpeg",
|
||||||
},
|
},
|
||||||
)}
|
]
|
||||||
/>
|
: [],
|
||||||
<span className="material-symbols-rounded audio-player-image-icon">
|
});
|
||||||
music_note
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div className="audio-player-info-text">
|
|
||||||
<Typography
|
|
||||||
variant="subtitle2"
|
|
||||||
style={{
|
|
||||||
width: "100%",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{item?.Name}
|
|
||||||
</Typography>
|
|
||||||
<Typography
|
|
||||||
variant="caption"
|
|
||||||
style={{
|
|
||||||
opacity: 0.5,
|
|
||||||
}}
|
|
||||||
noWrap
|
|
||||||
>
|
|
||||||
by {item?.Artists?.map((artist) => artist).join(",")}
|
|
||||||
</Typography>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
),
|
|
||||||
[tracks?.[currentTrack]?.Id, currentTrack, api?.configuration],
|
|
||||||
);
|
|
||||||
|
|
||||||
const controls = useMemo(
|
|
||||||
() => (
|
|
||||||
<div style={{ display: "flex", gap: "1em" }}>
|
|
||||||
<PlayPreviousButton />
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: "inline-flex",
|
|
||||||
alignItems: "center",
|
|
||||||
justifyContent: "center",
|
|
||||||
position: "relative",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Fab
|
|
||||||
size="small"
|
|
||||||
onClick={() =>
|
|
||||||
audioRef.current?.paused
|
|
||||||
? audioRef.current.play()
|
|
||||||
: audioRef.current?.pause()
|
|
||||||
}
|
}
|
||||||
>
|
}, [item, api]);
|
||||||
<div
|
|
||||||
className="material-symbols-rounded"
|
|
||||||
style={{
|
|
||||||
fontSize: "2em",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{playing ? "pause" : "play_arrow"}
|
|
||||||
</div>
|
|
||||||
</Fab>
|
|
||||||
</div>
|
|
||||||
<PlayNextButton />
|
|
||||||
</div>
|
|
||||||
),
|
|
||||||
[tracks?.[currentTrack]?.Id, playing, tracks?.length],
|
|
||||||
);
|
|
||||||
|
|
||||||
const buttons = useMemo(
|
// Media Session Action Handlers
|
||||||
() => (
|
useEffect(() => {
|
||||||
<div
|
if ("mediaSession" in navigator) {
|
||||||
style={{
|
navigator.mediaSession.setActionHandler("play", () => {
|
||||||
display: "flex",
|
audioRef.current?.play();
|
||||||
alignItems: "center",
|
});
|
||||||
justifyContent: "flex-end",
|
navigator.mediaSession.setActionHandler("pause", () => {
|
||||||
}}
|
audioRef.current?.pause();
|
||||||
>
|
});
|
||||||
<IconButton onClick={() => navigate({ to: "/player/audio" })}>
|
navigator.mediaSession.setActionHandler("previoustrack", () => {
|
||||||
<span className="material-symbols-rounded">info</span>
|
if (user?.Id && api) {
|
||||||
</IconButton>
|
playItemFromQueue("previous", user.Id, api);
|
||||||
<QueueButton />
|
|
||||||
<IconButton
|
|
||||||
onClick={() => {
|
|
||||||
setIsMuted(!isMuted);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div className="material-symbols-rounded">
|
|
||||||
{isMuted ? "volume_mute" : "volume_up"}
|
|
||||||
</div>
|
|
||||||
</IconButton>
|
|
||||||
<Slider
|
|
||||||
value={isMuted ? 0 : volume * 100}
|
|
||||||
step={1}
|
|
||||||
max={100}
|
|
||||||
onChange={(_, newVal) => {
|
|
||||||
if (!audioRef.current) {
|
|
||||||
console.error("Audio ref not found");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
Array.isArray(newVal)
|
});
|
||||||
? setVolume(newVal[0] / 100)
|
navigator.mediaSession.setActionHandler("nexttrack", () => {
|
||||||
: setVolume(newVal / 100);
|
if (user?.Id && api) {
|
||||||
if (Array.isArray(newVal)) {
|
playItemFromQueue("next", user.Id, api);
|
||||||
audioRef.current.volume = newVal[0] / 100;
|
}
|
||||||
|
});
|
||||||
|
navigator.mediaSession.setActionHandler("seekto", (details) => {
|
||||||
|
if (audioRef.current && details.seekTime !== undefined) {
|
||||||
|
audioRef.current.currentTime = details.seekTime;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [api, user?.Id]);
|
||||||
|
|
||||||
|
const updatePositionState = () => {
|
||||||
|
if (
|
||||||
|
"mediaSession" in navigator &&
|
||||||
|
audioRef.current &&
|
||||||
|
!Number.isNaN(audioRef.current.duration)
|
||||||
|
) {
|
||||||
|
try {
|
||||||
|
navigator.mediaSession.setPositionState({
|
||||||
|
duration: audioRef.current.duration,
|
||||||
|
playbackRate: audioRef.current.playbackRate,
|
||||||
|
position: audioRef.current.currentTime,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error updating media session position state:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handlePlayPause = () => {
|
||||||
|
if (audioRef.current) {
|
||||||
|
if (audioRef.current.paused) {
|
||||||
|
audioRef.current.play();
|
||||||
|
setPlaying(true);
|
||||||
} else {
|
} else {
|
||||||
audioRef.current.volume = newVal / 100;
|
audioRef.current.pause();
|
||||||
|
setPlaying(false);
|
||||||
}
|
}
|
||||||
}}
|
}
|
||||||
valueLabelDisplay="auto"
|
};
|
||||||
valueLabelFormat={(value) => Math.floor(value)}
|
|
||||||
size="small"
|
const handleTimeUpdate = (e: SyntheticEvent<HTMLAudioElement>) => {
|
||||||
sx={{
|
setProgress(secToTicks(e.currentTarget.currentTime));
|
||||||
mr: 1,
|
};
|
||||||
ml: 1,
|
|
||||||
width: "10em",
|
const handleEnded = () => {
|
||||||
"& .MuiSlider-valueLabel": {
|
setPlaying(false);
|
||||||
lineHeight: 1.2,
|
if (tracks?.[currentTrack + 1]?.Id && api && user?.Id) {
|
||||||
fontSize: 24,
|
playItemFromQueue("next", user.Id, api);
|
||||||
background: "rgb(0 0 0 / 0.5)",
|
}
|
||||||
backdropFilter: "blur(5px)",
|
};
|
||||||
padding: 1,
|
|
||||||
borderRadius: "10px",
|
const handleSeekCommit = (value: number) => {
|
||||||
border: "1px solid rgb(255 255 255 / 0.15)",
|
if (audioRef.current) {
|
||||||
boxShadow: "0 0 10px rgb(0 0 0 / 0.4) ",
|
audioRef.current.currentTime = ticksToSec(value);
|
||||||
transform: "translatey(-120%) scale(0)",
|
setProgress(value);
|
||||||
"&:before": {
|
}
|
||||||
display: "none",
|
};
|
||||||
},
|
|
||||||
"&.MuiSlider-valueLabelOpen": {
|
const handleVolumeChange = (newVolume: number) => {
|
||||||
transform: "translateY(-120%) scale(1)",
|
setVolume(newVolume);
|
||||||
},
|
};
|
||||||
"& > *": {
|
|
||||||
transform: "rotate(0deg)",
|
const handleMuteToggle = () => {
|
||||||
},
|
setIsMuted(!isMuted);
|
||||||
},
|
};
|
||||||
}}
|
|
||||||
/>
|
const handleClose = () => {
|
||||||
<IconButton
|
|
||||||
onClick={() => {
|
|
||||||
useAudioPlayback.setState(useAudioPlayback.getInitialState());
|
useAudioPlayback.setState(useAudioPlayback.getInitialState());
|
||||||
}}
|
};
|
||||||
>
|
|
||||||
<div className="material-symbols-rounded">close</div>
|
|
||||||
</IconButton>
|
|
||||||
</div>
|
|
||||||
),
|
|
||||||
[volume, isMuted, currentTrack],
|
|
||||||
);
|
|
||||||
|
|
||||||
// if (audioRef.current) {
|
const handleNavigate = () => {
|
||||||
// audioRef.current.addEventListener("change", () => {
|
navigate({ to: "/player/audio" });
|
||||||
// console.log("Audio Player changed state : ", currentTrack);
|
};
|
||||||
// });
|
|
||||||
// audioRef.current.addEventListener("ended", () => {
|
|
||||||
|
|
||||||
// });
|
// Listen to play/pause events directly from audio element to keep state in sync
|
||||||
// }
|
// (e.g. if paused by media keys)
|
||||||
|
const onPlay = () => {
|
||||||
|
setPlaying(true);
|
||||||
|
updatePositionState();
|
||||||
|
if ("mediaSession" in navigator) {
|
||||||
|
navigator.mediaSession.playbackState = "playing";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const onPause = () => {
|
||||||
|
setPlaying(false);
|
||||||
|
updatePositionState();
|
||||||
|
if ("mediaSession" in navigator) {
|
||||||
|
navigator.mediaSession.playbackState = "paused";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AnimatePresence mode="sync">
|
<AnimatePresence mode="sync">
|
||||||
{display && (
|
{display && (
|
||||||
<motion.div
|
<motion.div
|
||||||
initial={{
|
initial={{ transform: "translate(-50%, 150%)" }}
|
||||||
transform: "translateY(100%)",
|
|
||||||
}}
|
|
||||||
animate={{
|
animate={{
|
||||||
transform:
|
transform:
|
||||||
location.pathname === "/player/audio"
|
location.pathname === "/player/audio"
|
||||||
? "translateY(100%)"
|
? "translate(-50%, 150%)"
|
||||||
: "translateY(0%)",
|
: "translate(-50%, 0%)",
|
||||||
}}
|
|
||||||
exit={{
|
|
||||||
transform: "translateY(100%)",
|
|
||||||
}}
|
|
||||||
style={{
|
|
||||||
width: "100%",
|
|
||||||
}}
|
|
||||||
transition={{
|
|
||||||
duration: 0.2,
|
|
||||||
ease: "easeInOut",
|
|
||||||
}}
|
}}
|
||||||
|
exit={{ transform: "translate(-50%, 150%)" }}
|
||||||
|
transition={{ duration: 0.3, ease: "circOut" }}
|
||||||
className="audio-player glass"
|
className="audio-player glass"
|
||||||
>
|
>
|
||||||
{info}
|
<PlayerInfo
|
||||||
|
item={item}
|
||||||
|
api={api}
|
||||||
|
trackName={tracks?.[currentTrack]?.Name}
|
||||||
|
/>
|
||||||
|
|
||||||
<audio
|
<audio
|
||||||
autoPlay
|
autoPlay
|
||||||
src={url}
|
src={url}
|
||||||
ref={audioRef}
|
ref={audioRef}
|
||||||
key={item?.Id ?? "noItem"}
|
key={item?.Id ?? "noItem"}
|
||||||
onTimeUpdate={(e) =>
|
onTimeUpdate={handleTimeUpdate}
|
||||||
setProgress(secToTicks(e.currentTarget.currentTime))
|
onEnded={handleEnded}
|
||||||
}
|
onPlay={onPlay}
|
||||||
onEnded={() => {
|
onPause={onPause}
|
||||||
if (tracks?.[currentTrack + 1]?.Id && api && user?.Id) {
|
onSeeked={updatePositionState}
|
||||||
playItemFromQueue("next", user.Id, api);
|
onLoadedMetadata={updatePositionState}
|
||||||
}
|
|
||||||
}}
|
|
||||||
id="audio-player"
|
id="audio-player"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div className="audio-player-controls">
|
<div className="audio-player-controls">
|
||||||
{controls}
|
<PlayerControls playing={playing} onPlayPause={handlePlayPause} />
|
||||||
<div
|
<PlayerProgress
|
||||||
style={{
|
progress={progress}
|
||||||
width: "100%",
|
duration={item?.RunTimeTicks ?? 1}
|
||||||
display: "flex",
|
onSeekCommit={handleSeekCommit}
|
||||||
gap: "1em",
|
|
||||||
alignItems: "center",
|
|
||||||
justifyContent: "center",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Typography
|
|
||||||
variant="subtitle2"
|
|
||||||
fontWeight={300}
|
|
||||||
style={{
|
|
||||||
opacity: 0.8,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{getRuntimeMusic(progress)}
|
|
||||||
</Typography>
|
|
||||||
<Slider
|
|
||||||
value={isScrubbing ? sliderProgress : progress}
|
|
||||||
step={1}
|
|
||||||
size="small"
|
|
||||||
max={item?.RunTimeTicks ?? 1}
|
|
||||||
onChange={(_, value) => {
|
|
||||||
setIsScrubbing(true);
|
|
||||||
Array.isArray(value)
|
|
||||||
? setSliderProgress(value[0])
|
|
||||||
: setSliderProgress(value);
|
|
||||||
}}
|
|
||||||
onChangeCommitted={(_, value) => {
|
|
||||||
if (!audioRef.current) {
|
|
||||||
console.error("Audio ref not found");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setIsScrubbing(false);
|
|
||||||
// console.log(ticksToSec(value * item.RunTimeTicks));
|
|
||||||
Array.isArray(value)
|
|
||||||
? setProgress(value[0])
|
|
||||||
: setProgress(value);
|
|
||||||
if (Array.isArray(value)) {
|
|
||||||
audioRef.current.currentTime = ticksToSec(value[0]);
|
|
||||||
} else {
|
|
||||||
audioRef.current.currentTime = ticksToSec(value);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
<Typography
|
|
||||||
variant="subtitle2"
|
|
||||||
fontWeight={300}
|
|
||||||
style={{
|
|
||||||
opacity: 0.8,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{getRuntimeMusic(item?.RunTimeTicks ?? 0)}
|
|
||||||
</Typography>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
{buttons}
|
<PlayerActions onNavigate={handleNavigate} onClose={handleClose}>
|
||||||
|
<PlayerVolume
|
||||||
|
volume={volume}
|
||||||
|
isMuted={isMuted}
|
||||||
|
onVolumeChange={handleVolumeChange}
|
||||||
|
onMuteToggle={handleMuteToggle}
|
||||||
|
/>
|
||||||
|
</PlayerActions>
|
||||||
</motion.div>
|
</motion.div>
|
||||||
)}
|
)}
|
||||||
</AnimatePresence>
|
</AnimatePresence>
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ type QueueListItemProps = {
|
|||||||
dragHandleProps?: any;
|
dragHandleProps?: any;
|
||||||
isEpisode?: boolean;
|
isEpisode?: boolean;
|
||||||
index?: number;
|
index?: number;
|
||||||
|
className?: string;
|
||||||
|
sx?: any;
|
||||||
};
|
};
|
||||||
|
|
||||||
const QueueListItem = ({
|
const QueueListItem = ({
|
||||||
@@ -30,6 +32,8 @@ const QueueListItem = ({
|
|||||||
dragHandleProps,
|
dragHandleProps,
|
||||||
isEpisode,
|
isEpisode,
|
||||||
index,
|
index,
|
||||||
|
className,
|
||||||
|
sx,
|
||||||
}: QueueListItemProps) => {
|
}: QueueListItemProps) => {
|
||||||
const api = useApiInContext((s) => s.api);
|
const api = useApiInContext((s) => s.api);
|
||||||
|
|
||||||
@@ -66,6 +70,8 @@ const QueueListItem = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<ListItem
|
<ListItem
|
||||||
|
component="div"
|
||||||
|
className={className}
|
||||||
secondaryAction={
|
secondaryAction={
|
||||||
onDelete && (
|
onDelete && (
|
||||||
<IconButton
|
<IconButton
|
||||||
@@ -100,6 +106,7 @@ const QueueListItem = ({
|
|||||||
boxShadow: active ? "none" : 2,
|
boxShadow: active ? "none" : 2,
|
||||||
},
|
},
|
||||||
pr: onDelete ? 6 : 2,
|
pr: onDelete ? 6 : 2,
|
||||||
|
...sx,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{dragHandleProps && (
|
{dragHandleProps && (
|
||||||
|
|||||||
@@ -1,21 +1,18 @@
|
|||||||
import { getRuntimeMusic } from "@/utils/date/time";
|
|
||||||
import useQueue from "@/utils/store/queue";
|
|
||||||
|
|
||||||
import { useSortable } from "@dnd-kit/sortable";
|
import { useSortable } from "@dnd-kit/sortable";
|
||||||
import { CSS } from "@dnd-kit/utilities";
|
import { CSS } from "@dnd-kit/utilities";
|
||||||
|
|
||||||
import type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client";
|
import type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client";
|
||||||
import { Typography } from "@mui/material";
|
import { IconButton, Typography } from "@mui/material";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
import { getRuntimeMusic } from "@/utils/date/time";
|
||||||
|
import useQueue from "@/utils/store/queue";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
track: BaseItemDto;
|
track: BaseItemDto;
|
||||||
index: number;
|
index: number;
|
||||||
|
onRemove?: () => void;
|
||||||
};
|
};
|
||||||
const QueueTrack = (props: Props) => {
|
const QueueTrack = (props: Props) => {
|
||||||
const { track, index } = props;
|
const { track, index, onRemove } = props;
|
||||||
const [currentItemIndex] = useQueue((s) => [s.currentItemIndex]);
|
const [currentItemIndex] = useQueue((s) => [s.currentItemIndex]);
|
||||||
|
|
||||||
const { attributes, listeners, setNodeRef, transform, transition } =
|
const { attributes, listeners, setNodeRef, transform, transition } =
|
||||||
@@ -50,9 +47,21 @@ const QueueTrack = (props: Props) => {
|
|||||||
{track.Artists?.join(", ")}
|
{track.Artists?.join(", ")}
|
||||||
</Typography>
|
</Typography>
|
||||||
</div>
|
</div>
|
||||||
|
<div style={{ display: "flex", alignItems: "center", gap: "0.5em" }}>
|
||||||
<Typography className="opacity-07">
|
<Typography className="opacity-07">
|
||||||
{getRuntimeMusic(track.RunTimeTicks ?? 0)}
|
{getRuntimeMusic(track.RunTimeTicks ?? 0)}
|
||||||
</Typography>
|
</Typography>
|
||||||
|
{onRemove && (
|
||||||
|
<IconButton size="small" onClick={onRemove}>
|
||||||
|
<span
|
||||||
|
className="material-symbols-rounded"
|
||||||
|
style={{ fontSize: "1.2em" }}
|
||||||
|
>
|
||||||
|
close
|
||||||
|
</span>
|
||||||
|
</IconButton>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,38 +1,159 @@
|
|||||||
.audio {
|
.audio {
|
||||||
&-hidden {
|
&-background {
|
||||||
transform: translateY(-100%);
|
position: fixed;
|
||||||
}
|
top: 0;
|
||||||
&-info {
|
left: 0;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding: 4em;
|
height: 100%;
|
||||||
gap: 0.5em;
|
z-index: -1;
|
||||||
display: flex;
|
overflow: hidden;
|
||||||
flex-direction: column;
|
|
||||||
|
&::after {
|
||||||
|
content: "";
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
background: rgba(0, 0, 0, 0.6); // Dark overlay
|
||||||
|
backdrop-filter: blur(60px);
|
||||||
|
-webkit-backdrop-filter: blur(60px);
|
||||||
|
}
|
||||||
|
|
||||||
|
&-image {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
object-fit: cover;
|
||||||
|
transform: scale(1.1); // Prevent white edges from blur
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
&-container {
|
&-container {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 0em;
|
flex-direction: column;
|
||||||
|
height: 100vh;
|
||||||
|
width: 100%;
|
||||||
|
padding: 1rem;
|
||||||
|
gap: 1rem;
|
||||||
|
box-sizing: border-box;
|
||||||
|
position: relative;
|
||||||
|
z-index: 1;
|
||||||
|
color: white;
|
||||||
|
overflow: hidden;
|
||||||
|
|
||||||
|
@media (min-width: 900px) {
|
||||||
|
flex-direction: row;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: flex-start;
|
justify-content: center;
|
||||||
|
padding: 4rem;
|
||||||
|
gap: 3rem;
|
||||||
|
max-width: 1600px;
|
||||||
|
margin: 0 auto;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&-left-column {
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 1.5rem;
|
||||||
|
width: 100%;
|
||||||
|
max-width: 500px;
|
||||||
|
margin: 0 auto;
|
||||||
|
min-height: 0; // Allow shrinking
|
||||||
|
|
||||||
|
@media (min-width: 900px) {
|
||||||
|
gap: 2rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&-right-column {
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
max-width: 600px;
|
||||||
|
overflow: hidden;
|
||||||
|
background: rgba(255, 255, 255, 0.05);
|
||||||
|
border-radius: 1.5rem;
|
||||||
|
padding: 0;
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||||
|
backdrop-filter: blur(20px);
|
||||||
|
-webkit-backdrop-filter: blur(20px);
|
||||||
|
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
|
||||||
|
min-height: 0; // Allow shrinking
|
||||||
|
}
|
||||||
|
|
||||||
|
&-right-content {
|
||||||
|
flex: 1;
|
||||||
|
padding: 1.5rem;
|
||||||
|
overflow-y: auto;
|
||||||
|
overflow-x: hidden;
|
||||||
|
|
||||||
|
&::-webkit-scrollbar {
|
||||||
|
width: 6px;
|
||||||
|
}
|
||||||
|
&::-webkit-scrollbar-track {
|
||||||
|
background: transparent;
|
||||||
|
}
|
||||||
|
&::-webkit-scrollbar-thumb {
|
||||||
|
background: rgba(255, 255, 255, 0.2);
|
||||||
|
border-radius: 3px;
|
||||||
|
}
|
||||||
|
&::-webkit-scrollbar-thumb:hover {
|
||||||
|
background: rgba(255, 255, 255, 0.3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&-info {
|
||||||
|
width: 100%;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: flex-start; // Left align text
|
||||||
|
text-align: left;
|
||||||
|
gap: 0.5em;
|
||||||
|
|
||||||
|
@media (max-width: 900px) {
|
||||||
|
align-items: center;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
&-image {
|
&-image {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
aspect-ratio: 1;
|
aspect-ratio: 1;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
object-fit: cover;
|
object-fit: cover;
|
||||||
|
border-radius: 1.5rem;
|
||||||
|
box-shadow: 0 20px 50px rgba(0,0,0,0.5);
|
||||||
|
transition: transform 0.3s ease;
|
||||||
|
|
||||||
&-container {
|
&-container {
|
||||||
width: 25em;
|
width: 100%;
|
||||||
aspect-ratio: 1;
|
aspect-ratio: 1;
|
||||||
position: relative;
|
position: relative;
|
||||||
border-radius: $border-radius-default;
|
border-radius: 1.5rem;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
|
||||||
|
@media (max-width: 900px) {
|
||||||
|
max-width: 70vw;
|
||||||
|
max-height: 35vh;
|
||||||
|
margin: 0 auto 1rem auto;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
&-icon {
|
&-icon {
|
||||||
font-size: 4em;
|
font-size: 8em;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
background: rgb(255 255 255 / 0.2);
|
width: 100%;
|
||||||
|
background: rgba(255, 255, 255, 0.1);
|
||||||
|
border-radius: 1.5rem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
&-controls {
|
&-controls {
|
||||||
@@ -40,82 +161,90 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
gap: 1em;
|
gap: 1.5em;
|
||||||
|
margin-top: 1rem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&-queue {
|
&-queue {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
align-items: center;
|
align-items: stretch; // Ensure items take full width
|
||||||
|
|
||||||
margin-top: 2em;
|
// Remove old track styles as we now use QueueListItem
|
||||||
&-track {
|
|
||||||
padding: 1em;
|
|
||||||
display: grid;
|
|
||||||
grid-template-columns: 3em 1fr 6em;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
width: 100%;
|
|
||||||
gap: 1em;
|
|
||||||
.material-symbols-rounded{
|
|
||||||
cursor: grab;
|
|
||||||
}
|
|
||||||
&-info-name {
|
|
||||||
transition: $transition-time-fast;
|
|
||||||
}
|
|
||||||
&.active {
|
|
||||||
.audio-queue-track-info-name {
|
|
||||||
color: $clr-accent-default;
|
|
||||||
font-weight: 500;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
&.dragging {
|
|
||||||
background: black;
|
|
||||||
border-radius: 10px;
|
|
||||||
width: calc(100% + 2em);
|
|
||||||
cursor: grabbing;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
&-lyrics {
|
&-lyrics {
|
||||||
max-height: 40vh;
|
padding: 1rem;
|
||||||
overflow: visible;
|
|
||||||
background: rgb(255 255 255 / 0.05);
|
|
||||||
// border: 1px solid rgb(255 255 255 / 0.2);
|
|
||||||
padding: 2em;
|
|
||||||
position: relative;
|
|
||||||
margin-bottom: 2em;
|
|
||||||
border-radius: 20px;
|
|
||||||
overscroll-behavior: contain;
|
|
||||||
&-line {
|
|
||||||
width: fit-content;
|
|
||||||
white-space: wrap;
|
|
||||||
text-align: center;
|
text-align: center;
|
||||||
font-size: 1.5em;
|
width: 100%;
|
||||||
opacity: 0.5;
|
|
||||||
transform: scale(1);
|
|
||||||
transition: transform $transition-time-default;
|
|
||||||
&[data-active-lyric="true"] {
|
|
||||||
opacity: 1;
|
|
||||||
transform: scale(1.2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
&[data-has-synced-lyrics="false"] {
|
|
||||||
.audio-lyrics-line {
|
|
||||||
opacity: 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
&-container {
|
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
overflow-y: scroll;
|
|
||||||
height: calc(40vh - 4em);
|
|
||||||
width: 100%;
|
|
||||||
overflow-x: visible !important;
|
|
||||||
align-items: center;
|
align-items: center;
|
||||||
position: relative;
|
min-height: 100%;
|
||||||
top: 0;
|
|
||||||
|
&-container {
|
||||||
|
width: 100%;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
padding-bottom: 4rem; // Space for unsynced notice
|
||||||
|
}
|
||||||
|
|
||||||
|
&-status {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
opacity: 0.7;
|
||||||
|
min-height: 200px;
|
||||||
|
}
|
||||||
|
|
||||||
|
&-line {
|
||||||
|
margin-bottom: 1.5rem;
|
||||||
|
opacity: 0.5;
|
||||||
|
transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
|
||||||
|
border-radius: 1rem;
|
||||||
|
padding: 0.75rem 1.5rem;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 1.5rem !important;
|
||||||
|
line-height: 1.6 !important;
|
||||||
|
font-weight: 600 !important;
|
||||||
|
max-width: 90%;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
opacity: 0.8;
|
||||||
|
background: rgba(255, 255, 255, 0.05);
|
||||||
|
}
|
||||||
|
|
||||||
|
&[data-active-lyric="true"] {
|
||||||
|
opacity: 1;
|
||||||
|
font-weight: 800 !important;
|
||||||
|
transform: scale(1.05);
|
||||||
|
text-shadow: 0 0 30px rgba(255,255,255,0.3);
|
||||||
|
color: var(--primary-color, #90caf9);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&-unsynced-notice {
|
||||||
|
position: sticky;
|
||||||
|
bottom: 1rem;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 0.5rem;
|
||||||
|
padding: 0.5rem 1rem;
|
||||||
|
background: rgba(0, 0, 0, 0.4);
|
||||||
|
backdrop-filter: blur(10px);
|
||||||
|
border-radius: 2rem;
|
||||||
|
margin-top: auto;
|
||||||
|
opacity: 0.8;
|
||||||
|
|
||||||
|
.material-symbols-rounded {
|
||||||
|
font-size: 1.2rem;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+206
-356
@@ -1,249 +1,200 @@
|
|||||||
import { useApiInContext } from "@/utils/store/api";
|
import { Box, Tab, Tabs, Typography } from "@mui/material";
|
||||||
import { useAudioPlayback } from "@/utils/store/audioPlayback";
|
|
||||||
import useQueue, { setQueue } from "@/utils/store/queue";
|
|
||||||
import { Fab, IconButton, Slider, Typography } from "@mui/material";
|
|
||||||
import { createFileRoute } from "@tanstack/react-router";
|
import { createFileRoute } from "@tanstack/react-router";
|
||||||
import React, { useEffect, useRef, useState } from "react";
|
import React, { useEffect, useMemo, useState } from "react";
|
||||||
|
import { useApiInContext } from "@/utils/store/api";
|
||||||
|
import {
|
||||||
|
setIsMuted,
|
||||||
|
setVolume,
|
||||||
|
useAudioPlayback,
|
||||||
|
} from "@/utils/store/audioPlayback";
|
||||||
|
import useQueue from "@/utils/store/queue";
|
||||||
|
|
||||||
import "./audio.scss";
|
import "./audio.scss";
|
||||||
import PlayNextButton from "@/components/buttons/playNextButton";
|
|
||||||
import PlayPreviousButton from "@/components/buttons/playPreviousButtom";
|
|
||||||
import QueueTrack from "@/components/queueTrack";
|
|
||||||
import { getRuntimeMusic, secToTicks, ticksToSec } from "@/utils/date/time";
|
|
||||||
import getImageUrlsApi from "@/utils/methods/getImageUrlsApi";
|
|
||||||
import { getLyricsApi } from "@jellyfin/sdk/lib/utils/api/lyrics-api";
|
|
||||||
import { useQuery } from "@tanstack/react-query";
|
|
||||||
|
|
||||||
import {
|
import type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client";
|
||||||
DndContext,
|
import LyricsPanel from "@/components/playback/audioPlayer/components/LyricsPanel";
|
||||||
type DragEndEvent,
|
import PlayerControls from "@/components/playback/audioPlayer/components/PlayerControls";
|
||||||
DragOverlay,
|
import PlayerProgress from "@/components/playback/audioPlayer/components/PlayerProgress";
|
||||||
KeyboardSensor,
|
import PlayerVolume from "@/components/playback/audioPlayer/components/PlayerVolume";
|
||||||
PointerSensor,
|
import QueuePanel from "@/components/playback/audioPlayer/components/QueuePanel";
|
||||||
closestCenter,
|
import StatsPanel from "@/components/playback/audioPlayer/components/StatsPanel";
|
||||||
useSensor,
|
import { secToTicks, ticksToSec } from "@/utils/date/time";
|
||||||
useSensors,
|
import getImageUrlsApi from "@/utils/methods/getImageUrlsApi";
|
||||||
} from "@dnd-kit/core";
|
|
||||||
import {
|
|
||||||
restrictToVerticalAxis,
|
|
||||||
restrictToWindowEdges,
|
|
||||||
} from "@dnd-kit/modifiers";
|
|
||||||
import {
|
|
||||||
SortableContext,
|
|
||||||
arrayMove,
|
|
||||||
sortableKeyboardCoordinates,
|
|
||||||
verticalListSortingStrategy,
|
|
||||||
} from "@dnd-kit/sortable";
|
|
||||||
|
|
||||||
export const Route = createFileRoute("/_api/player/audio")({
|
export const Route = createFileRoute("/_api/player/audio")({
|
||||||
component: AudioPlayerRoute,
|
component: AudioPlayerRoute,
|
||||||
});
|
});
|
||||||
|
|
||||||
const SEEK_AMOUNT = 10; // seconds to skip on fast_rewind or fast_forward button click
|
const SEEK_AMOUNT = 10;
|
||||||
|
|
||||||
|
const AudioInfo = React.memo(
|
||||||
|
({
|
||||||
|
item,
|
||||||
|
imageUrl,
|
||||||
|
}: {
|
||||||
|
item: BaseItemDto | undefined | null;
|
||||||
|
imageUrl: string | undefined;
|
||||||
|
}) => (
|
||||||
|
<>
|
||||||
|
<div className="audio-info-image-container">
|
||||||
|
{imageUrl ? (
|
||||||
|
<img
|
||||||
|
alt={item?.Name ?? "Music"}
|
||||||
|
src={imageUrl}
|
||||||
|
className="audio-info-image"
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<div className="audio-info-image-icon">
|
||||||
|
<span
|
||||||
|
className="material-symbols-rounded"
|
||||||
|
style={{ fontSize: "inherit" }}
|
||||||
|
>
|
||||||
|
music_note
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="audio-info">
|
||||||
|
<Typography
|
||||||
|
variant="h4"
|
||||||
|
fontWeight={700}
|
||||||
|
noWrap
|
||||||
|
style={{ width: "100%", marginBottom: "0.2em" }}
|
||||||
|
>
|
||||||
|
{item?.Name}
|
||||||
|
</Typography>
|
||||||
|
<Typography
|
||||||
|
variant="h6"
|
||||||
|
fontWeight={400}
|
||||||
|
className="opacity-07"
|
||||||
|
noWrap
|
||||||
|
style={{ width: "100%" }}
|
||||||
|
>
|
||||||
|
{item?.Artists?.join(", ")}
|
||||||
|
</Typography>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
function AudioPlayerRoute() {
|
function AudioPlayerRoute() {
|
||||||
const api = useApiInContext((s) => s.api);
|
const api = useApiInContext((s) => s.api);
|
||||||
const [queue, currentTrack] = useQueue((s) => [s.tracks, s.currentItemIndex]);
|
const [queue, currentTrack] = useQueue((s) => [s.tracks, s.currentItemIndex]);
|
||||||
const [item, audioPlayerRef] = useAudioPlayback((s) => [
|
const [item, audioPlayerRef, volume, isMuted] = useAudioPlayback((s) => [
|
||||||
s.item,
|
s.item,
|
||||||
s.player.ref,
|
s.player.ref,
|
||||||
|
s.player.volume,
|
||||||
|
s.player.isMuted,
|
||||||
]);
|
]);
|
||||||
const [audioPlayer, setAudioPlayer] = useState<HTMLAudioElement | null>(
|
|
||||||
audioPlayerRef?.current ? audioPlayerRef?.current : null,
|
|
||||||
);
|
|
||||||
useEffect(() => {
|
|
||||||
if (audioPlayerRef?.current) {
|
|
||||||
setAudioPlayer(audioPlayerRef?.current);
|
|
||||||
}
|
|
||||||
}, [audioPlayerRef?.current]);
|
|
||||||
|
|
||||||
console.log(audioPlayer?.paused);
|
const [progress, setProgress] = useState(0);
|
||||||
|
const [playing, setPlaying] = useState(false);
|
||||||
const [isScrubbing, setIsScrubbing] = useState(false);
|
const [tabValue, setTabValue] = useState(0);
|
||||||
const [sliderProgress, setSliderProgress] = useState<number | number[]>(0); // this state hold the slider scrubbing value allowing user to scrub track without changing current time
|
|
||||||
const [progress, setProgress] = useState<number | number[]>(
|
|
||||||
audioPlayer?.currentTime ?? 0,
|
|
||||||
);
|
|
||||||
|
|
||||||
const [showLyrics, setShowLyrics] = useState(false);
|
|
||||||
|
|
||||||
const lyrics = useQuery({
|
|
||||||
queryKey: ["player", "audio", item?.Id, "lyrics"],
|
|
||||||
queryFn: async () => {
|
|
||||||
if (!item?.Id || !api) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
await getLyricsApi(api).getLyrics({
|
|
||||||
itemId: item?.Id,
|
|
||||||
})
|
|
||||||
).data;
|
|
||||||
},
|
|
||||||
enabled: Boolean(item?.Id),
|
|
||||||
});
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
audioPlayerRef?.current?.addEventListener("timeupdate", () => {
|
const player = audioPlayerRef?.current;
|
||||||
setProgress(audioPlayerRef?.current?.currentTime ?? 0);
|
if (!player) return;
|
||||||
});
|
|
||||||
|
const updateProgress = () => setProgress(player.currentTime);
|
||||||
|
const updatePlaying = () => setPlaying(!player.paused);
|
||||||
|
|
||||||
|
player.addEventListener("timeupdate", updateProgress);
|
||||||
|
player.addEventListener("play", updatePlaying);
|
||||||
|
player.addEventListener("pause", updatePlaying);
|
||||||
|
|
||||||
|
// Initial state
|
||||||
|
setProgress(player.currentTime);
|
||||||
|
setPlaying(!player.paused);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
audioPlayerRef?.current?.removeEventListener("timeupdate", () => {
|
player.removeEventListener("timeupdate", updateProgress);
|
||||||
setProgress(audioPlayerRef?.current?.currentTime ?? 0);
|
player.removeEventListener("play", updatePlaying);
|
||||||
});
|
player.removeEventListener("pause", updatePlaying);
|
||||||
};
|
};
|
||||||
}, [item?.Id, currentTrack]);
|
}, [audioPlayerRef?.current, item?.Id]);
|
||||||
|
|
||||||
const lyricsContainer = useRef<HTMLDivElement | null>(null);
|
const handlePlayPause = () => {
|
||||||
useEffect(() => {
|
const player = audioPlayerRef?.current;
|
||||||
if (showLyrics) {
|
if (player) {
|
||||||
const currentLyric = document.querySelector("[data-active-lyric='true']");
|
if (player.paused) {
|
||||||
currentLyric?.scrollIntoView({
|
player.play();
|
||||||
block: "nearest",
|
} else {
|
||||||
inline: "nearest",
|
player.pause();
|
||||||
behavior: "smooth",
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}, [showLyrics, audioPlayer?.currentTime]);
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const sensors = useSensors(
|
const handleSeek = (value: number) => {
|
||||||
useSensor(PointerSensor),
|
setProgress(ticksToSec(value));
|
||||||
useSensor(KeyboardSensor, {
|
};
|
||||||
coordinateGetter: sortableKeyboardCoordinates,
|
|
||||||
}),
|
const handleSeekCommit = (value: number) => {
|
||||||
|
const player = audioPlayerRef?.current;
|
||||||
|
if (player) {
|
||||||
|
player.currentTime = ticksToSec(value);
|
||||||
|
setProgress(ticksToSec(value));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleRewind = () => {
|
||||||
|
const player = audioPlayerRef?.current;
|
||||||
|
if (player) {
|
||||||
|
player.currentTime -= SEEK_AMOUNT;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleForward = () => {
|
||||||
|
const player = audioPlayerRef?.current;
|
||||||
|
if (player) {
|
||||||
|
player.currentTime += SEEK_AMOUNT;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const handleTabChange = (_: React.SyntheticEvent, newValue: number) => {
|
||||||
|
setTabValue(newValue);
|
||||||
|
};
|
||||||
|
|
||||||
|
const imageUrl = useMemo(
|
||||||
|
() =>
|
||||||
|
item?.ImageTags?.Primary
|
||||||
|
? api &&
|
||||||
|
getImageUrlsApi(api).getItemImageUrlById(item.Id ?? "", "Primary", {
|
||||||
|
tag: item.ImageTags.Primary,
|
||||||
|
})
|
||||||
|
: undefined,
|
||||||
|
[item?.Id, item?.ImageTags?.Primary, api],
|
||||||
);
|
);
|
||||||
const handleDragEnd = (event: DragEndEvent) => {
|
|
||||||
const { active, over } = event;
|
|
||||||
if (active.id !== over?.id) {
|
|
||||||
const prevState = queue;
|
|
||||||
const oldIndex = prevState
|
|
||||||
?.map((item) => item.Id)
|
|
||||||
.indexOf(String(active.id));
|
|
||||||
const newIndex = prevState
|
|
||||||
?.map((item) => item.Id)
|
|
||||||
.indexOf(String(over?.id));
|
|
||||||
|
|
||||||
if (oldIndex === newIndex) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!oldIndex || !newIndex) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (oldIndex === -1 || newIndex === -1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const newState = prevState
|
|
||||||
? arrayMove(prevState, oldIndex, newIndex)
|
|
||||||
: prevState;
|
|
||||||
|
|
||||||
const currentTrack = newState?.map((item) => item.Id).indexOf(item?.Id);
|
|
||||||
|
|
||||||
if (!currentTrack) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setQueue(newState, currentTrack);
|
|
||||||
// setQueue(newState);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const [currentDraggingIndex, setCurrentDraggingIndex] = useState<
|
|
||||||
number | null
|
|
||||||
>(null);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<>
|
||||||
className="scrollY padded-top flex flex-column"
|
<div className="audio-background">
|
||||||
style={{ gap: "1em" }}
|
{imageUrl && (
|
||||||
key={item?.Id}
|
<img src={imageUrl} alt="" className="audio-background-image" />
|
||||||
>
|
|
||||||
<div className="audio-info-container">
|
|
||||||
<div className="audio-info-image-container">
|
|
||||||
{item?.ImageTags?.Primary ? (
|
|
||||||
<img
|
|
||||||
alt={item.Name ?? "Music"}
|
|
||||||
src={
|
|
||||||
api &&
|
|
||||||
getImageUrlsApi(api).getItemImageUrlById(
|
|
||||||
item.Id ?? "",
|
|
||||||
"Primary",
|
|
||||||
{
|
|
||||||
tag: item.ImageTags.Primary,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
className="audio-info-image"
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<span className="material-symbols-rounded fill audio-info-image-icon">
|
|
||||||
music_note
|
|
||||||
</span>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="audio-info">
|
<div className="audio-container" key={item?.Id}>
|
||||||
<Typography variant="h4" fontWeight={400}>
|
<div className="audio-left-column">
|
||||||
{item?.Name}
|
<AudioInfo item={item} imageUrl={imageUrl} />
|
||||||
</Typography>
|
|
||||||
<Typography
|
<PlayerProgress
|
||||||
variant="subtitle1"
|
progress={secToTicks(progress)}
|
||||||
fontWeight={300}
|
duration={item?.RunTimeTicks ?? 1}
|
||||||
className="opacity-07"
|
onSeek={handleSeek}
|
||||||
>
|
onSeekCommit={handleSeekCommit}
|
||||||
by {item?.Artists?.join(", ")}
|
/>
|
||||||
</Typography>
|
|
||||||
<div
|
<div className="audio-info-controls">
|
||||||
className="flex flex-row"
|
<PlayerControls
|
||||||
style={{ gap: "1em", alignItems: "center" }}
|
playing={playing}
|
||||||
>
|
onPlayPause={handlePlayPause}
|
||||||
<Typography variant="subtitle2" className="opacity-07">
|
size="large"
|
||||||
{getRuntimeMusic(secToTicks(audioPlayer?.currentTime ?? 0) ?? 0)}
|
onRewind={handleRewind}
|
||||||
</Typography>
|
onForward={handleForward}
|
||||||
<Slider
|
|
||||||
value={
|
|
||||||
isScrubbing ? sliderProgress : secToTicks(Number(progress))
|
|
||||||
}
|
|
||||||
max={item?.RunTimeTicks ?? 1}
|
|
||||||
step={1}
|
|
||||||
key={item?.Id}
|
|
||||||
onChange={(_, newVal) => {
|
|
||||||
setIsScrubbing(true);
|
|
||||||
setSliderProgress(newVal);
|
|
||||||
}}
|
|
||||||
onChangeCommitted={(_, newVal) => {
|
|
||||||
setIsScrubbing(false);
|
|
||||||
Array.isArray(newVal)
|
|
||||||
? setProgress(ticksToSec(newVal[0]))
|
|
||||||
: setProgress(ticksToSec(newVal));
|
|
||||||
if (audioPlayerRef?.current) {
|
|
||||||
audioPlayerRef.current.currentTime = Array.isArray(newVal)
|
|
||||||
? ticksToSec(newVal[0])
|
|
||||||
: ticksToSec(newVal);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
sx={{
|
|
||||||
"& .MuiSlider-thumb": {
|
|
||||||
width: 14,
|
|
||||||
height: 14,
|
|
||||||
transition: "0.1s ease-in-out",
|
|
||||||
opacity: 0,
|
|
||||||
"&.Mui-active": {
|
|
||||||
width: 20,
|
|
||||||
height: 20,
|
|
||||||
opacity: 1,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"&:hover .MuiSlider-thumb": {
|
|
||||||
opacity: 1,
|
|
||||||
},
|
|
||||||
"& .MuiSlider-rail": {
|
|
||||||
opacity: 0.28,
|
|
||||||
background: "white",
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
<Typography variant="subtitle2" className="opacity-07">
|
|
||||||
{getRuntimeMusic(item?.RunTimeTicks ?? 0)}
|
|
||||||
</Typography>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
|
className="audio-info-volume"
|
||||||
style={{
|
style={{
|
||||||
display: "flex",
|
display: "flex",
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
@@ -251,154 +202,53 @@ function AudioPlayerRoute() {
|
|||||||
width: "100%",
|
width: "100%",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div className="audio-info-controls">
|
<PlayerVolume
|
||||||
<PlayPreviousButton />
|
volume={volume}
|
||||||
<IconButton
|
isMuted={isMuted}
|
||||||
onClick={() => {
|
onVolumeChange={setVolume}
|
||||||
if (audioPlayer) {
|
onMuteToggle={() => setIsMuted(!isMuted)}
|
||||||
audioPlayer.currentTime -= SEEK_AMOUNT;
|
/>
|
||||||
}
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="audio-right-column">
|
||||||
|
<Box sx={{ borderBottom: 1, borderColor: "rgba(255,255,255,0.1)" }}>
|
||||||
|
<Tabs
|
||||||
|
value={tabValue}
|
||||||
|
onChange={handleTabChange}
|
||||||
|
aria-label="audio player tabs"
|
||||||
|
variant="fullWidth"
|
||||||
|
scrollButtons="auto"
|
||||||
|
allowScrollButtonsMobile
|
||||||
|
textColor="inherit"
|
||||||
|
indicatorColor="primary"
|
||||||
|
sx={{
|
||||||
|
"& .MuiTab-root": {
|
||||||
|
color: "rgba(255,255,255,0.5)",
|
||||||
|
"&.Mui-selected": { color: "white" },
|
||||||
|
},
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<span className="material-symbols-rounded">fast_rewind</span>
|
<Tab label="Queue" />
|
||||||
</IconButton>
|
<Tab label="Lyrics" />
|
||||||
<Fab
|
<Tab label="Stats" />
|
||||||
disabled={!audioPlayerRef?.current?.readyState}
|
</Tabs>
|
||||||
//@ts-ignore
|
</Box>
|
||||||
color="white"
|
|
||||||
size="large"
|
<div className="audio-right-content">
|
||||||
onClick={() =>
|
{tabValue === 0 && queue && (
|
||||||
audioPlayerRef?.current?.paused
|
<QueuePanel queue={queue} currentTrackIndex={currentTrack} />
|
||||||
? audioPlayerRef?.current?.play()
|
|
||||||
: audioPlayerRef?.current?.pause()
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
className="fill material-symbols-rounded"
|
|
||||||
style={{
|
|
||||||
fontSize: "2.4em",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{audioPlayerRef?.current?.paused ? "play_arrow" : "pause"}
|
|
||||||
</span>
|
|
||||||
</Fab>
|
|
||||||
<IconButton
|
|
||||||
onClick={() => {
|
|
||||||
if (audioPlayer) {
|
|
||||||
audioPlayer.currentTime += SEEK_AMOUNT;
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<span className="material-symbols-rounded">fast_forward</span>
|
|
||||||
</IconButton>
|
|
||||||
<PlayNextButton />
|
|
||||||
</div>
|
|
||||||
<IconButton onClick={() => setShowLyrics((s) => !s)}>
|
|
||||||
<span
|
|
||||||
className={
|
|
||||||
showLyrics
|
|
||||||
? "material-symbols-rounded fill"
|
|
||||||
: "material-symbols-rounded"
|
|
||||||
}
|
|
||||||
>
|
|
||||||
lyrics
|
|
||||||
</span>
|
|
||||||
</IconButton>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{showLyrics && (
|
|
||||||
<div
|
|
||||||
className="audio-lyrics"
|
|
||||||
data-has-synced-lyrics={Boolean(
|
|
||||||
(lyrics.data?.Lyrics?.[0].Start ?? -1) >= 0,
|
|
||||||
)}
|
)}
|
||||||
>
|
{tabValue === 1 && (
|
||||||
<div className="audio-lyrics-container" ref={lyricsContainer}>
|
<LyricsPanel item={item} api={api} currentTime={progress} />
|
||||||
{lyrics.data?.Lyrics?.map((lyric, index) => (
|
)}
|
||||||
<div
|
{tabValue === 2 && (
|
||||||
className="audio-lyrics-line"
|
<StatsPanel item={item} audioRef={audioPlayerRef} />
|
||||||
key={`${lyric.Text}${index}`}
|
|
||||||
data-active-lyric={
|
|
||||||
secToTicks(audioPlayer?.currentTime ?? 0) >=
|
|
||||||
(lyric.Start ?? 0) &&
|
|
||||||
secToTicks(audioPlayer?.currentTime ?? 0) <
|
|
||||||
(lyrics.data?.Lyrics?.[index + 1]?.Start ?? 0)
|
|
||||||
}
|
|
||||||
>
|
|
||||||
{lyric.Text}
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
{!((lyrics.data?.Lyrics?.[0].Start ?? -1) >= 0) && (
|
|
||||||
<Typography
|
|
||||||
className="flex flex-align-center"
|
|
||||||
style={{
|
|
||||||
position: "absolute",
|
|
||||||
bottom: "-2em",
|
|
||||||
opacity: 0.7,
|
|
||||||
gap: "0.4em",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<span className="material-symbols-rounded">info</span>
|
|
||||||
Synced subtitles no available
|
|
||||||
</Typography>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
|
||||||
<DndContext
|
|
||||||
sensors={sensors}
|
|
||||||
collisionDetection={closestCenter}
|
|
||||||
onDragEnd={handleDragEnd}
|
|
||||||
onDragStart={(event) => {
|
|
||||||
const { active } = event;
|
|
||||||
setCurrentDraggingIndex(
|
|
||||||
queue?.map((item) => item.Id).indexOf(String(active.id) ?? "") ?? 0,
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
modifiers={[restrictToVerticalAxis]}
|
|
||||||
>
|
|
||||||
{queue && (
|
|
||||||
<div className="audio-queue-container">
|
|
||||||
<Typography variant="h5">Queue:</Typography>
|
|
||||||
<SortableContext
|
|
||||||
//@ts-ignore
|
|
||||||
items={queue?.map((track) => track.Id)}
|
|
||||||
strategy={verticalListSortingStrategy}
|
|
||||||
>
|
|
||||||
<div className="audio-queue">
|
|
||||||
{queue?.map((track, index) => (
|
|
||||||
<QueueTrack key={track.Id} track={track} index={index} />
|
|
||||||
))}
|
|
||||||
</div>
|
</div>
|
||||||
</SortableContext>
|
|
||||||
<DragOverlay modifiers={[restrictToWindowEdges]}>
|
|
||||||
{(currentDraggingIndex ?? -1) >= 0 && (
|
|
||||||
<div className="audio-queue-track dragging">
|
|
||||||
<span className="material-symbols-rounded">drag_handle</span>
|
|
||||||
<div className="audio-queue-track-info">
|
|
||||||
<Typography className="audio-queue-track-info-name">
|
|
||||||
{queue[currentDraggingIndex ?? 0].Name}
|
|
||||||
</Typography>
|
|
||||||
<Typography
|
|
||||||
fontWeight={300}
|
|
||||||
className="opacity-07"
|
|
||||||
variant="subtitle2"
|
|
||||||
>
|
|
||||||
{queue[currentDraggingIndex ?? 0].Artists?.join(", ")}
|
|
||||||
</Typography>
|
|
||||||
</div>
|
|
||||||
<Typography className="opacity-07">
|
|
||||||
{getRuntimeMusic(
|
|
||||||
queue[currentDraggingIndex ?? 0].RunTimeTicks ?? 0,
|
|
||||||
)}
|
|
||||||
</Typography>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</DragOverlay>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</DndContext>
|
|
||||||
</div>
|
</div>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -14,6 +14,8 @@ type AudioPlaybackStore = {
|
|||||||
currentTick: number;
|
currentTick: number;
|
||||||
playing: boolean;
|
playing: boolean;
|
||||||
ref: React.RefObject<HTMLAudioElement> | null;
|
ref: React.RefObject<HTMLAudioElement> | null;
|
||||||
|
volume: number;
|
||||||
|
isMuted: boolean;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
export const useAudioPlayback = createWithEqualityFn<AudioPlaybackStore>(
|
export const useAudioPlayback = createWithEqualityFn<AudioPlaybackStore>(
|
||||||
@@ -26,6 +28,8 @@ export const useAudioPlayback = createWithEqualityFn<AudioPlaybackStore>(
|
|||||||
currentTick: 0,
|
currentTick: 0,
|
||||||
playing: false,
|
playing: false,
|
||||||
ref: null,
|
ref: null,
|
||||||
|
volume: 0.8,
|
||||||
|
isMuted: false,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
shallow,
|
shallow,
|
||||||
@@ -80,7 +84,7 @@ export const generateAudioStreamUrl = (
|
|||||||
transcodingContainer: transcodingProfile?.Container,
|
transcodingContainer: transcodingProfile?.Container,
|
||||||
transcodingProtocol: transcodingProfile?.Protocol,
|
transcodingProtocol: transcodingProfile?.Protocol,
|
||||||
audioCodec: transcodingProfile?.AudioCodec,
|
audioCodec: transcodingProfile?.AudioCodec,
|
||||||
playSessionId: new Date().getTime(),
|
playSessionId: Date.now(),
|
||||||
startTimeTicks: 0,
|
startTimeTicks: 0,
|
||||||
enableRemoteMedia: false,
|
enableRemoteMedia: false,
|
||||||
enableAudioVbrEncoding: true,
|
enableAudioVbrEncoding: true,
|
||||||
@@ -100,3 +104,32 @@ export const setProgress = (ticks: number) => {
|
|||||||
state.player.currentTick = ticks;
|
state.player.currentTick = ticks;
|
||||||
useAudioPlayback.setState(state);
|
useAudioPlayback.setState(state);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const setVolume = (volume: number) => {
|
||||||
|
const state = useAudioPlayback.getState();
|
||||||
|
state.player.volume = volume;
|
||||||
|
useAudioPlayback.setState(state);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const setIsMuted = (isMuted: boolean) => {
|
||||||
|
const state = useAudioPlayback.getState();
|
||||||
|
state.player.isMuted = isMuted;
|
||||||
|
useAudioPlayback.setState(state);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const stopPlayback = () => {
|
||||||
|
const current = useAudioPlayback.getState();
|
||||||
|
useAudioPlayback.setState({
|
||||||
|
display: false,
|
||||||
|
url: "",
|
||||||
|
item: undefined,
|
||||||
|
playlistItemId: undefined,
|
||||||
|
player: {
|
||||||
|
currentTick: 0,
|
||||||
|
playing: false,
|
||||||
|
ref: null,
|
||||||
|
volume: current.player.volume,
|
||||||
|
isMuted: current.player.isMuted,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
Reference in new issue
Block a user