feat: show upNext card for episode items in player

This commit is contained in:
Prayag Prajapati committed 2024-07-22 21:52:01 +05:30
1 parent ffbca70de3
commit 3163951439
8 files changed
+414 -212

No files matched your search

+27 -5
View File
@@ -108,9 +108,14 @@ const PlayButton = ({
case BaseItemKind.Episode:
result = await getTvShowsApi(api).getEpisodes({
seriesId: item.SeriesId,
fields: [ItemFields.MediaSources, ItemFields.MediaStreams],
fields: [
ItemFields.MediaSources,
ItemFields.MediaStreams,
ItemFields.Overview,
],
enableUserData: true,
userId: userId,
seasonId: item.SeasonId,
// startItemId: item.Id,
});
mediaSource = await getMediaInfoApi(api).getPostedPlaybackInfo({
@@ -142,11 +147,29 @@ const PlayButton = ({
} catch (error) {
console.error(error);
}
try {
introInfo = (
await axiosClient.get(
`${api.basePath}/Episode/${result.data.Items?.[0]?.Id}/IntroSkipperSegments`,
{
headers: {
Authorization: `MediaBrowser Token=${api.accessToken}`,
},
},
)
)?.data;
} catch (error) {
console.error(error);
}
break;
case BaseItemKind.Series:
result = await getTvShowsApi(api).getEpisodes({
seriesId: itemId,
fields: [ItemFields.MediaSources, ItemFields.MediaStreams],
fields: [
ItemFields.MediaSources,
ItemFields.MediaStreams,
ItemFields.Overview,
],
enableUserData: true,
userId: userId,
});
@@ -166,7 +189,7 @@ const PlayButton = ({
try {
introInfo = (
await axiosClient.get(
`${api.basePath}/Episode/${result.data.Items?.[0]?.Id}/IntroTimestamps`,
`${api.basePath}/Episode/${result.data.Items?.[0]?.Id}/IntroSkipperSegments`,
{
headers: {
Authorization: `MediaBrowser Token=${api.accessToken}`,
@@ -251,7 +274,7 @@ const PlayButton = ({
api_key: api?.accessToken,
};
const urlParams = new URLSearchParams(urlOptions).toString();
const playbackUrl = `${api.basePath}/Audio/${result?.item.Items[0].Id}/universal?${urlParams}`;
playAudio(playbackUrl, result?.item.Items[0], undefined);
setQueue(result?.item.Items ?? [], 0);
@@ -272,7 +295,6 @@ const PlayButton = ({
currentSubTrack,
result?.mediaSource.MediaSources?.[0].MediaStreams,
);
console.log(subtitle);
// URL generation
const urlOptions = {
Static: true,
+1 -1
View File
@@ -126,7 +126,7 @@ const Carousel = ({
setCurrentSlide(index);
}}
>
{item.ImageTags?.Primary ? (
{item.ImageTags?.Thumb ? (
<img
src={api.getItemImageUrl(item.Id, "Thumb", {
tag: item.ImageTags.Primary,
+87
View File
@@ -0,0 +1,87 @@
import { useApiInContext } from "@/utils/store/api";
import { playItemFromQueue, usePlaybackStore } from "@/utils/store/playback";
import useQueue from "@/utils/store/queue";
import { Button, Typography } from "@mui/material";
import React from "react";
import { getTypeIcon } from "../utils/iconsCollection";
import "./outroCard.scss";
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
import { useMutation, useQuery } from "@tanstack/react-query";
const OutroCard = (props: { handleShowCredits: () => void }) => {
const api = useApiInContext((s) => s.api);
const [nextItemIndex, queueItems] = useQueue((s) => [
s.currentItemIndex,
s.tracks,
]);
const item = queueItems[nextItemIndex + 1];
const user = useQuery({
queryKey: ["user"],
queryFn: async () => {
const result = await getUserApi(api).getCurrentUser();
return result.data;
},
});
const handlePlayNext = useMutation({
mutationKey: ["playNextButton"],
mutationFn: () => playItemFromQueue("next", user.data?.Id, api),
onError: (error) => [console.error(error)],
});
return (
<div className="outro-card">
<Typography variant="h4">Up Next</Typography>
<div className="outro-card-content">
{item?.ImageTags?.Primary ? (
<img
className="outro-card-content-image"
alt={item.Name ?? "Cover"}
src={api.getItemImageUrl(item.Id, "Primary", {
tag: item.ImageTags.Primary,
quality: 80,
})}
/>
) : (
<div className="outro-card-content-image icon">
{getTypeIcon(item?.Type)}
</div>
)}
<Typography variant="h5" className="outro-card-content-title">
{item.Name}
</Typography>
<Typography variant="subtitle2" className="outro-card-content-overview">
{item.Overview}
</Typography>
<div className="outro-card-content-buttons">
<Button
onClick={handlePlayNext.mutate}
color="white"
variant="contained"
startIcon={
<div
className="material-symbols-rounded fill"
style={{
zIndex: 1,
fontSize: "2em",
}}
>
play_arrow
</div>
}
>
Play Now
</Button>
<Button
onClick={props.handleShowCredits}
color="white"
variant="outlined"
>
Watch Credits
</Button>
</div>
</div>
</div>
);
};
export default OutroCard;
+50
View File
@@ -0,0 +1,50 @@
.outro-card {
position: absolute;
bottom: 0;
left: 0;
right: 0;
z-index: 1000;
display: flex;
flex-direction: column;
padding: 0 5vw 2em 5vw;
gap: 1.2em;
background: linear-gradient(to top, rgb(10 10 10), rgb(10 10 10 / 0.7) 50%, transparent);
padding-top: 25vh;
&-content {
display: grid;
grid-template-areas: "img title"
"img info"
"img buttons";
grid-template-columns: 20em 1fr;
align-items: center;
gap: 1em;
&-image {
grid-area: img;
max-height: 14em;
width: 20em;
object-fit: cover;
border-radius: $border-radius-default;
}
&-title {
grid-area: title;
}
&-overview {
grid-area: info;
display: -webkit-box;
text-overflow: ellipsis;
overflow: hidden;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
}
&-buttons {
grid-area: buttons;
display: flex;
gap: 1em;
}
}
}
+1
View File
@@ -38,6 +38,7 @@ import heroBg from "@/assets/herobg.png";
import "./boxset.scss";
import IconLink from "@/components/iconLink";
import { getTypeIcon } from "@/components/utils/iconsCollection";
import { createFileRoute } from "@tanstack/react-router";
function TabPanel(props) {
+235 -200
View File
@@ -39,6 +39,7 @@ import wasmUrl from "jassub/dist/jassub-worker.wasm?url";
import PlayNextButton from "@/components/buttons/playNextButton";
import PlayPreviousButton from "@/components/buttons/playPreviousButtom";
import QueueButton from "@/components/buttons/queueButton";
import OutroCard from "@/components/outroCard";
import { createFileRoute, useRouter } from "@tanstack/react-router";
import type { OnProgressProps } from "react-player/base";
import subtitleFont from "./Noto-Sans-Indosphere.ttf";
@@ -64,7 +65,7 @@ const ticksDisplay = (ticks: number) => {
})}`;
return formatedTime;
};
const VOLUME_SCROLL_INTERVAL = 0.05
const VOLUME_SCROLL_INTERVAL = 0.05;
export const Route = createFileRoute("/_api/player/")({
component: VideoPlayer,
@@ -116,8 +117,8 @@ function VideoPlayer() {
useEffect(() => setBackdrop("", ""), []);
const [clickTimeout, setClickTimeout] = useState<NodeJS.Timeout>(null)
const [clickTimeout, setClickTimeout] = useState<NodeJS.Timeout>(null);
const showSubtitles = useMemo(
() => mediaSource.subtitle.enable,
[mediaSource.subtitle],
@@ -164,14 +165,14 @@ function VideoPlayer() {
PlaybackStartTimeTicks: startPosition,
PositionTicks: secToTicks(event.playedSeconds),
RepeatMode: RepeatMode.RepeatNone,
VolumeLevel: volume * 100,
VolumeLevel: Math.floor(volume * 100),
},
});
};
const handleExitPlayer = async () => {
appWindow.getCurrent().setFullscreen(false);
history.back();
// Report Jellyfin server: Playback has ended/stopped
getPlaystateApi(api).reportPlaybackStopped({
@@ -246,28 +247,27 @@ function VideoPlayer() {
};
}, [handleKeyPress]);
useEffect(() => {
const handleMouseWheel = (event: WheelEvent) => {
console.log(event.deltaY);
if (event.deltaY < 0) {
// increase volume
setVolume((state) => Math.min(1, state + VOLUME_SCROLL_INTERVAL))
} else if (event.deltaY > 0) {
// decrease volume
setVolume((state) => Math.max(0, state - VOLUME_SCROLL_INTERVAL))
}
}
useEffect(() => {
const handleMouseWheel = (event: WheelEvent) => {
console.log(event.deltaY);
if (event.deltaY < 0) {
// increase volume
setVolume((state) => Math.min(1, state + VOLUME_SCROLL_INTERVAL));
} else if (event.deltaY > 0) {
// decrease volume
setVolume((state) => Math.max(0, state - VOLUME_SCROLL_INTERVAL));
}
};
// attach the event listener
document.addEventListener("wheel", handleMouseWheel);
document.addEventListener("wheel", handleMouseWheel);
// remove the event listener
return () => {
document.removeEventListener("wheel", handleMouseWheel);
}
}, [])
return () => {
document.removeEventListener("wheel", handleMouseWheel);
};
}, []);
useLayoutEffect(() => {
setPlaying(true);
@@ -321,17 +321,43 @@ function VideoPlayer() {
const showSkipIntroButton = useMemo(() => {
if (
ticksToSec(progress) >= introInfo?.ShowSkipPromptAt &&
ticksToSec(progress) < introInfo?.HideSkipPromptAt
ticksToSec(progress) >=
(introInfo?.Introduction?.ShowSkipPromptAt ?? 0) &&
ticksToSec(progress) < (introInfo?.Introduction?.HideSkipPromptAt ?? 0)
)
return true;
return false;
}, [progress]);
const showUpNextCard = useMemo(() => {
if (introInfo?.Credits) {
if (
ticksToSec(progress) >= introInfo?.Credits.ShowSkipPromptAt &&
ticksToSec(progress) < introInfo?.Credits.HideSkipPromptAt
)
return true;
}
if (
Math.ceil(ticksToSec(itemDuration) - ticksToSec(progress)) <= 30 &&
Math.ceil(ticksToSec(itemDuration) - ticksToSec(progress)) > 0
) {
return true;
}
return false;
}, [progress, item?.Id]);
const handleSkipIntro = useCallback(() => {
player.current?.seekTo(introInfo?.IntroEnd);
player.current?.seekTo(
introInfo?.Introduction.IntroEnd ?? player.current?.getCurrentTime(),
);
}, [item?.Id]);
const [forceShowCredits, setForceShowCredits] = useState(false);
const handleShowCredits = useCallback(() => {
setForceShowCredits(true);
}, []);
useEffect(() => setForceShowCredits(false), [item?.Id]);
return (
<div className="video-player">
<AnimatePresence>
@@ -374,6 +400,9 @@ function VideoPlayer() {
Skip Intro
</Button>
)}
{!forceShowCredits && showUpNextCard && (
<OutroCard handleShowCredits={handleShowCredits} />
)}
<motion.div
className={
hoveringOsd || !playing || isSeeking
@@ -390,24 +419,25 @@ function VideoPlayer() {
style={{
zIndex: 2,
}}
onClick={(event) => {
if (event.currentTarget !== event.target) {
return
}
onClick={(event) => {
if (event.currentTarget !== event.target) {
return;
}
if (event.detail === 1) {
setClickTimeout(
setTimeout(() => {
setPlaying((state) => !state);
}, 200))
} else if (event.detail === 2){
clearTimeout(clickTimeout)
setAppFullscreen((state) => {
appWindow.getCurrent().setFullscreen(!state);
return !state
});
}
}}
if (event.detail === 1) {
setClickTimeout(
setTimeout(() => {
setPlaying((state) => !state);
}, 200),
);
} else if (event.detail === 2) {
clearTimeout(clickTimeout);
setAppFullscreen((state) => {
appWindow.getCurrent().setFullscreen(!state);
return !state;
});
}
}}
>
<div className="video-player-osd-header flex flex-justify-spaced-between flex-align-center">
<IconButton onClick={handleExitPlayer}>
@@ -459,172 +489,177 @@ function VideoPlayer() {
</TextField>
</Menu>
</div>
<div className="video-player-osd-info">
<Typography variant="h4" fontWeight={500} mb={2}>
{itemName}
{episodeTitle && (
<Typography variant="h6" fontWeight={300} mt={1}>
{episodeTitle}
</Typography>
)}
</Typography>
<div className="video-player-osd-controls">
<div className="video-player-osd-controls-progress">
<Slider
value={isSeeking ? sliderProgress : progress}
max={itemDuration}
step={secToTicks(1)}
onChange={(e, newValue) => {
setIsSeeking(true);
setSliderProgress(newValue);
}}
onChangeCommitted={(e, newValue) => {
setIsSeeking(false);
setProgress(newValue);
player.current.seekTo(ticksToSec(newValue), "seconds");
}}
sx={{
"& .MuiSlider-thumb": {
width: 14,
height: 14,
transition: "0.1s ease-in-out",
opacity: 0,
"&.Mui-active": {
width: 20,
height: 20,
{(forceShowCredits || !showUpNextCard) && (
<div className="video-player-osd-info">
<Typography variant="h4" fontWeight={500} mb={2}>
{itemName}
{episodeTitle && (
<Typography variant="h6" fontWeight={300} mt={1}>
{episodeTitle}
</Typography>
)}
</Typography>
<div className="video-player-osd-controls">
<div className="video-player-osd-controls-progress">
<Slider
value={isSeeking ? sliderProgress : progress}
max={itemDuration}
step={secToTicks(10)}
onChange={(e, newValue) => {
setIsSeeking(true);
setSliderProgress(newValue);
}}
onChangeCommitted={(e, newValue) => {
setIsSeeking(false);
setProgress(newValue);
player.current?.seekTo(ticksToSec(newValue), "seconds");
}}
sx={{
"& .MuiSlider-thumb": {
width: 14,
height: 14,
transition: "0.1s ease-in-out",
opacity: 0,
"&.Mui-active": {
width: 20,
height: 20,
opacity: 1,
},
},
"&:hover .MuiSlider-thumb": {
opacity: 1,
},
},
"&:hover .MuiSlider-thumb": {
opacity: 1,
},
"& .MuiSlider-rail": {
opacity: 0.28,
background: "white",
},
}}
/>
<div className="video-player-osd-controls-progress-text">
<Typography>
{ticksDisplay(isSeeking ? sliderProgress : progress)}
</Typography>
<Typography>{ticksDisplay(itemDuration)}</Typography>
</div>
</div>
<div className="flex flex-row flex-justify-spaced-between">
<div className="video-player-osd-controls-buttons">
<PlayPreviousButton />
<IconButton
onClick={() =>
player.current.seekTo(player.current.getCurrentTime() - 15)
}
>
<span className="material-symbols-rounded fill">
fast_rewind
</span>
</IconButton>
<IconButton onClick={() => setPlaying((state) => !state)}>
<span className="material-symbols-rounded fill">
{playing ? "pause" : "play_arrow"}
</span>
</IconButton>
<IconButton
onClick={() =>
player.current.seekTo(player.current.getCurrentTime() + 15)
}
>
<span className="material-symbols-rounded fill">
fast_forward
</span>
</IconButton>
<PlayNextButton />
<Typography variant="subtitle1">
{isSeeking
? endsAt(itemDuration - sliderProgress)
: endsAt(itemDuration - progress)}
</Typography>
</div>
<div className="video-player-osd-controls-buttons">
<motion.div
style={{
width: "13em",
padding: "0.5em 1.5em",
paddingLeft: "0.8em",
gap: "0.4em",
background: "black",
borderRadius: "100px",
display: "grid",
justifyContent: "center",
alignItems: "center",
gridTemplateColumns: "2em 1fr",
opacity: 0,
"& .MuiSlider-rail": {
opacity: 0.28,
background: "white",
},
}}
animate={{
opacity: showVolumeControl ? 1 : 0,
}}
whileHover={{
opacity: 1,
}}
onMouseLeave={() => setShowVolumeControl(false)}
>
<Typography textAlign="center">
{muted ? 0 : Math.round(volume * 100)}
/>
<div className="video-player-osd-controls-progress-text">
<Typography>
{ticksDisplay(isSeeking ? sliderProgress : progress)}
</Typography>
<Slider
step={0.01}
max={1}
size="small"
value={muted ? 0 : volume}
onChange={(e, newVal) => {
setVolume(newVal);
if (newVal === 0) setMuted(true);
else setMuted(false);
<Typography>{ticksDisplay(itemDuration)}</Typography>
</div>
</div>
<div className="flex flex-row flex-justify-spaced-between">
<div className="video-player-osd-controls-buttons">
<PlayPreviousButton />
<IconButton
onClick={() =>
player.current.seekTo(
player.current.getCurrentTime() - 15,
)
}
>
<span className="material-symbols-rounded fill">
fast_rewind
</span>
</IconButton>
<IconButton onClick={() => setPlaying((state) => !state)}>
<span className="material-symbols-rounded fill">
{playing ? "pause" : "play_arrow"}
</span>
</IconButton>
<IconButton
onClick={() =>
player.current.seekTo(
player.current.getCurrentTime() + 15,
)
}
>
<span className="material-symbols-rounded fill">
fast_forward
</span>
</IconButton>
<PlayNextButton />
<Typography variant="subtitle1">
{isSeeking
? endsAt(itemDuration - sliderProgress)
: endsAt(itemDuration - progress)}
</Typography>
</div>
<div className="video-player-osd-controls-buttons">
<motion.div
style={{
width: "13em",
padding: "0.5em 1.5em",
paddingLeft: "0.8em",
gap: "0.4em",
background: "black",
borderRadius: "100px",
display: "grid",
justifyContent: "center",
alignItems: "center",
gridTemplateColumns: "2em 1fr",
opacity: 0,
}}
/>
</motion.div>
<IconButton
onClick={() => setMuted((state) => !state)}
onMouseMoveCapture={() => {
setShowVolumeControl(true);
}}
>
<span className="material-symbols-rounded">
{muted
? "volume_off"
: volume < 0.4
? "volume_down"
: "volume_up"}
</span>
</IconButton>
<QueueButton />
<IconButton
disabled={mediaSource.subtitle.track === -2}
onClick={toggleSubtitleTrack}
>
<span className={"material-symbols-rounded"}>
{mediaSource.subtitle.enable
? "closed_caption"
: "closed_caption_disabled"}
</span>
</IconButton>
<IconButton
onClick={async () => {
setAppFullscreen((state) => {
appWindow.getCurrent().setFullscreen(!state);
return !state;
});
}}
>
<span className="material-symbols-rounded fill">
{appFullscreen ? "fullscreen_exit" : "fullscreen"}
</span>
</IconButton>
animate={{
opacity: showVolumeControl ? 1 : 0,
}}
whileHover={{
opacity: 1,
}}
onMouseLeave={() => setShowVolumeControl(false)}
>
<Typography textAlign="center">
{muted ? 0 : Math.round(volume * 100)}
</Typography>
<Slider
step={0.01}
max={1}
size="small"
value={muted ? 0 : volume}
onChange={(e, newVal) => {
setVolume(newVal);
if (newVal === 0) setMuted(true);
else setMuted(false);
}}
/>
</motion.div>
<IconButton
onClick={() => setMuted((state) => !state)}
onMouseMoveCapture={() => {
setShowVolumeControl(true);
}}
>
<span className="material-symbols-rounded">
{muted
? "volume_off"
: volume < 0.4
? "volume_down"
: "volume_up"}
</span>
</IconButton>
<QueueButton />
<IconButton
disabled={mediaSource.subtitle.track === -2}
onClick={toggleSubtitleTrack}
>
<span className={"material-symbols-rounded"}>
{mediaSource.subtitle.enable
? "closed_caption"
: "closed_caption_disabled"}
</span>
</IconButton>
<IconButton
onClick={async () => {
setAppFullscreen((state) => {
appWindow.getCurrent().setFullscreen(!state);
return !state;
});
}}
>
<span className="material-symbols-rounded fill">
{appFullscreen ? "fullscreen_exit" : "fullscreen"}
</span>
</IconButton>
</div>
</div>
</div>
</div>
</div>
)}
</motion.div>
{/* <video src={hlsStream}></video> */}
<ReactPlayer
key={item?.Id}
playing={playing}
+7 -5
View File
@@ -130,6 +130,9 @@ export const playItemFromQueue = async (
: index === "previous"
? currentItemIndex - 1
: index;
const prevItem = queueItems[currentItemIndex];
const prevPlaySessionId = usePlaybackStore.getState().playsessionId;
const prevMediaSourceId = usePlaybackStore.getState().mediaSource.id;
const item = queueItems[requestedItemIndex];
if (item.Type === "Audio") {
const urlOptions = {
@@ -157,7 +160,6 @@ export const playItemFromQueue = async (
},
})
).data;
console.log(mediaSource);
let itemName = item.Name;
let episodeTitle = "";
if (item.SeriesId) {
@@ -197,7 +199,7 @@ export const playItemFromQueue = async (
try {
introInfo = (
await axiosClient.get(
`${api.basePath}/Episode/${item.Id}/IntroTimestamps`,
`${api.basePath}/Episode/${item.Id}/IntroSkipperSegments`,
{
headers: {
Authorization: `MediaBrowser Token=${api.accessToken}`,
@@ -213,9 +215,9 @@ export const playItemFromQueue = async (
getPlaystateApi(api).reportPlaybackStopped({
playbackStopInfo: {
Failed: false,
ItemId: item?.Id,
MediaSourceId: mediaSource.MediaSources?.[0].Id,
PlaySessionId: mediaSource.PlaySessionId,
ItemId: prevItem?.Id,
MediaSourceId: prevMediaSourceId,
PlaySessionId: prevPlaySessionId,
},
});
+6 -1
View File
@@ -1,4 +1,4 @@
type IntroMediaInfo = {
type introSkipperResult = {
EpisodeId: string;
Valid: true;
IntroStart: number;
@@ -7,4 +7,9 @@ type IntroMediaInfo = {
HideSkipPromptAt: number;
};
type IntroMediaInfo = {
Introduction: introSkipperResult;
Credits: introSkipperResult;
};
export default IntroMediaInfo