feat: implement proper queue functionality and improve upnext flyout and skip segment buttons
This commit is contained in:
10 files changed
+977
-555
No files matched your search
@@ -1,7 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
type BaseItemDto,
|
type BaseItemDto,
|
||||||
BaseItemKind,
|
BaseItemKind,
|
||||||
PlayMethod,
|
|
||||||
} from "@jellyfin/sdk/lib/generated-client";
|
} from "@jellyfin/sdk/lib/generated-client";
|
||||||
import { getTvShowsApi } from "@jellyfin/sdk/lib/utils/api/tv-shows-api";
|
import { getTvShowsApi } from "@jellyfin/sdk/lib/utils/api/tv-shows-api";
|
||||||
import type { SxProps } from "@mui/material";
|
import type { SxProps } from "@mui/material";
|
||||||
@@ -15,13 +14,11 @@ import { useSnackbar } from "notistack";
|
|||||||
import React, { type MouseEvent, memo } from "react"; // Import memo
|
import React, { type MouseEvent, memo } from "react"; // Import memo
|
||||||
import type PlayResult from "@//utils/types/playResult";
|
import type PlayResult from "@//utils/types/playResult";
|
||||||
import { getRuntimeCompact } from "@/utils/date/time";
|
import { getRuntimeCompact } from "@/utils/date/time";
|
||||||
import getSubtitle from "@/utils/methods/getSubtitles";
|
|
||||||
import { getNextEpisode, getPlaybackInfo } from "@/utils/methods/playback";
|
import { getNextEpisode, getPlaybackInfo } from "@/utils/methods/playback";
|
||||||
import { useApiInContext } from "@/utils/store/api";
|
import { useApiInContext } from "@/utils/store/api";
|
||||||
import { generateAudioStreamUrl, playAudio } from "@/utils/store/audioPlayback";
|
import { generateAudioStreamUrl, playAudio } from "@/utils/store/audioPlayback";
|
||||||
import { useCentralStore } from "@/utils/store/central";
|
|
||||||
import { usePhotosPlayback } from "@/utils/store/photosPlayback";
|
import { usePhotosPlayback } from "@/utils/store/photosPlayback";
|
||||||
import { playItem } from "@/utils/store/playback";
|
import { initializePlayback } from "@/utils/store/playback";
|
||||||
import { setQueue } from "@/utils/store/queue";
|
import { setQueue } from "@/utils/store/queue";
|
||||||
|
|
||||||
type PlayButtonProps = {
|
type PlayButtonProps = {
|
||||||
@@ -86,7 +83,6 @@ const PlayButton = ({
|
|||||||
// (state) => state.setisPending,
|
// (state) => state.setisPending,
|
||||||
// );
|
// );
|
||||||
const playPhotos = usePhotosPlayback((s) => s.playPhotos);
|
const playPhotos = usePhotosPlayback((s) => s.playPhotos);
|
||||||
const currentUser = useCentralStore((s) => s.currentUser);
|
|
||||||
|
|
||||||
const { enqueueSnackbar } = useSnackbar();
|
const { enqueueSnackbar } = useSnackbar();
|
||||||
|
|
||||||
@@ -157,149 +153,29 @@ const PlayButton = ({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const episodeIndex = result.episodeIndex;
|
const episodeIndex = result.episodeIndex;
|
||||||
|
const queue = result?.item?.Items ?? [];
|
||||||
|
|
||||||
// Creates a queue containing all Episodes for a particular season(series) or collection of movies
|
let playItemValue = queue[episodeIndex];
|
||||||
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];
|
|
||||||
if (itemType === BaseItemKind.Movie) {
|
if (itemType === BaseItemKind.Movie) {
|
||||||
playItemValue = result?.item?.Items?.[0];
|
playItemValue = queue[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
const startPosition =
|
if (!playItemValue) {
|
||||||
result?.item?.Items?.[episodeIndex].UserData?.PlaybackPositionTicks;
|
console.error("No item to play found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const videoTrack =
|
const startPosition = playItemValue.UserData?.PlaybackPositionTicks;
|
||||||
result.mediaSource.MediaSources?.[0].MediaStreams?.filter(
|
|
||||||
(value) => value.Type === "Video",
|
|
||||||
);
|
|
||||||
|
|
||||||
playItem({
|
initializePlayback({
|
||||||
metadata: {
|
api,
|
||||||
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,
|
|
||||||
userId,
|
userId,
|
||||||
queueItems: queue ?? [],
|
item: playItemValue,
|
||||||
queueItemIndex: episodeIndex,
|
mediaSource: result.mediaSource,
|
||||||
|
mediaSegments: result.mediaSegments,
|
||||||
|
queueItems: queue,
|
||||||
|
queueIndex: episodeIndex,
|
||||||
|
startPositionTicks: startPosition,
|
||||||
});
|
});
|
||||||
navigate({ to: "/player" });
|
navigate({ to: "/player" });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
$image-size: 5em;
|
|
||||||
|
|
||||||
.queue{
|
.queue{
|
||||||
&-item{
|
&-item{
|
||||||
|
--image-size: 5em;
|
||||||
|
&.episode {
|
||||||
|
--image-size: 8em !important;
|
||||||
|
}
|
||||||
width: 32em;
|
width: 32em;
|
||||||
padding: 1em;
|
padding: 1em;
|
||||||
display: grid !important;
|
display: grid !important;
|
||||||
opacity: 1 !important;
|
opacity: 1 !important;
|
||||||
gap: 1em;
|
gap: 1em;
|
||||||
height: 5em;
|
height: 5em;
|
||||||
grid-template-columns: 3em $image-size 1fr;
|
grid-template-columns: 3em var(--image-size) 1fr;
|
||||||
justify-items: center;
|
justify-items: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
&-image{
|
&-image{
|
||||||
@@ -25,6 +27,7 @@ $image-size: 5em;
|
|||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
position: relative;
|
position: relative;
|
||||||
|
width: var(--image-size);
|
||||||
}
|
}
|
||||||
&-icon {
|
&-icon {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
@@ -52,4 +55,5 @@ $image-size: 5em;
|
|||||||
opacity: 0.5 !important;
|
opacity: 0.5 !important;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,20 +1,86 @@
|
|||||||
import { playItemFromQueue } from "@/utils/store/playback";
|
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
||||||
import useQueue from "@/utils/store/queue";
|
|
||||||
import {
|
import {
|
||||||
|
Box,
|
||||||
|
Drawer,
|
||||||
IconButton,
|
IconButton,
|
||||||
Menu,
|
List,
|
||||||
MenuItem,
|
Tooltip,
|
||||||
MenuList,
|
|
||||||
Typography,
|
Typography,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import React, { useState } from "react";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import { getTypeIcon } from "../utils/iconsCollection";
|
import React, { useMemo, useState } from "react";
|
||||||
|
import { playItemFromQueue } from "@/utils/store/playback";
|
||||||
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
import useQueue, {
|
||||||
import { useMutation, useQuery } from "@tanstack/react-query";
|
clearUpcoming,
|
||||||
|
removeFromQueue,
|
||||||
|
reorderQueue,
|
||||||
|
shuffleUpcoming,
|
||||||
|
} from "@/utils/store/queue";
|
||||||
import "./queueButton.scss";
|
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";
|
import { useApiInContext } from "@/utils/store/api";
|
||||||
|
import QueueListItem from "../queueListItem";
|
||||||
|
|
||||||
|
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 style = {
|
||||||
|
transform: CSS.Transform.toString(transform),
|
||||||
|
transition,
|
||||||
|
opacity: isDragging ? 0.5 : 1,
|
||||||
|
position: "relative" as const,
|
||||||
|
zIndex: isDragging ? 2 : 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<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 QueueButton = () => {
|
||||||
const api = useApiInContext((s) => s.api);
|
const api = useApiInContext((s) => s.api);
|
||||||
|
|
||||||
@@ -23,262 +89,281 @@ const QueueButton = () => {
|
|||||||
state.currentItemIndex,
|
state.currentItemIndex,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const user = useQuery({
|
const [open, setOpen] = useState(false);
|
||||||
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({
|
const user = useQuery({
|
||||||
mutationKey: ["handlePlayIndex"],
|
queryKey: ["currentUser"],
|
||||||
mutationFn: async ({ index }: { index: number }) => {
|
queryFn: async () => {
|
||||||
const result = playItemFromQueue(index, user.data?.Id, api);
|
if (!api) throw new Error("API not available");
|
||||||
return result;
|
return (await getUserApi(api).getCurrentUser()).data;
|
||||||
},
|
|
||||||
onSuccess: () => {
|
|
||||||
setButtonEl(null);
|
|
||||||
},
|
|
||||||
onError: (error) => {
|
|
||||||
console.error(error);
|
|
||||||
},
|
},
|
||||||
|
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 (
|
return (
|
||||||
<>
|
<>
|
||||||
<Menu
|
<Drawer
|
||||||
open={Boolean(buttonEl)}
|
anchor="right"
|
||||||
onClose={() => setButtonEl(null)}
|
open={open}
|
||||||
anchorEl={buttonEl}
|
onClose={() => setOpen(false)}
|
||||||
anchorOrigin={{
|
PaperProps={{
|
||||||
vertical: "top",
|
sx: {
|
||||||
horizontal: "center",
|
width: 450,
|
||||||
|
maxWidth: "100%",
|
||||||
|
display: "flex",
|
||||||
|
flexDirection: "column",
|
||||||
|
bgcolor: "background.default",
|
||||||
|
backgroundImage: "none",
|
||||||
|
},
|
||||||
}}
|
}}
|
||||||
transformOrigin={{
|
>
|
||||||
vertical: "bottom",
|
<Box
|
||||||
horizontal: "center",
|
p={3}
|
||||||
|
display="flex"
|
||||||
|
justifyContent="space-between"
|
||||||
|
alignItems="center"
|
||||||
|
sx={{
|
||||||
|
position: "sticky",
|
||||||
|
top: 0,
|
||||||
|
zIndex: 20,
|
||||||
|
bgcolor: "background.default",
|
||||||
|
borderBottom: "1px solid",
|
||||||
|
borderColor: "divider",
|
||||||
}}
|
}}
|
||||||
slotProps={{
|
>
|
||||||
paper: {
|
<Box display="flex" alignItems="center" gap={1}>
|
||||||
style: {
|
<Typography variant="h5" fontWeight="bold">
|
||||||
maxHeight: "30em",
|
Play Queue
|
||||||
overflowX: "hidden",
|
</Typography>
|
||||||
|
<Typography
|
||||||
|
variant="caption"
|
||||||
|
color="text.secondary"
|
||||||
|
sx={{
|
||||||
|
ml: 1,
|
||||||
|
fontWeight: 600,
|
||||||
|
bgcolor: "action.hover",
|
||||||
|
px: 1,
|
||||||
|
py: 0.5,
|
||||||
|
borderRadius: 2,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{queueItems?.length || 0}
|
||||||
|
</Typography>
|
||||||
|
</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",
|
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)",
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<MenuList
|
{queueItems && queueItems.length > 0 ? (
|
||||||
style={{
|
<List disablePadding>
|
||||||
height: "fit-content",
|
{/* Current Item */}
|
||||||
width: " 32em",
|
{queueItems[currentItemIndex] && (
|
||||||
position: "relative",
|
<Box sx={{ mb: 4 }}>
|
||||||
|
<Typography
|
||||||
|
variant="overline"
|
||||||
|
sx={{
|
||||||
|
display: "block",
|
||||||
|
opacity: 0.6,
|
||||||
|
mb: 1,
|
||||||
|
fontWeight: 600,
|
||||||
|
letterSpacing: 1.2,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{queueItems?.[currentItemIndex]?.Id && (
|
NOW PLAYING
|
||||||
<>
|
|
||||||
<Typography px="1em" mb={2} variant="h5" fontWeight={300}>
|
|
||||||
Currently Playing:
|
|
||||||
</Typography>
|
</Typography>
|
||||||
<MenuItem
|
<Box
|
||||||
className="queue-item"
|
sx={{
|
||||||
disabled
|
bgcolor: "background.paper",
|
||||||
key={queueItems[currentItemIndex].Id}
|
borderRadius: 3,
|
||||||
|
overflow: "hidden",
|
||||||
|
boxShadow: 4,
|
||||||
|
border: "1px solid",
|
||||||
|
borderColor: "divider",
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<Typography variant="subtitle2">
|
<QueueListItem
|
||||||
{queueItems[currentItemIndex]?.Type === "Audio"
|
queueItem={queueItems[currentItemIndex]}
|
||||||
? currentItemIndex + 1
|
active={true}
|
||||||
: queueItems[currentItemIndex].IndexNumberEnd
|
isEpisode={
|
||||||
? `S${queueItems[currentItemIndex].ParentIndexNumber}:E${queueItems[currentItemIndex].IndexNumber} / ${queueItems[currentItemIndex].IndexNumberEnd}`
|
queueItems[currentItemIndex].Type === "Episode"
|
||||||
: `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"}
|
index={currentItemIndex + 1}
|
||||||
/>
|
/>
|
||||||
) : (queueItems[currentItemIndex].AlbumPrimaryImageTag
|
</Box>
|
||||||
?.length ?? -1) > 0 ? (
|
</Box>
|
||||||
<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>
|
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{/* Upcoming Items */}
|
||||||
|
{upcomingItems.length > 0 && (
|
||||||
|
<>
|
||||||
|
<Typography
|
||||||
|
variant="overline"
|
||||||
|
sx={{
|
||||||
|
display: "block",
|
||||||
|
opacity: 0.6,
|
||||||
|
mb: 1,
|
||||||
|
fontWeight: 600,
|
||||||
|
letterSpacing: 1.2,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
NEXT UP
|
||||||
|
</Typography>
|
||||||
|
<DndContext
|
||||||
|
sensors={sensors}
|
||||||
|
collisionDetection={closestCenter}
|
||||||
|
onDragEnd={handleDragEnd}
|
||||||
|
modifiers={[restrictToVerticalAxis]}
|
||||||
|
>
|
||||||
|
<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>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</List>
|
||||||
|
) : (
|
||||||
|
<Box
|
||||||
|
p={4}
|
||||||
|
textAlign="center"
|
||||||
|
display="flex"
|
||||||
|
flexDirection="column"
|
||||||
|
alignItems="center"
|
||||||
|
gap={2}
|
||||||
|
sx={{ opacity: 0.5 }}
|
||||||
|
>
|
||||||
<span
|
<span
|
||||||
className="material-symbols-rounded"
|
className="material-symbols-rounded"
|
||||||
style={{
|
style={{ fontSize: 48 }}
|
||||||
position: "absolute",
|
|
||||||
top: "50%",
|
|
||||||
left: "50%",
|
|
||||||
transform: "translate(-50%,-50%)",
|
|
||||||
fontSize: "2em",
|
|
||||||
//@ts-ignore
|
|
||||||
"--wght": "100",
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
equalizer
|
queue_music
|
||||||
</span>
|
</span>
|
||||||
</div>
|
<Typography>Your queue is empty</Typography>
|
||||||
<div className="queue-item-info">
|
</Box>
|
||||||
{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>
|
</Box>
|
||||||
</MenuItem>
|
</Drawer>
|
||||||
</>
|
<IconButton onClick={() => setOpen(true)}>
|
||||||
)}
|
|
||||||
{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}`}
|
|
||||||
</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>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
<div className="queue-item-info">
|
|
||||||
{item.SeriesName ? (
|
|
||||||
<>
|
|
||||||
<Typography
|
|
||||||
variant="subtitle1"
|
|
||||||
width="100%"
|
|
||||||
sx={{ overflow: "hidden", textOverflow: "ellipsis" }}
|
|
||||||
>
|
|
||||||
{item.SeriesName}
|
|
||||||
</Typography>
|
|
||||||
<Typography
|
|
||||||
variant="subtitle2"
|
|
||||||
width="100%"
|
|
||||||
style={{ opacity: 0.6 }}
|
|
||||||
>
|
|
||||||
{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>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</MenuItem>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</MenuList>
|
|
||||||
</Menu>
|
|
||||||
<IconButton onClick={(e) => setButtonEl(e.currentTarget)}>
|
|
||||||
<span className="material-symbols-rounded">playlist_play</span>
|
<span className="material-symbols-rounded">playlist_play</span>
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -199,7 +199,7 @@ const BubbleSlider = () => {
|
|||||||
trickplayResolution.Width / trickplayResolution.Height;
|
trickplayResolution.Width / trickplayResolution.Height;
|
||||||
|
|
||||||
trickplayStyle = {
|
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`,
|
backgroundPositionX: `${backgroundOffsetX}px`,
|
||||||
backgroundPositionY: `${backgroundOffsetY}px`,
|
backgroundPositionY: `${backgroundOffsetY}px`,
|
||||||
width: `${trickplayResolution.Width}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 React from "react";
|
||||||
import { useShallow } from "zustand/shallow";
|
import { useShallow } from "zustand/shallow";
|
||||||
import { usePlaybackStore } from "@/utils/store/playback";
|
import { usePlaybackStore } from "@/utils/store/playback";
|
||||||
@@ -24,33 +25,67 @@ const SkipSegmentButton = () => {
|
|||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (
|
const shouldShow =
|
||||||
!mediaSegments?.Items?.length ||
|
mediaSegments?.Items?.length &&
|
||||||
currentSegmentIndex < 0 ||
|
currentSegmentIndex >= 0 &&
|
||||||
!activeSegmentId ||
|
activeSegmentId &&
|
||||||
mediaSegments?.Items?.[currentSegmentIndex].Type === "Outro"
|
mediaSegments?.Items?.[currentSegmentIndex].Type !== "Outro";
|
||||||
) {
|
|
||||||
return null; // No segments to skip
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Button
|
<AnimatePresence>
|
||||||
variant="outlined"
|
{shouldShow && (
|
||||||
size="large"
|
<motion.div
|
||||||
//@ts-ignore
|
initial={{ opacity: 0, x: 20, scale: 0.9 }}
|
||||||
color="white"
|
animate={{ opacity: 1, x: 0, scale: 1 }}
|
||||||
|
exit={{ opacity: 0, x: 20, scale: 0.9 }}
|
||||||
|
transition={{
|
||||||
|
type: "spring",
|
||||||
|
stiffness: 300,
|
||||||
|
damping: 30,
|
||||||
|
}}
|
||||||
style={{
|
style={{
|
||||||
position: "absolute",
|
position: "absolute",
|
||||||
bottom:
|
right: "3em",
|
||||||
isUserHovering || !isPlayerPlaying || isUserSeeking ? "18vh" : "2em",
|
|
||||||
right: "2em",
|
|
||||||
transition: "bottom 0.3s ease-in-out",
|
|
||||||
zIndex: 10000,
|
zIndex: 10000,
|
||||||
|
bottom:
|
||||||
|
isUserHovering || !isPlayerPlaying || isUserSeeking ? "20vh" : "6em",
|
||||||
|
transition: "bottom 0.3s ease-in-out",
|
||||||
}}
|
}}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
onClick={skipSegment}
|
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}
|
Skip {mediaSegments?.Items?.[currentSegmentIndex].Type}
|
||||||
</Button>
|
</Button>
|
||||||
|
</motion.div>
|
||||||
|
)}
|
||||||
|
</AnimatePresence>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Button, Typography } from "@mui/material";
|
import { Box, Button, IconButton, Typography } from "@mui/material";
|
||||||
import { motion } from "motion/react";
|
import { AnimatePresence, motion } from "motion/react";
|
||||||
import React, { useMemo } from "react";
|
import React, { useEffect, useMemo, useState } from "react";
|
||||||
import { useShallow } from "zustand/shallow";
|
import { useShallow } from "zustand/shallow";
|
||||||
import getImageUrlsApi from "@/utils/methods/getImageUrlsApi";
|
import getImageUrlsApi from "@/utils/methods/getImageUrlsApi";
|
||||||
import { useApiInContext } from "@/utils/store/api";
|
import { useApiInContext } from "@/utils/store/api";
|
||||||
@@ -36,6 +36,13 @@ const UpNextFlyout = () => {
|
|||||||
tracks: state.tracks,
|
tracks: state.tracks,
|
||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const [isHidden, setIsHidden] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setIsHidden(false);
|
||||||
|
}, [activeSegmentId]);
|
||||||
|
|
||||||
const areControlsVisible = useMemo(() => {
|
const areControlsVisible = useMemo(() => {
|
||||||
return isUserHovering || isUserSeeking || !isPlayerPlaying;
|
return isUserHovering || isUserSeeking || !isPlayerPlaying;
|
||||||
}, [isUserHovering, isUserSeeking, isPlayerPlaying]);
|
}, [isUserHovering, isUserSeeking, isPlayerPlaying]);
|
||||||
@@ -45,7 +52,8 @@ const UpNextFlyout = () => {
|
|||||||
if (
|
if (
|
||||||
!api ||
|
!api ||
|
||||||
!activeSegmentId ||
|
!activeSegmentId ||
|
||||||
mediaSegments?.Items?.[currentSegmemtIndex].Type !== "Outro"
|
mediaSegments?.Items?.[currentSegmemtIndex].Type !== "Outro" ||
|
||||||
|
isHidden
|
||||||
) {
|
) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -56,53 +64,154 @@ const UpNextFlyout = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<AnimatePresence>
|
||||||
<motion.div
|
<motion.div
|
||||||
className={
|
className={
|
||||||
areControlsVisible
|
areControlsVisible
|
||||||
? "video-player-up_next_flyout floating"
|
? "video-player-up_next_flyout floating"
|
||||||
: "video-player-up_next_flyout"
|
: "video-player-up_next_flyout"
|
||||||
}
|
}
|
||||||
initial={{ opacity: 0 }}
|
initial={{ opacity: 0, y: 50, scale: 0.95 }}
|
||||||
animate={{ opacity: 1 }}
|
animate={{ opacity: 1, y: 0, scale: 1 }}
|
||||||
>
|
exit={{ opacity: 0, y: 20, scale: 0.95 }}
|
||||||
<img
|
transition={{ duration: 0.4, ease: [0.4, 0, 0.2, 1] }}
|
||||||
className="video-player-up_next_flyout-thumbnail"
|
style={{
|
||||||
src={getImageUrlsApi(api).getItemImageUrlById(item.Id, "Primary", {
|
background: "rgba(20, 20, 20, 0.6)",
|
||||||
tag: item.ImageTags?.Primary,
|
backdropFilter: "blur(16px) saturate(180%)",
|
||||||
quality: 80,
|
border: "1px solid rgba(255, 255, 255, 0.1)",
|
||||||
fillWidth: 300,
|
boxShadow: "0 8px 32px 0 rgba(0, 0, 0, 0.3)",
|
||||||
})}
|
borderRadius: "24px",
|
||||||
alt={"next item thumbnail"}
|
padding: "16px",
|
||||||
/>
|
display: "flex",
|
||||||
<div className="video-player-up_next_flyout-details">
|
gap: "16px",
|
||||||
<Typography variant="h5">
|
maxWidth: "500px",
|
||||||
{`S${item.ParentIndexNumber}:E${item.IndexNumber} `}
|
width: "100%",
|
||||||
{item.Name}
|
|
||||||
</Typography>
|
|
||||||
<Typography
|
|
||||||
variant="subtitle2"
|
|
||||||
// noWrap
|
|
||||||
textOverflow="ellipsis"
|
|
||||||
maxWidth="100%"
|
|
||||||
sx={{
|
|
||||||
display: "-webkit-box",
|
|
||||||
webkitLineClamp: "3",
|
|
||||||
webkitBoxOrient: "vertical",
|
|
||||||
overflow: "hidden",
|
overflow: "hidden",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{item.Overview}
|
<Box
|
||||||
|
sx={{
|
||||||
|
position: "relative",
|
||||||
|
width: "160px",
|
||||||
|
minWidth: "160px",
|
||||||
|
borderRadius: "8px",
|
||||||
|
overflow: "hidden",
|
||||||
|
aspectRatio: "16/9",
|
||||||
|
boxShadow: "0 4px 12px rgba(0,0,0,0.3)",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<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",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Typography
|
||||||
|
variant="overline"
|
||||||
|
sx={{
|
||||||
|
color: "primary.main",
|
||||||
|
fontWeight: 700,
|
||||||
|
lineHeight: 1,
|
||||||
|
mb: 0.5,
|
||||||
|
letterSpacing: 1.2,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
UP NEXT
|
||||||
</Typography>
|
</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
|
<Button
|
||||||
onClick={skipSegment}
|
onClick={skipSegment}
|
||||||
variant="contained"
|
variant="contained"
|
||||||
color="primary"
|
color="primary"
|
||||||
className="video-player-up_next_flyout-button"
|
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
|
Play Now
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
<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>
|
</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 "./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 { useMutation } from "@tanstack/react-query";
|
||||||
import { createFileRoute, useRouter } from "@tanstack/react-router";
|
import { createFileRoute, useRouter } from "@tanstack/react-router";
|
||||||
import JASSUB from "jassub";
|
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);
|
const idleTimerRef = useRef<NodeJS.Timeout | null>(null);
|
||||||
|
|
||||||
// Function to clear the existing idle timer
|
// Function to clear the existing idle timer
|
||||||
|
|||||||
+152
-96
@@ -1,13 +1,15 @@
|
|||||||
import type { Api } from "@jellyfin/sdk";
|
import type { Api } from "@jellyfin/sdk";
|
||||||
import type {
|
import {
|
||||||
BaseItemDto,
|
type BaseItemDto,
|
||||||
MediaSegmentDtoQueryResult,
|
type MediaSegmentDtoQueryResult,
|
||||||
MediaStream,
|
type MediaStream,
|
||||||
|
type PlaybackInfoResponse,
|
||||||
PlayMethod,
|
PlayMethod,
|
||||||
} from "@jellyfin/sdk/lib/generated-client";
|
} from "@jellyfin/sdk/lib/generated-client";
|
||||||
import { getMediaInfoApi } from "@jellyfin/sdk/lib/utils/api/media-info-api";
|
import { getMediaInfoApi } from "@jellyfin/sdk/lib/utils/api/media-info-api";
|
||||||
import { getMediaSegmentsApi } from "@jellyfin/sdk/lib/utils/api/media-segments-api";
|
import { getMediaSegmentsApi } from "@jellyfin/sdk/lib/utils/api/media-segments-api";
|
||||||
import { getPlaystateApi } from "@jellyfin/sdk/lib/utils/api/playstate-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 { WebviewWindow as appWindow } from "@tauri-apps/api/webviewWindow";
|
||||||
import { create } from "zustand";
|
import { create } from "zustand";
|
||||||
import { immer } from "zustand/middleware/immer";
|
import { immer } from "zustand/middleware/immer";
|
||||||
@@ -371,7 +373,6 @@ export const usePlaybackStore = create<
|
|||||||
|
|
||||||
if (nextSegmentIndex !== -1) {
|
if (nextSegmentIndex !== -1) {
|
||||||
const nextSegment = metadata.mediaSegments?.Items?.[nextSegmentIndex];
|
const nextSegment = metadata.mediaSegments?.Items?.[nextSegmentIndex];
|
||||||
console.info("Next segment:", nextSegment);
|
|
||||||
if (nextSegment && ticks >= (nextSegment.StartTicks ?? ticks + 1)) {
|
if (nextSegment && ticks >= (nextSegment.StartTicks ?? ticks + 1)) {
|
||||||
// If the current time is past the next segment's start time, set it as active.
|
// If the current time is past the next segment's start time, set it as active.
|
||||||
// clearActiveSegment();
|
// clearActiveSegment();
|
||||||
@@ -669,6 +670,145 @@ export const playItem = (args: {
|
|||||||
setQueue(args.queueItems, args.queueItemIndex ?? 0);
|
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 (
|
export const playItemFromQueue = async (
|
||||||
index: "next" | "previous" | number,
|
index: "next" | "previous" | number,
|
||||||
userId: string | undefined,
|
userId: string | undefined,
|
||||||
@@ -767,98 +907,14 @@ export const playItemFromQueue = async (
|
|||||||
const mediaSource = playbackInfoResponse.data;
|
const mediaSource = playbackInfoResponse.data;
|
||||||
const mediaSegments = segmentsResponse.data;
|
const mediaSegments = segmentsResponse.data;
|
||||||
|
|
||||||
if (!mediaSource.MediaSources?.[0]?.Id) {
|
initializePlayback({
|
||||||
throw new Error("Media source is undefined in playItemFromQueue");
|
api,
|
||||||
}
|
|
||||||
|
|
||||||
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,
|
|
||||||
userId,
|
userId,
|
||||||
queueItems: queueItems,
|
item,
|
||||||
queueItemIndex: requestedItemIndex,
|
mediaSource,
|
||||||
|
mediaSegments,
|
||||||
|
queueItems: queueItems ?? [],
|
||||||
|
queueIndex: requestedItemIndex,
|
||||||
});
|
});
|
||||||
|
|
||||||
return "playing"; // Return any value to end mutation pending status
|
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 }));
|
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
|
* Resets the Queue store
|
||||||
|
|||||||
Reference in new issue
Block a user