Add more feat to audioPlayer #173
This commit is contained in:
13 files changed
+424
-118
No files matched your search
@@ -13,7 +13,14 @@ import { MdiHeartOutline } from "../icons/mdiHeartOutline";
|
||||
import { useSnackbar } from "notistack";
|
||||
import CircularProgress from "@mui/material/CircularProgress";
|
||||
|
||||
const LikeButton = ({ itemId, isFavorite, queryKey, userId, itemName }) => {
|
||||
const LikeButton = ({
|
||||
itemId,
|
||||
isFavorite,
|
||||
queryKey,
|
||||
userId,
|
||||
itemName,
|
||||
color = "white",
|
||||
}) => {
|
||||
const queryClient = useQueryClient();
|
||||
const { enqueueSnackbar } = useSnackbar();
|
||||
|
||||
@@ -89,7 +96,7 @@ const LikeButton = ({ itemId, isFavorite, queryKey, userId, itemName }) => {
|
||||
{isFavorite ? (
|
||||
<MdiHeart sx={{ color: pink[700] }} />
|
||||
) : (
|
||||
<MdiHeartOutline />
|
||||
<MdiHeartOutline sx={{ color: color }} />
|
||||
)}
|
||||
</IconButton>
|
||||
</div>
|
||||
|
||||
@@ -14,7 +14,11 @@ import { useMutation, useQuery } from "@tanstack/react-query";
|
||||
import { getUserLibraryApi } from "@jellyfin/sdk/lib/utils/api/user-library-api";
|
||||
import { getTvShowsApi } from "@jellyfin/sdk/lib/utils/api/tv-shows-api";
|
||||
import { getItemsApi } from "@jellyfin/sdk/lib/utils/api/items-api";
|
||||
import { BaseItemKind, ItemFields } from "@jellyfin/sdk/lib/generated-client";
|
||||
import {
|
||||
BaseItemKind,
|
||||
ItemFields,
|
||||
SortOrder,
|
||||
} from "@jellyfin/sdk/lib/generated-client";
|
||||
import { useSnackbar } from "notistack";
|
||||
import { useAudioPlayback } from "../../utils/store/audioPlayback";
|
||||
|
||||
@@ -51,9 +55,13 @@ const PlayButton = ({
|
||||
state.setSubtitleTracks,
|
||||
state.setSelectedSubtitleTrack,
|
||||
]);
|
||||
const [setAudioUrl, setAudioDisplay, setAudioItem] = useAudioPlayback(
|
||||
(state) => [state.setUrl, state.setDisplay, state.setItem],
|
||||
);
|
||||
const [setAudioUrl, setAudioDisplay, setAudioItem, setAudioTracks] =
|
||||
useAudioPlayback((state) => [
|
||||
state.setUrl,
|
||||
state.setDisplay,
|
||||
state.setItem,
|
||||
state.setTracks,
|
||||
]);
|
||||
const setPlaybackDataLoading = usePlaybackDataLoadStore(
|
||||
(state) => state.setIsLoading,
|
||||
);
|
||||
@@ -83,6 +91,8 @@ const PlayButton = ({
|
||||
ItemFields.MediaSources,
|
||||
ItemFields.MediaStreams,
|
||||
],
|
||||
sortOrder: SortOrder.Ascending,
|
||||
sortBy: "IndexNumber",
|
||||
});
|
||||
} else {
|
||||
result = await getItemsApi(window.api).getItems({
|
||||
@@ -92,13 +102,15 @@ const PlayButton = ({
|
||||
ItemFields.MediaSources,
|
||||
ItemFields.MediaStreams,
|
||||
],
|
||||
sortOrder: SortOrder.Ascending,
|
||||
sortBy: "IndexNumber",
|
||||
});
|
||||
}
|
||||
return result.data;
|
||||
},
|
||||
onSuccess: (item) => {
|
||||
if (audio) {
|
||||
console.log(item);
|
||||
setAudioTracks(item.Items);
|
||||
setAudioUrl(
|
||||
`${window.api.basePath}/Audio/${item.Items[0].Id}/universal?deviceId=${window.api.deviceInfo.id}&userId=${userId}&api_key=${window.api.accessToken}`,
|
||||
);
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
/** @format */
|
||||
import SvgIcon from "@mui/material/SvgIcon";
|
||||
|
||||
import { mdiSkipNext } from "@mdi/js";
|
||||
|
||||
export const MdiSkipNext = (props) => {
|
||||
return (
|
||||
<SvgIcon {...props}>
|
||||
<path d={mdiSkipNext}></path>
|
||||
</SvgIcon>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
/** @format */
|
||||
import SvgIcon from "@mui/material/SvgIcon";
|
||||
|
||||
import { mdiSkipPrevious } from "@mdi/js";
|
||||
|
||||
export const MdiSkipPrevious = (props) => {
|
||||
return (
|
||||
<SvgIcon {...props}>
|
||||
<path d={mdiSkipPrevious}></path>
|
||||
</SvgIcon>
|
||||
);
|
||||
};
|
||||
@@ -41,6 +41,7 @@ import TextLink from "../../textLink";
|
||||
* @property {bool} disableLikeButton
|
||||
* @property {bool} disableMarkAsPlayedButton
|
||||
* @property {string} albumBy
|
||||
* @property {bool} audioPlayButton
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -61,6 +62,7 @@ const Hero = ({
|
||||
disableLikeButton,
|
||||
disableMarkAsPlayedButton,
|
||||
albumBy,
|
||||
audioPlayButton = false,
|
||||
}) => {
|
||||
const filterMediaStreamVideo = (source) => {
|
||||
if (source.Type == MediaStreamType.Video) {
|
||||
@@ -360,6 +362,7 @@ const Hero = ({
|
||||
size: "large",
|
||||
}}
|
||||
itemUserData={item.UserData}
|
||||
audio={audioPlayButton}
|
||||
/>
|
||||
)}
|
||||
{!disableLikeButton && (
|
||||
|
||||
@@ -130,8 +130,7 @@ export const SideMenu = ({}) => {
|
||||
sx={{
|
||||
zIndex: 1,
|
||||
width: `calc(${theme.spacing(7)} + 10px)`,
|
||||
background:
|
||||
"linear-gradient(to right, rgb(0 0 0 / 0.35) , transparent) !important ",
|
||||
background: "transparent !important ",
|
||||
}}
|
||||
>
|
||||
<DrawerHeader
|
||||
|
||||
@@ -5,17 +5,19 @@
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
background: rgb(0 0 0 / 0.5);
|
||||
background: $clr-background-dark-opacity-0_8;
|
||||
z-index: 10;
|
||||
display: flex;
|
||||
display: grid;
|
||||
padding: 1em;
|
||||
margin: 1em;
|
||||
backdrop-filter: blur(10px);
|
||||
border-radius: 10px;
|
||||
overflow: hidden;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 1em;
|
||||
box-shadow: 0 0 20px rgb(0 0 0 / 0.25);
|
||||
|
||||
grid-template-columns: 20% 1fr 20%;
|
||||
|
||||
#waveform {
|
||||
width: 100%;
|
||||
}
|
||||
@@ -24,18 +26,43 @@
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 1em;
|
||||
width: 100%;
|
||||
flex-flow: column;
|
||||
}
|
||||
&-info {
|
||||
display: flex;
|
||||
display: grid;
|
||||
gap: 0.5em;
|
||||
flex-wrap: nowrap;
|
||||
grid-template-columns: minmax(0, 4.5em) minmax(0, 1fr);
|
||||
width: fit-content;
|
||||
align-items: center;
|
||||
flex-grow: 1;
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
&-image {
|
||||
width: 4em;
|
||||
width: 4.5em;
|
||||
aspect-ratio: 1;
|
||||
border-radius: $border-radius-default;
|
||||
object-fit: cover;
|
||||
z-index: 1;
|
||||
flex-shrink: 0;
|
||||
flex-grow: 1;
|
||||
|
||||
position: relative;
|
||||
&-container {
|
||||
border-radius: $border-radius-default;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
background: $clr-gradient-dark;
|
||||
height: fit-content;
|
||||
aspect-ratio: 1;
|
||||
}
|
||||
&-icon {
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
top: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
font-size: 2em !important;
|
||||
fill: url(#clr-gradient-default) !important;
|
||||
z-index: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import { useEffect, useRef, useState } from "react";
|
||||
|
||||
import { motion } from "framer-motion";
|
||||
|
||||
import Fab from "@mui/material/Fab";
|
||||
import IconButton from "@mui/material/IconButton";
|
||||
import Typography from "@mui/material/Typography";
|
||||
|
||||
@@ -16,28 +17,66 @@ import { MdiPause } from "../../icons/mdiPause";
|
||||
import { AnimatePresence } from "framer-motion";
|
||||
|
||||
import { getRuntimeMusic, secToTicks } from "../../../utils/date/time";
|
||||
import { MdiSkipNext } from "../../icons/mdiSkipNext";
|
||||
import { MdiSkipPrevious } from "../../icons/mdiSkipPrevious";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
||||
import { Icon } from "@mui/material";
|
||||
import { MdiClose } from "../../icons/mdiClose";
|
||||
import { MdiMusic } from "../../icons/mdiMusic";
|
||||
|
||||
const AudioPlayer = () => {
|
||||
const user = useQuery({
|
||||
queryKey: ["user"],
|
||||
queryFn: async () => {
|
||||
let usr = await getUserApi(window.api).getCurrentUser();
|
||||
return usr.data;
|
||||
},
|
||||
networkMode: "always",
|
||||
});
|
||||
|
||||
const waveSurferRef = useRef(null);
|
||||
const waveSurferContainerRef = useRef(null);
|
||||
const [playing, setPlaying] = useState(true);
|
||||
const [playing, setPlaying] = useState(false);
|
||||
|
||||
const [showWaveform, setShowWaveform] = useState(false);
|
||||
|
||||
const [currentTime, setCurrentTime] = useState(0);
|
||||
|
||||
const [url, display, item] = useAudioPlayback((state) => [
|
||||
const [
|
||||
url,
|
||||
display,
|
||||
item,
|
||||
tracks,
|
||||
currentTrack,
|
||||
setCurrentTrack,
|
||||
setAudioUrl,
|
||||
setAudioDisplay,
|
||||
setAudioItem,
|
||||
setAudioTracks,
|
||||
resetPlayer,
|
||||
] = useAudioPlayback((state) => [
|
||||
state.url,
|
||||
state.display,
|
||||
state.item,
|
||||
state.tracks,
|
||||
state.currentTrack,
|
||||
state.setCurrentTrack,
|
||||
state.setUrl,
|
||||
state.setDisplay,
|
||||
state.setItem,
|
||||
state.setTracks,
|
||||
state.reset,
|
||||
]);
|
||||
|
||||
useEffect(() => {
|
||||
if (display) {
|
||||
const waveSurfer = WaveSurfer.create({
|
||||
container: waveSurferContainerRef.current,
|
||||
// autoplay: true,
|
||||
barHeight: 0.6,
|
||||
autoplay: true,
|
||||
barHeight: 0.8,
|
||||
dragToSeek: true,
|
||||
height: 25,
|
||||
height: 35,
|
||||
cursorColor: "#fb2376",
|
||||
progressColor: "#fb2376",
|
||||
});
|
||||
@@ -46,9 +85,35 @@ const AudioPlayer = () => {
|
||||
waveSurferRef.current = waveSurfer;
|
||||
});
|
||||
waveSurfer.on("timeupdate", (e) => {
|
||||
console.log(e);
|
||||
setCurrentTime(e);
|
||||
});
|
||||
waveSurfer.on("redraw", () => {
|
||||
setShowWaveform(true);
|
||||
});
|
||||
waveSurfer.on("play", () => {
|
||||
setPlaying(true);
|
||||
});
|
||||
waveSurfer.on("pause", () => {
|
||||
setPlaying(false);
|
||||
});
|
||||
waveSurfer.on("finish", () => {
|
||||
setPlaying(false);
|
||||
if (currentTrack != tracks.length - 1) {
|
||||
setCurrentTrack(currentTrack + 1);
|
||||
setAudioUrl(
|
||||
`${window.api.basePath}/Audio/${
|
||||
tracks[currentTrack + 1].Id
|
||||
}/universal?deviceId=${
|
||||
window.api.deviceInfo.id
|
||||
}&userId=${user.data.Id}&api_key=${
|
||||
window.api.accessToken
|
||||
}`,
|
||||
);
|
||||
setAudioItem(tracks[currentTrack + 1]);
|
||||
setShowWaveform(false);
|
||||
}
|
||||
});
|
||||
|
||||
return () => {
|
||||
waveSurfer.destroy();
|
||||
};
|
||||
@@ -57,11 +122,36 @@ const AudioPlayer = () => {
|
||||
|
||||
const handlePlayPause = () => {
|
||||
waveSurferRef.current.playPause();
|
||||
setPlaying(!playing);
|
||||
};
|
||||
|
||||
const handleNext = () => {
|
||||
setCurrentTrack(currentTrack + 1);
|
||||
setAudioUrl(
|
||||
`${window.api.basePath}/Audio/${
|
||||
tracks[currentTrack + 1].Id
|
||||
}/universal?deviceId=${window.api.deviceInfo.id}&userId=${
|
||||
user.data.Id
|
||||
}&api_key=${window.api.accessToken}`,
|
||||
);
|
||||
setAudioItem(tracks[currentTrack + 1]);
|
||||
setShowWaveform(false);
|
||||
};
|
||||
|
||||
const handlePrevious = () => {
|
||||
setCurrentTrack(currentTrack - 1);
|
||||
setAudioUrl(
|
||||
`${window.api.basePath}/Audio/${
|
||||
tracks[currentTrack - 1].Id
|
||||
}/universal?deviceId=${window.api.deviceInfo.id}&userId=${
|
||||
user.data.Id
|
||||
}&api_key=${window.api.accessToken}`,
|
||||
);
|
||||
setAudioItem(tracks[currentTrack - 1]);
|
||||
setShowWaveform(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<AnimatePresence>
|
||||
<AnimatePresence wait>
|
||||
{display && (
|
||||
<motion.div
|
||||
initial={{
|
||||
@@ -70,40 +160,79 @@ const AudioPlayer = () => {
|
||||
animate={{ transform: "translateY(0)" }}
|
||||
className="audio-player"
|
||||
>
|
||||
<div className="audio-player-info">
|
||||
<img
|
||||
className="audio-player-image"
|
||||
src={window.api.getItemImageUrl(
|
||||
item.Id,
|
||||
"Primary",
|
||||
{
|
||||
quality: 85,
|
||||
fillHeight: 462,
|
||||
fillWidth: 462,
|
||||
},
|
||||
)}
|
||||
/>
|
||||
<motion.div
|
||||
key={item.Id}
|
||||
initial={{
|
||||
filter: "opacity(0)",
|
||||
}}
|
||||
animate={{
|
||||
filter: "opacity(1)",
|
||||
}}
|
||||
exit={{
|
||||
filter: "opacity(0)",
|
||||
}}
|
||||
className="audio-player-info"
|
||||
>
|
||||
<div className="audio-player-image-container">
|
||||
<img
|
||||
className="audio-player-image"
|
||||
src={window.api.getItemImageUrl(
|
||||
item.Id,
|
||||
"Primary",
|
||||
{
|
||||
quality: 85,
|
||||
fillHeight: 462,
|
||||
fillWidth: 462,
|
||||
},
|
||||
)}
|
||||
/>
|
||||
<MdiMusic className="audio-player-image-icon" />
|
||||
</div>
|
||||
<div className="audio-player-info-text">
|
||||
<Typography noWrap variant="subtitle1">
|
||||
{item.Name}
|
||||
<Typography
|
||||
variant="subtitle1"
|
||||
style={{
|
||||
width: "100%",
|
||||
}}
|
||||
fontWeight={500}
|
||||
>
|
||||
{item.IndexNumber}. {item.Name}
|
||||
</Typography>
|
||||
<Typography
|
||||
noWrap
|
||||
variant="subtitle2"
|
||||
style={{
|
||||
opacity: 0.5,
|
||||
}}
|
||||
noWrap
|
||||
fontWeight={400}
|
||||
>
|
||||
by{" "}
|
||||
{item.Artists.map(
|
||||
(artist) => artist,
|
||||
).join(",")}
|
||||
</Typography>
|
||||
</div>
|
||||
</div>
|
||||
</motion.div>
|
||||
<div className="audio-player-controls">
|
||||
<IconButton onClick={handlePlayPause}>
|
||||
{playing ? <MdiPause /> : <MdiPlay />}
|
||||
</IconButton>
|
||||
<div style={{ display: "flex", gap: "1em" }}>
|
||||
<IconButton
|
||||
onClick={handlePrevious}
|
||||
disabled={currentTrack == 0}
|
||||
>
|
||||
<MdiSkipPrevious />
|
||||
</IconButton>
|
||||
<Fab size="small" onClick={handlePlayPause}>
|
||||
{playing ? <MdiPause /> : <MdiPlay />}
|
||||
</Fab>
|
||||
<IconButton
|
||||
onClick={handleNext}
|
||||
disabled={
|
||||
tracks.length - 1 == currentTrack
|
||||
}
|
||||
>
|
||||
<MdiSkipNext />
|
||||
</IconButton>
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
width: "100%",
|
||||
@@ -113,20 +242,47 @@ const AudioPlayer = () => {
|
||||
justifyContent: "center",
|
||||
}}
|
||||
>
|
||||
<Typography variant="subtitle2">
|
||||
<Typography
|
||||
variant="subtitle2"
|
||||
fontWeight={300}
|
||||
style={{
|
||||
opacity: 0.8,
|
||||
}}
|
||||
>
|
||||
{getRuntimeMusic(
|
||||
secToTicks(currentTime),
|
||||
)}
|
||||
</Typography>
|
||||
<div
|
||||
id="waveform"
|
||||
style={{
|
||||
opacity: showWaveform ? 1 : 0,
|
||||
transition: "opacity 250ms",
|
||||
}}
|
||||
ref={waveSurferContainerRef}
|
||||
></div>
|
||||
<Typography variant="subtitle2">
|
||||
<Typography
|
||||
variant="subtitle2"
|
||||
fontWeight={300}
|
||||
style={{
|
||||
opacity: 0.8,
|
||||
}}
|
||||
>
|
||||
{getRuntimeMusic(item.RunTimeTicks)}
|
||||
</Typography>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "flex-end",
|
||||
}}
|
||||
>
|
||||
<IconButton onClick={resetPlayer}>
|
||||
<MdiClose />
|
||||
</IconButton>
|
||||
</div>
|
||||
</motion.div>
|
||||
)}
|
||||
</AnimatePresence>
|
||||
|
||||
Reference in new issue
Block a user