feat: shpw upNext card and reset segements while seeking
This commit is contained in:
6 files changed
+187
-3
No files matched your search
@@ -19,7 +19,6 @@ export default function Backdrop() {
|
|||||||
return (
|
return (
|
||||||
<div className="app-backdrop-container">
|
<div className="app-backdrop-container">
|
||||||
<BlurhashCanvas
|
<BlurhashCanvas
|
||||||
key={backdropHash}
|
|
||||||
blurhashString={backdropHash}
|
blurhashString={backdropHash}
|
||||||
width={300}
|
width={300}
|
||||||
height={150}
|
height={150}
|
||||||
|
|||||||
@@ -27,7 +27,8 @@ const SkipSegmentButton = () => {
|
|||||||
if (
|
if (
|
||||||
!mediaSegments?.Items?.length ||
|
!mediaSegments?.Items?.length ||
|
||||||
currentSegmentIndex < 0 ||
|
currentSegmentIndex < 0 ||
|
||||||
!activeSegmentId
|
!activeSegmentId ||
|
||||||
|
mediaSegments?.Items?.[currentSegmentIndex].Type === "Outro"
|
||||||
) {
|
) {
|
||||||
return null; // No segments to skip
|
return null; // No segments to skip
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
.video-player-up_next_flyout {
|
||||||
|
position: absolute;
|
||||||
|
bottom: 2em;
|
||||||
|
right: 2em;
|
||||||
|
width: 42em;
|
||||||
|
height: fit-content;
|
||||||
|
display: flex;
|
||||||
|
gap: 10px;
|
||||||
|
align-items: stretch;
|
||||||
|
justify-content: center;
|
||||||
|
background-color: rgba(60, 60, 60,1);
|
||||||
|
padding: 10px;
|
||||||
|
border-radius: $border-radius-default + 10px;
|
||||||
|
z-index: 10;
|
||||||
|
transition: bottom 0.3s ease-in-out;
|
||||||
|
|
||||||
|
&.floating {
|
||||||
|
bottom: 18vh
|
||||||
|
}
|
||||||
|
|
||||||
|
&-thumbnail {
|
||||||
|
max-width: 100%;
|
||||||
|
max-height: 100%;
|
||||||
|
width: 15em;
|
||||||
|
object-fit: cover;
|
||||||
|
border-radius: $border-radius-default;
|
||||||
|
}
|
||||||
|
&-details {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 5px;
|
||||||
|
overflow: hidden;
|
||||||
|
justify-content: flex-start;
|
||||||
|
align-items: flex-start;
|
||||||
|
// height: 100%;
|
||||||
|
}
|
||||||
|
&-button{
|
||||||
|
// justify-self: flex-end;
|
||||||
|
margin-top: auto;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,109 @@
|
|||||||
|
import { Button, Typography } from "@mui/material";
|
||||||
|
import { motion } from "motion/react";
|
||||||
|
import React, { useMemo } from "react";
|
||||||
|
import { useShallow } from "zustand/shallow";
|
||||||
|
import getImageUrlsApi from "@/utils/methods/getImageUrlsApi";
|
||||||
|
import { useApiInContext } from "@/utils/store/api";
|
||||||
|
import { usePlaybackStore } from "@/utils/store/playback";
|
||||||
|
import useQueue from "@/utils/store/queue";
|
||||||
|
|
||||||
|
import "./upNextFlyout.scss";
|
||||||
|
|
||||||
|
const UpNextFlyout = () => {
|
||||||
|
const {
|
||||||
|
activeSegmentId,
|
||||||
|
currentSegmemtIndex,
|
||||||
|
mediaSegments,
|
||||||
|
skipSegment,
|
||||||
|
isUserHovering,
|
||||||
|
isUserSeeking,
|
||||||
|
isPlayerPlaying,
|
||||||
|
} = usePlaybackStore(
|
||||||
|
useShallow((state) => ({
|
||||||
|
activeSegmentId: state.activeSegmentId,
|
||||||
|
currentSegmemtIndex: state.nextSegmentIndex - 1,
|
||||||
|
mediaSegments: state.metadata.mediaSegments,
|
||||||
|
skipSegment: state.skipSegment,
|
||||||
|
isUserHovering: state.playerState.isUserHovering,
|
||||||
|
isUserSeeking: state.playerState.isUserSeeking,
|
||||||
|
isPlayerPlaying: state.playerState.isPlayerPlaying,
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
|
||||||
|
const { nextItemIndex, tracks } = useQueue(
|
||||||
|
useShallow((state) => ({
|
||||||
|
nextItemIndex: state.currentItemIndex + 1,
|
||||||
|
tracks: state.tracks,
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
const areControlsVisible = useMemo(() => {
|
||||||
|
return isUserHovering || isUserSeeking || !isPlayerPlaying;
|
||||||
|
}, [isUserHovering, isUserSeeking, isPlayerPlaying]);
|
||||||
|
|
||||||
|
const api = useApiInContext((s) => s.api);
|
||||||
|
|
||||||
|
if (
|
||||||
|
!api ||
|
||||||
|
!activeSegmentId ||
|
||||||
|
mediaSegments?.Items?.[currentSegmemtIndex].Type !== "Outro"
|
||||||
|
) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const item = tracks?.[nextItemIndex];
|
||||||
|
if (!item || !item.Id) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
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%"
|
||||||
|
sx={{
|
||||||
|
display: "-webkit-box",
|
||||||
|
webkitLineClamp: "3",
|
||||||
|
webkitBoxOrient: "vertical",
|
||||||
|
overflow: "hidden",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{item.Overview}
|
||||||
|
</Typography>
|
||||||
|
<Button
|
||||||
|
onClick={skipSegment}
|
||||||
|
variant="contained"
|
||||||
|
color="primary"
|
||||||
|
className="video-player-up_next_flyout-button"
|
||||||
|
>
|
||||||
|
Play
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</motion.div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default UpNextFlyout;
|
||||||
@@ -23,6 +23,7 @@ import { useShallow } from "zustand/shallow";
|
|||||||
import SkipSegmentButton from "@/components/playback/videoPlayer/buttons/SkipSegmentButton";
|
import SkipSegmentButton from "@/components/playback/videoPlayer/buttons/SkipSegmentButton";
|
||||||
import VideoPlayerControls from "@/components/playback/videoPlayer/controls";
|
import VideoPlayerControls from "@/components/playback/videoPlayer/controls";
|
||||||
import LoadingIndicator from "@/components/playback/videoPlayer/LoadingIndicator";
|
import LoadingIndicator from "@/components/playback/videoPlayer/LoadingIndicator";
|
||||||
|
import UpNextFlyout from "@/components/playback/videoPlayer/upNextFlyout";
|
||||||
import VolumeChangeOverlay from "@/components/playback/videoPlayer/VolumeChangeOverlay";
|
import VolumeChangeOverlay from "@/components/playback/videoPlayer/VolumeChangeOverlay";
|
||||||
import { useApiInContext } from "@/utils/store/api";
|
import { useApiInContext } from "@/utils/store/api";
|
||||||
import { useBackdropStore } from "@/utils/store/backdrop";
|
import { useBackdropStore } from "@/utils/store/backdrop";
|
||||||
@@ -108,6 +109,7 @@ export function VideoPlayer() {
|
|||||||
registerPlayerActions,
|
registerPlayerActions,
|
||||||
toggleIsPlayerFullscreen,
|
toggleIsPlayerFullscreen,
|
||||||
setIsUserHovering,
|
setIsUserHovering,
|
||||||
|
handleOnSeek,
|
||||||
} = usePlaybackStore(
|
} = usePlaybackStore(
|
||||||
useShallow((state) => ({
|
useShallow((state) => ({
|
||||||
itemId: state.metadata.item?.Id,
|
itemId: state.metadata.item?.Id,
|
||||||
@@ -134,6 +136,7 @@ export function VideoPlayer() {
|
|||||||
setIsBuffering: state.setIsBuffering,
|
setIsBuffering: state.setIsBuffering,
|
||||||
registerPlayerActions: state.registerPlayerActions,
|
registerPlayerActions: state.registerPlayerActions,
|
||||||
setIsUserHovering: state.setIsUserHovering,
|
setIsUserHovering: state.setIsUserHovering,
|
||||||
|
handleOnSeek: state.handleOnSeek,
|
||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -446,6 +449,7 @@ export function VideoPlayer() {
|
|||||||
/>
|
/>
|
||||||
<SkipSegmentButton />
|
<SkipSegmentButton />
|
||||||
<VolumeChangeOverlay />
|
<VolumeChangeOverlay />
|
||||||
|
<UpNextFlyout />
|
||||||
|
|
||||||
<ReactPlayer
|
<ReactPlayer
|
||||||
key={playsessionId}
|
key={playsessionId}
|
||||||
@@ -465,6 +469,7 @@ export function VideoPlayer() {
|
|||||||
volume={isPlayerMuted ? 0 : volume}
|
volume={isPlayerMuted ? 0 : volume}
|
||||||
onWaiting={handleOnBuffer}
|
onWaiting={handleOnBuffer}
|
||||||
onPlaying={handleOnBufferEnd}
|
onPlaying={handleOnBufferEnd}
|
||||||
|
onSeeking={(e) => handleOnSeek(e.currentTarget.currentTime)}
|
||||||
playsInline
|
playsInline
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -250,6 +250,7 @@ type PlaybackStoreActions = {
|
|||||||
* Skip current media segment
|
* Skip current media segment
|
||||||
*/
|
*/
|
||||||
skipSegment: () => void;
|
skipSegment: () => void;
|
||||||
|
handleOnSeek: (seconds: number) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const usePlaybackStore = create<
|
export const usePlaybackStore = create<
|
||||||
@@ -487,7 +488,7 @@ export const usePlaybackStore = create<
|
|||||||
|
|
||||||
// -- ReactPlayer related actions --
|
// -- ReactPlayer related actions --
|
||||||
_playerActions: {
|
_playerActions: {
|
||||||
seekTo: (seconds: number) =>
|
seekTo: (_seconds: number) =>
|
||||||
console.warn(
|
console.warn(
|
||||||
"ReactPlayer has not yet initialized. Please wait until the player is ready to seek.",
|
"ReactPlayer has not yet initialized. Please wait until the player is ready to seek.",
|
||||||
),
|
),
|
||||||
@@ -581,6 +582,34 @@ export const usePlaybackStore = create<
|
|||||||
state.playerState.currentTime = ticks;
|
state.playerState.currentTime = ticks;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
handleOnSeek: (seconds) => {
|
||||||
|
const ticks = secToTicks(seconds);
|
||||||
|
const segments = get().metadata.mediaSegments?.Items;
|
||||||
|
if (!segments || segments.length === 0) {
|
||||||
|
console.warn("No segments available for seeking");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const segment = segments.find(
|
||||||
|
(s) =>
|
||||||
|
(s.StartTicks ?? ticks) <= ticks && (s.EndTicks ?? ticks) >= ticks,
|
||||||
|
);
|
||||||
|
const nextIndex = segments.findIndex(
|
||||||
|
(s) => (s.StartTicks ?? ticks) > ticks,
|
||||||
|
);
|
||||||
|
if (segment?.Id) {
|
||||||
|
// If the segment is found, set it as active
|
||||||
|
set({
|
||||||
|
activeSegmentId: segment.Id,
|
||||||
|
nextSegmentIndex: nextIndex !== -1 ? nextIndex : segments.length,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// If no segment is found, clear the active segment
|
||||||
|
set({
|
||||||
|
activeSegmentId: null,
|
||||||
|
nextSegmentIndex: nextIndex !== -1 ? nextIndex : segments.length,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user