feat: instant mix, remote control and stable music library
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
- Instant Mix button on albums, artists, the audio player and full-screen player - Remote control dialog (cast icon in app bar/header/item/player): lists other sessions, play/pause/next/prev/seek/stop, and Play-on-device for an item - Music library: repair persisted view types (CollectionFolder/undefined) and fall back to Songs when a music library has no album grouping - Music jitter: remove full-screen backdrop-filters (audio bar and player page) and the body ResizeObserver in the virtualized grid
This commit is contained in:
1 parent
cc1391bb7d
commit
a98663691d
18 files changed
+681
-22
No files matched your search
@@ -13,6 +13,7 @@ import { useCentralStore } from "@/utils/store/central";
|
||||
import useHeaderStore from "@/utils/store/header";
|
||||
import useSearchStore from "@/utils/store/search";
|
||||
import BackButton from "../buttons/backButton";
|
||||
import CastButton from "../buttons/castButton";
|
||||
import { UserAvatarMenu } from "../userAvatarMenu";
|
||||
import { NavigationDrawer } from "./navigationDrawer";
|
||||
|
||||
@@ -106,6 +107,7 @@ export const AppBar = () => {
|
||||
</div>
|
||||
|
||||
<div className="flex flex-row" data-tauri-drag-region style={{ gap: "0.6em" }}>
|
||||
<CastButton />
|
||||
<IconButton onClick={toggleSearchDialog}>
|
||||
<span className="material-symbols-rounded">search</span>
|
||||
</IconButton>
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client";
|
||||
import IconButton from "@mui/material/IconButton";
|
||||
import Tooltip from "@mui/material/Tooltip";
|
||||
import React from "react";
|
||||
import useRemoteControlStore from "@/utils/store/remoteControl";
|
||||
|
||||
type CastButtonProps = {
|
||||
item?: BaseItemDto | null;
|
||||
size?: "small" | "medium" | "large";
|
||||
};
|
||||
|
||||
const CastButton = ({ item, size = "medium" }: CastButtonProps) => {
|
||||
const openDialog = useRemoteControlStore((s) => s.openDialog);
|
||||
return (
|
||||
<Tooltip title={item ? "Play on another device" : "Remote control"}>
|
||||
<IconButton
|
||||
size={size}
|
||||
aria-label={item ? "Play on another device" : "Remote control"}
|
||||
onClick={() => openDialog(item ?? null)}
|
||||
>
|
||||
<span className="material-symbols-rounded">cast</span>
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
);
|
||||
};
|
||||
|
||||
export default CastButton;
|
||||
@@ -0,0 +1,69 @@
|
||||
import type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client";
|
||||
import IconButton from "@mui/material/IconButton";
|
||||
import Tooltip from "@mui/material/Tooltip";
|
||||
import { useSnackbar } from "notistack";
|
||||
import React, { useState } from "react";
|
||||
import { startInstantMix } from "@/utils/methods/instantMix";
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import { useCentralStore } from "@/utils/store/central";
|
||||
|
||||
type InstantMixButtonProps = {
|
||||
item?: BaseItemDto | null;
|
||||
/** Render a text button instead of an icon (e.g. on the album page). */
|
||||
withLabel?: boolean;
|
||||
};
|
||||
|
||||
const InstantMixButton = ({ item, withLabel = false }: InstantMixButtonProps) => {
|
||||
const api = useApiInContext((s) => s.api);
|
||||
const user = useCentralStore((s) => s.currentUser);
|
||||
const { enqueueSnackbar } = useSnackbar();
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
const handleClick = async () => {
|
||||
if (!api || !user?.Id || !item) return;
|
||||
setBusy(true);
|
||||
try {
|
||||
const { count } = await startInstantMix(api, user.Id, item);
|
||||
if (count === 0) {
|
||||
enqueueSnackbar("No tracks found for this Instant Mix", {
|
||||
variant: "warning",
|
||||
});
|
||||
} else {
|
||||
enqueueSnackbar(`Instant Mix: ${count} tracks`, {
|
||||
variant: "success",
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Instant Mix failed", error);
|
||||
enqueueSnackbar("Could not start Instant Mix", { variant: "error" });
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Tooltip title="Instant Mix">
|
||||
<span>
|
||||
{withLabel ? (
|
||||
<IconButton
|
||||
aria-label="Instant Mix"
|
||||
onClick={handleClick}
|
||||
disabled={busy || !item}
|
||||
>
|
||||
<span className="material-symbols-rounded">radio</span>
|
||||
</IconButton>
|
||||
) : (
|
||||
<IconButton
|
||||
aria-label="Instant Mix"
|
||||
onClick={handleClick}
|
||||
disabled={busy || !item}
|
||||
>
|
||||
<span className="material-symbols-rounded">radio</span>
|
||||
</IconButton>
|
||||
)}
|
||||
</span>
|
||||
</Tooltip>
|
||||
);
|
||||
};
|
||||
|
||||
export default InstantMixButton;
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
import Typography from "@mui/material/Typography";
|
||||
import { motion } from "motion/react";
|
||||
import React, { type ReactNode, useEffect, useRef } from "react";
|
||||
import CastButton from "@/components/buttons/castButton";
|
||||
import LikeButton from "@/components/buttons/likeButton";
|
||||
import MarkPlayedButton from "@/components/buttons/markPlayedButton";
|
||||
import TrailerButton from "@/components/buttons/trailerButton";
|
||||
@@ -74,6 +75,15 @@ const ItemDetailLayout = ({
|
||||
const containerRef = useRef<HTMLDivElement | null>(null);
|
||||
const queryKey = ["item", item.Id ?? ""];
|
||||
|
||||
const canCast =
|
||||
item.Type === BaseItemKind.Movie ||
|
||||
item.Type === BaseItemKind.Episode ||
|
||||
item.Type === BaseItemKind.Audio ||
|
||||
item.Type === BaseItemKind.AudioBook ||
|
||||
item.Type === BaseItemKind.MusicVideo ||
|
||||
item.Type === BaseItemKind.Video ||
|
||||
item.Type === BaseItemKind.Trailer;
|
||||
|
||||
const setBackdrop = useBackdropStore((s) => s.setBackdrop);
|
||||
const hash = backdropHash ?? getDefaultBackdropHash(item);
|
||||
useEffect(() => {
|
||||
@@ -114,6 +124,7 @@ const ItemDetailLayout = ({
|
||||
isFavorite={item.UserData?.IsFavorite}
|
||||
userId={user?.Id}
|
||||
/>
|
||||
{canCast && <CastButton item={item} />}
|
||||
{showMarkPlayed && (
|
||||
<MarkPlayedButton
|
||||
itemName={item.Name}
|
||||
|
||||
@@ -22,6 +22,7 @@ import { useLibraryStateStore } from "@/utils/store/libraryState";
|
||||
import useSearchStore from "@/utils/store/search";
|
||||
import { NavigationDrawer } from "../appBar/navigationDrawer";
|
||||
import BackButton from "../buttons/backButton";
|
||||
import CastButton from "../buttons/castButton";
|
||||
import { FiltersDialogTrigger } from "../filtersDialog";
|
||||
import { UserAvatarMenu } from "../userAvatarMenu";
|
||||
import "./libraryHeader.scss";
|
||||
@@ -386,6 +387,7 @@ export const LibraryHeader = () => {
|
||||
<FiltersDialogTrigger />
|
||||
</div>
|
||||
<div className="flex flex-row" style={{ gap: "0.6em" }}>
|
||||
<CastButton />
|
||||
<IconButton onClick={toggleSearchDialog}>
|
||||
<div className="material-symbols-rounded">search</div>
|
||||
</IconButton>
|
||||
|
||||
@@ -15,6 +15,7 @@ import React, {
|
||||
import "./libraryItemsGrid.scss";
|
||||
import { useShallow } from "zustand/shallow";
|
||||
import { getLibraryQueryOptions } from "@/utils/queries/library";
|
||||
import { AVAILABLE_VIEWS } from "@/utils/constants/library";
|
||||
import { getLibraryItemsQueryOptions } from "@/utils/queries/libraryItems";
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import { useBackdropStore } from "@/utils/store/backdrop";
|
||||
@@ -66,31 +67,74 @@ const LibraryItemsGrid = () => {
|
||||
getLibraryQueryOptions(api, user?.Id, currentLibraryId),
|
||||
);
|
||||
|
||||
const collectionType = currentLibrary.data.CollectionType;
|
||||
const defaultViewType: BaseItemKind =
|
||||
collectionType === "music"
|
||||
? BaseItemKind.MusicAlbum
|
||||
: collectionType === "movies"
|
||||
? BaseItemKind.Movie
|
||||
: collectionType === "tvshows"
|
||||
? BaseItemKind.Series
|
||||
: collectionType === "boxsets"
|
||||
? BaseItemKind.BoxSet
|
||||
: collectionType === "books"
|
||||
? BaseItemKind.Book
|
||||
: collectionType === "playlists"
|
||||
? BaseItemKind.Playlist
|
||||
: BaseItemKind.Movie;
|
||||
|
||||
// Persisted slices may hold no view type or a view from another collection
|
||||
// type (e.g. CollectionFolder left by an older build). Reset those.
|
||||
const compatibleViews = AVAILABLE_VIEWS.filter((view) =>
|
||||
view.compatibleCollectionTypes.includes(collectionType as any),
|
||||
).map((view) => view.value);
|
||||
const isViewValid =
|
||||
!!currentViewType &&
|
||||
(compatibleViews.includes(currentViewType) || currentViewType === "Artist");
|
||||
|
||||
useEffect(() => {
|
||||
if (currentLibraryId && !currentViewType && currentLibrary.data?.Type) {
|
||||
if (currentLibraryId && !isViewValid) {
|
||||
updateLibrary(currentLibraryId, {
|
||||
currentViewType: currentLibrary.data.Type as BaseItemKind,
|
||||
currentViewType: defaultViewType,
|
||||
});
|
||||
}
|
||||
}, [
|
||||
currentLibrary.data?.Type,
|
||||
currentLibraryId,
|
||||
currentViewType,
|
||||
updateLibrary,
|
||||
]);
|
||||
}, [currentLibraryId, isViewValid, defaultViewType, updateLibrary]);
|
||||
|
||||
const effectiveViewType: BaseItemKind | "Artist" = isViewValid
|
||||
? (currentViewType as BaseItemKind | "Artist")
|
||||
: defaultViewType;
|
||||
|
||||
const items = useSuspenseQuery(
|
||||
getLibraryItemsQueryOptions(api, user?.Id, currentLibraryId, {
|
||||
currentViewType,
|
||||
currentViewType: effectiveViewType,
|
||||
sortAscending,
|
||||
sortBy,
|
||||
filters,
|
||||
videoTypesState,
|
||||
nameStartsWith,
|
||||
genreIds,
|
||||
collectionType: currentLibrary.data.CollectionType as any,
|
||||
collectionType: collectionType as any,
|
||||
}),
|
||||
);
|
||||
// A music library with no album grouping (flat audio files) opens on an
|
||||
// empty "Albums" view. Fall back to Songs so the tracks are visible.
|
||||
useEffect(() => {
|
||||
if (collectionType !== "music") return;
|
||||
if (effectiveViewType !== BaseItemKind.MusicAlbum) return;
|
||||
if (!items.isSuccess) return;
|
||||
if ((items.data?.TotalRecordCount ?? 0) > 0) return;
|
||||
updateLibrary(currentLibraryId, {
|
||||
currentViewType: BaseItemKind.Audio,
|
||||
});
|
||||
}, [
|
||||
collectionType,
|
||||
effectiveViewType,
|
||||
items.isSuccess,
|
||||
items.data?.TotalRecordCount,
|
||||
currentLibraryId,
|
||||
updateLibrary,
|
||||
]);
|
||||
|
||||
// --- Backdrop ---
|
||||
const setBackdrop = useBackdropStore(useShallow((s) => s.setBackdrop));
|
||||
const backdropItems = useMemo<BaseItemDto[]>(() => {
|
||||
@@ -147,9 +191,8 @@ const LibraryItemsGrid = () => {
|
||||
|
||||
const ro = new ResizeObserver(() => measureColumns());
|
||||
ro.observe(parentRef.current);
|
||||
// The header above the grid can change height (filters, wrapping): keep the
|
||||
// window-virtualizer offset in sync so rows never jump while scrolling.
|
||||
ro.observe(document.body);
|
||||
// The audio player and headers can change the page layout; a resize
|
||||
// listener is enough (observing <body> fires on every image load).
|
||||
window.addEventListener("resize", measureColumns);
|
||||
return () => {
|
||||
ro.disconnect();
|
||||
|
||||
@@ -18,9 +18,9 @@ $art-size: 48px;
|
||||
padding: 0 0.75rem 0 1rem;
|
||||
|
||||
color: white;
|
||||
background: rgb(18 18 24 / 0.92);
|
||||
backdrop-filter: blur(16px);
|
||||
-webkit-backdrop-filter: blur(16px);
|
||||
// Opaque bar: backdrop-filter over the virtualized grid caused constant
|
||||
// compositing/shifting on WebKit.
|
||||
background: rgb(18 18 24 / 0.98);
|
||||
border: 1px solid rgb(255 255 255 / 0.08);
|
||||
border-radius: 14px;
|
||||
box-shadow: 0 12px 40px rgb(0 0 0 / 0.45);
|
||||
|
||||
@@ -1,19 +1,26 @@
|
||||
import type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client";
|
||||
import IconButton from "@mui/material/IconButton";
|
||||
import Tooltip from "@mui/material/Tooltip";
|
||||
import React, { type ReactNode } from "react";
|
||||
import CastButton from "@/components/buttons/castButton";
|
||||
import InstantMixButton from "@/components/buttons/instantMixButton";
|
||||
import QueueButton from "@/components/buttons/queueButton";
|
||||
|
||||
interface PlayerActionsProps {
|
||||
/** Opens the full-screen player. */
|
||||
onExpand: () => void;
|
||||
onClose: () => void;
|
||||
/** The track currently playing (for cast / instant mix). */
|
||||
item?: BaseItemDto | null;
|
||||
/** Volume control, rendered between the queue and expand buttons. */
|
||||
children?: ReactNode;
|
||||
}
|
||||
|
||||
const PlayerActions = ({ onExpand, onClose, children }: PlayerActionsProps) => {
|
||||
const PlayerActions = ({ onExpand, onClose, item, children }: PlayerActionsProps) => {
|
||||
return (
|
||||
<div className="audio-player-actions">
|
||||
{item && <InstantMixButton item={item} />}
|
||||
{item && <CastButton item={item} />}
|
||||
<QueueButton />
|
||||
<div className="audio-player-volume">{children}</div>
|
||||
<Tooltip title="Open player">
|
||||
|
||||
@@ -245,7 +245,7 @@ const AudioPlayer = () => {
|
||||
/>
|
||||
</div>
|
||||
|
||||
<PlayerActions onExpand={handleNavigate} onClose={handleClose}>
|
||||
<PlayerActions onExpand={handleNavigate} onClose={handleClose} item={item}>
|
||||
<PlayerVolume
|
||||
volume={volume}
|
||||
isMuted={isMuted}
|
||||
|
||||
@@ -10,6 +10,7 @@ import React, {
|
||||
useState,
|
||||
} from "react";
|
||||
import { useShallow } from "zustand/shallow";
|
||||
import CastButton from "@/components/buttons/castButton";
|
||||
import PlayNextButton from "@/components/buttons/playNextButton";
|
||||
import PlayPreviousButton from "@/components/buttons/playPreviousButtom";
|
||||
import QueueButton from "@/components/buttons/queueButton";
|
||||
@@ -55,6 +56,7 @@ const VideoPlayerControls = ({
|
||||
const {
|
||||
mediaSourceId,
|
||||
itemId,
|
||||
item,
|
||||
itemName,
|
||||
episodeTitle,
|
||||
playsessionId,
|
||||
@@ -76,6 +78,7 @@ const VideoPlayerControls = ({
|
||||
mediaSourceId: state.mediaSource.id,
|
||||
itemChapters: state.metadata.item.Chapters,
|
||||
itemId: state.metadata.item.Id,
|
||||
item: state.metadata.item,
|
||||
itemName: state.metadata.itemName,
|
||||
episodeTitle: state.metadata.episodeTitle,
|
||||
// mediaSegments: state.metadata.mediaSegments,
|
||||
@@ -304,6 +307,7 @@ const VideoPlayerControls = ({
|
||||
: "volume_up"}
|
||||
</span>
|
||||
</IconButton>
|
||||
<CastButton item={item} />
|
||||
<QueueButton />
|
||||
|
||||
<ChaptersListButton />
|
||||
|
||||
@@ -0,0 +1,373 @@
|
||||
import {
|
||||
PlayCommand,
|
||||
PlaystateCommand,
|
||||
type SessionInfoDto,
|
||||
} from "@jellyfin/sdk/lib/generated-client";
|
||||
import { getSessionApi } from "@jellyfin/sdk/lib/utils/api/session-api";
|
||||
import {
|
||||
Button,
|
||||
Chip,
|
||||
CircularProgress,
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogTitle,
|
||||
Divider,
|
||||
IconButton,
|
||||
LinearProgress,
|
||||
List,
|
||||
ListItem,
|
||||
Tooltip,
|
||||
Typography,
|
||||
} from "@mui/material";
|
||||
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||
import { useSnackbar } from "notistack";
|
||||
import React from "react";
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import { useCentralStore } from "@/utils/store/central";
|
||||
import useRemoteControlStore from "@/utils/store/remoteControl";
|
||||
|
||||
const TICKS_PER_SECOND = 10_000_000;
|
||||
|
||||
const formatTime = (ticks: number | null | undefined) => {
|
||||
const total = Math.max(0, Math.round((ticks ?? 0) / TICKS_PER_SECOND));
|
||||
const h = Math.floor(total / 3600);
|
||||
const m = Math.floor((total % 3600) / 60);
|
||||
const s = total % 60;
|
||||
return h > 0
|
||||
? `${h}:${String(m).padStart(2, "0")}:${String(s).padStart(2, "0")}`
|
||||
: `${m}:${String(s).padStart(2, "0")}`;
|
||||
};
|
||||
|
||||
const sessionLabel = (session: SessionInfoDto) =>
|
||||
session.DeviceName || session.Client || session.DeviceId || "Unknown device";
|
||||
|
||||
const RemoteControlDialog = () => {
|
||||
const { open, item, closeDialog } = useRemoteControlStore();
|
||||
const api = useApiInContext((s) => s.api);
|
||||
const user = useCentralStore((s) => s.currentUser);
|
||||
const { enqueueSnackbar } = useSnackbar();
|
||||
|
||||
const sessions = useQuery({
|
||||
queryKey: ["remoteSessions"],
|
||||
queryFn: async () => {
|
||||
if (!api || !user?.Id) return [];
|
||||
const result = await getSessionApi(api).getSessions({
|
||||
controllableByUserId: user.Id,
|
||||
});
|
||||
return result.data;
|
||||
},
|
||||
enabled: open && !!api && !!user?.Id,
|
||||
refetchInterval: open ? 3000 : false,
|
||||
networkMode: "always",
|
||||
});
|
||||
|
||||
const sendCommand = useMutation({
|
||||
mutationFn: async ({
|
||||
session,
|
||||
command,
|
||||
seekPositionTicks,
|
||||
}: {
|
||||
session: SessionInfoDto;
|
||||
command: PlaystateCommand;
|
||||
seekPositionTicks?: number;
|
||||
}) => {
|
||||
if (!api || !session.Id) return;
|
||||
await getSessionApi(api).sendPlaystateCommand({
|
||||
sessionId: session.Id,
|
||||
command,
|
||||
seekPositionTicks,
|
||||
controllingUserId: user?.Id,
|
||||
});
|
||||
},
|
||||
onError: () =>
|
||||
enqueueSnackbar("Command failed", { variant: "error" }),
|
||||
onSettled: () => sessions.refetch(),
|
||||
});
|
||||
|
||||
const playOn = useMutation({
|
||||
mutationFn: async (session: SessionInfoDto) => {
|
||||
if (!api || !session.Id || !item?.Id) return;
|
||||
await getSessionApi(api).play({
|
||||
sessionId: session.Id,
|
||||
playCommand: PlayCommand.PlayNow,
|
||||
itemIds: [item.Id],
|
||||
startPositionTicks: 0,
|
||||
mediaSourceId: item.MediaSources?.[0]?.Id ?? undefined,
|
||||
});
|
||||
},
|
||||
onSuccess: (_data, session) => {
|
||||
enqueueSnackbar(`Playing on ${sessionLabel(session)}`, {
|
||||
variant: "success",
|
||||
});
|
||||
closeDialog();
|
||||
},
|
||||
onError: () =>
|
||||
enqueueSnackbar("Could not start playback on the device", {
|
||||
variant: "error",
|
||||
}),
|
||||
});
|
||||
|
||||
const remoteSessions = (sessions.data ?? []).filter(
|
||||
(session) =>
|
||||
session.Id &&
|
||||
session.DeviceId !== api?.deviceInfo.id &&
|
||||
session.SupportsRemoteControl !== false,
|
||||
);
|
||||
|
||||
const seek = (session: SessionInfoDto, offsetSeconds: number) => {
|
||||
const current = (session.PlayState?.PositionTicks ?? 0) / TICKS_PER_SECOND;
|
||||
const next = Math.max(0, current + offsetSeconds);
|
||||
sendCommand.mutate({
|
||||
session,
|
||||
command: PlaystateCommand.Seek,
|
||||
seekPositionTicks: Math.round(next * TICKS_PER_SECOND),
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog
|
||||
open={open}
|
||||
onClose={closeDialog}
|
||||
fullWidth
|
||||
maxWidth="sm"
|
||||
slotProps={{
|
||||
paper: {
|
||||
className: "glass-dialog-paper",
|
||||
sx: { borderRadius: 3 },
|
||||
},
|
||||
}}
|
||||
>
|
||||
<DialogTitle sx={{ display: "flex", alignItems: "center", gap: 1 }}>
|
||||
<span className="material-symbols-rounded">cast</span>
|
||||
<span style={{ flex: 1 }}>
|
||||
{item ? `Play "${item.Name}" on…` : "Remote control"}
|
||||
</span>
|
||||
<IconButton onClick={closeDialog} aria-label="Close">
|
||||
<span className="material-symbols-rounded">close</span>
|
||||
</IconButton>
|
||||
</DialogTitle>
|
||||
<DialogContent sx={{ pb: 2 }}>
|
||||
{item && (
|
||||
<Typography variant="body2" sx={{ opacity: 0.7, mb: 1 }}>
|
||||
Choose a device to start playback on it.
|
||||
</Typography>
|
||||
)}
|
||||
{sessions.isPending ? (
|
||||
<div style={{ display: "flex", justifyContent: "center", padding: 24 }}>
|
||||
<CircularProgress size={28} />
|
||||
</div>
|
||||
) : remoteSessions.length === 0 ? (
|
||||
<Typography sx={{ opacity: 0.7, py: 2 }}>
|
||||
No other controllable devices are online. Open a Jellyfin client
|
||||
(e.g. on your TV) and make sure remote control is allowed.
|
||||
</Typography>
|
||||
) : (
|
||||
<List disablePadding>
|
||||
{remoteSessions.map((session) => {
|
||||
const nowPlaying = session.NowPlayingItem;
|
||||
const playState = session.PlayState;
|
||||
const duration = nowPlaying?.RunTimeTicks ?? 0;
|
||||
const position = playState?.PositionTicks ?? 0;
|
||||
const supportsControl = session.SupportsRemoteControl !== false;
|
||||
return (
|
||||
<React.Fragment key={session.Id}>
|
||||
<ListItem
|
||||
sx={{
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
alignItems: "stretch",
|
||||
gap: 1,
|
||||
px: 0,
|
||||
py: 1.5,
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
gap: 8,
|
||||
}}
|
||||
>
|
||||
<span className="material-symbols-rounded">tv</span>
|
||||
<div style={{ flex: 1, minWidth: 0 }}>
|
||||
<Typography variant="subtitle1" noWrap>
|
||||
{sessionLabel(session)}
|
||||
</Typography>
|
||||
<Typography
|
||||
variant="caption"
|
||||
sx={{ opacity: 0.6, display: "block" }}
|
||||
noWrap
|
||||
>
|
||||
{[session.Client, session.UserName]
|
||||
.filter(Boolean)
|
||||
.join(" · ")}
|
||||
</Typography>
|
||||
</div>
|
||||
{item && (
|
||||
<Button
|
||||
size="small"
|
||||
variant="contained"
|
||||
disabled={playOn.isPending || !item.Id}
|
||||
onClick={() => playOn.mutate(session)}
|
||||
>
|
||||
Play here
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{nowPlaying ? (
|
||||
<>
|
||||
<Typography variant="body2" noWrap>
|
||||
{nowPlaying.Name}
|
||||
{nowPlaying.Genres?.length ? (
|
||||
<Chip
|
||||
size="small"
|
||||
label={nowPlaying.Genres[0]}
|
||||
sx={{ ml: 1 }}
|
||||
/>
|
||||
) : null}
|
||||
</Typography>
|
||||
<LinearProgress
|
||||
variant="determinate"
|
||||
value={
|
||||
duration > 0
|
||||
? Math.min(100, (position / duration) * 100)
|
||||
: 0
|
||||
}
|
||||
sx={{ borderRadius: 1 }}
|
||||
/>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "space-between",
|
||||
}}
|
||||
>
|
||||
<Typography variant="caption" sx={{ opacity: 0.6 }}>
|
||||
{formatTime(position)} / {formatTime(duration)}
|
||||
{playState?.IsPaused ? " · paused" : ""}
|
||||
</Typography>
|
||||
<div style={{ display: "flex" }}>
|
||||
<Tooltip title="Back 10s">
|
||||
<span>
|
||||
<IconButton
|
||||
size="small"
|
||||
disabled={!supportsControl || playState?.CanSeek === false}
|
||||
onClick={() => seek(session, -10)}
|
||||
>
|
||||
<span className="material-symbols-rounded">
|
||||
replay_10
|
||||
</span>
|
||||
</IconButton>
|
||||
</span>
|
||||
</Tooltip>
|
||||
<Tooltip title="Previous">
|
||||
<span>
|
||||
<IconButton
|
||||
size="small"
|
||||
disabled={!supportsControl}
|
||||
onClick={() =>
|
||||
sendCommand.mutate({
|
||||
session,
|
||||
command: PlaystateCommand.PreviousTrack,
|
||||
})
|
||||
}
|
||||
>
|
||||
<span className="material-symbols-rounded">
|
||||
skip_previous
|
||||
</span>
|
||||
</IconButton>
|
||||
</span>
|
||||
</Tooltip>
|
||||
<Tooltip
|
||||
title={playState?.IsPaused ? "Play" : "Pause"}
|
||||
>
|
||||
<span>
|
||||
<IconButton
|
||||
size="small"
|
||||
disabled={!supportsControl}
|
||||
onClick={() =>
|
||||
sendCommand.mutate({
|
||||
session,
|
||||
command: PlaystateCommand.PlayPause,
|
||||
})
|
||||
}
|
||||
>
|
||||
<span className="material-symbols-rounded">
|
||||
{playState?.IsPaused
|
||||
? "play_arrow"
|
||||
: "pause"}
|
||||
</span>
|
||||
</IconButton>
|
||||
</span>
|
||||
</Tooltip>
|
||||
<Tooltip title="Next">
|
||||
<span>
|
||||
<IconButton
|
||||
size="small"
|
||||
disabled={!supportsControl}
|
||||
onClick={() =>
|
||||
sendCommand.mutate({
|
||||
session,
|
||||
command: PlaystateCommand.NextTrack,
|
||||
})
|
||||
}
|
||||
>
|
||||
<span className="material-symbols-rounded">
|
||||
skip_next
|
||||
</span>
|
||||
</IconButton>
|
||||
</span>
|
||||
</Tooltip>
|
||||
<Tooltip title="Forward 10s">
|
||||
<span>
|
||||
<IconButton
|
||||
size="small"
|
||||
disabled={!supportsControl || playState?.CanSeek === false}
|
||||
onClick={() => seek(session, 10)}
|
||||
>
|
||||
<span className="material-symbols-rounded">
|
||||
forward_10
|
||||
</span>
|
||||
</IconButton>
|
||||
</span>
|
||||
</Tooltip>
|
||||
<Tooltip title="Stop">
|
||||
<span>
|
||||
<IconButton
|
||||
size="small"
|
||||
disabled={!supportsControl}
|
||||
onClick={() =>
|
||||
sendCommand.mutate({
|
||||
session,
|
||||
command: PlaystateCommand.Stop,
|
||||
})
|
||||
}
|
||||
>
|
||||
<span className="material-symbols-rounded">
|
||||
stop
|
||||
</span>
|
||||
</IconButton>
|
||||
</span>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<Typography variant="caption" sx={{ opacity: 0.6 }}>
|
||||
Idle
|
||||
</Typography>
|
||||
)}
|
||||
</ListItem>
|
||||
<Divider />
|
||||
</React.Fragment>
|
||||
);
|
||||
})}
|
||||
</List>
|
||||
)}
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
};
|
||||
|
||||
export default RemoteControlDialog;
|
||||
@@ -27,6 +27,7 @@ import { DndProvider } from "react-dnd";
|
||||
import { HTML5Backend } from "react-dnd-html5-backend";
|
||||
import Backdrop from "@/components/backdrop";
|
||||
import { ErrorNotice } from "@/components/notices/errorNotice/errorNotice";
|
||||
import RemoteControlDialog from "@/components/remoteControl";
|
||||
import RouterLoading from "@/components/routerLoading";
|
||||
import Search from "@/components/search";
|
||||
import Updater from "@/components/updater";
|
||||
@@ -56,6 +57,7 @@ export const Route = createRootRouteWithContext<ApiContext>()({
|
||||
<Updater />
|
||||
<Backdrop />
|
||||
<Search />
|
||||
<RemoteControlDialog />
|
||||
<AppBar />
|
||||
<AudioPlayer />
|
||||
<Outlet />
|
||||
|
||||
@@ -6,6 +6,7 @@ import Typography from "@mui/material/Typography";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import React, { useLayoutEffect, useMemo } from "react";
|
||||
import LikeButton from "@/components/buttons/likeButton";
|
||||
import InstantMixButton from "@/components/buttons/instantMixButton";
|
||||
import PlayButton from "@/components/buttons/playButton";
|
||||
import { Card } from "@/components/card/card";
|
||||
import CardScroller from "@/components/cardScroller/cardScroller";
|
||||
@@ -186,6 +187,7 @@ function MusicAlbumTitlePage() {
|
||||
itemType={item.data.Type ?? "Audio"}
|
||||
userId={user?.Id}
|
||||
/>
|
||||
<InstantMixButton item={item.data} />
|
||||
<LikeButton
|
||||
itemId={item.data.Id}
|
||||
isFavorite={item.data.UserData?.IsFavorite}
|
||||
|
||||
@@ -21,6 +21,7 @@ import React, {
|
||||
} from "react";
|
||||
|
||||
import LikeButton from "@/components/buttons/likeButton";
|
||||
import InstantMixButton from "@/components/buttons/instantMixButton";
|
||||
import PlayButton from "@/components/buttons/playButton";
|
||||
import { Card } from "@/components/card/card";
|
||||
import ItemHeader from "@/components/itemHeader";
|
||||
@@ -276,6 +277,7 @@ function ArtistTitlePage() {
|
||||
</IconButton>
|
||||
</span>
|
||||
</Tooltip>
|
||||
<InstantMixButton item={item.data} />
|
||||
<LikeButton
|
||||
itemName={item.data.Name}
|
||||
itemId={item.data.Id}
|
||||
|
||||
@@ -15,16 +15,18 @@
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: rgba(0, 0, 0, 0.6); // Dark overlay
|
||||
backdrop-filter: blur(60px);
|
||||
-webkit-backdrop-filter: blur(60px);
|
||||
// No live backdrop-filter here: blurring a full-screen layer over a
|
||||
// repainting page made the whole player shimmer.
|
||||
background: rgba(0, 0, 0, 0.55);
|
||||
}
|
||||
|
||||
&-image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
transform: scale(1.1); // Prevent white edges from blur
|
||||
// Blur the image itself instead of the layer behind the page.
|
||||
filter: blur(70px) brightness(0.55) saturate(1.2);
|
||||
transform: scale(1.2); // Hide blurred edges
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,8 @@ import {
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { createFileRoute, Link, useNavigate } from "@tanstack/react-router";
|
||||
import React, { useEffect, useMemo, useState } from "react";
|
||||
import CastButton from "@/components/buttons/castButton";
|
||||
import InstantMixButton from "@/components/buttons/instantMixButton";
|
||||
import LikeButton from "@/components/buttons/likeButton";
|
||||
import LyricsPanel, {
|
||||
getLyricsQueryOptions,
|
||||
@@ -204,6 +206,8 @@ function AudioPlayerRoute() {
|
||||
</Typography>
|
||||
{item && <TrackSubtitle item={item} />}
|
||||
</div>
|
||||
{item && <InstantMixButton item={item} />}
|
||||
{item && <CastButton item={item} />}
|
||||
<LikeButton
|
||||
itemId={item?.Id ?? undefined}
|
||||
itemName={item?.Name}
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
import type { Api } from "@jellyfin/sdk";
|
||||
import {
|
||||
type BaseItemDto,
|
||||
BaseItemKind,
|
||||
ItemFields,
|
||||
} from "@jellyfin/sdk/lib/generated-client";
|
||||
import { getInstantMixApi } from "@jellyfin/sdk/lib/utils/api/instant-mix-api";
|
||||
import { playItemFromQueue } from "@/utils/store/playback";
|
||||
import { setQueue } from "@/utils/store/queue";
|
||||
|
||||
export type InstantMixResult = {
|
||||
count: number;
|
||||
};
|
||||
|
||||
/**
|
||||
* Start a Jellyfin "Instant Mix" (radio) from any music item: track, album,
|
||||
* artist, playlist or genre. Fetches the mix, replaces the queue and plays it.
|
||||
*/
|
||||
export const startInstantMix = async (
|
||||
api: Api | undefined,
|
||||
userId: string | undefined,
|
||||
item: BaseItemDto | undefined | null,
|
||||
): Promise<InstantMixResult> => {
|
||||
if (!api) throw new Error("API is not available");
|
||||
if (!userId) throw new Error("User is not available");
|
||||
if (!item?.Id) throw new Error("Item is not available");
|
||||
|
||||
const params = {
|
||||
userId,
|
||||
limit: 50,
|
||||
fields: [ItemFields.MediaSources],
|
||||
enableImages: true,
|
||||
enableUserData: true,
|
||||
};
|
||||
|
||||
const mixApi = getInstantMixApi(api);
|
||||
let response;
|
||||
|
||||
switch (item.Type) {
|
||||
case BaseItemKind.MusicAlbum:
|
||||
response = await mixApi.getInstantMixFromAlbum({
|
||||
itemId: item.Id,
|
||||
...params,
|
||||
});
|
||||
break;
|
||||
case BaseItemKind.MusicArtist:
|
||||
response = await mixApi.getInstantMixFromArtists({
|
||||
itemId: item.Id,
|
||||
...params,
|
||||
});
|
||||
break;
|
||||
case BaseItemKind.Audio:
|
||||
case BaseItemKind.AudioBook:
|
||||
response = await mixApi.getInstantMixFromSong({
|
||||
itemId: item.Id,
|
||||
...params,
|
||||
});
|
||||
break;
|
||||
case BaseItemKind.Playlist:
|
||||
response = await mixApi.getInstantMixFromPlaylist({
|
||||
itemId: item.Id,
|
||||
...params,
|
||||
});
|
||||
break;
|
||||
case BaseItemKind.MusicGenre:
|
||||
case BaseItemKind.Genre:
|
||||
response = await mixApi.getInstantMixFromMusicGenreById({
|
||||
id: item.Id,
|
||||
...params,
|
||||
});
|
||||
break;
|
||||
default:
|
||||
response = await mixApi.getInstantMixFromItem({
|
||||
itemId: item.Id,
|
||||
...params,
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
const tracks = (response.data.Items ?? []).filter(
|
||||
(track) => track.Id && track.Type !== BaseItemKind.Folder,
|
||||
);
|
||||
if (tracks.length === 0) {
|
||||
return { count: 0 };
|
||||
}
|
||||
|
||||
setQueue(tracks, 0);
|
||||
await playItemFromQueue(0, userId, api);
|
||||
return { count: tracks.length };
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
import type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client";
|
||||
import { create } from "zustand";
|
||||
|
||||
type RemoteControlState = {
|
||||
open: boolean;
|
||||
/** Item to offer for "Play on ..." when the dialog is opened from a player. */
|
||||
item: BaseItemDto | null;
|
||||
openDialog: (item?: BaseItemDto | null) => void;
|
||||
closeDialog: () => void;
|
||||
};
|
||||
|
||||
const useRemoteControlStore = create<RemoteControlState>((set) => ({
|
||||
open: false,
|
||||
item: null,
|
||||
openDialog: (item = null) => set({ open: true, item: item ?? null }),
|
||||
closeDialog: () => set({ open: false, item: null }),
|
||||
}));
|
||||
|
||||
export default useRemoteControlStore;
|
||||
Reference in new issue
Block a user