feat: implement proper queue functionality and improve upnext flyout and skip segment buttons
This commit is contained in:
10 files changed
+1019
-597
No files matched your search
@@ -1,7 +1,6 @@
|
||||
import {
|
||||
type BaseItemDto,
|
||||
BaseItemKind,
|
||||
PlayMethod,
|
||||
} from "@jellyfin/sdk/lib/generated-client";
|
||||
import { getTvShowsApi } from "@jellyfin/sdk/lib/utils/api/tv-shows-api";
|
||||
import type { SxProps } from "@mui/material";
|
||||
@@ -15,13 +14,11 @@ import { useSnackbar } from "notistack";
|
||||
import React, { type MouseEvent, memo } from "react"; // Import memo
|
||||
import type PlayResult from "@//utils/types/playResult";
|
||||
import { getRuntimeCompact } from "@/utils/date/time";
|
||||
import getSubtitle from "@/utils/methods/getSubtitles";
|
||||
import { getNextEpisode, getPlaybackInfo } from "@/utils/methods/playback";
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import { generateAudioStreamUrl, playAudio } from "@/utils/store/audioPlayback";
|
||||
import { useCentralStore } from "@/utils/store/central";
|
||||
import { usePhotosPlayback } from "@/utils/store/photosPlayback";
|
||||
import { playItem } from "@/utils/store/playback";
|
||||
import { initializePlayback } from "@/utils/store/playback";
|
||||
import { setQueue } from "@/utils/store/queue";
|
||||
|
||||
type PlayButtonProps = {
|
||||
@@ -86,7 +83,6 @@ const PlayButton = ({
|
||||
// (state) => state.setisPending,
|
||||
// );
|
||||
const playPhotos = usePhotosPlayback((s) => s.playPhotos);
|
||||
const currentUser = useCentralStore((s) => s.currentUser);
|
||||
|
||||
const { enqueueSnackbar } = useSnackbar();
|
||||
|
||||
@@ -157,149 +153,29 @@ const PlayButton = ({
|
||||
return;
|
||||
}
|
||||
const episodeIndex = result.episodeIndex;
|
||||
const queue = result?.item?.Items ?? [];
|
||||
|
||||
// Creates a queue containing all Episodes for a particular season(series) or collection of movies
|
||||
const queue = result?.item?.Items;
|
||||
|
||||
let itemName = item.Name;
|
||||
let episodeTitle = "";
|
||||
if (result?.item?.Items?.[episodeIndex].SeriesId) {
|
||||
itemName = result?.item.Items[episodeIndex].SeriesName;
|
||||
episodeTitle = `S${result?.item.Items[episodeIndex].ParentIndexNumber ?? 0}:E${
|
||||
result?.item.Items[episodeIndex].IndexNumber ?? 0
|
||||
} ${result?.item.Items[episodeIndex].Name}`;
|
||||
}
|
||||
|
||||
if (itemType === "BoxSet") {
|
||||
itemName = result.item.Items[0].Name;
|
||||
}
|
||||
|
||||
// Subtitle
|
||||
const userSubtitleLanguagePreference =
|
||||
currentUser?.Configuration?.SubtitleLanguagePreference;
|
||||
// Get all subtitle streams
|
||||
const allSubtitles =
|
||||
result?.mediaSource?.MediaSources?.[0]?.MediaStreams?.filter(
|
||||
(stream) => stream.Type === "Subtitle",
|
||||
);
|
||||
// Find preferred subtitle based on user's language preference
|
||||
const preferredSubtitle =
|
||||
allSubtitles?.find(
|
||||
(sub) => sub.Language === userSubtitleLanguagePreference,
|
||||
) || null;
|
||||
|
||||
const subtitle = getSubtitle(
|
||||
preferredSubtitle?.Index ??
|
||||
result.mediaSource.MediaSources?.[0].DefaultSubtitleStreamIndex ??
|
||||
-1,
|
||||
result?.mediaSource?.MediaSources?.[0]?.MediaStreams,
|
||||
);
|
||||
|
||||
// Audio
|
||||
const userAudioLanguagePreference =
|
||||
currentUser?.Configuration?.AudioLanguagePreference;
|
||||
// Get all audio streams
|
||||
const allAudioTracks =
|
||||
result.mediaSource.MediaSources?.[0].MediaStreams?.filter(
|
||||
(value) => value.Type === "Audio",
|
||||
);
|
||||
// Find preferred audio track based on user's language preference
|
||||
const preferredAudioTrack =
|
||||
allAudioTracks?.find(
|
||||
(track) => track.Language === userAudioLanguagePreference,
|
||||
) ||
|
||||
allAudioTracks?.find((track) => track.IsDefault) ||
|
||||
allAudioTracks?.[0];
|
||||
|
||||
const audio = {
|
||||
track:
|
||||
preferredAudioTrack?.Index ??
|
||||
result.mediaSource.MediaSources?.[0].DefaultAudioStreamIndex ??
|
||||
0,
|
||||
allTracks: allAudioTracks,
|
||||
};
|
||||
|
||||
// URL generation
|
||||
const urlOptions: URLSearchParams = {
|
||||
//@ts-expect-error
|
||||
Static: true,
|
||||
tag: result?.mediaSource.MediaSources?.[0].ETag,
|
||||
mediaSourceId: result?.mediaSource.MediaSources?.[0].Id,
|
||||
deviceId: api?.deviceInfo.id,
|
||||
api_key: api?.accessToken,
|
||||
};
|
||||
const urlParams = new URLSearchParams(urlOptions).toString();
|
||||
let playbackUrl = `${api?.basePath}/Videos/${result?.mediaSource.MediaSources?.[0].Id}/stream.${result?.mediaSource.MediaSources?.[0].Container}?${urlParams}`;
|
||||
|
||||
const source = result.mediaSource.MediaSources?.[0];
|
||||
let playMethod = PlayMethod.Transcode;
|
||||
if (source?.SupportsDirectPlay) {
|
||||
playMethod = PlayMethod.DirectPlay;
|
||||
} else if (source?.SupportsDirectStream) {
|
||||
playMethod = PlayMethod.DirectStream;
|
||||
}
|
||||
|
||||
if (
|
||||
playMethod === PlayMethod.Transcode &&
|
||||
result?.mediaSource.MediaSources?.[0].TranscodingUrl
|
||||
) {
|
||||
playbackUrl = `${api.basePath}${result.mediaSource.MediaSources[0].TranscodingUrl}`;
|
||||
}
|
||||
let playItemValue = result?.item?.Items?.[episodeIndex];
|
||||
let playItemValue = queue[episodeIndex];
|
||||
if (itemType === BaseItemKind.Movie) {
|
||||
playItemValue = result?.item?.Items?.[0];
|
||||
playItemValue = queue[0];
|
||||
}
|
||||
|
||||
const startPosition =
|
||||
result?.item?.Items?.[episodeIndex].UserData?.PlaybackPositionTicks;
|
||||
if (!playItemValue) {
|
||||
console.error("No item to play found");
|
||||
return;
|
||||
}
|
||||
|
||||
const videoTrack =
|
||||
result.mediaSource.MediaSources?.[0].MediaStreams?.filter(
|
||||
(value) => value.Type === "Video",
|
||||
);
|
||||
const startPosition = playItemValue.UserData?.PlaybackPositionTicks;
|
||||
|
||||
playItem({
|
||||
metadata: {
|
||||
itemName: itemName ?? "",
|
||||
episodeTitle: episodeTitle,
|
||||
isEpisode: !!item.SeriesId,
|
||||
itemDuration: playItemValue?.RunTimeTicks ?? item.RunTimeTicks ?? 0,
|
||||
item: playItemValue ?? item,
|
||||
mediaSegments: result.mediaSegments,
|
||||
userDataLastPlayedPositionTicks: startPosition ?? 0,
|
||||
},
|
||||
mediaSource: {
|
||||
videoTrack: videoTrack?.[0]?.Index ?? 0,
|
||||
audioTrack: audio.track,
|
||||
container: result.mediaSource.MediaSources?.[0].Container ?? "",
|
||||
id: result.mediaSource.MediaSources?.[0]?.Id,
|
||||
subtitle: {
|
||||
url: subtitle?.url,
|
||||
track: subtitle?.track ?? -1,
|
||||
format: subtitle?.format ?? "nosub",
|
||||
allTracks:
|
||||
result.mediaSource.MediaSources?.[0].MediaStreams?.filter(
|
||||
(value) => value.Type === "Subtitle",
|
||||
),
|
||||
enable: subtitle?.enable ?? false,
|
||||
},
|
||||
audio: audio,
|
||||
bitrate: result.mediaSource.MediaSources?.[0].Bitrate ?? 0,
|
||||
videoCodec: videoTrack?.[0]?.Codec ?? "",
|
||||
audioCodec:
|
||||
audio.allTracks?.find((t) => t.Index === audio.track)?.Codec ??
|
||||
"",
|
||||
playMethod: playMethod,
|
||||
transcodingUrl:
|
||||
result.mediaSource.MediaSources?.[0].TranscodingUrl ?? "",
|
||||
},
|
||||
playbackStream: playbackUrl,
|
||||
playsessionId: result.mediaSource.PlaySessionId,
|
||||
userDataPlayedPositionTicks:
|
||||
item.UserData?.PlaybackPositionTicks ?? 0,
|
||||
initializePlayback({
|
||||
api,
|
||||
userId,
|
||||
queueItems: queue ?? [],
|
||||
queueItemIndex: episodeIndex,
|
||||
item: playItemValue,
|
||||
mediaSource: result.mediaSource,
|
||||
mediaSegments: result.mediaSegments,
|
||||
queueItems: queue,
|
||||
queueIndex: episodeIndex,
|
||||
startPositionTicks: startPosition,
|
||||
});
|
||||
navigate({ to: "/player" });
|
||||
}
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
$image-size: 5em;
|
||||
|
||||
.queue{
|
||||
&-item{
|
||||
--image-size: 5em;
|
||||
&.episode {
|
||||
--image-size: 8em !important;
|
||||
}
|
||||
width: 32em;
|
||||
padding: 1em;
|
||||
display: grid !important;
|
||||
opacity: 1 !important;
|
||||
gap: 1em;
|
||||
height: 5em;
|
||||
grid-template-columns: 3em $image-size 1fr;
|
||||
grid-template-columns: 3em var(--image-size) 1fr;
|
||||
justify-items: center;
|
||||
align-items: center;
|
||||
&-image{
|
||||
@@ -25,6 +27,7 @@ $image-size: 5em;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
position: relative;
|
||||
width: var(--image-size);
|
||||
}
|
||||
&-icon {
|
||||
width: 100%;
|
||||
@@ -51,5 +54,6 @@ $image-size: 5em;
|
||||
.queue-item-image,.queue-item-image-icon{
|
||||
opacity: 0.5 !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,288 +1,373 @@
|
||||
import { playItemFromQueue } from "@/utils/store/playback";
|
||||
import useQueue from "@/utils/store/queue";
|
||||
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
||||
import {
|
||||
Box,
|
||||
Drawer,
|
||||
IconButton,
|
||||
Menu,
|
||||
MenuItem,
|
||||
MenuList,
|
||||
List,
|
||||
Tooltip,
|
||||
Typography,
|
||||
} from "@mui/material";
|
||||
import React, { useState } from "react";
|
||||
import { getTypeIcon } from "../utils/iconsCollection";
|
||||
|
||||
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
||||
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import React, { useMemo, useState } from "react";
|
||||
import { playItemFromQueue } from "@/utils/store/playback";
|
||||
import useQueue, {
|
||||
clearUpcoming,
|
||||
removeFromQueue,
|
||||
reorderQueue,
|
||||
shuffleUpcoming,
|
||||
} from "@/utils/store/queue";
|
||||
import "./queueButton.scss";
|
||||
import getImageUrlsApi from "@/utils/methods/getImageUrlsApi";
|
||||
import {
|
||||
closestCenter,
|
||||
DndContext,
|
||||
type DragEndEvent,
|
||||
KeyboardSensor,
|
||||
PointerSensor,
|
||||
useSensor,
|
||||
useSensors,
|
||||
} from "@dnd-kit/core";
|
||||
import { restrictToVerticalAxis } from "@dnd-kit/modifiers";
|
||||
import {
|
||||
arrayMove,
|
||||
SortableContext,
|
||||
sortableKeyboardCoordinates,
|
||||
useSortable,
|
||||
verticalListSortingStrategy,
|
||||
} from "@dnd-kit/sortable";
|
||||
import { CSS } from "@dnd-kit/utilities";
|
||||
import type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client";
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
const QueueButton = () => {
|
||||
const api = useApiInContext((s) => s.api);
|
||||
import QueueListItem from "../queueListItem";
|
||||
|
||||
const [queueItems, currentItemIndex] = useQueue((state) => [
|
||||
state.tracks,
|
||||
state.currentItemIndex,
|
||||
]);
|
||||
function SortableQueueItem({
|
||||
item,
|
||||
onDelete,
|
||||
onPlay,
|
||||
index,
|
||||
}: {
|
||||
item: BaseItemDto;
|
||||
onDelete: () => void;
|
||||
onPlay: () => void;
|
||||
index: number;
|
||||
}) {
|
||||
const {
|
||||
attributes,
|
||||
listeners,
|
||||
setNodeRef,
|
||||
transform,
|
||||
transition,
|
||||
isDragging,
|
||||
} = useSortable({ id: item.Id || "" });
|
||||
|
||||
const user = useQuery({
|
||||
queryKey: ["user"],
|
||||
queryFn: async () => {
|
||||
if (!api) return;
|
||||
const result = await getUserApi(api).getCurrentUser();
|
||||
return result.data;
|
||||
},
|
||||
});
|
||||
const [buttonEl, setButtonEl] = useState<HTMLButtonElement | null>(null);
|
||||
|
||||
const handlePlay = useMutation({
|
||||
mutationKey: ["handlePlayIndex"],
|
||||
mutationFn: async ({ index }: { index: number }) => {
|
||||
const result = playItemFromQueue(index, user.data?.Id, api);
|
||||
return result;
|
||||
},
|
||||
onSuccess: () => {
|
||||
setButtonEl(null);
|
||||
},
|
||||
onError: (error) => {
|
||||
console.error(error);
|
||||
},
|
||||
});
|
||||
const style = {
|
||||
transform: CSS.Transform.toString(transform),
|
||||
transition,
|
||||
opacity: isDragging ? 0.5 : 1,
|
||||
position: "relative" as const,
|
||||
zIndex: isDragging ? 2 : 1,
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Menu
|
||||
open={Boolean(buttonEl)}
|
||||
onClose={() => setButtonEl(null)}
|
||||
anchorEl={buttonEl}
|
||||
anchorOrigin={{
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
}}
|
||||
transformOrigin={{
|
||||
vertical: "bottom",
|
||||
horizontal: "center",
|
||||
}}
|
||||
slotProps={{
|
||||
paper: {
|
||||
style: {
|
||||
maxHeight: "30em",
|
||||
overflowX: "hidden",
|
||||
overflowY: "auto",
|
||||
},
|
||||
},
|
||||
}}
|
||||
>
|
||||
<MenuList
|
||||
style={{
|
||||
height: "fit-content",
|
||||
width: " 32em",
|
||||
position: "relative",
|
||||
}}
|
||||
>
|
||||
{queueItems?.[currentItemIndex]?.Id && (
|
||||
<>
|
||||
<Typography px="1em" mb={2} variant="h5" fontWeight={300}>
|
||||
Currently Playing:
|
||||
</Typography>
|
||||
<MenuItem
|
||||
className="queue-item"
|
||||
disabled
|
||||
key={queueItems[currentItemIndex].Id}
|
||||
<div ref={setNodeRef} style={style}>
|
||||
<QueueListItem
|
||||
queueItem={item}
|
||||
onDelete={onDelete}
|
||||
onPlay={onPlay}
|
||||
dragHandleProps={{ ...attributes, ...listeners }}
|
||||
isEpisode={item.Type === "Episode"}
|
||||
index={index}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const QueueButton = () => {
|
||||
const api = useApiInContext((s) => s.api);
|
||||
|
||||
const [queueItems, currentItemIndex] = useQueue((state) => [
|
||||
state.tracks,
|
||||
state.currentItemIndex,
|
||||
]);
|
||||
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
const user = useQuery({
|
||||
queryKey: ["currentUser"],
|
||||
queryFn: async () => {
|
||||
if (!api) throw new Error("API not available");
|
||||
return (await getUserApi(api).getCurrentUser()).data;
|
||||
},
|
||||
enabled: !!api,
|
||||
});
|
||||
|
||||
const sensors = useSensors(
|
||||
useSensor(PointerSensor),
|
||||
useSensor(KeyboardSensor, {
|
||||
coordinateGetter: sortableKeyboardCoordinates,
|
||||
}),
|
||||
);
|
||||
|
||||
const upcomingItems = useMemo(() => {
|
||||
return queueItems ? queueItems.slice(currentItemIndex + 1) : [];
|
||||
}, [queueItems, currentItemIndex]);
|
||||
|
||||
const upcomingIds = useMemo(() => {
|
||||
return upcomingItems.map((item) => item.Id || "");
|
||||
}, [upcomingItems]);
|
||||
|
||||
const handleDragEnd = (event: DragEndEvent) => {
|
||||
const { active, over } = event;
|
||||
|
||||
if (active.id !== over?.id && queueItems) {
|
||||
const oldIndex = upcomingItems.findIndex(
|
||||
(item) => item.Id === active.id,
|
||||
);
|
||||
const newIndex = upcomingItems.findIndex(
|
||||
(item) => item.Id === over?.id,
|
||||
);
|
||||
|
||||
if (oldIndex !== -1 && newIndex !== -1) {
|
||||
const newUpcoming = arrayMove(upcomingItems, oldIndex, newIndex);
|
||||
const newQueue = [
|
||||
...queueItems.slice(0, currentItemIndex + 1),
|
||||
...newUpcoming,
|
||||
];
|
||||
reorderQueue(newQueue);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const handleDelete = (index: number) => {
|
||||
removeFromQueue(index);
|
||||
};
|
||||
|
||||
const handlePlay = (index: number) => {
|
||||
playItemFromQueue(index, user.data?.Id, api);
|
||||
};
|
||||
|
||||
const handleClear = () => {
|
||||
clearUpcoming();
|
||||
};
|
||||
|
||||
const handleShuffle = () => {
|
||||
shuffleUpcoming();
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Drawer
|
||||
anchor="right"
|
||||
open={open}
|
||||
onClose={() => setOpen(false)}
|
||||
PaperProps={{
|
||||
sx: {
|
||||
width: 450,
|
||||
maxWidth: "100%",
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
bgcolor: "background.default",
|
||||
backgroundImage: "none",
|
||||
},
|
||||
}}
|
||||
>
|
||||
<Box
|
||||
p={3}
|
||||
display="flex"
|
||||
justifyContent="space-between"
|
||||
alignItems="center"
|
||||
sx={{
|
||||
position: "sticky",
|
||||
top: 0,
|
||||
zIndex: 20,
|
||||
bgcolor: "background.default",
|
||||
borderBottom: "1px solid",
|
||||
borderColor: "divider",
|
||||
}}
|
||||
>
|
||||
<Typography variant="subtitle2">
|
||||
{queueItems[currentItemIndex]?.Type === "Audio"
|
||||
? currentItemIndex + 1
|
||||
: queueItems[currentItemIndex].IndexNumberEnd
|
||||
? `S${queueItems[currentItemIndex].ParentIndexNumber}:E${queueItems[currentItemIndex].IndexNumber} / ${queueItems[currentItemIndex].IndexNumberEnd}`
|
||||
: `S${queueItems[currentItemIndex].ParentIndexNumber}:E${queueItems[currentItemIndex].IndexNumber}`}
|
||||
</Typography>
|
||||
<div className="queue-item-image-container">
|
||||
{queueItems[currentItemIndex].ImageTags?.Primary ? (
|
||||
<img
|
||||
className="queue-item-image"
|
||||
src={
|
||||
api &&
|
||||
getImageUrlsApi(api).getItemImageUrlById(
|
||||
queueItems[currentItemIndex]?.Id,
|
||||
"Primary",
|
||||
{
|
||||
tag: queueItems[currentItemIndex].ImageTags
|
||||
?.Primary,
|
||||
},
|
||||
)
|
||||
}
|
||||
alt={queueItems[currentItemIndex].Name ?? "image"}
|
||||
/>
|
||||
) : (queueItems[currentItemIndex].AlbumPrimaryImageTag
|
||||
?.length ?? -1) > 0 ? (
|
||||
<img
|
||||
className="queue-item-image"
|
||||
src={
|
||||
api &&
|
||||
getImageUrlsApi(api).getItemImageUrlById(
|
||||
queueItems?.[currentItemIndex]?.AlbumId ?? "",
|
||||
"Primary",
|
||||
{
|
||||
tag: queueItems?.[currentItemIndex]
|
||||
.AlbumPrimaryImageTag?.[0],
|
||||
},
|
||||
)
|
||||
}
|
||||
alt={queueItems[currentItemIndex].Name ?? "image"}
|
||||
/>
|
||||
) : (
|
||||
<div className="queue-item-image-icon">
|
||||
{queueItems[currentItemIndex].Type &&
|
||||
getTypeIcon(queueItems[currentItemIndex].Type)}
|
||||
</div>
|
||||
)}
|
||||
<span
|
||||
className="material-symbols-rounded"
|
||||
style={{
|
||||
position: "absolute",
|
||||
top: "50%",
|
||||
left: "50%",
|
||||
transform: "translate(-50%,-50%)",
|
||||
fontSize: "2em",
|
||||
//@ts-ignore
|
||||
"--wght": "100",
|
||||
<Box display="flex" alignItems="center" gap={1}>
|
||||
<Typography variant="h5" fontWeight="bold">
|
||||
Play Queue
|
||||
</Typography>
|
||||
<Typography
|
||||
variant="caption"
|
||||
color="text.secondary"
|
||||
sx={{
|
||||
ml: 1,
|
||||
fontWeight: 600,
|
||||
bgcolor: "action.hover",
|
||||
px: 1,
|
||||
py: 0.5,
|
||||
borderRadius: 2,
|
||||
}}
|
||||
>
|
||||
equalizer
|
||||
</span>
|
||||
</div>
|
||||
<div className="queue-item-info">
|
||||
{queueItems[currentItemIndex].SeriesName ? (
|
||||
<>
|
||||
<Typography variant="subtitle1" width="100%">
|
||||
{queueItems[currentItemIndex].SeriesName}
|
||||
</Typography>
|
||||
<Typography
|
||||
variant="subtitle2"
|
||||
width="100%"
|
||||
style={{ opacity: 0.6 }}
|
||||
>
|
||||
{queueItems[currentItemIndex].Name}
|
||||
</Typography>
|
||||
</>
|
||||
) : (
|
||||
<Typography variant="subtitle1" width="100%">
|
||||
{queueItems[currentItemIndex].Name}
|
||||
</Typography>
|
||||
)}
|
||||
</div>
|
||||
</MenuItem>
|
||||
</>
|
||||
)}
|
||||
{queueItems &&
|
||||
queueItems.slice(currentItemIndex + 1, queueItems.length - 1)
|
||||
.length > 0 && (
|
||||
<Typography px="1em" my={2} variant="h5" fontWeight={300}>
|
||||
Queue:
|
||||
</Typography>
|
||||
)}
|
||||
{queueItems
|
||||
?.slice(currentItemIndex + 1, queueItems.length - 1)
|
||||
.map((item, index) => {
|
||||
return (
|
||||
<MenuItem
|
||||
className="queue-item"
|
||||
onClick={() =>
|
||||
handlePlay.mutate({ index: index + currentItemIndex })
|
||||
}
|
||||
key={item.Id}
|
||||
>
|
||||
<Typography variant="subtitle2">
|
||||
{item.Type === "Audio"
|
||||
? index + 1
|
||||
: item.IndexNumberEnd
|
||||
? `S${item.ParentIndexNumber}:E${item.IndexNumber} / ${item.IndexNumberEnd}`
|
||||
: `S${item.ParentIndexNumber}:E${item.IndexNumber}`}
|
||||
{queueItems?.length || 0}
|
||||
</Typography>
|
||||
<div className="queue-item-image-container">
|
||||
{item.ImageTags?.Primary ? (
|
||||
<img
|
||||
className="queue-item-image"
|
||||
src={
|
||||
api &&
|
||||
getImageUrlsApi(api).getItemImageUrlById(
|
||||
item?.Id ?? "",
|
||||
"Primary",
|
||||
{
|
||||
tag: item.ImageTags?.Primary,
|
||||
},
|
||||
)
|
||||
}
|
||||
alt={item.Name ?? "image"}
|
||||
/>
|
||||
) : (item.AlbumPrimaryImageTag?.length ?? -1) > 0 ? (
|
||||
<img
|
||||
className="queue-item-image"
|
||||
src={
|
||||
api &&
|
||||
getImageUrlsApi(api).getItemImageUrlById(
|
||||
item?.AlbumId ?? "",
|
||||
"Primary",
|
||||
{
|
||||
tag: item.AlbumPrimaryImageTag?.[0],
|
||||
},
|
||||
)
|
||||
}
|
||||
alt={item.Name ?? "image"}
|
||||
/>
|
||||
) : (
|
||||
<div className="queue-item-image-icon">
|
||||
{item.Type && getTypeIcon(item.Type)}
|
||||
</div>
|
||||
</Box>
|
||||
<Box display="flex" gap={0.5}>
|
||||
<Tooltip title="Shuffle Upcoming">
|
||||
<span>
|
||||
<IconButton
|
||||
onClick={handleShuffle}
|
||||
size="small"
|
||||
disabled={upcomingItems.length < 2}
|
||||
>
|
||||
<span className="material-symbols-rounded">
|
||||
shuffle
|
||||
</span>
|
||||
</IconButton>
|
||||
</span>
|
||||
</Tooltip>
|
||||
<Tooltip title="Clear Upcoming">
|
||||
<span>
|
||||
<IconButton
|
||||
onClick={handleClear}
|
||||
size="small"
|
||||
disabled={upcomingItems.length === 0}
|
||||
>
|
||||
<span className="material-symbols-rounded">
|
||||
clear_all
|
||||
</span>
|
||||
</IconButton>
|
||||
</span>
|
||||
</Tooltip>
|
||||
<IconButton onClick={() => setOpen(false)} size="small">
|
||||
<span className="material-symbols-rounded">close</span>
|
||||
</IconButton>
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
<Box
|
||||
sx={{
|
||||
overflowY: "auto",
|
||||
flex: 1,
|
||||
p: 2,
|
||||
"&::-webkit-scrollbar": { width: 8 },
|
||||
"&::-webkit-scrollbar-track": { background: "transparent" },
|
||||
"&::-webkit-scrollbar-thumb": {
|
||||
background: "rgba(128,128,128,0.2)",
|
||||
borderRadius: 4,
|
||||
},
|
||||
"&::-webkit-scrollbar-thumb:hover": {
|
||||
background: "rgba(128,128,128,0.3)",
|
||||
},
|
||||
}}
|
||||
>
|
||||
{queueItems && queueItems.length > 0 ? (
|
||||
<List disablePadding>
|
||||
{/* Current Item */}
|
||||
{queueItems[currentItemIndex] && (
|
||||
<Box sx={{ mb: 4 }}>
|
||||
<Typography
|
||||
variant="overline"
|
||||
sx={{
|
||||
display: "block",
|
||||
opacity: 0.6,
|
||||
mb: 1,
|
||||
fontWeight: 600,
|
||||
letterSpacing: 1.2,
|
||||
}}
|
||||
>
|
||||
NOW PLAYING
|
||||
</Typography>
|
||||
<Box
|
||||
sx={{
|
||||
bgcolor: "background.paper",
|
||||
borderRadius: 3,
|
||||
overflow: "hidden",
|
||||
boxShadow: 4,
|
||||
border: "1px solid",
|
||||
borderColor: "divider",
|
||||
}}
|
||||
>
|
||||
<QueueListItem
|
||||
queueItem={queueItems[currentItemIndex]}
|
||||
active={true}
|
||||
isEpisode={
|
||||
queueItems[currentItemIndex].Type === "Episode"
|
||||
}
|
||||
index={currentItemIndex + 1}
|
||||
/>
|
||||
</Box>
|
||||
</Box>
|
||||
)}
|
||||
</div>
|
||||
<div className="queue-item-info">
|
||||
{item.SeriesName ? (
|
||||
|
||||
{/* Upcoming Items */}
|
||||
{upcomingItems.length > 0 && (
|
||||
<>
|
||||
<Typography
|
||||
variant="subtitle1"
|
||||
width="100%"
|
||||
sx={{ overflow: "hidden", textOverflow: "ellipsis" }}
|
||||
variant="overline"
|
||||
sx={{
|
||||
display: "block",
|
||||
opacity: 0.6,
|
||||
mb: 1,
|
||||
fontWeight: 600,
|
||||
letterSpacing: 1.2,
|
||||
}}
|
||||
>
|
||||
{item.SeriesName}
|
||||
NEXT UP
|
||||
</Typography>
|
||||
<Typography
|
||||
variant="subtitle2"
|
||||
width="100%"
|
||||
style={{ opacity: 0.6 }}
|
||||
<DndContext
|
||||
sensors={sensors}
|
||||
collisionDetection={closestCenter}
|
||||
onDragEnd={handleDragEnd}
|
||||
modifiers={[restrictToVerticalAxis]}
|
||||
>
|
||||
{item.Name}
|
||||
</Typography>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Typography
|
||||
variant="subtitle1"
|
||||
width="100%"
|
||||
sx={{ overflow: "hidden", textOverflow: "ellipsis" }}
|
||||
>
|
||||
{item.Name}
|
||||
</Typography>
|
||||
<Typography
|
||||
variant="subtitle2"
|
||||
width="100%"
|
||||
style={{ opacity: 0.6 }}
|
||||
sx={{ overflow: "hidden", textOverflow: "ellipsis" }}
|
||||
>
|
||||
{item.Artists?.join(", ")}
|
||||
</Typography>
|
||||
<SortableContext
|
||||
items={upcomingIds}
|
||||
strategy={verticalListSortingStrategy}
|
||||
>
|
||||
<Box
|
||||
sx={{
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
gap: 1,
|
||||
}}
|
||||
>
|
||||
{upcomingItems.map((item, index) => (
|
||||
<SortableQueueItem
|
||||
key={item.Id || index}
|
||||
item={item}
|
||||
onDelete={() =>
|
||||
handleDelete(currentItemIndex + 1 + index)
|
||||
}
|
||||
onPlay={() =>
|
||||
handlePlay(currentItemIndex + 1 + index)
|
||||
}
|
||||
index={currentItemIndex + 1 + index + 1}
|
||||
/>
|
||||
))}
|
||||
</Box>
|
||||
</SortableContext>
|
||||
</DndContext>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</MenuItem>
|
||||
);
|
||||
})}
|
||||
</MenuList>
|
||||
</Menu>
|
||||
<IconButton onClick={(e) => setButtonEl(e.currentTarget)}>
|
||||
<span className="material-symbols-rounded">playlist_play</span>
|
||||
</IconButton>
|
||||
</>
|
||||
);
|
||||
</List>
|
||||
) : (
|
||||
<Box
|
||||
p={4}
|
||||
textAlign="center"
|
||||
display="flex"
|
||||
flexDirection="column"
|
||||
alignItems="center"
|
||||
gap={2}
|
||||
sx={{ opacity: 0.5 }}
|
||||
>
|
||||
<span
|
||||
className="material-symbols-rounded"
|
||||
style={{ fontSize: 48 }}
|
||||
>
|
||||
queue_music
|
||||
</span>
|
||||
<Typography>Your queue is empty</Typography>
|
||||
</Box>
|
||||
)}
|
||||
</Box>
|
||||
</Drawer>
|
||||
<IconButton onClick={() => setOpen(true)}>
|
||||
<span className="material-symbols-rounded">playlist_play</span>
|
||||
</IconButton>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default QueueButton;
|
||||
@@ -199,7 +199,7 @@ const BubbleSlider = () => {
|
||||
trickplayResolution.Width / trickplayResolution.Height;
|
||||
|
||||
trickplayStyle = {
|
||||
background: `url(${api?.basePath}/Videos/${itemId}/Trickplay/${trickplayResolution.Width}/${index}.jpg?${imgUrlParams})`,
|
||||
backgroundImage: `url(${api?.basePath}/Videos/${itemId}/Trickplay/${trickplayResolution.Width}/${index}.jpg?${imgUrlParams})`,
|
||||
backgroundPositionX: `${backgroundOffsetX}px`,
|
||||
backgroundPositionY: `${backgroundOffsetY}px`,
|
||||
width: `${trickplayResolution.Width}px`,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Button } from "@mui/material";
|
||||
import { Box, Button } from "@mui/material";
|
||||
import { AnimatePresence, motion } from "motion/react";
|
||||
import React from "react";
|
||||
import { useShallow } from "zustand/shallow";
|
||||
import { usePlaybackStore } from "@/utils/store/playback";
|
||||
@@ -24,33 +25,67 @@ const SkipSegmentButton = () => {
|
||||
})),
|
||||
);
|
||||
|
||||
if (
|
||||
!mediaSegments?.Items?.length ||
|
||||
currentSegmentIndex < 0 ||
|
||||
!activeSegmentId ||
|
||||
mediaSegments?.Items?.[currentSegmentIndex].Type === "Outro"
|
||||
) {
|
||||
return null; // No segments to skip
|
||||
}
|
||||
const shouldShow =
|
||||
mediaSegments?.Items?.length &&
|
||||
currentSegmentIndex >= 0 &&
|
||||
activeSegmentId &&
|
||||
mediaSegments?.Items?.[currentSegmentIndex].Type !== "Outro";
|
||||
|
||||
return (
|
||||
<Button
|
||||
variant="outlined"
|
||||
size="large"
|
||||
//@ts-ignore
|
||||
color="white"
|
||||
style={{
|
||||
position: "absolute",
|
||||
bottom:
|
||||
isUserHovering || !isPlayerPlaying || isUserSeeking ? "18vh" : "2em",
|
||||
right: "2em",
|
||||
transition: "bottom 0.3s ease-in-out",
|
||||
zIndex: 10000,
|
||||
}}
|
||||
onClick={skipSegment}
|
||||
>
|
||||
Skip {mediaSegments?.Items?.[currentSegmentIndex].Type}
|
||||
</Button>
|
||||
<AnimatePresence>
|
||||
{shouldShow && (
|
||||
<motion.div
|
||||
initial={{ opacity: 0, x: 20, scale: 0.9 }}
|
||||
animate={{ opacity: 1, x: 0, scale: 1 }}
|
||||
exit={{ opacity: 0, x: 20, scale: 0.9 }}
|
||||
transition={{
|
||||
type: "spring",
|
||||
stiffness: 300,
|
||||
damping: 30,
|
||||
}}
|
||||
style={{
|
||||
position: "absolute",
|
||||
right: "3em",
|
||||
zIndex: 10000,
|
||||
bottom:
|
||||
isUserHovering || !isPlayerPlaying || isUserSeeking ? "20vh" : "6em",
|
||||
transition: "bottom 0.3s ease-in-out",
|
||||
}}
|
||||
>
|
||||
<Button
|
||||
onClick={skipSegment}
|
||||
variant="contained"
|
||||
startIcon={
|
||||
<span className="material-symbols-rounded">skip_next</span>
|
||||
}
|
||||
sx={{
|
||||
bgcolor: "rgba(20, 20, 20, 0.6)",
|
||||
backdropFilter: "blur(16px) saturate(180%)",
|
||||
color: "white",
|
||||
border: "1px solid rgba(255, 255, 255, 0.1)",
|
||||
borderRadius: "12px",
|
||||
padding: "12px 24px",
|
||||
textTransform: "none",
|
||||
fontSize: "1rem",
|
||||
fontWeight: 600,
|
||||
boxShadow: "0 8px 32px 0 rgba(0, 0, 0, 0.2)",
|
||||
transition: "all 0.2s ease",
|
||||
"&:hover": {
|
||||
bgcolor: "rgba(255, 255, 255, 0.1)",
|
||||
transform: "scale(1.02)",
|
||||
boxShadow: "0 8px 32px 0 rgba(0, 0, 0, 0.3)",
|
||||
border: "1px solid rgba(255, 255, 255, 0.2)",
|
||||
},
|
||||
"&:active": {
|
||||
transform: "scale(0.98)",
|
||||
},
|
||||
}}
|
||||
>
|
||||
Skip {mediaSegments?.Items?.[currentSegmentIndex].Type}
|
||||
</Button>
|
||||
</motion.div>
|
||||
)}
|
||||
</AnimatePresence>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Button, Typography } from "@mui/material";
|
||||
import { motion } from "motion/react";
|
||||
import React, { useMemo } from "react";
|
||||
import { Box, Button, IconButton, Typography } from "@mui/material";
|
||||
import { AnimatePresence, motion } from "motion/react";
|
||||
import React, { useEffect, useMemo, useState } from "react";
|
||||
import { useShallow } from "zustand/shallow";
|
||||
import getImageUrlsApi from "@/utils/methods/getImageUrlsApi";
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
@@ -36,6 +36,13 @@ const UpNextFlyout = () => {
|
||||
tracks: state.tracks,
|
||||
})),
|
||||
);
|
||||
|
||||
const [isHidden, setIsHidden] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setIsHidden(false);
|
||||
}, [activeSegmentId]);
|
||||
|
||||
const areControlsVisible = useMemo(() => {
|
||||
return isUserHovering || isUserSeeking || !isPlayerPlaying;
|
||||
}, [isUserHovering, isUserSeeking, isPlayerPlaying]);
|
||||
@@ -45,7 +52,8 @@ const UpNextFlyout = () => {
|
||||
if (
|
||||
!api ||
|
||||
!activeSegmentId ||
|
||||
mediaSegments?.Items?.[currentSegmemtIndex].Type !== "Outro"
|
||||
mediaSegments?.Items?.[currentSegmemtIndex].Type !== "Outro" ||
|
||||
isHidden
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
@@ -56,53 +64,154 @@ const UpNextFlyout = () => {
|
||||
}
|
||||
|
||||
return (
|
||||
<motion.div
|
||||
className={
|
||||
areControlsVisible
|
||||
? "video-player-up_next_flyout floating"
|
||||
: "video-player-up_next_flyout"
|
||||
}
|
||||
initial={{ opacity: 0 }}
|
||||
animate={{ opacity: 1 }}
|
||||
>
|
||||
<img
|
||||
className="video-player-up_next_flyout-thumbnail"
|
||||
src={getImageUrlsApi(api).getItemImageUrlById(item.Id, "Primary", {
|
||||
tag: item.ImageTags?.Primary,
|
||||
quality: 80,
|
||||
fillWidth: 300,
|
||||
})}
|
||||
alt={"next item thumbnail"}
|
||||
/>
|
||||
<div className="video-player-up_next_flyout-details">
|
||||
<Typography variant="h5">
|
||||
{`S${item.ParentIndexNumber}:E${item.IndexNumber} `}
|
||||
{item.Name}
|
||||
</Typography>
|
||||
<Typography
|
||||
variant="subtitle2"
|
||||
// noWrap
|
||||
textOverflow="ellipsis"
|
||||
maxWidth="100%"
|
||||
<AnimatePresence>
|
||||
<motion.div
|
||||
className={
|
||||
areControlsVisible
|
||||
? "video-player-up_next_flyout floating"
|
||||
: "video-player-up_next_flyout"
|
||||
}
|
||||
initial={{ opacity: 0, y: 50, scale: 0.95 }}
|
||||
animate={{ opacity: 1, y: 0, scale: 1 }}
|
||||
exit={{ opacity: 0, y: 20, scale: 0.95 }}
|
||||
transition={{ duration: 0.4, ease: [0.4, 0, 0.2, 1] }}
|
||||
style={{
|
||||
background: "rgba(20, 20, 20, 0.6)",
|
||||
backdropFilter: "blur(16px) saturate(180%)",
|
||||
border: "1px solid rgba(255, 255, 255, 0.1)",
|
||||
boxShadow: "0 8px 32px 0 rgba(0, 0, 0, 0.3)",
|
||||
borderRadius: "24px",
|
||||
padding: "16px",
|
||||
display: "flex",
|
||||
gap: "16px",
|
||||
maxWidth: "500px",
|
||||
width: "100%",
|
||||
overflow: "hidden",
|
||||
}}
|
||||
>
|
||||
<Box
|
||||
sx={{
|
||||
display: "-webkit-box",
|
||||
webkitLineClamp: "3",
|
||||
webkitBoxOrient: "vertical",
|
||||
position: "relative",
|
||||
width: "160px",
|
||||
minWidth: "160px",
|
||||
borderRadius: "8px",
|
||||
overflow: "hidden",
|
||||
aspectRatio: "16/9",
|
||||
boxShadow: "0 4px 12px rgba(0,0,0,0.3)",
|
||||
}}
|
||||
>
|
||||
{item.Overview}
|
||||
</Typography>
|
||||
<Button
|
||||
onClick={skipSegment}
|
||||
variant="contained"
|
||||
color="primary"
|
||||
className="video-player-up_next_flyout-button"
|
||||
<img
|
||||
src={getImageUrlsApi(api).getItemImageUrlById(item.Id, "Primary", {
|
||||
tag: item.ImageTags?.Primary,
|
||||
quality: 90,
|
||||
fillWidth: 320,
|
||||
})}
|
||||
alt="next item thumbnail"
|
||||
style={{
|
||||
width: "100%",
|
||||
height: "100%",
|
||||
objectFit: "cover",
|
||||
}}
|
||||
/>
|
||||
<Box
|
||||
sx={{
|
||||
position: "absolute",
|
||||
inset: 0,
|
||||
background:
|
||||
"linear-gradient(to top, rgba(0,0,0,0.6) 0%, transparent 100%)",
|
||||
}}
|
||||
/>
|
||||
</Box>
|
||||
|
||||
<Box
|
||||
sx={{
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
flex: 1,
|
||||
minWidth: 0,
|
||||
justifyContent: "center",
|
||||
}}
|
||||
>
|
||||
Play
|
||||
</Button>
|
||||
</div>
|
||||
</motion.div>
|
||||
<Typography
|
||||
variant="overline"
|
||||
sx={{
|
||||
color: "primary.main",
|
||||
fontWeight: 700,
|
||||
lineHeight: 1,
|
||||
mb: 0.5,
|
||||
letterSpacing: 1.2,
|
||||
}}
|
||||
>
|
||||
UP NEXT
|
||||
</Typography>
|
||||
<Typography
|
||||
variant="h6"
|
||||
sx={{
|
||||
fontWeight: 600,
|
||||
lineHeight: 1.2,
|
||||
mb: 0.5,
|
||||
fontSize: "1.1rem",
|
||||
}}
|
||||
noWrap
|
||||
>
|
||||
{item.SeriesName || item.Name}
|
||||
</Typography>
|
||||
<Typography
|
||||
variant="body2"
|
||||
color="text.secondary"
|
||||
sx={{
|
||||
mb: 2,
|
||||
display: "-webkit-box",
|
||||
WebkitLineClamp: 1,
|
||||
WebkitBoxOrient: "vertical",
|
||||
overflow: "hidden",
|
||||
opacity: 0.8,
|
||||
}}
|
||||
>
|
||||
{item.SeriesName
|
||||
? `S${item.ParentIndexNumber}:E${item.IndexNumber} - ${item.Name}`
|
||||
: item.Overview || ""}
|
||||
</Typography>
|
||||
|
||||
<Box sx={{ display: "flex", gap: 1, mt: "auto" }}>
|
||||
<Button
|
||||
onClick={skipSegment}
|
||||
variant="contained"
|
||||
color="primary"
|
||||
startIcon={
|
||||
<span className="material-symbols-rounded fill">
|
||||
play_arrow
|
||||
</span>
|
||||
}
|
||||
sx={{
|
||||
borderRadius: "8px",
|
||||
textTransform: "none",
|
||||
fontWeight: 600,
|
||||
boxShadow:
|
||||
"0 4px 12px rgba(var(--mui-palette-primary-mainChannel), 0.3)",
|
||||
flex: 1,
|
||||
}}
|
||||
>
|
||||
Play Now
|
||||
</Button>
|
||||
<IconButton
|
||||
onClick={() => setIsHidden(true)}
|
||||
sx={{
|
||||
borderRadius: "8px",
|
||||
border: "1px solid rgba(255,255,255,0.1)",
|
||||
color: "text.secondary",
|
||||
"&:hover": {
|
||||
bgcolor: "rgba(255,255,255,0.1)",
|
||||
color: "white",
|
||||
},
|
||||
}}
|
||||
>
|
||||
<span className="material-symbols-rounded">close</span>
|
||||
</IconButton>
|
||||
</Box>
|
||||
</Box>
|
||||
</motion.div>
|
||||
</AnimatePresence>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,223 @@
|
||||
import type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client";
|
||||
import {
|
||||
Box,
|
||||
IconButton,
|
||||
ListItem,
|
||||
ListItemAvatar,
|
||||
ListItemText,
|
||||
Typography,
|
||||
} from "@mui/material";
|
||||
import React from "react";
|
||||
import getImageUrlsApi from "@/utils/methods/getImageUrlsApi";
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import { getTypeIcon } from "../utils/iconsCollection";
|
||||
|
||||
type QueueListItemProps = {
|
||||
queueItem: BaseItemDto;
|
||||
active?: boolean;
|
||||
onDelete?: () => void;
|
||||
onPlay?: () => void;
|
||||
dragHandleProps?: any;
|
||||
isEpisode?: boolean;
|
||||
index?: number;
|
||||
};
|
||||
|
||||
const QueueListItem = ({
|
||||
queueItem,
|
||||
active,
|
||||
onDelete,
|
||||
onPlay,
|
||||
dragHandleProps,
|
||||
isEpisode,
|
||||
index,
|
||||
}: QueueListItemProps) => {
|
||||
const api = useApiInContext((s) => s.api);
|
||||
|
||||
const imageUrl =
|
||||
api &&
|
||||
queueItem.Id &&
|
||||
(queueItem.ImageTags?.Primary
|
||||
? getImageUrlsApi(api).getItemImageUrlById(queueItem.Id, "Primary", {
|
||||
tag: queueItem.ImageTags.Primary,
|
||||
})
|
||||
: queueItem.AlbumPrimaryImageTag?.[0]
|
||||
? getImageUrlsApi(api).getItemImageUrlById(
|
||||
queueItem.AlbumId || "",
|
||||
"Primary",
|
||||
{ tag: queueItem.AlbumPrimaryImageTag[0] },
|
||||
)
|
||||
: null);
|
||||
|
||||
const primaryText = queueItem.SeriesName || queueItem.Name;
|
||||
|
||||
let secondaryText = "";
|
||||
if (isEpisode) {
|
||||
const season = queueItem.ParentIndexNumber;
|
||||
const episode = queueItem.IndexNumber;
|
||||
const episodeEnd = queueItem.IndexNumberEnd;
|
||||
const episodeString = episodeEnd
|
||||
? `S${season}:E${episode}-${episodeEnd}`
|
||||
: `S${season}:E${episode}`;
|
||||
|
||||
secondaryText = `${episodeString} - ${queueItem.Name}`;
|
||||
} else {
|
||||
secondaryText = queueItem.Artists?.join(", ") || "";
|
||||
}
|
||||
|
||||
return (
|
||||
<ListItem
|
||||
secondaryAction={
|
||||
onDelete && (
|
||||
<IconButton
|
||||
edge="end"
|
||||
aria-label="delete"
|
||||
onClick={onDelete}
|
||||
size="small"
|
||||
sx={{
|
||||
opacity: 0,
|
||||
transition: "opacity 0.2s",
|
||||
".MuiListItem-root:hover &": { opacity: 0.7 },
|
||||
"&:hover": { opacity: "1 !important", bgcolor: "action.hover" },
|
||||
}}
|
||||
>
|
||||
<span className="material-symbols-rounded" style={{ fontSize: 20 }}>
|
||||
close
|
||||
</span>
|
||||
</IconButton>
|
||||
)
|
||||
}
|
||||
sx={{
|
||||
opacity: active ? 1 : 1,
|
||||
bgcolor: active ? "transparent" : "background.paper",
|
||||
borderRadius: 3,
|
||||
mb: 0,
|
||||
transition: "all 0.2s ease",
|
||||
border: active ? "none" : "1px solid",
|
||||
borderColor: "divider",
|
||||
"&:hover": {
|
||||
bgcolor: active ? "transparent" : "action.hover",
|
||||
transform: active ? "none" : "translateY(-2px)",
|
||||
boxShadow: active ? "none" : 2,
|
||||
},
|
||||
pr: onDelete ? 6 : 2,
|
||||
}}
|
||||
>
|
||||
{dragHandleProps && (
|
||||
<div
|
||||
{...dragHandleProps}
|
||||
style={{
|
||||
cursor: "grab",
|
||||
marginRight: 12,
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
opacity: 0.3,
|
||||
transition: "opacity 0.2s",
|
||||
}}
|
||||
className="drag-handle"
|
||||
>
|
||||
<span className="material-symbols-rounded">drag_indicator</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<ListItemAvatar sx={{ minWidth: 64 }}>
|
||||
<Box
|
||||
onClick={onPlay}
|
||||
sx={{
|
||||
width: 48,
|
||||
height: 48,
|
||||
borderRadius: 2,
|
||||
overflow: "hidden",
|
||||
position: "relative",
|
||||
boxShadow: "0 2px 8px rgba(0,0,0,0.2)",
|
||||
cursor: onPlay ? "pointer" : "default",
|
||||
"&:hover .play-overlay": {
|
||||
opacity: 1,
|
||||
},
|
||||
}}
|
||||
>
|
||||
{imageUrl ? (
|
||||
<img
|
||||
src={imageUrl}
|
||||
alt={queueItem.Name || ""}
|
||||
style={{ width: "100%", height: "100%", objectFit: "cover" }}
|
||||
/>
|
||||
) : (
|
||||
<div
|
||||
style={{
|
||||
width: "100%",
|
||||
height: "100%",
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
background: "#2a2a2a",
|
||||
}}
|
||||
>
|
||||
{queueItem.Type && getTypeIcon(queueItem.Type)}
|
||||
</div>
|
||||
)}
|
||||
{active && (
|
||||
<div
|
||||
style={{
|
||||
position: "absolute",
|
||||
inset: 0,
|
||||
background: "rgba(0,0,0,0.4)",
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
backdropFilter: "blur(2px)",
|
||||
}}
|
||||
>
|
||||
<span
|
||||
className="material-symbols-rounded"
|
||||
style={{ fontSize: "1.5rem", color: "white" }}
|
||||
>
|
||||
equalizer
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
{!active && onPlay && (
|
||||
<Box
|
||||
className="play-overlay"
|
||||
sx={{
|
||||
position: "absolute",
|
||||
inset: 0,
|
||||
background: "rgba(0,0,0,0.4)",
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
opacity: 0,
|
||||
transition: "opacity 0.2s",
|
||||
backdropFilter: "blur(1px)",
|
||||
}}
|
||||
>
|
||||
<span
|
||||
className="material-symbols-rounded"
|
||||
style={{ fontSize: "2rem", color: "white" }}
|
||||
>
|
||||
play_arrow
|
||||
</span>
|
||||
</Box>
|
||||
)}
|
||||
</Box>
|
||||
</ListItemAvatar>
|
||||
|
||||
<ListItemText
|
||||
primary={primaryText}
|
||||
secondary={secondaryText}
|
||||
primaryTypographyProps={{
|
||||
noWrap: true,
|
||||
variant: "body2",
|
||||
fontWeight: active ? 700 : 500,
|
||||
sx: { mb: 0.5 },
|
||||
}}
|
||||
secondaryTypographyProps={{
|
||||
noWrap: true,
|
||||
variant: "caption",
|
||||
sx: { opacity: 0.7 },
|
||||
}}
|
||||
/>
|
||||
</ListItem>
|
||||
);
|
||||
};
|
||||
|
||||
export default QueueListItem;
|
||||
@@ -8,7 +8,7 @@ import { playItemFromQueue, usePlaybackStore } from "@/utils/store/playback";
|
||||
|
||||
import "./videoPlayer.scss";
|
||||
|
||||
import { PlayMethod, RepeatMode } from "@jellyfin/sdk/lib/generated-client";
|
||||
import { RepeatMode } from "@jellyfin/sdk/lib/generated-client";
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
import { createFileRoute, useRouter } from "@tanstack/react-router";
|
||||
import JASSUB from "jassub";
|
||||
@@ -508,25 +508,6 @@ export function VideoPlayer() {
|
||||
}
|
||||
}, []);
|
||||
|
||||
// useEffect(() => {
|
||||
// async function setVolumeInServer() {
|
||||
// if (!api) return null;
|
||||
// await getDisplayPreferencesApi(api).updateDisplayPreferences({
|
||||
// userId: user?.Id,
|
||||
// client: "blink",
|
||||
// displayPreferencesId: api.deviceInfo.id,
|
||||
// displayPreferencesDto: {
|
||||
// CustomPrefs: {
|
||||
// Volume: String(playerVolume),
|
||||
// },
|
||||
// },
|
||||
// });
|
||||
// }
|
||||
// if (user?.Id && initVolume !== playerVolume && initVolume !== undefined) {
|
||||
// setVolumeInServer();
|
||||
// }
|
||||
// }, [playerVolume]);
|
||||
|
||||
const idleTimerRef = useRef<NodeJS.Timeout | null>(null);
|
||||
|
||||
// Function to clear the existing idle timer
|
||||
|
||||
+152
-96
@@ -1,13 +1,15 @@
|
||||
import type { Api } from "@jellyfin/sdk";
|
||||
import type {
|
||||
BaseItemDto,
|
||||
MediaSegmentDtoQueryResult,
|
||||
MediaStream,
|
||||
import {
|
||||
type BaseItemDto,
|
||||
type MediaSegmentDtoQueryResult,
|
||||
type MediaStream,
|
||||
type PlaybackInfoResponse,
|
||||
PlayMethod,
|
||||
} from "@jellyfin/sdk/lib/generated-client";
|
||||
import { getMediaInfoApi } from "@jellyfin/sdk/lib/utils/api/media-info-api";
|
||||
import { getMediaSegmentsApi } from "@jellyfin/sdk/lib/utils/api/media-segments-api";
|
||||
import { getPlaystateApi } from "@jellyfin/sdk/lib/utils/api/playstate-api";
|
||||
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
||||
import { WebviewWindow as appWindow } from "@tauri-apps/api/webviewWindow";
|
||||
import { create } from "zustand";
|
||||
import { immer } from "zustand/middleware/immer";
|
||||
@@ -371,7 +373,6 @@ export const usePlaybackStore = create<
|
||||
|
||||
if (nextSegmentIndex !== -1) {
|
||||
const nextSegment = metadata.mediaSegments?.Items?.[nextSegmentIndex];
|
||||
console.info("Next segment:", nextSegment);
|
||||
if (nextSegment && ticks >= (nextSegment.StartTicks ?? ticks + 1)) {
|
||||
// If the current time is past the next segment's start time, set it as active.
|
||||
// clearActiveSegment();
|
||||
@@ -669,6 +670,145 @@ export const playItem = (args: {
|
||||
setQueue(args.queueItems, args.queueItemIndex ?? 0);
|
||||
};
|
||||
|
||||
export const initializePlayback = async (args: {
|
||||
api: Api;
|
||||
userId: string;
|
||||
item: BaseItemDto;
|
||||
mediaSource: PlaybackInfoResponse;
|
||||
mediaSegments?: MediaSegmentDtoQueryResult;
|
||||
queueItems: BaseItemDto[];
|
||||
queueIndex: number;
|
||||
startPositionTicks?: number;
|
||||
}) => {
|
||||
const {
|
||||
api,
|
||||
userId,
|
||||
item,
|
||||
mediaSource,
|
||||
mediaSegments,
|
||||
queueItems,
|
||||
queueIndex,
|
||||
startPositionTicks,
|
||||
} = args;
|
||||
|
||||
if (!mediaSource.MediaSources?.[0]?.Id) {
|
||||
throw new Error("Media source is undefined in initializePlayback");
|
||||
}
|
||||
|
||||
const source = mediaSource.MediaSources[0];
|
||||
const currentUser = (await getUserApi(api).getCurrentUser()).data;
|
||||
|
||||
let itemName = item.Name;
|
||||
let episodeTitle = "";
|
||||
if (item.SeriesId && item.SeriesName) {
|
||||
itemName = item.SeriesName;
|
||||
episodeTitle = `S${item.ParentIndexNumber ?? 0}:E${
|
||||
item.IndexNumber ?? 0
|
||||
} ${item.Name}`;
|
||||
}
|
||||
|
||||
// Subtitle
|
||||
const userSubtitleLanguagePreference =
|
||||
currentUser?.Configuration?.SubtitleLanguagePreference;
|
||||
const allSubtitles = source.MediaStreams?.filter(
|
||||
(stream) => stream.Type === "Subtitle",
|
||||
);
|
||||
const preferredSubtitle =
|
||||
allSubtitles?.find(
|
||||
(sub) => sub.Language === userSubtitleLanguagePreference,
|
||||
) || null;
|
||||
|
||||
const subtitle = getSubtitle(
|
||||
preferredSubtitle?.Index ?? source.DefaultSubtitleStreamIndex ?? -1,
|
||||
source.MediaStreams,
|
||||
);
|
||||
|
||||
// Audio
|
||||
const userAudioLanguagePreference =
|
||||
currentUser?.Configuration?.AudioLanguagePreference;
|
||||
const allAudioTracks = source.MediaStreams?.filter(
|
||||
(value) => value.Type === "Audio",
|
||||
);
|
||||
const preferredAudioTrack =
|
||||
allAudioTracks?.find(
|
||||
(track) => track.Language === userAudioLanguagePreference,
|
||||
) ||
|
||||
allAudioTracks?.find((track) => track.IsDefault) ||
|
||||
allAudioTracks?.[0];
|
||||
|
||||
const audio = {
|
||||
track: preferredAudioTrack?.Index ?? source.DefaultAudioStreamIndex ?? 0,
|
||||
allTracks: allAudioTracks,
|
||||
};
|
||||
|
||||
// URL generation
|
||||
const urlOptions: URLSearchParams = {
|
||||
//@ts-expect-error
|
||||
Static: true,
|
||||
tag: source.ETag,
|
||||
mediaSourceId: source.Id,
|
||||
deviceId: api.deviceInfo.id,
|
||||
api_key: api.accessToken,
|
||||
};
|
||||
|
||||
let playMethod: PlayMethod = PlayMethod.Transcode;
|
||||
if (source.SupportsDirectPlay) {
|
||||
playMethod = PlayMethod.DirectPlay;
|
||||
} else if (source.SupportsDirectStream) {
|
||||
playMethod = PlayMethod.DirectStream;
|
||||
}
|
||||
|
||||
const urlParams = new URLSearchParams(urlOptions).toString();
|
||||
let playbackUrl = `${api.basePath}/Videos/${source.Id}/stream.${source.Container}?${urlParams}`;
|
||||
if (playMethod === PlayMethod.Transcode && source.TranscodingUrl) {
|
||||
playbackUrl = `${api.basePath}${source.TranscodingUrl}`;
|
||||
}
|
||||
|
||||
const videoTrack = source.MediaStreams?.filter(
|
||||
(value) => value.Type === "Video",
|
||||
);
|
||||
|
||||
playItem({
|
||||
metadata: {
|
||||
itemName: itemName ?? "",
|
||||
episodeTitle: episodeTitle,
|
||||
isEpisode: !!item.SeriesId,
|
||||
itemDuration: item.RunTimeTicks ?? 0,
|
||||
item: item,
|
||||
mediaSegments: mediaSegments,
|
||||
userDataLastPlayedPositionTicks:
|
||||
startPositionTicks ?? item.UserData?.PlaybackPositionTicks ?? 0,
|
||||
},
|
||||
mediaSource: {
|
||||
videoTrack: videoTrack?.[0]?.Index ?? 0,
|
||||
audioTrack: audio.track,
|
||||
container: source.Container ?? "",
|
||||
id: source.Id ?? undefined,
|
||||
subtitle: {
|
||||
url: subtitle?.url,
|
||||
track: subtitle?.track ?? -1,
|
||||
format: subtitle?.format ?? "nosub",
|
||||
allTracks: allSubtitles,
|
||||
enable: subtitle?.enable ?? false,
|
||||
},
|
||||
audio: audio,
|
||||
bitrate: source.Bitrate ?? undefined,
|
||||
videoCodec: videoTrack?.[0]?.Codec ?? undefined,
|
||||
audioCodec:
|
||||
audio.allTracks?.find((t) => t.Index === audio.track)?.Codec ??
|
||||
undefined,
|
||||
playMethod: playMethod,
|
||||
transcodingUrl: source.TranscodingUrl ?? undefined,
|
||||
},
|
||||
playbackStream: playbackUrl,
|
||||
playsessionId: mediaSource.PlaySessionId,
|
||||
userDataPlayedPositionTicks: item.UserData?.PlaybackPositionTicks ?? 0,
|
||||
userId,
|
||||
queueItems: queueItems ?? [],
|
||||
queueItemIndex: queueIndex,
|
||||
});
|
||||
};
|
||||
|
||||
export const playItemFromQueue = async (
|
||||
index: "next" | "previous" | number,
|
||||
userId: string | undefined,
|
||||
@@ -767,98 +907,14 @@ export const playItemFromQueue = async (
|
||||
const mediaSource = playbackInfoResponse.data;
|
||||
const mediaSegments = segmentsResponse.data;
|
||||
|
||||
if (!mediaSource.MediaSources?.[0]?.Id) {
|
||||
throw new Error("Media source is undefined in playItemFromQueue");
|
||||
}
|
||||
|
||||
const source = mediaSource.MediaSources[0];
|
||||
|
||||
let itemName = item.Name;
|
||||
let episodeTitle = "";
|
||||
if (item.SeriesId && item.SeriesName) {
|
||||
itemName = item.SeriesName;
|
||||
episodeTitle = `S${item.ParentIndexNumber ?? 0}:E${
|
||||
item.IndexNumber ?? 0
|
||||
} ${item.Name}`;
|
||||
}
|
||||
|
||||
// Subtitle
|
||||
const subtitle = getSubtitle(
|
||||
source.DefaultSubtitleStreamIndex ?? "nosub",
|
||||
source.MediaStreams,
|
||||
);
|
||||
|
||||
// Audio
|
||||
const audio = {
|
||||
track: source.DefaultAudioStreamIndex ?? 0,
|
||||
allTracks: source.MediaStreams?.filter((value) => value.Type === "Audio"),
|
||||
};
|
||||
|
||||
// URL generation
|
||||
const urlOptions: URLSearchParams = {
|
||||
//@ts-expect-error
|
||||
Static: true,
|
||||
tag: source.ETag,
|
||||
mediaSourceId: source.Id,
|
||||
deviceId: api.deviceInfo.id,
|
||||
api_key: api.accessToken,
|
||||
};
|
||||
|
||||
let playMethod = PlayMethod.Transcode;
|
||||
if (source.SupportsDirectPlay) {
|
||||
playMethod = PlayMethod.DirectPlay;
|
||||
} else if (source.SupportsDirectStream) {
|
||||
playMethod = PlayMethod.DirectStream;
|
||||
}
|
||||
|
||||
const urlParams = new URLSearchParams(urlOptions).toString();
|
||||
let playbackUrl = `${api.basePath}/Videos/${source.Id}/stream.${source.Container}?${urlParams}`;
|
||||
if (playMethod === PlayMethod.Transcode && source.TranscodingUrl) {
|
||||
playbackUrl = `${api.basePath}${source.TranscodingUrl}`;
|
||||
}
|
||||
|
||||
const videoTrack = source.MediaStreams?.filter(
|
||||
(value) => value.Type === "Video",
|
||||
);
|
||||
|
||||
playItem({
|
||||
metadata: {
|
||||
itemName,
|
||||
episodeTitle: episodeTitle,
|
||||
isEpisode: !!item.SeriesId,
|
||||
itemDuration: item.RunTimeTicks,
|
||||
item: item,
|
||||
mediaSegments: mediaSegments,
|
||||
userDataLastPlayedPositionTicks:
|
||||
item.UserData?.PlaybackPositionTicks ?? 0,
|
||||
},
|
||||
mediaSource: {
|
||||
videoTrack: videoTrack?.[0]?.Index ?? 0,
|
||||
audioTrack: audio.track,
|
||||
container: source.Container ?? "",
|
||||
id: source.Id,
|
||||
subtitle: {
|
||||
url: subtitle?.url,
|
||||
track: subtitle?.track ?? -1,
|
||||
format: subtitle?.format ?? "nosub",
|
||||
allTracks: source.MediaStreams?.filter(
|
||||
(value) => value.Type === "Subtitle",
|
||||
),
|
||||
enable: subtitle?.enable ?? false,
|
||||
},
|
||||
audio: audio,
|
||||
bitrate: source.Bitrate,
|
||||
videoCodec: videoTrack?.[0]?.Codec,
|
||||
audioCodec: audio.allTracks?.find((t) => t.Index === audio.track)?.Codec,
|
||||
playMethod: playMethod,
|
||||
transcodingUrl: source.TranscodingUrl,
|
||||
},
|
||||
playbackStream: playbackUrl,
|
||||
playsessionId: mediaSource.PlaySessionId,
|
||||
userDataPlayedPositionTicks: item.UserData?.PlaybackPositionTicks ?? 0,
|
||||
initializePlayback({
|
||||
api,
|
||||
userId,
|
||||
queueItems: queueItems,
|
||||
queueItemIndex: requestedItemIndex,
|
||||
item,
|
||||
mediaSource,
|
||||
mediaSegments,
|
||||
queueItems: queueItems ?? [],
|
||||
queueIndex: requestedItemIndex,
|
||||
});
|
||||
|
||||
return "playing"; // Return any value to end mutation pending status
|
||||
|
||||
@@ -30,6 +30,59 @@ export const setTrackIndex = (index: number) => {
|
||||
useQueue.setState((state) => ({ ...state, currentItemIndex: index }));
|
||||
};
|
||||
|
||||
export const reorderQueue = (newOrder: BaseItemDto[]) => {
|
||||
useQueue.setState((state) => ({ ...state, tracks: newOrder }));
|
||||
};
|
||||
|
||||
export const removeFromQueue = (index: number) => {
|
||||
useQueue.setState((state) => {
|
||||
if (!state.tracks) return state;
|
||||
const newTracks = [...state.tracks];
|
||||
newTracks.splice(index, 1);
|
||||
|
||||
let newIndex = state.currentItemIndex;
|
||||
if (index < state.currentItemIndex) {
|
||||
newIndex--;
|
||||
} else if (index === state.currentItemIndex) {
|
||||
// If removing current item, ensure index is valid
|
||||
if (newIndex >= newTracks.length) {
|
||||
newIndex = Math.max(0, newTracks.length - 1);
|
||||
}
|
||||
}
|
||||
|
||||
return { ...state, tracks: newTracks, currentItemIndex: newIndex };
|
||||
});
|
||||
};
|
||||
|
||||
export const clearUpcoming = () => {
|
||||
useQueue.setState((state) => {
|
||||
if (!state.tracks) return state;
|
||||
// Keep only items up to and including the current item
|
||||
const newTracks = state.tracks.slice(0, state.currentItemIndex + 1);
|
||||
return { ...state, tracks: newTracks };
|
||||
});
|
||||
};
|
||||
|
||||
export const shuffleUpcoming = () => {
|
||||
useQueue.setState((state) => {
|
||||
if (!state.tracks || state.tracks.length <= state.currentItemIndex + 1)
|
||||
return state;
|
||||
|
||||
const currentItems = state.tracks.slice(0, state.currentItemIndex + 1);
|
||||
const upcomingItems = state.tracks.slice(state.currentItemIndex + 1);
|
||||
|
||||
// Fisher-Yates shuffle for upcoming items
|
||||
for (let i = upcomingItems.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
[upcomingItems[i], upcomingItems[j]] = [
|
||||
upcomingItems[j],
|
||||
upcomingItems[i],
|
||||
];
|
||||
}
|
||||
|
||||
return { ...state, tracks: [...currentItems, ...upcomingItems] };
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Resets the Queue store
|
||||
|
||||
Reference in new issue
Block a user