feat: add new audioPlayer route and allow reordering queue

This commit is contained in:
Prayag Prajapati committed 2024-07-31 11:41:44 +05:30
1 parent d824823624
commit 7a2e4ae595
17 files changed
+445 -35

No files matched your search

+1
View File
@@ -0,0 +1 @@
{}
+3
View File
@@ -34,5 +34,8 @@
"*.scss"
],
"ignoreUnknown": true
},
"formatter": {
"formatWithErrors": true
}
}
+3
View File
@@ -46,6 +46,8 @@
"notistack": "^3.0.1",
"react": "18.3.1",
"react-blurhash": "^0.3.0",
"react-dnd": "^16.0.1",
"react-dnd-html5-backend": "^16.0.1",
"react-dom": "18.3.1",
"react-error-boundary": "^4.0.13",
"react-markdown": "^9.0.1",
@@ -59,6 +61,7 @@
"zustand": "^4.5.4"
},
"devDependencies": {
"@babel/plugin-proposal-optional-chaining-assign": "^7.24.7",
"@biomejs/biome": "^1.8.3",
"@tanstack/router-cli": "^1.45.8",
"@tanstack/router-devtools": "^1.45.11",
+145 -2
View File
@@ -107,6 +107,12 @@ importers:
react-blurhash:
specifier: ^0.3.0
version: 0.3.0(blurhash@2.0.5)(react@18.3.1)
react-dnd:
specifier: ^16.0.1
version: 16.0.1(@types/node@22.0.0)(@types/react@18.3.3)(react@18.3.1)
react-dnd-html5-backend:
specifier: ^16.0.1
version: 16.0.1
react-dom:
specifier: 18.3.1
version: 18.3.1(react@18.3.1)
@@ -141,6 +147,9 @@ importers:
specifier: ^4.5.4
version: 4.5.4(@types/react@18.3.3)(react@18.3.1)
devDependencies:
'@babel/plugin-proposal-optional-chaining-assign':
specifier: ^7.24.7
version: 7.24.7(@babel/core@7.24.9)
'@biomejs/biome':
specifier: ^1.8.3
version: 1.8.3
@@ -228,6 +237,10 @@ packages:
resolution: {integrity: sha512-zBAIvbCMh5Ts+b86r/CjU+4XGYIs+R1j951gxI3KmmxBMhCg4oQMsv6ZXQ64XOm/cvzfU1FmoCyt6+owc5QMYg==}
engines: {node: '>=6.9.0'}
'@babel/helper-skip-transparent-expression-wrappers@7.24.7':
resolution: {integrity: sha512-IO+DLT3LQUElMbpzlatRASEyQtfhSE0+m465v++3jyyXeBTBUjtVZg28/gHeV5mrTJqvEKhKroBGAvhW+qPHiQ==}
engines: {node: '>=6.9.0'}
'@babel/helper-string-parser@7.24.8':
resolution: {integrity: sha512-pO9KhhRcuUyGnJWwyEgnRJTSIZHiT+vMD0kPeD+so0l7mxkMT19g3pjY9GTnHySck/hDzq+dtW/4VgnMkippsQ==}
engines: {node: '>=6.9.0'}
@@ -253,18 +266,41 @@ packages:
engines: {node: '>=6.0.0'}
hasBin: true
'@babel/plugin-proposal-optional-chaining-assign@7.24.7':
resolution: {integrity: sha512-a7+U9LJ06lqftkbRQB8P0tTIADoQhzZMl3owT/Rly7JZjcpDX/VNauogJmuK5VIBJN91jQMUd8EGPTpNehvvFQ==}
engines: {node: '>=6.9.0'}
peerDependencies:
'@babel/core': ^7.22.5
'@babel/plugin-syntax-jsx@7.24.7':
resolution: {integrity: sha512-6ddciUPe/mpMnOKv/U+RSd2vvVy+Yw/JfBB0ZHYjEZt9NLHmCUylNYlsbqCCS1Bffjlb0fCwC9Vqz+sBz6PsiQ==}
engines: {node: '>=6.9.0'}
peerDependencies:
'@babel/core': ^7.0.0-0
'@babel/plugin-syntax-optional-chaining-assign@7.24.7':
resolution: {integrity: sha512-syk5SNtBRAMFM32edresIIKDfJh4KHdJU8Cc5WLhUx2iRVovERCfiBaxJaZ5M1p4fxnVznc7ioSe21qPMCSwhw==}
engines: {node: '>=6.9.0'}
peerDependencies:
'@babel/core': ^7.0.0-0
'@babel/plugin-syntax-optional-chaining@7.8.3':
resolution: {integrity: sha512-KoK9ErH1MBlCPxV0VANkXW2/dw4vlbGDrFgz8bmUsBGYkFRcbRwMh6cIJubdPrkxRwuGdtCk0v/wPTKbQgBjkg==}
peerDependencies:
'@babel/core': ^7.0.0-0
'@babel/plugin-syntax-typescript@7.24.7':
resolution: {integrity: sha512-c/+fVeJBB0FeKsFvwytYiUD+LBvhHjGSI0g446PRGdSVGZLRNArBUno2PETbAly3tpiNAQR5XaZ+JslxkotsbA==}
engines: {node: '>=6.9.0'}
peerDependencies:
'@babel/core': ^7.0.0-0
'@babel/plugin-transform-optional-chaining@7.24.8':
resolution: {integrity: sha512-5cTOLSMs9eypEy8JUVvIKOu6NgvbJMnpG62VpIHrTmROdQ+L5mDAaI40g25k5vXti55JWNX5jCkq3HZxXBQANw==}
engines: {node: '>=6.9.0'}
peerDependencies:
'@babel/core': ^7.0.0-0
'@babel/plugin-transform-react-jsx-self@7.24.7':
resolution: {integrity: sha512-fOPQYbGSgH0HUp4UJO4sMBFjY6DuWq+2i8rixyUMb3CdGixs/gccURvYOAhajBdKDoGajFr3mUq5rH3phtkGzw==}
engines: {node: '>=6.9.0'}
@@ -931,6 +967,15 @@ packages:
'@popperjs/core@2.11.8':
resolution: {integrity: sha512-P1st0aksCrn9sGZhp8GMYwBnQsbvAWsZAX44oXNNvLHGqAOcoVxmjZiohstwQ7SqKnbR47akdNi+uleWD8+g6A==}
'@react-dnd/asap@5.0.2':
resolution: {integrity: sha512-WLyfoHvxhs0V9U+GTsGilGgf2QsPl6ZZ44fnv0/b8T3nQyvzxidxsg/ZltbWssbsRDlYW8UKSQMTGotuTotZ6A==}
'@react-dnd/invariant@4.0.2':
resolution: {integrity: sha512-xKCTqAK/FFauOM9Ta2pswIyT3D8AQlfrYdOi/toTPEhqCuAs1v5tcJ3Y08Izh1cJ5Jchwy9SeAXmMg6zrKs2iw==}
'@react-dnd/shallowequal@4.0.2':
resolution: {integrity: sha512-/RVXdLvJxLg4QKvMoM5WlwNR9ViO9z8B/qPcc+C0Sa/teJY7QG7kJ441DwzOjMYEY7GmU4dj5EcGHIkKZiQZCA==}
'@react-spring/animated@9.7.4':
resolution: {integrity: sha512-7As+8Pty2QlemJ9O5ecsuPKjmO0NKvmVkRR1n6mEotFgWar8FKuQt2xgxz3RTgxcccghpx1YdS1FCdElQNexmQ==}
peerDependencies:
@@ -1606,6 +1651,9 @@ packages:
resolution: {integrity: sha512-uIFDxqpRZGZ6ThOk84hEfqWoHx2devRFvpTZcTHur85vImfaxUbTW9Ryh4CpCuDnToOP1CEtXKIgytHBPVff5A==}
engines: {node: '>=0.3.1'}
dnd-core@16.0.1:
resolution: {integrity: sha512-HK294sl7tbw6F6IeuK16YSBUoorvHpY8RHO+9yFfaJyCDVb6n7PRcezrOEOa2SBCqiYpemh5Jx20ZcjKdFAVng==}
dom-helpers@5.2.1:
resolution: {integrity: sha512-nRCa7CK3VTrM2NmGkIy4cbK7IZlgBE/PYMn55rrXefr5xXDP0LdtfPnblFDoVdcAfslJ7or6iqAUnx0CCGIWQA==}
@@ -1675,6 +1723,9 @@ packages:
extend@3.0.2:
resolution: {integrity: sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==}
fast-deep-equal@3.1.3:
resolution: {integrity: sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==}
fetch-retry@6.0.0:
resolution: {integrity: sha512-BUFj1aMubgib37I3v4q78fYo63Po7t4HUPTpQ6/QE6yK6cIQrP+W43FYToeTEyg5m2Y7eFUtijUuAv/PDlWuag==}
@@ -2235,6 +2286,24 @@ packages:
blurhash: ^2.0.3
react: '>=15'
react-dnd-html5-backend@16.0.1:
resolution: {integrity: sha512-Wu3dw5aDJmOGw8WjH1I1/yTH+vlXEL4vmjk5p+MHxP8HuHJS1lAGeIdG/hze1AvNeXWo/JgULV87LyQOr+r5jw==}
react-dnd@16.0.1:
resolution: {integrity: sha512-QeoM/i73HHu2XF9aKksIUuamHPDvRglEwdHL4jsp784BgUuWcg6mzfxT0QDdQz8Wj0qyRKx2eMg8iZtWvU4E2Q==}
peerDependencies:
'@types/hoist-non-react-statics': '>= 3.3.1'
'@types/node': '>= 12'
'@types/react': '>= 16'
react: '>= 16.14'
peerDependenciesMeta:
'@types/hoist-non-react-statics':
optional: true
'@types/node':
optional: true
'@types/react':
optional: true
react-dom@18.3.1:
resolution: {integrity: sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==}
peerDependencies:
@@ -2293,6 +2362,9 @@ packages:
resolution: {integrity: sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==}
engines: {node: '>=8.10.0'}
redux@4.2.1:
resolution: {integrity: sha512-LAUYz4lc+Do8/g7aeRa8JkyDErK6ekstQaqWQrNRW//MY1TvCEpMtpTWvlQ+FPbWCx+Xixu/6SHt5N0HR+SB4w==}
regenerator-runtime@0.14.1:
resolution: {integrity: sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==}
@@ -2803,6 +2875,13 @@ snapshots:
transitivePeerDependencies:
- supports-color
'@babel/helper-skip-transparent-expression-wrappers@7.24.7':
dependencies:
'@babel/traverse': 7.25.1
'@babel/types': 7.25.0
transitivePeerDependencies:
- supports-color
'@babel/helper-string-parser@7.24.8': {}
'@babel/helper-validator-identifier@7.24.7': {}
@@ -2825,16 +2904,46 @@ snapshots:
dependencies:
'@babel/types': 7.25.0
'@babel/plugin-proposal-optional-chaining-assign@7.24.7(@babel/core@7.24.9)':
dependencies:
'@babel/core': 7.24.9
'@babel/helper-plugin-utils': 7.24.8
'@babel/helper-skip-transparent-expression-wrappers': 7.24.7
'@babel/plugin-syntax-optional-chaining-assign': 7.24.7(@babel/core@7.24.9)
'@babel/plugin-transform-optional-chaining': 7.24.8(@babel/core@7.24.9)
transitivePeerDependencies:
- supports-color
'@babel/plugin-syntax-jsx@7.24.7(@babel/core@7.24.9)':
dependencies:
'@babel/core': 7.24.9
'@babel/helper-plugin-utils': 7.24.8
'@babel/plugin-syntax-optional-chaining-assign@7.24.7(@babel/core@7.24.9)':
dependencies:
'@babel/core': 7.24.9
'@babel/helper-plugin-utils': 7.24.8
'@babel/helper-validator-option': 7.24.8
'@babel/plugin-syntax-optional-chaining@7.8.3(@babel/core@7.24.9)':
dependencies:
'@babel/core': 7.24.9
'@babel/helper-plugin-utils': 7.24.8
'@babel/plugin-syntax-typescript@7.24.7(@babel/core@7.24.9)':
dependencies:
'@babel/core': 7.24.9
'@babel/helper-plugin-utils': 7.24.8
'@babel/plugin-transform-optional-chaining@7.24.8(@babel/core@7.24.9)':
dependencies:
'@babel/core': 7.24.9
'@babel/helper-plugin-utils': 7.24.8
'@babel/helper-skip-transparent-expression-wrappers': 7.24.7
'@babel/plugin-syntax-optional-chaining': 7.8.3(@babel/core@7.24.9)
transitivePeerDependencies:
- supports-color
'@babel/plugin-transform-react-jsx-self@7.24.7(@babel/core@7.24.9)':
dependencies:
'@babel/core': 7.24.9
@@ -3200,8 +3309,8 @@ snapshots:
dependencies:
'@antfu/ni': 0.21.12
'@axiomhq/js': 1.0.0-rc.3
'@babel/core': 7.24.6
'@babel/types': 7.24.6
'@babel/core': 7.24.9
'@babel/types': 7.25.0
'@clack/prompts': 0.7.0
cli-high: 0.4.2
diff: 5.2.0
@@ -3423,6 +3532,12 @@ snapshots:
'@popperjs/core@2.11.8': {}
'@react-dnd/asap@5.0.2': {}
'@react-dnd/invariant@4.0.2': {}
'@react-dnd/shallowequal@4.0.2': {}
'@react-spring/animated@9.7.4(react@18.3.1)':
dependencies:
'@react-spring/shared': 9.7.4(react@18.3.1)
@@ -4082,6 +4197,12 @@ snapshots:
diff@5.2.0: {}
dnd-core@16.0.1:
dependencies:
'@react-dnd/asap': 5.0.2
'@react-dnd/invariant': 4.0.2
redux: 4.2.1
dom-helpers@5.2.1:
dependencies:
'@babel/runtime': 7.25.0
@@ -4188,6 +4309,8 @@ snapshots:
extend@3.0.2: {}
fast-deep-equal@3.1.3: {}
fetch-retry@6.0.0: {}
fflate@0.4.8: {}
@@ -4905,6 +5028,22 @@ snapshots:
blurhash: 2.0.5
react: 18.3.1
react-dnd-html5-backend@16.0.1:
dependencies:
dnd-core: 16.0.1
react-dnd@16.0.1(@types/node@22.0.0)(@types/react@18.3.3)(react@18.3.1):
dependencies:
'@react-dnd/invariant': 4.0.2
'@react-dnd/shallowequal': 4.0.2
dnd-core: 16.0.1
fast-deep-equal: 3.1.3
hoist-non-react-statics: 3.3.2
react: 18.3.1
optionalDependencies:
'@types/node': 22.0.0
'@types/react': 18.3.3
react-dom@18.3.1(react@18.3.1):
dependencies:
loose-envify: 1.4.0
@@ -4974,6 +5113,10 @@ snapshots:
dependencies:
picomatch: 2.3.1
redux@4.2.1:
dependencies:
'@babel/runtime': 7.25.0
regenerator-runtime@0.14.1: {}
registry-auth-token@5.0.2:
+2 -1
View File
@@ -78,7 +78,8 @@
"title": "Blink",
"visible": true,
"center": true,
"label": "main"
"label": "main",
"dragDropEnabled": false
}
],
"security": {
-3
View File
@@ -19,8 +19,6 @@ import { useQuery, useQueryClient } from "@tanstack/react-query";
import { delUser } from "@/utils/storage/user";
import "./appBar.scss";
import { EventEmitter as event } from "@/eventEmitter";
import { getTypeIcon } from "../utils/iconsCollection";
import { useApiInContext } from "@/utils/store/api";
@@ -121,7 +119,6 @@ export const AppBar = () => {
await api.logout();
delUser();
sessionStorage.removeItem("accessToken");
event.emit("create-jellyfin-api", api.basePath);
queryClient.clear();
setAnchorEl(null);
navigate({ to: "/login" });
+1 -1
View File
@@ -86,7 +86,7 @@ const QueueButton = () => {
>
<Typography variant="subtitle2">
{item.Type === "Audio"
? item.IndexNumber ?? 0
? index + 1
: item.IndexNumberEnd
? `S${item.ParentIndexNumber}:E${item.IndexNumber} / ${item.IndexNumberEnd}`
: `S${item.ParentIndexNumber}:E${item.IndexNumber}`}
@@ -93,7 +93,7 @@ const AudioPlayer = () => {
});
setAudioRef(audioRef);
}
}, [url, currentTrack]);
}, [url, tracks[currentTrack]?.Id]);
const navigate = useNavigate();
@@ -288,6 +288,7 @@ const AudioPlayer = () => {
onTimeUpdate={(e) =>
setProgress(secToTicks(e.currentTarget.currentTime))
}
id="audio-player"
/>
<div className="audio-player-controls">
{controls}
@@ -317,7 +318,6 @@ const AudioPlayer = () => {
onChange={(e, value) => {
setIsScrubbing(true);
setSliderProgress(value);
console.log(value);
}}
onChangeCommitted={(e, value) => {
setIsScrubbing(false);
+114
View File
@@ -0,0 +1,114 @@
import { getRuntimeMusic } from "@/utils/date/time";
import useQueue, { setQueue } from "@/utils/store/queue";
import type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client";
import { Typography } from "@mui/material";
import React from "react";
import { useCallback, useRef } from "react";
import { type XYCoord, useDrag, useDrop } from "react-dnd";
import type { Identifier } from "typescript";
type Props = {
track: BaseItemDto;
index: number;
};
const QueueTrack = (props: Props) => {
const { track, index } = props;
const [queue, currentItemIndex] = useQueue((s) => [
s.tracks,
s.currentItemIndex,
]);
const trackRef = useRef<HTMLDivElement | null>(null);
const handleQueueUpdate = useCallback(
(dragIndex: number, dropIndex: number) => {
const prevState = queue;
prevState.splice(dropIndex, 0, prevState.splice(dragIndex, 1)[0]);
setQueue(prevState, dropIndex);
},
[queue],
);
const [{ handlerId }, drop] = useDrop<
{
index: number;
id: string;
type: string;
},
void,
{ handlerId: Identifier | null }
>({
accept: "Row",
collect(monitor) {
return {
handlerId: monitor.getHandlerId(),
};
},
hover(hoverItem, monitor) {
console.log(hoverItem);
if (!trackRef.current) return;
const dragIndex = hoverItem.index;
const dropIndex = index;
if (dragIndex === dropIndex) return;
const hoverBoundingRect = trackRef.current?.getBoundingClientRect();
const hoverMiddleY =
(hoverBoundingRect.bottom - hoverBoundingRect.top) / 2;
const clientOffset = monitor.getClientOffset();
const hoverClientY = (clientOffset as XYCoord).y - hoverBoundingRect.top;
if (dragIndex < dropIndex && hoverClientY < hoverMiddleY) {
return;
}
if (dragIndex > dropIndex && hoverClientY > hoverMiddleY) {
return;
}
handleQueueUpdate(dragIndex, dropIndex);
hoverItem.index = dropIndex;
},
});
const [{ isDragging }, drag] = useDrag({
type: "Row",
item: () => {
const id = track.Id;
return { id, index };
},
collect: (monitor) => ({
isDragging: monitor.isDragging(),
}),
});
drag(drop(trackRef));
return (
<div
ref={trackRef}
style={{ opacity: isDragging ? 0.5 : 1 }}
className={
currentItemIndex === index
? "audio-queue-track active"
: "audio-queue-track"
}
>
<span className="material-symbols-rounded">drag_handle</span>
<div className="audio-queue-track-info">
<Typography className="audio-queue-track-info-name">
{track.Name}
</Typography>
<Typography fontWeight={300} className="opacity-07" variant="subtitle2">
{track.Artists?.join(", ")}
</Typography>
</div>
<Typography className="opacity-07">
{getRuntimeMusic(track.RunTimeTicks)}
</Typography>
</div>
);
};
export default QueueTrack;
-3
View File
@@ -1,3 +0,0 @@
import { EventEmitter as eventEmitter } from "events";
export const EventEmitter = new eventEmitter();
+7 -1
View File
@@ -46,6 +46,8 @@ import "material-symbols/rounded.scss";
import type { Api, Jellyfin } from "@jellyfin/sdk";
import type { UserDto } from "@jellyfin/sdk/lib/generated-client";
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
import { DndProvider } from "react-dnd";
import { HTML5Backend } from "react-dnd-html5-backend";
type ApiContext = {
api: Api;
@@ -94,6 +96,7 @@ export const Route = createRootRouteWithContext<ApiContext>()({
setBackdropLoading(true);
}, [backdropId]);
return (
<DndProvider backend={HTML5Backend}>
<Suspense fallback={<h1>Loading...</h1>}>
<ThemeProvider theme={theme}>
<SnackbarProvider maxSnack={5}>
@@ -160,7 +163,9 @@ export const Route = createRootRouteWithContext<ApiContext>()({
Update Available!
<Chip
icon={
<span className="material-symbols-rounded">update</span>
<span className="material-symbols-rounded">
update
</span>
}
label={`v${updateInfo.version}`}
color="success"
@@ -263,6 +268,7 @@ export const Route = createRootRouteWithContext<ApiContext>()({
</SnackbarProvider>
</ThemeProvider>
</Suspense>
</DndProvider>
);
},
});
+2 -6
View File
@@ -250,7 +250,7 @@ function MusicAlbumTitlePage() {
<Typography variant="subtitle1">Title</Typography>
<Typography variant="subtitle1">Duration</Typography>
</div>
{musicTracks.data?.Items?.map((track) => (
{musicTracks.data?.Items?.map((track, index) => (
<div
className={
currentPlayingItem?.Id === track.Id
@@ -259,11 +259,7 @@ function MusicAlbumTitlePage() {
}
key={track.Id}
onClick={() =>
handlePlayback(
track.IndexNumber,
track,
musicTracks.data.Items,
)
handlePlayback(index, track, musicTracks.data.Items)
}
>
<div className="index-container">
-3
View File
@@ -97,9 +97,6 @@ $border-radius: 20px;
flex-direction: column;
gap: 0.1em
}
&:nth-last-of-type(even):not(.header) {
background: rgb(0 0 0 / 0.2);
}
&:hover {
background: rgb(255 255 255 / 0.1) !important;
.index-container {
+41 -2
View File
@@ -1,7 +1,13 @@
.audio-info {
.audio {
&-info {
width: 100%;
padding: 4em;
gap: 0.5em;
display: flex;
flex-direction: column;
&-container {
display: flex;
gap: 1em;
gap: 0em;
align-items: center;
justify-content: flex-start;
}
@@ -18,4 +24,37 @@
overflow: hidden;
}
}
&-controls {
width: 100%;
display: flex;
align-items: center;
justify-content: center;
gap: 1em;
}
}
&-queue{
display: flex;
flex-direction: column;
width: 100%;
align-items: center;
gap: 1em;
margin-top: 2em;
&-track{
display: grid;
grid-template-columns: 3em 1fr 6em;
align-items: center;
justify-content: center;
width: 100%;
gap: 1em;
&-info-name{
transition: $transition-time-fast;
}
&.active{
.audio-queue-track-info-name{
color: $clr-accent-light;
font-weight: 500;
}
}
}
}
}
+112 -10
View File
@@ -1,25 +1,45 @@
import { useApiInContext } from "@/utils/store/api";
import { useAudioPlayback } from "@/utils/store/audioPlayback";
import useQueue from "@/utils/store/queue";
import { Typography } from "@mui/material";
import { Fab, IconButton, Slider, Typography } from "@mui/material";
import { createFileRoute } from "@tanstack/react-router";
import React from "react";
import React, { useCallback, useEffect, useRef, useState } from "react";
import "./audio.scss";
import LikeButton from "@/components/buttons/likeButton";
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 { useDrop } from "react-dnd";
import { Identifier } from "typescript";
export const Route = createFileRoute("/_api/player/audio")({
component: AudioPlayerRoute,
});
const SEEK_AMOUNT = 10; // seconds to skip on fast_rewind or fast_forward button click
function AudioPlayerRoute() {
const item = useAudioPlayback((s) => s.item);
const api = useApiInContext((s) => s.api);
const [queue, currentTrack] = useQueue((s) => [
s.currentItemIndex,
s.currentItemIndex,
]);
const [queue, currentTrack] = useQueue((s) => [s.tracks, s.currentItemIndex]);
const [item] = useAudioPlayback((s) => [s.item]);
const audioPlayer: HTMLAudioElement | null =
document.querySelector("#audio-player");
const [isScrubbing, setIsScrubbing] = useState(false);
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,
);
useEffect(() => {
audioPlayer?.addEventListener("timeupdate", () => {
setProgress(audioPlayer.currentTime);
});
}, [item?.Id]);
return (
<div className="scrollY padded-top">
<div className="scrollY padded-top flex flex-column" style={{ gap: "1em" }}>
<div className="audio-info-container">
<div className="audio-info-image-container">
{item?.ImageTags ? (
@@ -35,7 +55,7 @@ function AudioPlayerRoute() {
)}
</div>
<div className="audio-info">
<Typography variant="h4" fontWeight={300}>
<Typography variant="h4" fontWeight={400}>
{item?.Name}
</Typography>
<Typography
@@ -45,9 +65,91 @@ function AudioPlayerRoute() {
>
by {item?.Artists?.join(", ")}
</Typography>
<Slider
style={{
marginTop: "1.2em",
}}
value={isScrubbing ? sliderProgress : secToTicks(progress)}
max={item?.RunTimeTicks ?? 1}
step={1}
onChange={(_, newVal) => {
setIsScrubbing(true);
setSliderProgress(newVal);
}}
onChangeCommitted={(_, newVal) => {
setIsScrubbing(false);
Array.isArray(newVal)
? setProgress(ticksToSec(newVal[0]))
: setProgress(ticksToSec(newVal));
audioPlayer?.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",
},
}}
/>
<div className="audio-info-controls">
<PlayPreviousButton />
<IconButton
onClick={() => {
audioPlayer?.currentTime -= SEEK_AMOUNT;
}}
>
<span className="material-symbols-rounded">fast_rewind</span>
</IconButton>
<Fab
color="white"
size="large"
onClick={() =>
audioPlayer?.paused ? audioPlayer.play() : audioPlayer?.pause()
}
>
<span
className="fill material-symbols-rounded"
style={{
fontSize: "2.4em",
}}
>
{audioPlayer?.paused ? "play_arrow" : "pause"}
</span>
</Fab>
<IconButton
onClick={() => {
audioPlayer?.currentTime += SEEK_AMOUNT;
}}
>
<span className="material-symbols-rounded">fast_forward</span>
</IconButton>
<PlayNextButton />
</div>
</div>
</div>
<div className="audio-queue-container">
<Typography variant="h5">Queue:</Typography>
<div className="audio-queue">
{queue.map((track, index) => (
<QueueTrack key={track.Id} track={track} index={index} />
))}
</div>
</div>
<div className="audio-lyrics-container"></div>
</div>
);
}
+1
View File
@@ -1,5 +1,6 @@
$clr-accent-default: hsl(337, 96%, 56%);
$clr-accent-light: hsl(337, 96%, 90%);
$clr-accent-dark: hsl(337, 96%, 20%);
$clr-secondary-default: hsl(273, 100%, 36%);
$clr-secondary-dark: hsl(273, 100%, 12%);
+11 -1
View File
@@ -7,7 +7,17 @@ import path from "path";
// const ReactCompilerConfig = {compilationMode: "annotation"}
const plugins = [react(), svgr(), TanStackRouterVite()];
const plugins = [react({
babel: {
babelrc: true,
plugins: [
["@babel/plugin-proposal-optional-chaining-assign",
{
version: "2023-07"
}]
]
}
}), svgr(), TanStackRouterVite()];
export default defineConfig({
plugins: plugins,
css: {