feat: unify remote control into a Spotify-like media bar
Continuous Integration / build_web (push) Failing after 0s
Continuous Integration / build (macos-latest) (push) Skipped
Continuous Integration / build (ubuntu-22.04) (push) Skipped
Continuous Integration / build (windows-11-arm) (push) Skipped
Continuous Integration / build (windows-latest) (push) Skipped
Continuous Integration / nightly_release (push) Skipped
Continuous Integration / build_web (push) Failing after 0s
Continuous Integration / build (macos-latest) (push) Skipped
Continuous Integration / build (ubuntu-22.04) (push) Skipped
Continuous Integration / build (windows-11-arm) (push) Skipped
Continuous Integration / build (windows-latest) (push) Skipped
Continuous Integration / nightly_release (push) Skipped
- one bottom bar for local playback and remote devices, replacing the separate remote strip - minimal layout from the reference: cover/title/more, transport, seek times, queue/devices/volume/expand; extra actions in the overflow and device menus - selecting a device transfers playback (local<->remote) with position/queue - remote mode drives the session via playstate commands; local keeps shuffle/repeat/volume/queue
This commit is contained in:
1 parent
ffdedc7b9b
commit
a1af85dd72
6 files changed
+784
-279
No files matched your search
@@ -226,3 +226,201 @@ $art-size: 48px;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Unified, minimal media bar (local playback + remote device control). */
|
||||||
|
.audio-player {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
width: min(1440px, calc(100% - 1.5rem));
|
||||||
|
height: 84px;
|
||||||
|
gap: 1.25rem;
|
||||||
|
padding: 0 4.5rem 0 0.9rem; // keep the last controls clear of the palm easter egg
|
||||||
|
background: #0b0c12;
|
||||||
|
border: 1px solid rgb(255 255 255 / 0.08);
|
||||||
|
border-radius: 16px;
|
||||||
|
|
||||||
|
.media-bar {
|
||||||
|
&-left {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.75rem;
|
||||||
|
width: 30%;
|
||||||
|
min-width: 220px;
|
||||||
|
max-width: 360px;
|
||||||
|
}
|
||||||
|
|
||||||
|
&-cover {
|
||||||
|
width: 52px;
|
||||||
|
height: 52px;
|
||||||
|
flex: 0 0 52px;
|
||||||
|
padding: 0;
|
||||||
|
border: 0;
|
||||||
|
border-radius: 6px;
|
||||||
|
overflow: hidden;
|
||||||
|
background: rgb(255 255 255 / 0.06);
|
||||||
|
color: rgb(255 255 255 / 0.5);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
|
img {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
object-fit: cover;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&-info {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
min-width: 0;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
&-title {
|
||||||
|
font-weight: 600 !important;
|
||||||
|
line-height: 1.2 !important;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
cursor: pointer;
|
||||||
|
&:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&-subtitle {
|
||||||
|
opacity: 0.55;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
|
&-more {
|
||||||
|
flex-shrink: 0;
|
||||||
|
color: rgb(255 255 255 / 0.6);
|
||||||
|
}
|
||||||
|
|
||||||
|
&-center {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 1.25rem;
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
&-controls {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.15rem;
|
||||||
|
flex-shrink: 0;
|
||||||
|
|
||||||
|
.MuiIconButton-root {
|
||||||
|
color: rgb(255 255 255 / 0.7);
|
||||||
|
transition: color 0.15s ease, transform 0.15s ease;
|
||||||
|
&:hover {
|
||||||
|
color: #fff;
|
||||||
|
background: rgb(255 255 255 / 0.06);
|
||||||
|
}
|
||||||
|
&.active {
|
||||||
|
color: #7cc7ff;
|
||||||
|
}
|
||||||
|
.material-symbols-rounded {
|
||||||
|
font-size: 1.25rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&-play {
|
||||||
|
width: 42px !important;
|
||||||
|
height: 42px !important;
|
||||||
|
margin: 0 0.35rem;
|
||||||
|
border: 1px solid rgb(255 255 255 / 0.35);
|
||||||
|
color: #fff !important;
|
||||||
|
.material-symbols-rounded {
|
||||||
|
font-size: 1.6rem !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&-progress {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 140px;
|
||||||
|
|
||||||
|
.MuiSlider-root {
|
||||||
|
padding: 10px 0;
|
||||||
|
color: #7cc7ff;
|
||||||
|
}
|
||||||
|
.MuiSlider-rail {
|
||||||
|
background: rgb(255 255 255 / 0.16);
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
.MuiSlider-track {
|
||||||
|
border: 0;
|
||||||
|
}
|
||||||
|
.MuiSlider-thumb {
|
||||||
|
width: 12px;
|
||||||
|
height: 12px;
|
||||||
|
background: #fff;
|
||||||
|
box-shadow: none;
|
||||||
|
&:hover,
|
||||||
|
&.Mui-focusVisible {
|
||||||
|
box-shadow: 0 0 0 6px rgb(124 199 255 / 0.16);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.MuiTypography-root {
|
||||||
|
opacity: 0.55;
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
font-weight: 400;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&-right {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.1rem;
|
||||||
|
flex-shrink: 0;
|
||||||
|
|
||||||
|
.MuiIconButton-root {
|
||||||
|
color: rgb(255 255 255 / 0.65);
|
||||||
|
&:hover {
|
||||||
|
color: #fff;
|
||||||
|
background: rgb(255 255 255 / 0.06);
|
||||||
|
}
|
||||||
|
.material-symbols-rounded {
|
||||||
|
font-size: 1.3rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&-volume {
|
||||||
|
width: 84px !important;
|
||||||
|
margin: 0 0.35rem 0 0 !important;
|
||||||
|
color: #7cc7ff !important;
|
||||||
|
|
||||||
|
.MuiSlider-rail {
|
||||||
|
background: rgb(255 255 255 / 0.16);
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
.MuiSlider-thumb {
|
||||||
|
width: 10px;
|
||||||
|
height: 10px;
|
||||||
|
background: #fff;
|
||||||
|
box-shadow: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 900px) {
|
||||||
|
.audio-player {
|
||||||
|
.media-bar-left {
|
||||||
|
min-width: 160px;
|
||||||
|
}
|
||||||
|
.media-bar-volume,
|
||||||
|
.media-bar-right .MuiSlider-root {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,118 @@
|
|||||||
|
import type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client";
|
||||||
|
import type { SessionInfoDto } from "@jellyfin/sdk/lib/generated-client";
|
||||||
|
import {
|
||||||
|
Divider,
|
||||||
|
IconButton,
|
||||||
|
ListItemIcon,
|
||||||
|
ListItemText,
|
||||||
|
Menu,
|
||||||
|
MenuItem,
|
||||||
|
Tooltip,
|
||||||
|
} from "@mui/material";
|
||||||
|
import React, { useState } from "react";
|
||||||
|
|
||||||
|
type DeviceMenuProps = {
|
||||||
|
sessions: SessionInfoDto[];
|
||||||
|
activeRemoteId: string | null;
|
||||||
|
localActive: boolean;
|
||||||
|
localItem?: BaseItemDto | null;
|
||||||
|
onSelectLocal: () => void;
|
||||||
|
onSelectRemote: (session: SessionInfoDto) => void;
|
||||||
|
onOpenRemoteControl: () => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
const DeviceMenu = ({
|
||||||
|
sessions,
|
||||||
|
activeRemoteId,
|
||||||
|
localActive,
|
||||||
|
localItem,
|
||||||
|
onSelectLocal,
|
||||||
|
onSelectRemote,
|
||||||
|
onOpenRemoteControl,
|
||||||
|
}: DeviceMenuProps) => {
|
||||||
|
const [anchor, setAnchor] = useState<HTMLElement | null>(null);
|
||||||
|
|
||||||
|
const handleClose = () => setAnchor(null);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Tooltip title="Devices">
|
||||||
|
<IconButton
|
||||||
|
aria-label="Devices"
|
||||||
|
onClick={(event) => setAnchor(event.currentTarget)}
|
||||||
|
>
|
||||||
|
<span className="material-symbols-rounded">devices</span>
|
||||||
|
</IconButton>
|
||||||
|
</Tooltip>
|
||||||
|
<Menu
|
||||||
|
anchorEl={anchor}
|
||||||
|
open={Boolean(anchor)}
|
||||||
|
onClose={handleClose}
|
||||||
|
slotProps={{ paper: { className: "glass-menu-paper" } }}
|
||||||
|
>
|
||||||
|
<MenuItem
|
||||||
|
selected={!activeRemoteId}
|
||||||
|
onClick={() => {
|
||||||
|
handleClose();
|
||||||
|
onSelectLocal();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<ListItemIcon>
|
||||||
|
<span className="material-symbols-rounded">computer</span>
|
||||||
|
</ListItemIcon>
|
||||||
|
<ListItemText
|
||||||
|
primary="This device"
|
||||||
|
secondary={
|
||||||
|
localActive ? (localItem?.Name ?? "Playing") : "Idle"
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</MenuItem>
|
||||||
|
<Divider />
|
||||||
|
{sessions.length === 0 ? (
|
||||||
|
<MenuItem disabled>
|
||||||
|
<ListItemText primary="No other devices are online" />
|
||||||
|
</MenuItem>
|
||||||
|
) : (
|
||||||
|
sessions.map((session) => (
|
||||||
|
<MenuItem
|
||||||
|
key={session.Id}
|
||||||
|
selected={session.Id === activeRemoteId}
|
||||||
|
onClick={() => {
|
||||||
|
handleClose();
|
||||||
|
onSelectRemote(session);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<ListItemIcon>
|
||||||
|
<span className="material-symbols-rounded">
|
||||||
|
{session.NowPlayingItem ? "tv" : "devices_other"}
|
||||||
|
</span>
|
||||||
|
</ListItemIcon>
|
||||||
|
<ListItemText
|
||||||
|
primary={session.DeviceName || session.Client || "Device"}
|
||||||
|
secondary={
|
||||||
|
session.NowPlayingItem?.Name ??
|
||||||
|
session.Client ??
|
||||||
|
"Not playing"
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</MenuItem>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
<Divider />
|
||||||
|
<MenuItem
|
||||||
|
onClick={() => {
|
||||||
|
handleClose();
|
||||||
|
onOpenRemoteControl();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<ListItemIcon>
|
||||||
|
<span className="material-symbols-rounded">settings_remote</span>
|
||||||
|
</ListItemIcon>
|
||||||
|
<ListItemText primary="Remote control…" />
|
||||||
|
</MenuItem>
|
||||||
|
</Menu>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default DeviceMenu;
|
||||||
@@ -1,23 +1,46 @@
|
|||||||
|
import type {
|
||||||
|
BaseItemDto,
|
||||||
|
SessionInfoDto,
|
||||||
|
} from "@jellyfin/sdk/lib/generated-client";
|
||||||
|
import { PlaystateCommand } from "@jellyfin/sdk/lib/generated-client";
|
||||||
|
import { getSessionApi } from "@jellyfin/sdk/lib/utils/api/session-api";
|
||||||
|
import Divider from "@mui/material/Divider";
|
||||||
|
import IconButton from "@mui/material/IconButton";
|
||||||
|
import ListItemIcon from "@mui/material/ListItemIcon";
|
||||||
|
import ListItemText from "@mui/material/ListItemText";
|
||||||
|
import Menu from "@mui/material/Menu";
|
||||||
|
import MenuItem from "@mui/material/MenuItem";
|
||||||
|
import Slider from "@mui/material/Slider";
|
||||||
|
import Tooltip from "@mui/material/Tooltip";
|
||||||
|
import Typography from "@mui/material/Typography";
|
||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import { useLocation, useNavigate } from "@tanstack/react-router";
|
import { useLocation, useNavigate } from "@tanstack/react-router";
|
||||||
import { AnimatePresence, motion } from "motion/react";
|
import { AnimatePresence, motion } from "motion/react";
|
||||||
|
import { useSnackbar } from "notistack";
|
||||||
import React, { type SyntheticEvent, useEffect, useRef, useState } from "react";
|
import React, { type SyntheticEvent, useEffect, useRef, useState } from "react";
|
||||||
|
import QueueButton from "@/components/buttons/queueButton";
|
||||||
import { secToTicks, ticksToSec } from "@/utils/date/time";
|
import { secToTicks, ticksToSec } from "@/utils/date/time";
|
||||||
import getImageUrlsApi from "@/utils/methods/getImageUrlsApi";
|
import getImageUrlsApi from "@/utils/methods/getImageUrlsApi";
|
||||||
|
import { startInstantMix } from "@/utils/methods/instantMix";
|
||||||
|
import { transferSessionToLocal } from "@/utils/methods/transferPlayback";
|
||||||
import { useApiInContext } from "@/utils/store/api";
|
import { useApiInContext } from "@/utils/store/api";
|
||||||
import {
|
import {
|
||||||
setAudioRef,
|
setAudioRef,
|
||||||
setIsMuted,
|
setIsMuted,
|
||||||
setVolume,
|
setVolume,
|
||||||
|
stopPlayback,
|
||||||
useAudioPlayback,
|
useAudioPlayback,
|
||||||
} from "@/utils/store/audioPlayback";
|
} 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 useQueue, { getNextTrackIndex } from "@/utils/store/queue";
|
import useQueue, {
|
||||||
import PlayerActions from "./components/PlayerActions";
|
cycleRepeatMode,
|
||||||
import PlayerControls from "./components/PlayerControls";
|
getNextTrackIndex,
|
||||||
import PlayerInfo from "./components/PlayerInfo";
|
shuffleUpcoming,
|
||||||
|
} from "@/utils/store/queue";
|
||||||
|
import useRemoteControlStore from "@/utils/store/remoteControl";
|
||||||
|
import DeviceMenu from "./components/DeviceMenu";
|
||||||
import PlayerProgress from "./components/PlayerProgress";
|
import PlayerProgress from "./components/PlayerProgress";
|
||||||
import PlayerVolume from "./components/PlayerVolume";
|
|
||||||
|
|
||||||
import "./audioPlayer.scss";
|
import "./audioPlayer.scss";
|
||||||
|
|
||||||
@@ -26,6 +49,8 @@ const AudioPlayer = () => {
|
|||||||
const user = useCentralStore((s) => s.currentUser);
|
const user = useCentralStore((s) => s.currentUser);
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
|
const { enqueueSnackbar } = useSnackbar();
|
||||||
|
const openRemoteDialog = useRemoteControlStore((s) => s.openDialog);
|
||||||
|
|
||||||
const audioRef = useRef<HTMLAudioElement | null>(null);
|
const audioRef = useRef<HTMLAudioElement | null>(null);
|
||||||
const [url, display, item, volume, isMuted, startTimeTicks] =
|
const [url, display, item, volume, isMuted, startTimeTicks] =
|
||||||
@@ -42,33 +67,99 @@ const AudioPlayer = () => {
|
|||||||
seekAppliedRef.current = false;
|
seekAppliedRef.current = false;
|
||||||
}, [item?.Id]);
|
}, [item?.Id]);
|
||||||
|
|
||||||
const [tracks, currentTrack] = useQueue((state) => [
|
const [tracks, currentTrack, repeatMode] = useQueue((state) => [
|
||||||
state.tracks,
|
state.tracks,
|
||||||
state.currentItemIndex,
|
state.currentItemIndex,
|
||||||
|
state.repeatMode,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const [playing, setPlaying] = useState(false);
|
const [playing, setPlaying] = useState(false);
|
||||||
const [progress, setProgress] = useState(0);
|
const [progress, setProgress] = useState(0);
|
||||||
|
const [selectedRemoteId, setSelectedRemoteId] = useState<string | null>(null);
|
||||||
|
const [moreAnchor, setMoreAnchor] = useState<HTMLElement | null>(null);
|
||||||
|
|
||||||
// Sync volume and ref
|
const sessions = useQuery({
|
||||||
|
queryKey: ["remoteSessions"],
|
||||||
|
queryFn: async () => {
|
||||||
|
if (!api || !user?.Id) return [];
|
||||||
|
const result = await getSessionApi(api).getSessions();
|
||||||
|
return result.data;
|
||||||
|
},
|
||||||
|
enabled: !!api && !!user?.Id,
|
||||||
|
refetchInterval: 3000,
|
||||||
|
networkMode: "always",
|
||||||
|
});
|
||||||
|
|
||||||
|
const remoteSessions = (sessions.data ?? []).filter(
|
||||||
|
(session: SessionInfoDto) =>
|
||||||
|
session.Id &&
|
||||||
|
session.DeviceId !== api?.deviceInfo.id &&
|
||||||
|
session.UserId === user?.Id,
|
||||||
|
);
|
||||||
|
const playingRemote = remoteSessions.find(
|
||||||
|
(session: SessionInfoDto) => session.NowPlayingItem,
|
||||||
|
);
|
||||||
|
const selectedRemote = selectedRemoteId
|
||||||
|
? remoteSessions.find(
|
||||||
|
(session: SessionInfoDto) => session.Id === selectedRemoteId,
|
||||||
|
)
|
||||||
|
: undefined;
|
||||||
|
// Local playback takes precedence unless a remote device was selected.
|
||||||
|
const remote = selectedRemote?.NowPlayingItem
|
||||||
|
? selectedRemote
|
||||||
|
: !display
|
||||||
|
? playingRemote
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const activeItem: BaseItemDto | undefined | null =
|
||||||
|
remote?.NowPlayingItem ?? item;
|
||||||
|
const artists = activeItem?.ArtistItems?.length
|
||||||
|
? activeItem.ArtistItems
|
||||||
|
: (activeItem?.AlbumArtists ?? []);
|
||||||
|
const artistNames = artists.map((artist) => artist.Name).filter(Boolean);
|
||||||
|
const subtitle = remote
|
||||||
|
? [artistNames.join(", "), remote.DeviceName || remote.Client]
|
||||||
|
.filter(Boolean)
|
||||||
|
.join(" · ")
|
||||||
|
: artistNames.join(", ") || activeItem?.Album || "";
|
||||||
|
const coverUrl =
|
||||||
|
api && activeItem?.Id
|
||||||
|
? getImageUrlsApi(api).getItemImageUrlById(
|
||||||
|
activeItem.AlbumId ?? activeItem.Id,
|
||||||
|
"Primary",
|
||||||
|
{ quality: 85, fillHeight: 120, fillWidth: 120 },
|
||||||
|
)
|
||||||
|
: undefined;
|
||||||
|
const isPlaying = remote
|
||||||
|
? !remote.PlayState?.IsPaused
|
||||||
|
: playing;
|
||||||
|
const displayProgress = remote
|
||||||
|
? (remote.PlayState?.PositionTicks ?? 0)
|
||||||
|
: progress;
|
||||||
|
const displayDuration = activeItem?.RunTimeTicks ?? 1;
|
||||||
|
const barVisible = (display && item) || Boolean(remote);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (display) setSelectedRemoteId(null);
|
||||||
|
}, [display, item?.Id]);
|
||||||
|
|
||||||
|
// Sync local audio element.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (display) {
|
if (display) {
|
||||||
setAudioRef(audioRef);
|
setAudioRef(audioRef);
|
||||||
|
|
||||||
if (audioRef.current) {
|
if (audioRef.current) {
|
||||||
audioRef.current.volume = isMuted ? 0 : volume;
|
audioRef.current.volume = isMuted ? 0 : volume;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [display, url, tracks?.[currentTrack]?.Id]);
|
}, [display, url, tracks?.[currentTrack]?.Id, isMuted, volume]);
|
||||||
|
|
||||||
// Update volume when state changes
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (audioRef.current) {
|
if (audioRef.current) {
|
||||||
audioRef.current.volume = isMuted ? 0 : volume;
|
audioRef.current.volume = isMuted ? 0 : volume;
|
||||||
}
|
}
|
||||||
}, [volume, isMuted]);
|
}, [volume, isMuted]);
|
||||||
|
|
||||||
// Media Session Metadata
|
// Media Session metadata/actions for local playback.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if ("mediaSession" in navigator && item) {
|
if ("mediaSession" in navigator && item) {
|
||||||
const imageUrl = item.ImageTags?.Primary
|
const imageUrl = item.ImageTags?.Primary
|
||||||
@@ -77,50 +168,39 @@ const AudioPlayer = () => {
|
|||||||
tag: item.ImageTags.Primary,
|
tag: item.ImageTags.Primary,
|
||||||
})
|
})
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
navigator.mediaSession.metadata = new MediaMetadata({
|
navigator.mediaSession.metadata = new MediaMetadata({
|
||||||
title: item.Name ?? "Unknown Title",
|
title: item.Name ?? "Unknown Title",
|
||||||
artist: item.Artists?.join(", ") ?? "Unknown Artist",
|
artist: item.Artists?.join(", ") ?? "Unknown Artist",
|
||||||
album: item.Album ?? "Unknown Album",
|
album: item.Album ?? "Unknown Album",
|
||||||
artwork: imageUrl
|
artwork: imageUrl
|
||||||
? [
|
? [{ src: imageUrl, sizes: "512x512", type: "image/jpeg" }]
|
||||||
{
|
|
||||||
src: imageUrl,
|
|
||||||
sizes: "512x512",
|
|
||||||
type: "image/jpeg",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
: [],
|
: [],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [item, api]);
|
}, [item, api]);
|
||||||
|
|
||||||
// Media Session Action Handlers
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if ("mediaSession" in navigator) {
|
if (!("mediaSession" in navigator)) return;
|
||||||
navigator.mediaSession.setActionHandler("play", () => {
|
navigator.mediaSession.setActionHandler("play", () => {
|
||||||
audioRef.current?.play();
|
audioRef.current?.play();
|
||||||
});
|
});
|
||||||
navigator.mediaSession.setActionHandler("pause", () => {
|
navigator.mediaSession.setActionHandler("pause", () => {
|
||||||
audioRef.current?.pause();
|
audioRef.current?.pause();
|
||||||
});
|
});
|
||||||
navigator.mediaSession.setActionHandler("previoustrack", () => {
|
navigator.mediaSession.setActionHandler("previoustrack", () => {
|
||||||
if (user?.Id && api) {
|
if (user?.Id && api) playItemFromQueue("previous", user.Id, api);
|
||||||
playItemFromQueue("previous", user.Id, api);
|
});
|
||||||
}
|
navigator.mediaSession.setActionHandler("nexttrack", () => {
|
||||||
});
|
const nextIndex = getNextTrackIndex();
|
||||||
navigator.mediaSession.setActionHandler("nexttrack", () => {
|
if (nextIndex !== undefined && user?.Id && api) {
|
||||||
const nextIndex = getNextTrackIndex();
|
playItemFromQueue(nextIndex, user.Id, api);
|
||||||
if (nextIndex !== undefined && user?.Id && api) {
|
}
|
||||||
playItemFromQueue(nextIndex, user.Id, api);
|
});
|
||||||
}
|
navigator.mediaSession.setActionHandler("seekto", (details) => {
|
||||||
});
|
if (audioRef.current && details.seekTime !== undefined) {
|
||||||
navigator.mediaSession.setActionHandler("seekto", (details) => {
|
audioRef.current.currentTime = details.seekTime;
|
||||||
if (audioRef.current && details.seekTime !== undefined) {
|
}
|
||||||
audioRef.current.currentTime = details.seekTime;
|
});
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, [api, user?.Id]);
|
}, [api, user?.Id]);
|
||||||
|
|
||||||
const updatePositionState = () => {
|
const updatePositionState = () => {
|
||||||
@@ -190,11 +270,13 @@ const AudioPlayer = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleNavigate = () => {
|
const handleNavigate = () => {
|
||||||
navigate({ to: "/player/audio" });
|
if (remote) {
|
||||||
|
openRemoteDialog(remote.NowPlayingItem);
|
||||||
|
} else {
|
||||||
|
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 = () => {
|
const onPlay = () => {
|
||||||
setPlaying(true);
|
setPlaying(true);
|
||||||
updatePositionState();
|
updatePositionState();
|
||||||
@@ -210,23 +292,339 @@ const AudioPlayer = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const remoteCommand = async (
|
||||||
|
command: PlaystateCommand,
|
||||||
|
seekPositionTicks?: number,
|
||||||
|
) => {
|
||||||
|
if (!api || !remote?.Id) return;
|
||||||
|
try {
|
||||||
|
await getSessionApi(api).sendPlaystateCommand({
|
||||||
|
sessionId: remote.Id,
|
||||||
|
command,
|
||||||
|
seekPositionTicks,
|
||||||
|
controllingUserId: user?.Id,
|
||||||
|
});
|
||||||
|
await sessions.refetch();
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Remote command failed", error);
|
||||||
|
enqueueSnackbar("Remote command failed", { variant: "error" });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const transferToLocal = async () => {
|
||||||
|
if (!api || !user?.Id || !remote) {
|
||||||
|
setSelectedRemoteId(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const kind = await transferSessionToLocal(api, user.Id, remote);
|
||||||
|
setSelectedRemoteId(null);
|
||||||
|
await sessions.refetch();
|
||||||
|
if (kind === "video") navigate({ to: "/player" });
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Transfer failed", error);
|
||||||
|
enqueueSnackbar("Could not transfer playback", { variant: "error" });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const selectRemote = async (session: SessionInfoDto) => {
|
||||||
|
if (!session.Id) return;
|
||||||
|
try {
|
||||||
|
// Moving local playback: send the queue/position to the target first.
|
||||||
|
if (display && item?.Id && api && user?.Id) {
|
||||||
|
const queue = useQueue.getState();
|
||||||
|
const ids =
|
||||||
|
queue.tracks
|
||||||
|
?.map((track) => track.Id)
|
||||||
|
.filter((id): id is string => Boolean(id)) ?? [];
|
||||||
|
await getSessionApi(api).play({
|
||||||
|
sessionId: session.Id,
|
||||||
|
playCommand: "PlayNow",
|
||||||
|
itemIds: ids.length > 0 ? ids : [item.Id],
|
||||||
|
startIndex: queue.currentItemIndex,
|
||||||
|
startPositionTicks: progress,
|
||||||
|
mediaSourceId: item.MediaSources?.[0]?.Id ?? undefined,
|
||||||
|
});
|
||||||
|
stopPlayback();
|
||||||
|
}
|
||||||
|
setSelectedRemoteId(session.Id);
|
||||||
|
await sessions.refetch();
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Could not switch device", error);
|
||||||
|
enqueueSnackbar("Could not switch device", { variant: "error" });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleNext = () => {
|
||||||
|
if (remote) remoteCommand(PlaystateCommand.NextTrack);
|
||||||
|
else if (api && user?.Id) playItemFromQueue("next", user.Id, api);
|
||||||
|
};
|
||||||
|
const handlePrevious = () => {
|
||||||
|
if (remote) remoteCommand(PlaystateCommand.PreviousTrack);
|
||||||
|
else if (api && user?.Id) playItemFromQueue("previous", user.Id, api);
|
||||||
|
};
|
||||||
|
const handleShuffle = () => shuffleUpcoming();
|
||||||
|
const handleRepeat = () => cycleRepeatMode();
|
||||||
|
const handleRemoteSeek = (ticks: number) => {
|
||||||
|
remoteCommand(PlaystateCommand.Seek, Math.round(ticks));
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleMoreOpen = (event: React.MouseEvent<HTMLElement>) =>
|
||||||
|
setMoreAnchor(event.currentTarget);
|
||||||
|
|
||||||
|
const instantMix = async () => {
|
||||||
|
setMoreAnchor(null);
|
||||||
|
if (!api || !user?.Id || !activeItem) return;
|
||||||
|
try {
|
||||||
|
const { count } = await startInstantMix(api, user.Id, activeItem);
|
||||||
|
if (count === 0) {
|
||||||
|
enqueueSnackbar("No tracks found for Instant Mix", {
|
||||||
|
variant: "warning",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
enqueueSnackbar("Could not start Instant Mix", { variant: "error" });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const openCastForLocal = () => {
|
||||||
|
setMoreAnchor(null);
|
||||||
|
if (!item) return;
|
||||||
|
openRemoteDialog({
|
||||||
|
item,
|
||||||
|
kind: "audio",
|
||||||
|
positionTicks: progress,
|
||||||
|
queue: tracks ?? [],
|
||||||
|
startIndex: currentTrack,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!barVisible || location.pathname === "/player/audio") {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AnimatePresence mode="sync">
|
<AnimatePresence mode="sync">
|
||||||
{display && (
|
<motion.div
|
||||||
<motion.div
|
initial={{ transform: "translate(-50%, 150%)" }}
|
||||||
initial={{ transform: "translate(-50%, 150%)" }}
|
animate={{ transform: "translate(-50%, 0%)" }}
|
||||||
animate={{
|
exit={{ transform: "translate(-50%, 150%)" }}
|
||||||
transform:
|
transition={{ duration: 0.25, ease: "circOut" }}
|
||||||
location.pathname === "/player/audio"
|
className="audio-player"
|
||||||
? "translate(-50%, 150%)"
|
>
|
||||||
: "translate(-50%, 0%)",
|
<div className="media-bar-left">
|
||||||
}}
|
<button
|
||||||
exit={{ transform: "translate(-50%, 150%)" }}
|
type="button"
|
||||||
transition={{ duration: 0.3, ease: "circOut" }}
|
className="media-bar-cover"
|
||||||
className="audio-player"
|
onClick={handleNavigate}
|
||||||
>
|
aria-label="Open player"
|
||||||
<PlayerInfo item={item} api={api} onOpen={handleNavigate} />
|
>
|
||||||
|
{coverUrl ? (
|
||||||
|
<img src={coverUrl} alt="" />
|
||||||
|
) : (
|
||||||
|
<span className="material-symbols-rounded">music_note</span>
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
<div className="media-bar-info">
|
||||||
|
<Typography
|
||||||
|
variant="subtitle2"
|
||||||
|
className="media-bar-title"
|
||||||
|
title={activeItem?.Name ?? undefined}
|
||||||
|
onClick={handleNavigate}
|
||||||
|
>
|
||||||
|
{activeItem?.Name ?? "Unknown"}
|
||||||
|
</Typography>
|
||||||
|
<Typography variant="caption" noWrap className="media-bar-subtitle">
|
||||||
|
{subtitle || "Blink"}
|
||||||
|
</Typography>
|
||||||
|
</div>
|
||||||
|
<IconButton
|
||||||
|
size="small"
|
||||||
|
aria-label="More"
|
||||||
|
className="media-bar-more"
|
||||||
|
onClick={handleMoreOpen}
|
||||||
|
>
|
||||||
|
<span className="material-symbols-rounded">more_horiz</span>
|
||||||
|
</IconButton>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="media-bar-center">
|
||||||
|
<div className="media-bar-controls">
|
||||||
|
{!remote && (
|
||||||
|
<Tooltip title="Shuffle">
|
||||||
|
<IconButton size="small" onClick={handleShuffle}>
|
||||||
|
<span className="material-symbols-rounded">shuffle</span>
|
||||||
|
</IconButton>
|
||||||
|
</Tooltip>
|
||||||
|
)}
|
||||||
|
<IconButton size="small" onClick={handlePrevious}>
|
||||||
|
<span className="material-symbols-rounded">skip_previous</span>
|
||||||
|
</IconButton>
|
||||||
|
<IconButton
|
||||||
|
className="media-bar-play"
|
||||||
|
onClick={() =>
|
||||||
|
remote
|
||||||
|
? remoteCommand(PlaystateCommand.PlayPause)
|
||||||
|
: handlePlayPause()
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<span className="material-symbols-rounded">
|
||||||
|
{isPlaying ? "pause" : "play_arrow"}
|
||||||
|
</span>
|
||||||
|
</IconButton>
|
||||||
|
<IconButton size="small" onClick={handleNext}>
|
||||||
|
<span className="material-symbols-rounded">skip_next</span>
|
||||||
|
</IconButton>
|
||||||
|
{!remote && (
|
||||||
|
<Tooltip
|
||||||
|
title={
|
||||||
|
repeatMode === "off"
|
||||||
|
? "Repeat off"
|
||||||
|
: repeatMode === "all"
|
||||||
|
? "Repeat all"
|
||||||
|
: "Repeat one"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<IconButton
|
||||||
|
size="small"
|
||||||
|
onClick={handleRepeat}
|
||||||
|
className={repeatMode !== "off" ? "active" : ""}
|
||||||
|
>
|
||||||
|
<span className="material-symbols-rounded">
|
||||||
|
{repeatMode === "one" ? "repeat_one" : "repeat"}
|
||||||
|
</span>
|
||||||
|
</IconButton>
|
||||||
|
</Tooltip>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<PlayerProgress
|
||||||
|
className="media-bar-progress"
|
||||||
|
progress={displayProgress}
|
||||||
|
duration={displayDuration}
|
||||||
|
onSeekCommit={remote ? handleRemoteSeek : handleSeekCommit}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="media-bar-right">
|
||||||
|
{remote ? (
|
||||||
|
<Tooltip title="Transfer to this device">
|
||||||
|
<IconButton
|
||||||
|
size="small"
|
||||||
|
aria-label="Transfer to this device"
|
||||||
|
onClick={transferToLocal}
|
||||||
|
>
|
||||||
|
<span className="material-symbols-rounded">
|
||||||
|
system_update_alt
|
||||||
|
</span>
|
||||||
|
</IconButton>
|
||||||
|
</Tooltip>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<QueueButton />
|
||||||
|
<Tooltip title={isMuted ? "Unmute" : "Mute"}>
|
||||||
|
<IconButton size="small" onClick={handleMuteToggle}>
|
||||||
|
<span className="material-symbols-rounded">
|
||||||
|
{isMuted || volume === 0 ? "volume_off" : "volume_up"}
|
||||||
|
</span>
|
||||||
|
</IconButton>
|
||||||
|
</Tooltip>
|
||||||
|
<Slider
|
||||||
|
size="small"
|
||||||
|
className="media-bar-volume"
|
||||||
|
value={isMuted ? 0 : volume}
|
||||||
|
min={0}
|
||||||
|
max={1}
|
||||||
|
step={0.01}
|
||||||
|
aria-label="Volume"
|
||||||
|
onChange={(_, value) => {
|
||||||
|
const next = Array.isArray(value) ? value[0] : value;
|
||||||
|
handleVolumeChange(next);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
<DeviceMenu
|
||||||
|
sessions={remoteSessions}
|
||||||
|
activeRemoteId={remote?.Id ?? null}
|
||||||
|
localActive={display && Boolean(item)}
|
||||||
|
localItem={item}
|
||||||
|
onSelectLocal={transferToLocal}
|
||||||
|
onSelectRemote={selectRemote}
|
||||||
|
onOpenRemoteControl={() => openRemoteDialog()}
|
||||||
|
/>
|
||||||
|
<Tooltip title="Open player">
|
||||||
|
<IconButton size="small" onClick={handleNavigate}>
|
||||||
|
<span className="material-symbols-rounded">open_in_full</span>
|
||||||
|
</IconButton>
|
||||||
|
</Tooltip>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Menu
|
||||||
|
anchorEl={moreAnchor}
|
||||||
|
open={Boolean(moreAnchor)}
|
||||||
|
onClose={() => setMoreAnchor(null)}
|
||||||
|
slotProps={{ paper: { className: "glass-menu-paper" } }}
|
||||||
|
>
|
||||||
|
<MenuItem onClick={instantMix} disabled={!activeItem}>
|
||||||
|
<ListItemIcon>
|
||||||
|
<span className="material-symbols-rounded">radio</span>
|
||||||
|
</ListItemIcon>
|
||||||
|
<ListItemText primary="Instant Mix" />
|
||||||
|
</MenuItem>
|
||||||
|
{remote ? (
|
||||||
|
<MenuItem
|
||||||
|
onClick={() => {
|
||||||
|
setMoreAnchor(null);
|
||||||
|
transferToLocal();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<ListItemIcon>
|
||||||
|
<span className="material-symbols-rounded">
|
||||||
|
system_update_alt
|
||||||
|
</span>
|
||||||
|
</ListItemIcon>
|
||||||
|
<ListItemText primary="Transfer to this device" />
|
||||||
|
</MenuItem>
|
||||||
|
) : (
|
||||||
|
<MenuItem onClick={openCastForLocal}>
|
||||||
|
<ListItemIcon>
|
||||||
|
<span className="material-symbols-rounded">cast</span>
|
||||||
|
</ListItemIcon>
|
||||||
|
<ListItemText primary="Play on another device…" />
|
||||||
|
</MenuItem>
|
||||||
|
)}
|
||||||
|
<MenuItem
|
||||||
|
onClick={() => {
|
||||||
|
setMoreAnchor(null);
|
||||||
|
openRemoteDialog();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<ListItemIcon>
|
||||||
|
<span className="material-symbols-rounded">settings_remote</span>
|
||||||
|
</ListItemIcon>
|
||||||
|
<ListItemText primary="Remote control…" />
|
||||||
|
</MenuItem>
|
||||||
|
<Divider />
|
||||||
|
<MenuItem
|
||||||
|
onClick={() => {
|
||||||
|
setMoreAnchor(null);
|
||||||
|
if (remote) {
|
||||||
|
remoteCommand(PlaystateCommand.Stop);
|
||||||
|
setSelectedRemoteId(null);
|
||||||
|
} else {
|
||||||
|
handleClose();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<ListItemIcon>
|
||||||
|
<span className="material-symbols-rounded">stop</span>
|
||||||
|
</ListItemIcon>
|
||||||
|
<ListItemText primary="Stop" />
|
||||||
|
</MenuItem>
|
||||||
|
</Menu>
|
||||||
|
|
||||||
|
{display && (
|
||||||
<audio
|
<audio
|
||||||
autoPlay
|
autoPlay
|
||||||
src={url}
|
src={url}
|
||||||
@@ -238,43 +636,17 @@ const AudioPlayer = () => {
|
|||||||
onPause={onPause}
|
onPause={onPause}
|
||||||
onSeeked={updatePositionState}
|
onSeeked={updatePositionState}
|
||||||
onLoadedMetadata={(event) => {
|
onLoadedMetadata={(event) => {
|
||||||
const player = event.currentTarget;
|
const player = event.currentTarget;
|
||||||
if (!seekAppliedRef.current && startTimeTicks > 0) {
|
if (!seekAppliedRef.current && startTimeTicks > 0) {
|
||||||
seekAppliedRef.current = true;
|
seekAppliedRef.current = true;
|
||||||
player.currentTime = ticksToSec(startTimeTicks);
|
player.currentTime = ticksToSec(startTimeTicks);
|
||||||
}
|
}
|
||||||
updatePositionState();
|
updatePositionState();
|
||||||
}}
|
}}
|
||||||
id="audio-player"
|
id="audio-player"
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
<div className="audio-player-center">
|
</motion.div>
|
||||||
<PlayerControls playing={playing} onPlayPause={handlePlayPause} />
|
|
||||||
<PlayerProgress
|
|
||||||
className="audio-player-progress"
|
|
||||||
progress={progress}
|
|
||||||
duration={item?.RunTimeTicks ?? 1}
|
|
||||||
onSeekCommit={handleSeekCommit}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<PlayerActions
|
|
||||||
onExpand={handleNavigate}
|
|
||||||
onClose={handleClose}
|
|
||||||
item={item}
|
|
||||||
positionTicks={secToTicks(progress)}
|
|
||||||
queue={tracks ?? []}
|
|
||||||
startIndex={currentTrack}
|
|
||||||
>
|
|
||||||
<PlayerVolume
|
|
||||||
volume={volume}
|
|
||||||
isMuted={isMuted}
|
|
||||||
onVolumeChange={handleVolumeChange}
|
|
||||||
onMuteToggle={handleMuteToggle}
|
|
||||||
/>
|
|
||||||
</PlayerActions>
|
|
||||||
</motion.div>
|
|
||||||
)}
|
|
||||||
</AnimatePresence>
|
</AnimatePresence>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,139 +0,0 @@
|
|||||||
import { PlaystateCommand, type SessionInfoDto } from "@jellyfin/sdk/lib/generated-client";
|
|
||||||
import { getSessionApi } from "@jellyfin/sdk/lib/utils/api/session-api";
|
|
||||||
import { Button, IconButton, Tooltip, Typography } from "@mui/material";
|
|
||||||
import { useMutation, useQuery } from "@tanstack/react-query";
|
|
||||||
import { useLocation, useNavigate } from "@tanstack/react-router";
|
|
||||||
import { useSnackbar } from "notistack";
|
|
||||||
import React from "react";
|
|
||||||
import { transferSessionToLocal } from "@/utils/methods/transferPlayback";
|
|
||||||
import { useApiInContext } from "@/utils/store/api";
|
|
||||||
import { useAudioPlayback } from "@/utils/store/audioPlayback";
|
|
||||||
import { useCentralStore } from "@/utils/store/central";
|
|
||||||
import useRemoteControlStore from "@/utils/store/remoteControl";
|
|
||||||
|
|
||||||
import "./remotePlaybackBar.scss";
|
|
||||||
|
|
||||||
const RemotePlaybackBar = () => {
|
|
||||||
const api = useApiInContext((s) => s.api);
|
|
||||||
const user = useCentralStore((s) => s.currentUser);
|
|
||||||
const location = useLocation();
|
|
||||||
const navigate = useNavigate();
|
|
||||||
const { enqueueSnackbar } = useSnackbar();
|
|
||||||
const openDialog = useRemoteControlStore((s) => s.openDialog);
|
|
||||||
const audioDisplay = useAudioPlayback((s) => s.display);
|
|
||||||
|
|
||||||
const sessions = useQuery({
|
|
||||||
queryKey: ["remoteSessions"],
|
|
||||||
queryFn: async () => {
|
|
||||||
if (!api || !user?.Id) return [];
|
|
||||||
// Get every session: many Jellyfin clients don't report
|
|
||||||
// SupportsRemoteControl, so filtering by controllableByUserId hides
|
|
||||||
// devices that can still receive commands.
|
|
||||||
const result = await getSessionApi(api).getSessions();
|
|
||||||
return result.data;
|
|
||||||
},
|
|
||||||
enabled: !!api && !!user?.Id,
|
|
||||||
refetchInterval: 5000,
|
|
||||||
networkMode: "always",
|
|
||||||
});
|
|
||||||
|
|
||||||
const remote = (sessions.data ?? []).find(
|
|
||||||
(session: SessionInfoDto) =>
|
|
||||||
session.Id &&
|
|
||||||
session.DeviceId !== api?.deviceInfo.id &&
|
|
||||||
session.UserId === user?.Id &&
|
|
||||||
session.NowPlayingItem,
|
|
||||||
);
|
|
||||||
|
|
||||||
const command = useMutation({
|
|
||||||
mutationFn: async ({
|
|
||||||
session,
|
|
||||||
command,
|
|
||||||
}: {
|
|
||||||
session: SessionInfoDto;
|
|
||||||
command: PlaystateCommand;
|
|
||||||
}) => {
|
|
||||||
if (!api || !session.Id) return;
|
|
||||||
await getSessionApi(api).sendPlaystateCommand({
|
|
||||||
sessionId: session.Id,
|
|
||||||
command,
|
|
||||||
controllingUserId: user?.Id,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
onSettled: () => sessions.refetch(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const transfer = useMutation({
|
|
||||||
mutationFn: async (session: SessionInfoDto) =>
|
|
||||||
transferSessionToLocal(api, user?.Id, session),
|
|
||||||
onSuccess: async (kind) => {
|
|
||||||
await sessions.refetch();
|
|
||||||
if (kind === "none") {
|
|
||||||
enqueueSnackbar("Could not transfer playback", { variant: "error" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
enqueueSnackbar("Playback transferred to this device", {
|
|
||||||
variant: "success",
|
|
||||||
});
|
|
||||||
if (kind === "video") {
|
|
||||||
navigate({ to: "/player" });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onError: () =>
|
|
||||||
enqueueSnackbar("Could not transfer playback", { variant: "error" }),
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!remote || location.pathname.startsWith("/player")) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const paused = remote.PlayState?.IsPaused;
|
|
||||||
const title = remote.NowPlayingItem?.Name ?? "Unknown";
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className={`remote-playback-bar${audioDisplay ? " with-audio" : ""}`}>
|
|
||||||
<IconButton
|
|
||||||
size="small"
|
|
||||||
aria-label="Open remote control"
|
|
||||||
onClick={() => openDialog()}
|
|
||||||
>
|
|
||||||
<span className="material-symbols-rounded">cast_connected</span>
|
|
||||||
</IconButton>
|
|
||||||
<div className="remote-playback-bar-info">
|
|
||||||
<Typography variant="caption" className="remote-playback-bar-device">
|
|
||||||
Playing on {remote.DeviceName || remote.Client || "device"}
|
|
||||||
</Typography>
|
|
||||||
<Typography variant="body2" noWrap className="remote-playback-bar-title">
|
|
||||||
{title}
|
|
||||||
</Typography>
|
|
||||||
</div>
|
|
||||||
<Tooltip title={paused ? "Play" : "Pause"}>
|
|
||||||
<IconButton
|
|
||||||
size="small"
|
|
||||||
onClick={() =>
|
|
||||||
command.mutate({
|
|
||||||
session: remote,
|
|
||||||
command: paused
|
|
||||||
? PlaystateCommand.Unpause
|
|
||||||
: PlaystateCommand.Pause,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<span className="material-symbols-rounded">
|
|
||||||
{paused ? "play_arrow" : "pause"}
|
|
||||||
</span>
|
|
||||||
</IconButton>
|
|
||||||
</Tooltip>
|
|
||||||
<Button
|
|
||||||
size="small"
|
|
||||||
variant="contained"
|
|
||||||
disabled={transfer.isPending}
|
|
||||||
onClick={() => transfer.mutate(remote)}
|
|
||||||
>
|
|
||||||
Transfer here
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default React.memo(RemotePlaybackBar);
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
.remote-playback-bar {
|
|
||||||
position: fixed;
|
|
||||||
left: 50%;
|
|
||||||
bottom: 1rem;
|
|
||||||
transform: translateX(-50%);
|
|
||||||
z-index: 99;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 0.6rem;
|
|
||||||
width: min(620px, calc(100% - 2rem));
|
|
||||||
padding: 0.4rem 0.4rem 0.4rem 0.6rem;
|
|
||||||
box-sizing: border-box;
|
|
||||||
border-radius: 12px;
|
|
||||||
background: rgb(18 18 24 / 0.97);
|
|
||||||
border: 1px solid rgb(255 255 255 / 0.1);
|
|
||||||
box-shadow: 0 10px 30px rgb(0 0 0 / 0.45);
|
|
||||||
color: white;
|
|
||||||
|
|
||||||
&.with-audio {
|
|
||||||
bottom: 6.2rem; // above the 80px audio player
|
|
||||||
}
|
|
||||||
|
|
||||||
.material-symbols-rounded {
|
|
||||||
color: rgb(255 255 255 / 0.85);
|
|
||||||
}
|
|
||||||
|
|
||||||
&-info {
|
|
||||||
flex: 1;
|
|
||||||
min-width: 0;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
line-height: 1.15;
|
|
||||||
}
|
|
||||||
|
|
||||||
&-device {
|
|
||||||
opacity: 0.6;
|
|
||||||
}
|
|
||||||
|
|
||||||
&-title {
|
|
||||||
font-weight: 600;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -28,7 +28,6 @@ import { HTML5Backend } from "react-dnd-html5-backend";
|
|||||||
import Backdrop from "@/components/backdrop";
|
import Backdrop from "@/components/backdrop";
|
||||||
import { ErrorNotice } from "@/components/notices/errorNotice/errorNotice";
|
import { ErrorNotice } from "@/components/notices/errorNotice/errorNotice";
|
||||||
import RemoteControlDialog from "@/components/remoteControl";
|
import RemoteControlDialog from "@/components/remoteControl";
|
||||||
import RemotePlaybackBar from "@/components/remotePlaybackBar";
|
|
||||||
import RouterLoading from "@/components/routerLoading";
|
import RouterLoading from "@/components/routerLoading";
|
||||||
import Search from "@/components/search";
|
import Search from "@/components/search";
|
||||||
import Updater from "@/components/updater";
|
import Updater from "@/components/updater";
|
||||||
@@ -59,7 +58,6 @@ export const Route = createRootRouteWithContext<ApiContext>()({
|
|||||||
<Backdrop />
|
<Backdrop />
|
||||||
<Search />
|
<Search />
|
||||||
<RemoteControlDialog />
|
<RemoteControlDialog />
|
||||||
<RemotePlaybackBar />
|
|
||||||
<AppBar />
|
<AppBar />
|
||||||
<AudioPlayer />
|
<AudioPlayer />
|
||||||
<Outlet />
|
<Outlet />
|
||||||
|
|||||||
Reference in new issue
Block a user