feat: add new audioPlayer route and allow reordering queue
This commit is contained in:
17 files changed
+629
-219
No files matched your search
@@ -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">
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -1,21 +1,60 @@
|
||||
.audio-info {
|
||||
&-container {
|
||||
display: flex;
|
||||
gap: 1em;
|
||||
align-items: center;
|
||||
justify-content: flex-start;
|
||||
}
|
||||
&-image {
|
||||
.audio {
|
||||
&-info {
|
||||
width: 100%;
|
||||
aspect-ratio: 1;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
padding: 4em;
|
||||
gap: 0.5em;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
&-container {
|
||||
width: 25em;
|
||||
display: flex;
|
||||
gap: 0em;
|
||||
align-items: center;
|
||||
justify-content: flex-start;
|
||||
}
|
||||
&-image {
|
||||
width: 100%;
|
||||
aspect-ratio: 1;
|
||||
position: relative;
|
||||
border-radius: $border-radius-default;
|
||||
overflow: hidden;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
&-container {
|
||||
width: 25em;
|
||||
aspect-ratio: 1;
|
||||
position: relative;
|
||||
border-radius: $border-radius-default;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user