fix: episode and series not playing if episode is not present in nextUp and continueWatching
This commit is contained in:
6 files changed
+66
-40
No files matched your search
@@ -20,7 +20,7 @@ export default function LikeButton({
|
||||
isFavorite: boolean | undefined;
|
||||
queryKey: string[] | undefined;
|
||||
userId: string | undefined;
|
||||
itemName: string | undefined;
|
||||
itemName?: string | null;
|
||||
}) {
|
||||
const api = useApiInContext((s) => s.api);
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
@@ -20,7 +20,7 @@ export default function MarkPlayedButton({
|
||||
isPlayed?: boolean;
|
||||
queryKey?: string[];
|
||||
userId?: string;
|
||||
itemName?: string;
|
||||
itemName?: string | null;
|
||||
}) {
|
||||
const api = useApiInContext((s) => s.api);
|
||||
|
||||
|
||||
@@ -145,7 +145,15 @@ const PlayButton = ({
|
||||
seasonId: item.SeasonId,
|
||||
// startItemId: item.Id,
|
||||
});
|
||||
index = result.data.Items?.map((i) => i.Id).indexOf(item.Id) ?? 0;
|
||||
if (
|
||||
result.data.Items?.map((i) => i.Id).indexOf(currentEpisodeId) &&
|
||||
result.data.Items?.map((i) => i.Id).indexOf(currentEpisodeId) >
|
||||
-1
|
||||
) {
|
||||
index = result.data.Items?.map((i) => i.Id).indexOf(
|
||||
currentEpisodeId,
|
||||
);
|
||||
}
|
||||
mediaSource = await getMediaInfoApi(api).getPostedPlaybackInfo({
|
||||
audioStreamIndex: currentAudioTrack,
|
||||
subtitleStreamIndex:
|
||||
@@ -180,11 +188,14 @@ const PlayButton = ({
|
||||
enableUserData: true,
|
||||
userId: userId,
|
||||
});
|
||||
index =
|
||||
result.data.Items?.map((i) => i.Id).indexOf(
|
||||
currentEpisodeId ?? "",
|
||||
) ?? 0;
|
||||
|
||||
if (
|
||||
result.data.Items?.map((i) => i.Id).indexOf(currentEpisodeId) &&
|
||||
result.data.Items?.map((i) => i.Id).indexOf(currentEpisodeId) > -1
|
||||
) {
|
||||
index = result.data.Items?.map((i) => i.Id).indexOf(
|
||||
currentEpisodeId,
|
||||
);
|
||||
}
|
||||
if (
|
||||
result.data.Items?.[index]?.Id &&
|
||||
result.data.Items?.[index].MediaSources?.[0]?.Id
|
||||
@@ -475,7 +486,7 @@ const PlayButton = ({
|
||||
if (!item.Id) {
|
||||
throw new Error("Item ID is not available");
|
||||
}
|
||||
let data: BaseItemDtoQueryResult | undefined;
|
||||
let data: BaseItemDtoQueryResult | null = null;
|
||||
const continueWatching = await getItemsApi(api).getResumeItems({
|
||||
userId: userId,
|
||||
limit: 1,
|
||||
@@ -493,10 +504,12 @@ const PlayButton = ({
|
||||
data = continueWatching.data;
|
||||
} else if ((nextUp.data.Items?.length ?? 0) > 0) {
|
||||
data = nextUp.data;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return data;
|
||||
},
|
||||
enabled: itemType === BaseItemKind.Series,
|
||||
// enabled: itemType === BaseItemKind.Series,
|
||||
});
|
||||
return (
|
||||
<div
|
||||
@@ -531,7 +544,7 @@ const PlayButton = ({
|
||||
color="white"
|
||||
size={size}
|
||||
>
|
||||
Watch S{currentEpisode.data?.Items?.[0].ParentIndexNumber}E
|
||||
Watch S{currentEpisode.data?.Items?.[0].ParentIndexNumber ?? 1}E
|
||||
{currentEpisode.data?.Items?.[0]?.IndexNumber ?? 1}
|
||||
<MemoizedLinearProgress
|
||||
//@ts-ignore
|
||||
|
||||
@@ -4,7 +4,6 @@ import { motion } from "framer-motion";
|
||||
|
||||
import Button from "@mui/material/Button";
|
||||
import Chip from "@mui/material/Chip";
|
||||
import Paper from "@mui/material/Paper";
|
||||
import Stack from "@mui/material/Stack";
|
||||
import Typography from "@mui/material/Typography";
|
||||
|
||||
@@ -17,6 +16,7 @@ import { getTypeIcon } from "../utils/iconsCollection";
|
||||
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import { useCarouselStore } from "@/utils/store/carousel";
|
||||
import { useCentralStore } from "@/utils/store/central";
|
||||
import {
|
||||
type BaseItemDto,
|
||||
BaseItemKind,
|
||||
@@ -24,7 +24,6 @@ import {
|
||||
import LikeButton from "../buttons/likeButton";
|
||||
import MarkPlayedButton from "../buttons/markPlayedButton";
|
||||
import PlayButton from "../buttons/playButton";
|
||||
import { useCentralStore } from "@/utils/store/central";
|
||||
|
||||
const CarouselSlide = ({ item }: { item: BaseItemDto }) => {
|
||||
const api = useApiInContext((s) => s.api);
|
||||
@@ -74,20 +73,20 @@ const CarouselSlide = ({ item }: { item: BaseItemDto }) => {
|
||||
className="hero-carousel-background-image"
|
||||
src={
|
||||
item.ParentBackdropItemId
|
||||
? `${api.basePath}/Items/${item.ParentBackdropItemId}/Images/Backdrop?quality=80`
|
||||
: `${api.basePath}/Items/${item.Id}/Images/Backdrop?quality=80&fillHeight=1400`
|
||||
? `${api?.basePath}/Items/${item.ParentBackdropItemId}/Images/Backdrop?quality=80`
|
||||
: `${api?.basePath}/Items/${item.Id}/Images/Backdrop?quality=80&fillHeight=1400`
|
||||
}
|
||||
style={{
|
||||
opacity: 0,
|
||||
}}
|
||||
onLoad={(e) => {
|
||||
e.target.style.opacity = 1;
|
||||
e.currentTarget.style.opacity = "1";
|
||||
}}
|
||||
loading="eager"
|
||||
/>
|
||||
) : (
|
||||
<div className="hero-carousel-background-icon-container">
|
||||
{getTypeIcon(item.Type)}
|
||||
{getTypeIcon(item.Type ?? "Movie")}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
@@ -129,16 +128,16 @@ const CarouselSlide = ({ item }: { item: BaseItemDto }) => {
|
||||
item.Name
|
||||
) : (
|
||||
<img
|
||||
alt={item.Name}
|
||||
alt={item.Name ?? "Item"}
|
||||
className="hero-carousel-text-logo"
|
||||
src={`${api.basePath}/Items/${item.Id}/Images/Logo?quality=90&tag=${item.ImageTags.Logo}`}
|
||||
src={`${api?.basePath}/Items/${item.Id}/Images/Logo?quality=90&tag=${item.ImageTags.Logo}`}
|
||||
style={{
|
||||
opacity: 0,
|
||||
transition: "opacity 0.2s",
|
||||
objectFit: "contain",
|
||||
}}
|
||||
onLoad={(e) => {
|
||||
e.target.style.opacity = 1;
|
||||
e.currentTarget.style.opacity = "1";
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
@@ -240,15 +239,21 @@ const CarouselSlide = ({ item }: { item: BaseItemDto }) => {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{item.RunTimeTicks && (
|
||||
{item.RunTimeTicks ? (
|
||||
<Typography style={{ opacity: "0.8" }} variant="subtitle2">
|
||||
{getRuntime(item.RunTimeTicks)}
|
||||
</Typography>
|
||||
) : (
|
||||
<></>
|
||||
)}
|
||||
{item.RunTimeTicks && (
|
||||
{item.RunTimeTicks ? (
|
||||
<Typography style={{ opacity: "0.8" }} variant="subtitle2">
|
||||
{endsAt(item.RunTimeTicks - item.UserData.PlaybackPositionTicks)}
|
||||
{endsAt(
|
||||
item.RunTimeTicks - (item.UserData?.PlaybackPositionTicks ?? 0),
|
||||
)}
|
||||
</Typography>
|
||||
) : (
|
||||
<></>
|
||||
)}
|
||||
<Typography variant="subtitle2" style={{ opacity: 0.8 }}>
|
||||
{item.Genres?.slice(0, 4).join(" / ")}
|
||||
@@ -305,16 +310,14 @@ const CarouselSlide = ({ item }: { item: BaseItemDto }) => {
|
||||
>
|
||||
<PlayButton
|
||||
item={item}
|
||||
itemId={item.Id}
|
||||
userId={user?.Id}
|
||||
itemType={item.Type}
|
||||
itemType={item.Type ?? "Movie"}
|
||||
currentAudioTrack={0}
|
||||
currentSubTrack={0}
|
||||
currentVideoTrack={0}
|
||||
buttonProps={{
|
||||
size: "large",
|
||||
}}
|
||||
itemUserData={item.UserData}
|
||||
audio={
|
||||
item.Type === BaseItemKind.MusicAlbum ||
|
||||
item.Type === BaseItemKind.Audio ||
|
||||
@@ -327,6 +330,7 @@ const CarouselSlide = ({ item }: { item: BaseItemDto }) => {
|
||||
|
||||
<Button
|
||||
size="large"
|
||||
//@ts-ignore
|
||||
color="white"
|
||||
variant="outlined"
|
||||
endIcon={
|
||||
|
||||
Reference in new issue
Block a user