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
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:
1 parent
5994b94406
commit
c80d13744d
1 file changed
+144
-50
@@ -2,7 +2,10 @@ import type {
|
|||||||
BaseItemDto,
|
BaseItemDto,
|
||||||
SessionInfoDto,
|
SessionInfoDto,
|
||||||
} from "@jellyfin/sdk/lib/generated-client";
|
} 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 { getSessionApi } from "@jellyfin/sdk/lib/utils/api/session-api";
|
||||||
import Divider from "@mui/material/Divider";
|
import Divider from "@mui/material/Divider";
|
||||||
import IconButton from "@mui/material/IconButton";
|
import IconButton from "@mui/material/IconButton";
|
||||||
@@ -77,6 +80,10 @@ const AudioPlayer = () => {
|
|||||||
const [progress, setProgress] = useState(0);
|
const [progress, setProgress] = useState(0);
|
||||||
const [selectedRemoteId, setSelectedRemoteId] = useState<string | null>(null);
|
const [selectedRemoteId, setSelectedRemoteId] = useState<string | null>(null);
|
||||||
const [moreAnchor, setMoreAnchor] = useState<HTMLElement | null>(null);
|
const [moreAnchor, setMoreAnchor] = useState<HTMLElement | null>(null);
|
||||||
|
const [remoteVolumeDraft, setRemoteVolumeDraft] = useState<number | null>(
|
||||||
|
null,
|
||||||
|
);
|
||||||
|
useEffect(() => setRemoteVolumeDraft(null), [selectedRemoteId]);
|
||||||
|
|
||||||
const sessions = useQuery({
|
const sessions = useQuery({
|
||||||
queryKey: ["remoteSessions"],
|
queryKey: ["remoteSessions"],
|
||||||
@@ -136,6 +143,14 @@ const AudioPlayer = () => {
|
|||||||
const isPlaying = remote
|
const isPlaying = remote
|
||||||
? !remote.PlayState?.IsPaused
|
? !remote.PlayState?.IsPaused
|
||||||
: playing;
|
: 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
|
const displayProgress = remote
|
||||||
? (remote.PlayState?.PositionTicks ?? 0)
|
? (remote.PlayState?.PositionTicks ?? 0)
|
||||||
: progress;
|
: progress;
|
||||||
@@ -366,8 +381,60 @@ const AudioPlayer = () => {
|
|||||||
if (remote) remoteCommand(PlaystateCommand.PreviousTrack);
|
if (remote) remoteCommand(PlaystateCommand.PreviousTrack);
|
||||||
else if (api && user?.Id) playItemFromQueue("previous", user.Id, api);
|
else if (api && user?.Id) playItemFromQueue("previous", user.Id, api);
|
||||||
};
|
};
|
||||||
const handleShuffle = () => shuffleUpcoming();
|
const sendGeneral = async (
|
||||||
const handleRepeat = () => cycleRepeatMode();
|
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) => {
|
const handleRemoteSeek = (ticks: number) => {
|
||||||
remoteCommand(PlaystateCommand.Seek, Math.round(ticks));
|
remoteCommand(PlaystateCommand.Seek, Math.round(ticks));
|
||||||
};
|
};
|
||||||
@@ -454,13 +521,15 @@ const AudioPlayer = () => {
|
|||||||
|
|
||||||
<div className="media-bar-center">
|
<div className="media-bar-center">
|
||||||
<div className="media-bar-controls">
|
<div className="media-bar-controls">
|
||||||
{!remote && (
|
<Tooltip title="Shuffle">
|
||||||
<Tooltip title="Shuffle">
|
<IconButton
|
||||||
<IconButton size="small" onClick={handleShuffle}>
|
size="small"
|
||||||
<span className="material-symbols-rounded">shuffle</span>
|
onClick={handleShuffle}
|
||||||
</IconButton>
|
className={(remote ? remoteShuffled : false) ? "active" : ""}
|
||||||
</Tooltip>
|
>
|
||||||
)}
|
<span className="material-symbols-rounded">shuffle</span>
|
||||||
|
</IconButton>
|
||||||
|
</Tooltip>
|
||||||
<IconButton size="small" onClick={handlePrevious}>
|
<IconButton size="small" onClick={handlePrevious}>
|
||||||
<span className="material-symbols-rounded">skip_previous</span>
|
<span className="material-symbols-rounded">skip_previous</span>
|
||||||
</IconButton>
|
</IconButton>
|
||||||
@@ -479,27 +548,37 @@ const AudioPlayer = () => {
|
|||||||
<IconButton size="small" onClick={handleNext}>
|
<IconButton size="small" onClick={handleNext}>
|
||||||
<span className="material-symbols-rounded">skip_next</span>
|
<span className="material-symbols-rounded">skip_next</span>
|
||||||
</IconButton>
|
</IconButton>
|
||||||
{!remote && (
|
<Tooltip
|
||||||
<Tooltip
|
title={
|
||||||
title={
|
remote
|
||||||
repeatMode === "off"
|
? remoteRepeat === "RepeatNone"
|
||||||
|
? "Repeat off"
|
||||||
|
: remoteRepeat === "RepeatAll"
|
||||||
|
? "Repeat all"
|
||||||
|
: "Repeat one"
|
||||||
|
: repeatMode === "off"
|
||||||
? "Repeat off"
|
? "Repeat off"
|
||||||
: repeatMode === "all"
|
: repeatMode === "all"
|
||||||
? "Repeat all"
|
? "Repeat all"
|
||||||
: "Repeat one"
|
: "Repeat one"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<IconButton
|
||||||
|
size="small"
|
||||||
|
onClick={handleRepeat}
|
||||||
|
className={
|
||||||
|
(remote ? remoteRepeat !== "RepeatNone" : repeatMode !== "off")
|
||||||
|
? "active"
|
||||||
|
: ""
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<IconButton
|
<span className="material-symbols-rounded">
|
||||||
size="small"
|
{(remote ? remoteRepeat === "RepeatOne" : repeatMode === "one")
|
||||||
onClick={handleRepeat}
|
? "repeat_one"
|
||||||
className={repeatMode !== "off" ? "active" : ""}
|
: "repeat"}
|
||||||
>
|
</span>
|
||||||
<span className="material-symbols-rounded">
|
</IconButton>
|
||||||
{repeatMode === "one" ? "repeat_one" : "repeat"}
|
</Tooltip>
|
||||||
</span>
|
|
||||||
</IconButton>
|
|
||||||
</Tooltip>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
<PlayerProgress
|
<PlayerProgress
|
||||||
className="media-bar-progress"
|
className="media-bar-progress"
|
||||||
@@ -510,7 +589,7 @@ const AudioPlayer = () => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="media-bar-right">
|
<div className="media-bar-right">
|
||||||
{remote ? (
|
{remote && (
|
||||||
<Tooltip title="Transfer to this device">
|
<Tooltip title="Transfer to this device">
|
||||||
<IconButton
|
<IconButton
|
||||||
size="small"
|
size="small"
|
||||||
@@ -522,31 +601,46 @@ const AudioPlayer = () => {
|
|||||||
</span>
|
</span>
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</Tooltip>
|
</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
|
<DeviceMenu
|
||||||
sessions={remoteSessions}
|
sessions={remoteSessions}
|
||||||
activeRemoteId={remote?.Id ?? null}
|
activeRemoteId={remote?.Id ?? null}
|
||||||
|
|||||||
Reference in new issue
Block a user