feat: shuffle, repeat and volume for remote playback
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

Use SendFullGeneralCommand with SetShuffleQueue, SetRepeatMode and SetVolume,
reflecting PlayState.PlaybackOrder/RepeatMode/VolumeLevel. The media bar now
shows these controls in remote mode like it does locally.
This commit is contained in:
1xDed committed 2026-11-27 17:56:34 +03:00
1 parent 5994b94406
commit c80d13744d
1 file changed
+144 -50
+144 -50
View File
@@ -2,7 +2,10 @@ import type {
BaseItemDto,
SessionInfoDto,
} from "@jellyfin/sdk/lib/generated-client";
import { PlaystateCommand } from "@jellyfin/sdk/lib/generated-client";
import {
GeneralCommandType,
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";
@@ -77,6 +80,10 @@ const AudioPlayer = () => {
const [progress, setProgress] = useState(0);
const [selectedRemoteId, setSelectedRemoteId] = useState<string | null>(null);
const [moreAnchor, setMoreAnchor] = useState<HTMLElement | null>(null);
const [remoteVolumeDraft, setRemoteVolumeDraft] = useState<number | null>(
null,
);
useEffect(() => setRemoteVolumeDraft(null), [selectedRemoteId]);
const sessions = useQuery({
queryKey: ["remoteSessions"],
@@ -136,6 +143,14 @@ const AudioPlayer = () => {
const isPlaying = remote
? !remote.PlayState?.IsPaused
: playing;
const remoteRepeat = remote?.PlayState?.RepeatMode ?? "RepeatNone";
const remoteShuffled = remote?.PlayState?.PlaybackOrder === "Shuffle";
const remoteVolume =
remoteVolumeDraft ??
(remote?.PlayState?.VolumeLevel != null
? remote.PlayState.VolumeLevel / 100
: 1);
const remoteMuted = remote?.PlayState?.IsMuted ?? false;
const displayProgress = remote
? (remote.PlayState?.PositionTicks ?? 0)
: progress;
@@ -366,8 +381,60 @@ const AudioPlayer = () => {
if (remote) remoteCommand(PlaystateCommand.PreviousTrack);
else if (api && user?.Id) playItemFromQueue("previous", user.Id, api);
};
const handleShuffle = () => shuffleUpcoming();
const handleRepeat = () => cycleRepeatMode();
const sendGeneral = async (
name: GeneralCommandType,
args?: Record<string, string>,
) => {
if (!api || !remote?.Id) return;
try {
await getSessionApi(api).sendFullGeneralCommand({
sessionId: remote.Id,
generalCommand: {
Name: name,
Arguments: args,
ControllingUserId: user?.Id,
},
});
await sessions.refetch();
} catch (error) {
console.error("Remote general command failed", error);
enqueueSnackbar("Remote command failed", { variant: "error" });
}
};
const handleShuffle = () => {
if (remote) {
sendGeneral(GeneralCommandType.SetShuffleQueue, {
ShuffleMode: remoteShuffled ? "Sorted" : "Shuffle",
});
} else {
shuffleUpcoming();
}
};
const handleRepeat = () => {
if (remote) {
const next =
remoteRepeat === "RepeatNone"
? "RepeatAll"
: remoteRepeat === "RepeatAll"
? "RepeatOne"
: "RepeatNone";
sendGeneral(GeneralCommandType.SetRepeatMode, { RepeatMode: next });
} else {
cycleRepeatMode();
}
};
const handleMute = () => {
if (remote) {
sendGeneral(
remoteMuted
? GeneralCommandType.Unmute
: GeneralCommandType.Mute,
);
} else {
handleMuteToggle();
}
};
const handleRemoteSeek = (ticks: number) => {
remoteCommand(PlaystateCommand.Seek, Math.round(ticks));
};
@@ -454,13 +521,15 @@ const AudioPlayer = () => {
<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>
)}
<Tooltip title="Shuffle">
<IconButton
size="small"
onClick={handleShuffle}
className={(remote ? remoteShuffled : false) ? "active" : ""}
>
<span className="material-symbols-rounded">shuffle</span>
</IconButton>
</Tooltip>
<IconButton size="small" onClick={handlePrevious}>
<span className="material-symbols-rounded">skip_previous</span>
</IconButton>
@@ -479,27 +548,37 @@ const AudioPlayer = () => {
<IconButton size="small" onClick={handleNext}>
<span className="material-symbols-rounded">skip_next</span>
</IconButton>
{!remote && (
<Tooltip
title={
repeatMode === "off"
<Tooltip
title={
remote
? remoteRepeat === "RepeatNone"
? "Repeat off"
: remoteRepeat === "RepeatAll"
? "Repeat all"
: "Repeat one"
: repeatMode === "off"
? "Repeat off"
: repeatMode === "all"
? "Repeat all"
: "Repeat one"
}
>
<IconButton
size="small"
onClick={handleRepeat}
className={
(remote ? remoteRepeat !== "RepeatNone" : repeatMode !== "off")
? "active"
: ""
}
>
<IconButton
size="small"
onClick={handleRepeat}
className={repeatMode !== "off" ? "active" : ""}
>
<span className="material-symbols-rounded">
{repeatMode === "one" ? "repeat_one" : "repeat"}
</span>
</IconButton>
</Tooltip>
)}
<span className="material-symbols-rounded">
{(remote ? remoteRepeat === "RepeatOne" : repeatMode === "one")
? "repeat_one"
: "repeat"}
</span>
</IconButton>
</Tooltip>
</div>
<PlayerProgress
className="media-bar-progress"
@@ -510,7 +589,7 @@ const AudioPlayer = () => {
</div>
<div className="media-bar-right">
{remote ? (
{remote && (
<Tooltip title="Transfer to this device">
<IconButton
size="small"
@@ -522,31 +601,46 @@ const AudioPlayer = () => {
</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);
}}
/>
</>
)}
{!remote && <QueueButton />}
<Tooltip title={remote ? (remoteMuted ? "Unmute" : "Mute") : (isMuted ? "Unmute" : "Mute")}>
<IconButton size="small" onClick={handleMute}>
<span className="material-symbols-rounded">
{remote
? remoteMuted || remoteVolume === 0
? "volume_off"
: "volume_up"
: isMuted || volume === 0
? "volume_off"
: "volume_up"}
</span>
</IconButton>
</Tooltip>
<Slider
size="small"
className="media-bar-volume"
value={remote ? (remoteMuted ? 0 : remoteVolume) : isMuted ? 0 : volume}
min={0}
max={1}
step={0.01}
aria-label="Volume"
onChange={(_, value) => {
const next = Array.isArray(value) ? value[0] : value;
if (remote) {
setRemoteVolumeDraft(next);
} else {
handleVolumeChange(next);
}
}}
onChangeCommitted={(_, value) => {
if (!remote) return;
const next = Array.isArray(value) ? value[0] : value;
setRemoteVolumeDraft(null);
sendGeneral(GeneralCommandType.SetVolume, {
Volume: String(Math.round(next * 100)),
});
}}
/>
<DeviceMenu
sessions={remoteSessions}
activeRemoteId={remote?.Id ?? null}