From c232c1bf120e2307841e3939d25a503631be1fe4 Mon Sep 17 00:00:00 2001 From: --remove-section Date: Tue, 20 Oct 2026 18:31:09 +0530 Subject: [PATCH] feat: added new music player and fix some UI issues --- src/components/buttons/playNextButton.tsx | 26 +- src/components/buttons/queueButton.tsx | 387 +--------------- src/components/itemHeader/index.tsx | 6 +- .../playback/audioPlayer/audioPlayer.scss | 288 +++++++----- .../audioPlayer/components/LyricsPanel.tsx | 55 ++- .../audioPlayer/components/PlayerActions.tsx | 40 +- .../audioPlayer/components/PlayerControls.tsx | 5 +- .../audioPlayer/components/PlayerInfo.tsx | 91 ++-- .../audioPlayer/components/PlayerProgress.tsx | 44 ++ .../audioPlayer/components/PlayerVolume.tsx | 21 +- .../audioPlayer/components/QueuePanel.tsx | 302 ------------- .../audioPlayer/components/StatsPanel.tsx | 2 +- src/components/playback/audioPlayer/index.tsx | 66 +-- src/components/queue/queue.scss | 325 ++++++++++++++ src/components/queue/queueRow.tsx | 178 ++++++++ src/components/queue/queueView.tsx | 273 ++++++++++++ src/components/queueListItem/index.tsx | 236 ---------- src/routes/_api/favorite/favorite.scss | 7 +- src/routes/_api/music/artist/$id.tsx | 96 +++- src/routes/_api/music/artist/artist.scss | 2 +- src/routes/_api/player/audio.scss | 407 ++++++++++------- src/routes/_api/player/audio.tsx | 415 +++++++++++------- src/routes/_api/search/index.tsx | 2 +- src/routes/_api/search/search.scss | 5 + src/utils/store/audioPlayback.ts | 29 +- src/utils/store/queue.ts | 45 +- 26 files changed, 1862 insertions(+), 1491 deletions(-) delete mode 100644 src/components/playback/audioPlayer/components/QueuePanel.tsx create mode 100644 src/components/queue/queue.scss create mode 100644 src/components/queue/queueRow.tsx create mode 100644 src/components/queue/queueView.tsx delete mode 100644 src/components/queueListItem/index.tsx diff --git a/src/components/buttons/playNextButton.tsx b/src/components/buttons/playNextButton.tsx index af8340b..550ab56 100644 --- a/src/components/buttons/playNextButton.tsx +++ b/src/components/buttons/playNextButton.tsx @@ -1,10 +1,10 @@ -import { useApiInContext } from "@/utils/store/api"; -import { playItemFromQueue } from "@/utils/store/playback"; -import useQueue from "@/utils/store/queue"; import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api"; import { IconButton } from "@mui/material"; import { useMutation, useQuery } from "@tanstack/react-query"; import React from "react"; +import { useApiInContext } from "@/utils/store/api"; +import { playItemFromQueue } from "@/utils/store/playback"; +import useQueue, { getNextTrackIndex } from "@/utils/store/queue"; const PlayNextButton = () => { const api = useApiInContext((s) => s.api); @@ -19,21 +19,21 @@ const PlayNextButton = () => { }); const handlePlayNext = useMutation({ mutationKey: ["playNextButton"], - mutationFn: () => playItemFromQueue("next", user.data?.Id, api), + mutationFn: async () => { + const nextIndex = getNextTrackIndex(); + if (nextIndex === undefined) return; + return playItemFromQueue(nextIndex, user.data?.Id, api); + }, onError: (error) => console.error(error), }); - const [queueItems, currentItemIndex] = useQueue((state) => [ - state.tracks, - state.currentItemIndex, - ]); + // Re-render when the queue position or repeat mode changes. + useQueue((state) => [state.tracks, state.currentItemIndex, state.repeatMode]); + const hasNext = getNextTrackIndex() !== undefined; return ( - handlePlayNext.mutate()} - > + handlePlayNext.mutate()}> skip_next ); }; -export default PlayNextButton; \ No newline at end of file +export default PlayNextButton; diff --git a/src/components/buttons/queueButton.tsx b/src/components/buttons/queueButton.tsx index 1fbe4b3..32eb9c5 100644 --- a/src/components/buttons/queueButton.tsx +++ b/src/components/buttons/queueButton.tsx @@ -1,390 +1,31 @@ -import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api"; -import { - Box, - Drawer, - IconButton, - List, - Tooltip, - Typography, -} from "@mui/material"; -import { useQuery } from "@tanstack/react-query"; -import React, { useMemo, useState } from "react"; -import { playItemFromQueue } from "@/utils/store/playback"; -import useQueue, { - clearUpcoming, - removeFromQueue, - reorderQueue, - shuffleUpcoming, -} from "@/utils/store/queue"; -import "./queueButton.scss"; -import { - closestCenter, - DndContext, - type DragEndEvent, - KeyboardSensor, - PointerSensor, - useSensor, - useSensors, -} from "@dnd-kit/core"; -import { restrictToVerticalAxis } 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 { useApiInContext } from "@/utils/store/api"; -import QueueListItem from "../queueListItem"; - -function SortableQueueItem({ - item, - onDelete, - onPlay, - index, -}: { - item: BaseItemDto; - onDelete: () => void; - onPlay: () => void; - index: number; -}) { - const { - attributes, - listeners, - setNodeRef, - transform, - transition, - isDragging, - } = useSortable({ id: item.Id || "" }); - - const style = { - transform: CSS.Transform.toString(transform), - transition, - opacity: isDragging ? 0.5 : 1, - position: "relative" as const, - zIndex: isDragging ? 2 : 1, - }; - - return ( -
- -
- ); -} +import Drawer from "@mui/material/Drawer"; +import IconButton from "@mui/material/IconButton"; +import Tooltip from "@mui/material/Tooltip"; +import React, { useState } from "react"; +import QueueView from "@/components/queue/queueView"; +/** Opens the play queue in a side drawer. */ const QueueButton = () => { - const api = useApiInContext((s) => s.api); - - const [queueItems, currentItemIndex] = useQueue((state) => [ - state.tracks, - state.currentItemIndex, - ]); - const [open, setOpen] = useState(false); - const user = useQuery({ - queryKey: ["currentUser"], - queryFn: async () => { - if (!api) throw new Error("API not available"); - return (await getUserApi(api).getCurrentUser()).data; - }, - enabled: !!api, - }); - - const sensors = useSensors( - useSensor(PointerSensor), - useSensor(KeyboardSensor, { - coordinateGetter: sortableKeyboardCoordinates, - }), - ); - - const upcomingItems = useMemo(() => { - return queueItems ? queueItems.slice(currentItemIndex + 1) : []; - }, [queueItems, currentItemIndex]); - - const upcomingIds = useMemo(() => { - return upcomingItems.map((item) => item.Id || ""); - }, [upcomingItems]); - - const handleDragEnd = (event: DragEndEvent) => { - const { active, over } = event; - - if (active.id !== over?.id && queueItems) { - const oldIndex = upcomingItems.findIndex((item) => item.Id === active.id); - const newIndex = upcomingItems.findIndex((item) => item.Id === over?.id); - - if (oldIndex !== -1 && newIndex !== -1) { - const newUpcoming = arrayMove(upcomingItems, oldIndex, newIndex); - const newQueue = [ - ...queueItems.slice(0, currentItemIndex + 1), - ...newUpcoming, - ]; - reorderQueue(newQueue); - } - } - }; - - const handleDelete = (index: number) => { - removeFromQueue(index); - }; - - const handlePlay = (index: number) => { - playItemFromQueue(index, user.data?.Id, api); - }; - - const handleClear = () => { - clearUpcoming(); - }; - - const handleShuffle = () => { - shuffleUpcoming(); - }; - return ( <> + + setOpen(true)} aria-label="Open queue"> + queue_music + + setOpen(false)} slotProps={{ - backdrop: { - sx: { - backgroundColor: "rgba(0, 0, 0, 0.2)", - backdropFilter: "blur(4px)", - }, - }, - paper: { - className: "glass", - sx: { - width: 450, - maxWidth: "100%", - display: "flex", - flexDirection: "column", - borderLeft: "1px solid rgba(255, 255, 255, 0.08)", - }, - }, + backdrop: { sx: { backgroundColor: "rgb(0 0 0 / 0.3)" } }, + paper: { className: "queue-drawer-paper" }, }} > - - - - Play Queue - - - {queueItems?.length || 0} - - - - - - - shuffle - - - - - - - clear_all - - - - setOpen(false)} size="small"> - close - - - - - - {queueItems && queueItems.length > 0 ? ( - - {/* Current Item */} - {queueItems[currentItemIndex] && ( - - - NOW PLAYING - - - - - - )} - - {/* Upcoming Items */} - {upcomingItems.length > 0 && ( - <> - - NEXT UP - - - - - {upcomingItems.map((item, index) => ( - - handleDelete(currentItemIndex + 1 + index) - } - onPlay={() => - handlePlay(currentItemIndex + 1 + index) - } - index={currentItemIndex + 1 + index + 1} - /> - ))} - - - - - )} - - ) : ( - - - queue_music - - Your queue is empty - - )} - + setOpen(false)} /> - setOpen(true)}> - playlist_play - ); }; diff --git a/src/components/itemHeader/index.tsx b/src/components/itemHeader/index.tsx index 48c6069..ce0ae83 100644 --- a/src/components/itemHeader/index.tsx +++ b/src/components/itemHeader/index.tsx @@ -47,6 +47,8 @@ const ItemHeader = ({ backdropSrc, }: ItemHeaderProps) => { const isEpisode = item.Type === "Episode"; + // A runtime / "ends at" is meaningless for people and artists (it sums their whole catalogue) + const showRuntime = item.Type !== "MusicArtist" && item.Type !== "Person"; const backdropTag = isEpisode && item.ParentBackdropImageTags?.length ? item.ParentBackdropImageTags[0] @@ -294,12 +296,12 @@ const ItemHeader = ({ )} - {item.RunTimeTicks && ( + {showRuntime && item.RunTimeTicks && ( {getRuntime(item.RunTimeTicks)} )} - {item.RunTimeTicks && ( + {showRuntime && item.RunTimeTicks && ( {endsAt( item.RunTimeTicks - (item.UserData?.PlaybackPositionTicks ?? 0), diff --git a/src/components/playback/audioPlayer/audioPlayer.scss b/src/components/playback/audioPlayer/audioPlayer.scss index 22403cf..4289db2 100644 --- a/src/components/playback/audioPlayer/audioPlayer.scss +++ b/src/components/playback/audioPlayer/audioPlayer.scss @@ -1,140 +1,228 @@ -$image-size: 4em; +$art-size: 48px; .audio-player { position: fixed; - bottom: 1rem; + bottom: 0.75rem; left: 50%; transform: translateX(-50%); - width: 95%; - max-width: 1200px; + width: min(1100px, calc(100% - 1.5rem)); + height: 80px; + box-sizing: border-box; z-index: 100; + display: grid; - padding: 0.75em 1.5em; - gap: 1.5em; - box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37); - grid-template-columns: 25% 1fr 25%; - @include glass-effect($blur: 12px, $bg-color: rgba(18, 18, 18, 0.85)); - // 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; + // Equal side columns keep the transport truly centred + grid-template-columns: minmax(0, 1fr) minmax(0, 540px) minmax(0, 1fr); align-items: center; + gap: 1.5rem; + padding: 0 0.75rem 0 1rem; - @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 - } - } + color: white; + background: rgb(18 18 24 / 0.92); + backdrop-filter: blur(16px); + -webkit-backdrop-filter: blur(16px); + border: 1px solid rgb(255 255 255 / 0.08); + border-radius: 14px; + box-shadow: 0 12px 40px rgb(0 0 0 / 0.45); - #waveform { - width: 100%; - transform: scaleY(0); - transition: transform $transition-time-default; - &[data-show="true"] { - transform: scaleY(1) !important; - } - } - &-controls { + &-info { display: flex; align-items: center; - justify-content: center; - gap: 0.5em; - padding: 0.5em 0; - flex-flow: column; - } - &-info { - display: grid; - gap: 1em; - grid-template-columns: minmax(0, $image-size) minmax(0, 1fr); - width: fit-content; - align-items: center; - flex-grow: 1; - width: 100%; - overflow: hidden; + gap: 0.75rem; + min-width: 0; + + > .MuiIconButton-root { + flex-shrink: 0; + color: rgb(255 255 255 / 0.75); + .material-symbols-rounded { + font-size: 1.25rem; + } + } &-text { display: flex; flex-direction: column; - overflow: hidden; min-width: 0; } + + &-title { + all: unset; + cursor: pointer; + font-weight: 600 !important; + line-height: 1.25 !important; + // Wrap long titles onto a second line before truncating + display: -webkit-box; + -webkit-box-orient: vertical; + -webkit-line-clamp: 2; + overflow: hidden; + overflow-wrap: anywhere; + + &:hover, + &:focus-visible { + text-decoration: underline; + } + } + + &-artist { + opacity: 0.6; + + a { + color: inherit; + text-decoration: none; + &:hover { + text-decoration: underline; + } + } + } } + &-image { - width: $image-size; - aspect-ratio: 1; + position: absolute; + inset: 0; + width: 100%; + height: 100%; object-fit: cover; z-index: 1; - flex-shrink: 0; - flex-grow: 1; - - position: relative; + &-container { - border-radius: $border-radius_04; + all: unset; position: relative; + flex-shrink: 0; + width: $art-size; + height: $art-size; + border-radius: 8px; overflow: hidden; - height: fit-content; - aspect-ratio: 1; - background: rgb(255 255 255 / 0.1); + cursor: pointer; + background: rgb(255 255 255 / 0.08); + + &:hover .audio-player-image-expand, + &:focus-visible .audio-player-image-expand { + opacity: 1; + } } - &-icon { + + &-icon, + &-expand { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); - font-size: 2em !important; - z-index: 0; + } + + &-icon { + font-size: 1.5rem !important; + opacity: 0.5; + } + + // "Open player" affordance shown over the art on hover + &-expand { + z-index: 2; + inset: 0; + transform: none; + display: flex; + align-items: center; + justify-content: center; + background: rgb(0 0 0 / 0.5); + opacity: 0; + transition: opacity 0.15s ease; } } - &-track { - grid-template-columns: $image-size 60% 0.5fr 0.5fr !important; - } - &-playlist{ - background: $clr-background-dark !important; - border: 1.2px solid rgb(255 255 255 / 0.2); + + // Transport on top, compact seek row underneath + &-center { display: flex; flex-direction: column; - gap: 1em; - // Magic scrollbar - &::-webkit-scrollbar { - &-thumb { - height: 150px; - max-height: 33%; - } - &-track { - margin-top: 20px; - margin-bottom: 20px; - background: transparent !important; + align-items: center; + gap: 2px; + min-width: 0; + + .player-controls { + gap: 0.5rem !important; + + .MuiFab-root { + width: 36px; + height: 36px; + min-height: 36px; + box-shadow: none; + + .material-symbols-rounded { + font-size: 1.6rem !important; + } } } - - &-track{ - display: grid; - gap: 1em; - grid-template-columns: 4em 1fr 4em; - cursor: pointer; - &.active{ - color: $clr-accent-default; - } - &-image{ - background: rgb(255 255 255 / 0.1); - border: 1.2px solid rgb(255 255 255 / 0.1); - overflow: hidden; - border-radius:5px; - width: 100%; - aspect-ratio: 1; - height: 4em; + } + + &-progress { + gap: 0.6rem !important; + + .MuiTypography-root { + min-width: 2.75em !important; + font-size: 0.7rem; + opacity: 0.6 !important; + } + + .MuiSlider-root { + padding: 8px 0; + } + .MuiSlider-thumb { + width: 10px; + height: 10px; + opacity: 0; + transition: opacity 0.15s ease; + } + &:hover .MuiSlider-thumb, + .MuiSlider-root.Mui-active .MuiSlider-thumb { + opacity: 1; + } + } + + &-actions { + display: flex; + align-items: center; + justify-content: flex-end; + gap: 0.25rem; + min-width: 0; + + .MuiIconButton-root { + color: rgb(255 255 255 / 0.75); + &:hover { + color: white; } } - + } + + &-volume { + display: flex; + align-items: center; + min-width: 0; + + // Secondary control: neutral and compact + .MuiSlider-root { + width: 5.5rem !important; + color: rgb(255 255 255 / 0.85); + } + } + + @media (max-width: 900px) { + .audio-player-volume, + .audio-player-progress .MuiTypography-root { + display: none; + } + } + + @media (max-width: 640px) { + grid-template-columns: minmax(0, 1fr) auto auto; + gap: 0.5rem; + bottom: 0.5rem; + width: calc(100% - 1rem); + height: 64px; + + .audio-player-center .player-controls > :not(:has(.MuiFab-root)), + .audio-player-progress { + display: none; + } + .audio-player-actions > :not(:last-child) { + display: none; + } } } diff --git a/src/components/playback/audioPlayer/components/LyricsPanel.tsx b/src/components/playback/audioPlayer/components/LyricsPanel.tsx index acf725a..51eef32 100644 --- a/src/components/playback/audioPlayer/components/LyricsPanel.tsx +++ b/src/components/playback/audioPlayer/components/LyricsPanel.tsx @@ -2,20 +2,15 @@ import type { Api } from "@jellyfin/sdk"; import type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client"; import { getLyricApi } from "@jellyfin/sdk/lib/utils/api/lyric-api"; import { Typography } from "@mui/material"; -import { useQuery } from "@tanstack/react-query"; -import React, { useEffect, useRef, useState } from "react"; +import { queryOptions, useQuery } from "@tanstack/react-query"; +import React, { useEffect, useRef } 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(null); - - const lyrics = useQuery({ +export const getLyricsQueryOptions = ( + item: BaseItemDto | undefined | null, + api: Api | undefined, +) => + queryOptions({ queryKey: ["player", "audio", item?.Id, "lyrics"], queryFn: async () => { if (!item?.Id || !api) { @@ -23,17 +18,30 @@ const LyricsPanel = ({ item, api, currentTime }: LyricsPanelProps) => { } try { const response = await getLyricApi(api).getLyrics({ - itemId: item?.Id, + itemId: item.Id, }); return response.data; - } catch (e) { - console.error("Failed to fetch lyrics", e); + } catch { + // Items without lyrics return 404 return null; } }, enabled: Boolean(item?.Id) && Boolean(api), }); +interface LyricsPanelProps { + item: BaseItemDto | undefined | null; + api: Api | undefined; + currentTime: number; + /** Seeks playback to a position in ticks; enables clicking synced lines. */ + onSeek?: (ticks: number) => void; +} + +const LyricsPanel = ({ item, api, currentTime, onSeek }: LyricsPanelProps) => { + const lyricsContainer = useRef(null); + + const lyrics = useQuery(getLyricsQueryOptions(item, api)); + useEffect(() => { if (lyrics.data && lyricsContainer.current) { const currentLyric = lyricsContainer.current.querySelector( @@ -78,6 +86,11 @@ const LyricsPanel = ({ item, api, currentTime }: LyricsPanelProps) => { (lyrics.data?.Lyrics?.[index + 1]?.Start ?? Number.POSITIVE_INFINITY); + const canSeek = hasSyncedLyrics && onSeek && lyric.Start != null; + const seek = () => { + if (canSeek) onSeek(lyric.Start ?? 0); + }; + return ( { className={`audio-lyrics-line ${isActive ? "active" : ""}`} key={`${lyric.Text}-${index}`} data-active-lyric={isActive} + {...(canSeek && { + role: "button", + tabIndex: 0, + "data-seekable": true, + onClick: seek, + onKeyDown: (e: React.KeyboardEvent) => { + if (e.key === "Enter" || e.key === " ") { + e.preventDefault(); + seek(); + } + }, + })} > {lyric.Text} diff --git a/src/components/playback/audioPlayer/components/PlayerActions.tsx b/src/components/playback/audioPlayer/components/PlayerActions.tsx index 364d2fe..b05d3bd 100644 --- a/src/components/playback/audioPlayer/components/PlayerActions.tsx +++ b/src/components/playback/audioPlayer/components/PlayerActions.tsx @@ -1,35 +1,31 @@ import IconButton from "@mui/material/IconButton"; -import type { ReactNode } from "react"; -import React from "react"; +import Tooltip from "@mui/material/Tooltip"; +import React, { type ReactNode } from "react"; import QueueButton from "@/components/buttons/queueButton"; interface PlayerActionsProps { - onNavigate: () => void; + /** Opens the full-screen player. */ + onExpand: () => void; onClose: () => void; + /** Volume control, rendered between the queue and expand buttons. */ children?: ReactNode; } -const PlayerActions = ({ - onNavigate, - onClose, - children, -}: PlayerActionsProps) => { +const PlayerActions = ({ onExpand, onClose, children }: PlayerActionsProps) => { return ( -
- - info - +
- {children} - -
close
-
+
{children}
+ + + open_in_full + + + + + close + +
); }; diff --git a/src/components/playback/audioPlayer/components/PlayerControls.tsx b/src/components/playback/audioPlayer/components/PlayerControls.tsx index 35018ba..9ae72df 100644 --- a/src/components/playback/audioPlayer/components/PlayerControls.tsx +++ b/src/components/playback/audioPlayer/components/PlayerControls.tsx @@ -20,7 +20,10 @@ const PlayerControls = ({ onForward, }: PlayerControlsProps) => { return ( -
+
{onRewind && ( diff --git a/src/components/playback/audioPlayer/components/PlayerInfo.tsx b/src/components/playback/audioPlayer/components/PlayerInfo.tsx index 714169d..b881a4b 100644 --- a/src/components/playback/audioPlayer/components/PlayerInfo.tsx +++ b/src/components/playback/audioPlayer/components/PlayerInfo.tsx @@ -1,58 +1,97 @@ import type { Api } from "@jellyfin/sdk"; import type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client"; import Typography from "@mui/material/Typography"; +import { useQuery } from "@tanstack/react-query"; +import { Link } from "@tanstack/react-router"; import React from "react"; +import LikeButton from "@/components/buttons/likeButton"; import getImageUrlsApi from "@/utils/methods/getImageUrlsApi"; +import { getItemQueryOptions } from "@/utils/queries/items"; +import { useCentralStore } from "@/utils/store/central"; interface PlayerInfoProps { item: BaseItemDto | undefined | null; api: Api | undefined; - trackName?: string; + /** Opens the full-screen player. */ + onOpen: () => void; } -const PlayerInfo = ({ item, api, trackName }: PlayerInfoProps) => { +const PlayerInfo = ({ item, api, onOpen }: PlayerInfoProps) => { + const user = useCentralStore((s) => s.currentUser); + // Fresh user data so the like button reflects changes immediately. + const itemDetails = useQuery({ + ...getItemQueryOptions(item?.Id ?? "", api, user?.Id), + enabled: Boolean(item?.Id && api && user?.Id), + }); + if (!api || !item) return null; + const artists = item.ArtistItems?.length + ? item.ArtistItems + : (item.AlbumArtists ?? []); + return (
-
- {trackName +
+ + + expand_less + +
- {item?.Name} + {item.Name} - by {item?.Artists?.map((artist) => artist).join(",")} + {artists.map((artist, index) => ( + + {index > 0 && ", "} + {artist.Id ? ( + + {artist.Name} + + ) : ( + artist.Name + )} + + ))}
+
); }; diff --git a/src/components/playback/audioPlayer/components/PlayerProgress.tsx b/src/components/playback/audioPlayer/components/PlayerProgress.tsx index 11aedd0..a29b2a5 100644 --- a/src/components/playback/audioPlayer/components/PlayerProgress.tsx +++ b/src/components/playback/audioPlayer/components/PlayerProgress.tsx @@ -8,6 +8,12 @@ interface PlayerProgressProps { duration: number; onSeek?: (value: number) => void; onSeekCommit: (value: number) => void; + /** + * "inline" puts the times beside the bar, "stacked" puts them underneath, + * "bare" renders only the slider. + */ + layout?: "inline" | "stacked" | "bare"; + className?: string; } const PlayerProgress = ({ @@ -15,6 +21,8 @@ const PlayerProgress = ({ duration, onSeek, onSeekCommit, + layout = "inline", + className, }: PlayerProgressProps) => { const [isScrubbing, setIsScrubbing] = useState(false); const [sliderValue, setSliderValue] = useState(progress); @@ -38,8 +46,44 @@ const PlayerProgress = ({ onSeekCommit(newValue); }; + if (layout === "bare") { + return ( + + ); + } + + if (layout === "stacked") { + return ( +
+ +
+ {getRuntimeMusic(sliderValue)} + -{getRuntimeMusic(Math.max(duration - sliderValue, 0))} +
+
+ ); + } + return (
theme.zIndex.tooltip, lineHeight: 1.2, - fontSize: 24, - background: "rgb(0 0 0 / 0.5)", - backdropFilter: "blur(5px)", - padding: 1, - borderRadius: "10px", + fontSize: "0.75rem", + fontWeight: 600, + fontVariantNumeric: "tabular-nums", + minWidth: "2.25em", + background: "rgb(0 0 0 / 0.75)", + padding: "2px 6px", + borderRadius: "6px", border: "1px solid rgb(255 255 255 / 0.15)", - boxShadow: "0 0 10px rgb(0 0 0 / 0.4) ", - transform: "translatey(-120%) scale(0)", + boxShadow: "0 2px 8px rgb(0 0 0 / 0.4)", + top: -6, + transform: "translatey(-100%) scale(0)", "&:before": { display: "none", }, "&.MuiSlider-valueLabelOpen": { - transform: "translateY(-120%) scale(1)", + transform: "translateY(-100%) scale(1)", }, "& > *": { transform: "rotate(0deg)", diff --git a/src/components/playback/audioPlayer/components/QueuePanel.tsx b/src/components/playback/audioPlayer/components/QueuePanel.tsx deleted file mode 100644 index ceb9a00..0000000 --- a/src/components/playback/audioPlayer/components/QueuePanel.tsx +++ /dev/null @@ -1,302 +0,0 @@ -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 ( -
- -
- ); -} - -const QueuePanel = ({ queue, currentTrackIndex }: QueuePanelProps) => { - const [activeId, setActiveId] = useState(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); - const open = Boolean(anchorEl); - const handleClick = (event: React.MouseEvent) => { - setAnchorEl(event.currentTarget); - }; - const handleClose = () => { - setAnchorEl(null); - }; - - const handleClearQueue = () => { - stopPlayback(); - clearQueue(); - handleClose(); - }; - - return ( - -
- - - Queue - - - - shuffleUpcoming()} size="small"> - shuffle - - - - more_vert - - - - - - clear_all - - Clear Queue - - - - - track.Id ?? "")} - strategy={verticalListSortingStrategy} - > -
- {queue.map((track, index) => ( - removeFromQueue(index)} - isActive={currentTrackIndex === index} - /> - ))} -
-
- - - {activeItem ? ( - {}} // 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} - -
-
- ); -}; - -export default React.memo(QueuePanel); diff --git a/src/components/playback/audioPlayer/components/StatsPanel.tsx b/src/components/playback/audioPlayer/components/StatsPanel.tsx index ed74e22..dbc90b2 100644 --- a/src/components/playback/audioPlayer/components/StatsPanel.tsx +++ b/src/components/playback/audioPlayer/components/StatsPanel.tsx @@ -4,7 +4,7 @@ import React, { useEffect, useState } from "react"; interface StatsPanelProps { item: BaseItemDto | undefined | null; - audioRef: React.RefObject | null; + audioRef: React.RefObject | null; } const StatRow = ({ diff --git a/src/components/playback/audioPlayer/index.tsx b/src/components/playback/audioPlayer/index.tsx index a368f8f..d906ca7 100644 --- a/src/components/playback/audioPlayer/index.tsx +++ b/src/components/playback/audioPlayer/index.tsx @@ -12,7 +12,7 @@ import { } from "@/utils/store/audioPlayback"; import { useCentralStore } from "@/utils/store/central"; import { playItemFromQueue } from "@/utils/store/playback"; -import useQueue from "@/utils/store/queue"; +import useQueue, { getNextTrackIndex } from "@/utils/store/queue"; import PlayerActions from "./components/PlayerActions"; import PlayerControls from "./components/PlayerControls"; import PlayerInfo from "./components/PlayerInfo"; @@ -26,7 +26,7 @@ const AudioPlayer = () => { const user = useCentralStore((s) => s.currentUser); const navigate = useNavigate(); const location = useLocation(); - + const audioRef = useRef(null); const [url, display, item, volume, isMuted] = useAudioPlayback((state) => [ state.url, @@ -35,15 +35,15 @@ const AudioPlayer = () => { state.player.volume, state.player.isMuted, ]); - + const [tracks, currentTrack] = useQueue((state) => [ state.tracks, state.currentItemIndex, ]); - + const [playing, setPlaying] = useState(false); const [progress, setProgress] = useState(0); - + // Sync volume and ref useEffect(() => { if (display) { @@ -54,14 +54,14 @@ const AudioPlayer = () => { } } }, [display, url, tracks?.[currentTrack]?.Id]); - + // Update volume when state changes useEffect(() => { if (audioRef.current) { audioRef.current.volume = isMuted ? 0 : volume; } }, [volume, isMuted]); - + // Media Session Metadata useEffect(() => { if ("mediaSession" in navigator && item) { @@ -88,7 +88,7 @@ const AudioPlayer = () => { }); } }, [item, api]); - + // Media Session Action Handlers useEffect(() => { if ("mediaSession" in navigator) { @@ -104,8 +104,9 @@ const AudioPlayer = () => { } }); navigator.mediaSession.setActionHandler("nexttrack", () => { - if (user?.Id && api) { - playItemFromQueue("next", user.Id, api); + const nextIndex = getNextTrackIndex(); + if (nextIndex !== undefined && user?.Id && api) { + playItemFromQueue(nextIndex, user.Id, api); } }); navigator.mediaSession.setActionHandler("seekto", (details) => { @@ -115,7 +116,7 @@ const AudioPlayer = () => { }); } }, [api, user?.Id]); - + const updatePositionState = () => { if ( "mediaSession" in navigator && @@ -133,7 +134,7 @@ const AudioPlayer = () => { } } }; - + const handlePlayPause = () => { if (audioRef.current) { if (audioRef.current.paused) { @@ -145,41 +146,47 @@ const AudioPlayer = () => { } } }; - + const handleTimeUpdate = (e: SyntheticEvent) => { setProgress(secToTicks(e.currentTarget.currentTime)); }; - + const handleEnded = () => { + if (useQueue.getState().repeatMode === "one" && audioRef.current) { + audioRef.current.currentTime = 0; + audioRef.current.play(); + return; + } setPlaying(false); - if (tracks?.[currentTrack + 1]?.Id && api && user?.Id) { - playItemFromQueue("next", user.Id, api); + const nextIndex = getNextTrackIndex(); + if (nextIndex !== undefined && api && user?.Id) { + playItemFromQueue(nextIndex, user.Id, api); } }; - + const handleSeekCommit = (value: number) => { if (audioRef.current) { audioRef.current.currentTime = ticksToSec(value); setProgress(value); } }; - + const handleVolumeChange = (newVolume: number) => { setVolume(newVolume); }; - + const handleMuteToggle = () => { setIsMuted(!isMuted); }; - + const handleClose = () => { useAudioPlayback.setState(useAudioPlayback.getInitialState()); }; - + const handleNavigate = () => { navigate({ to: "/player/audio" }); }; - + // Listen to play/pause events directly from audio element to keep state in sync // (e.g. if paused by media keys) const onPlay = () => { @@ -196,7 +203,7 @@ const AudioPlayer = () => { navigator.mediaSession.playbackState = "paused"; } }; - + return ( {display && ( @@ -210,13 +217,9 @@ const AudioPlayer = () => { }} exit={{ transform: "translate(-50%, 150%)" }} transition={{ duration: 0.3, ease: "circOut" }} - className="audio-player glass" + className="audio-player" > - +