feat: show current time while scrubbing video progress #339

This commit is contained in:
Prayag Prajapati committed 2024-12-10 18:59:29 +05:30
1 parent 06015d7702
commit 7d2659f32b
4 files changed
+172 -80

No files matched your search

+2
View File
@@ -27,6 +27,7 @@
"@million/lint": "^1.0.13", "@million/lint": "^1.0.13",
"@mui/lab": "6.0.0-beta.17", "@mui/lab": "6.0.0-beta.17",
"@mui/material": "6.1.9", "@mui/material": "6.1.9",
"@popperjs/core": "^2.11.8",
"@react-spring/web": "^9.7.5", "@react-spring/web": "^9.7.5",
"@tanem/react-nprogress": "^5.0.53", "@tanem/react-nprogress": "^5.0.53",
"@tanstack/react-query": "^5.62.0", "@tanstack/react-query": "^5.62.0",
@@ -64,6 +65,7 @@
"react-markdown": "^9.0.1", "react-markdown": "^9.0.1",
"react-multi-carousel": "^2.8.5", "react-multi-carousel": "^2.8.5",
"react-player": "^2.16.0", "react-player": "^2.16.0",
"react-popper": "^2.3.0",
"react-use-konami": "^1.1.0", "react-use-konami": "^1.1.0",
"remark-gfm": "^4.0.0", "remark-gfm": "^4.0.0",
"typescript": "^5.7.2", "typescript": "^5.7.2",
+28
View File
@@ -50,6 +50,9 @@ importers:
'@mui/material': '@mui/material':
specifier: 6.1.9 specifier: 6.1.9
version: 6.1.9(@emotion/react@11.13.5(@types/react@18.3.12)(react@18.3.1))(@emotion/styled@11.13.5(@emotion/react@11.13.5(@types/react@18.3.12)(react@18.3.1))(@types/react@18.3.12)(react@18.3.1))(@types/react@18.3.12)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) version: 6.1.9(@emotion/react@11.13.5(@types/react@18.3.12)(react@18.3.1))(@emotion/styled@11.13.5(@emotion/react@11.13.5(@types/react@18.3.12)(react@18.3.1))(@types/react@18.3.12)(react@18.3.1))(@types/react@18.3.12)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
'@popperjs/core':
specifier: ^2.11.8
version: 2.11.8
'@react-spring/web': '@react-spring/web':
specifier: ^9.7.5 specifier: ^9.7.5
version: 9.7.5(react-dom@18.3.1(react@18.3.1))(react@18.3.1) version: 9.7.5(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
@@ -161,6 +164,9 @@ importers:
react-player: react-player:
specifier: ^2.16.0 specifier: ^2.16.0
version: 2.16.0(react@18.3.1) version: 2.16.0(react@18.3.1)
react-popper:
specifier: ^2.3.0
version: 2.3.0(@popperjs/core@2.11.8)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
react-use-konami: react-use-konami:
specifier: ^1.1.0 specifier: ^1.1.0
version: 1.1.0(react-dom@18.3.1(react@18.3.1))(react@18.3.1) version: 1.1.0(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
@@ -2762,6 +2768,13 @@ packages:
peerDependencies: peerDependencies:
react: '>=16.6.0' react: '>=16.6.0'
react-popper@2.3.0:
resolution: {integrity: sha512-e1hj8lL3uM+sgSR4Lxzn5h1GxBlpa4CQz0XLF8kx4MDrDRWY0Ena4c97PUeSX9i5W3UAfDP0z0FXCTQkoXUl3Q==}
peerDependencies:
'@popperjs/core': ^2.0.0
react: ^16.8.0 || ^17 || ^18
react-dom: ^16.8.0 || ^17 || ^18
react-refresh@0.14.2: react-refresh@0.14.2:
resolution: {integrity: sha512-jCvmsr+1IUSMUyzOkRcvnVbX3ZYC6g9TDrDbFuFmRDq7PD4yaGbLKNQL6k2jnArV8hjYxh7hVhAZB6s9HDGpZA==} resolution: {integrity: sha512-jCvmsr+1IUSMUyzOkRcvnVbX3ZYC6g9TDrDbFuFmRDq7PD4yaGbLKNQL6k2jnArV8hjYxh7hVhAZB6s9HDGpZA==}
engines: {node: '>=0.10.0'} engines: {node: '>=0.10.0'}
@@ -3107,6 +3120,9 @@ packages:
yaml: yaml:
optional: true optional: true
warning@4.0.3:
resolution: {integrity: sha512-rpJyN222KWIvHJ/F53XSZv0Zl/accqHR8et1kpaMTD/fLCRxtV8iX8czMzY7sVZupTI3zcUTg8eycS2kNF9l6w==}
wavesurfer.js@7.8.10: wavesurfer.js@7.8.10:
resolution: {integrity: sha512-fQtMENm5uPvB7GGZtWj61W82IighH2Jx6nbW6ciL1uITU6Ea9i3rvp+Z2CTJaau5dMwAD6pCALkNvTkIXIIeYw==} resolution: {integrity: sha512-fQtMENm5uPvB7GGZtWj61W82IighH2Jx6nbW6ciL1uITU6Ea9i3rvp+Z2CTJaau5dMwAD6pCALkNvTkIXIIeYw==}
@@ -5783,6 +5799,14 @@ snapshots:
react: 18.3.1 react: 18.3.1
react-fast-compare: 3.2.2 react-fast-compare: 3.2.2
react-popper@2.3.0(@popperjs/core@2.11.8)(react-dom@18.3.1(react@18.3.1))(react@18.3.1):
dependencies:
'@popperjs/core': 2.11.8
react: 18.3.1
react-dom: 18.3.1(react@18.3.1)
react-fast-compare: 3.2.2
warning: 4.0.3
react-refresh@0.14.2: {} react-refresh@0.14.2: {}
react-scan@0.0.31: react-scan@0.0.31:
@@ -6195,6 +6219,10 @@ snapshots:
tsx: 4.19.2 tsx: 4.19.2
yaml: 2.6.1 yaml: 2.6.1
warning@4.0.3:
dependencies:
loose-envify: 1.4.0
wavesurfer.js@7.8.10: {} wavesurfer.js@7.8.10: {}
webidl-conversions@3.0.1: {} webidl-conversions@3.0.1: {}
+130 -77
View File
@@ -41,7 +41,13 @@ import { AnimatePresence, motion } from "framer-motion";
import { useBackdropStore } from "@/utils/store/backdrop"; import { useBackdropStore } from "@/utils/store/backdrop";
import { Button, LinearProgress, Popover, TextField } from "@mui/material"; import {
Button,
LinearProgress,
Popover,
TextField,
Tooltip,
} from "@mui/material";
import JASSUB from "jassub"; import JASSUB from "jassub";
//@ts-ignore //@ts-ignore
import workerUrl from "jassub/dist/jassub-worker.js?url"; import workerUrl from "jassub/dist/jassub-worker.js?url";
@@ -60,6 +66,7 @@ import { toNumber } from "lodash";
import type { OnProgressProps } from "react-player/base"; import type { OnProgressProps } from "react-player/base";
import type subtitlePlaybackInfo from "@/utils/types/subtitlePlaybackInfo"; import type subtitlePlaybackInfo from "@/utils/types/subtitlePlaybackInfo";
import type { Instance } from "@popperjs/core";
//@ts-ignore //@ts-ignore
import font from "./Noto-Sans-Indosphere.ttf?url"; import font from "./Noto-Sans-Indosphere.ttf?url";
@@ -493,24 +500,12 @@ function VideoPlayer() {
if (index + 1 === item.Chapters?.length) { if (index + 1 === item.Chapters?.length) {
return chapter; return chapter;
} }
if (isSeeking) { if (
if ( (item.Chapters?.[index + 1]?.StartPositionTicks ?? value) - value >=
(item.Chapters?.[index + 1]?.StartPositionTicks ?? sliderProgress) - 0 &&
sliderProgress >= (chapter.StartPositionTicks ?? value) - value < 0
0 && ) {
(chapter.StartPositionTicks ?? sliderProgress) - sliderProgress < 0 return chapter;
) {
return chapter;
}
} else {
if (
(item.Chapters?.[index + 1]?.StartPositionTicks ?? progress) -
progress >=
0 &&
(chapter.StartPositionTicks ?? progress) - progress < 0
) {
return chapter;
}
} }
}); });
@@ -564,41 +559,43 @@ function VideoPlayer() {
}; };
const imgUrlParams = new URLSearchParams(imgUrlParamsObject).toString(); const imgUrlParams = new URLSearchParams(imgUrlParamsObject).toString();
const imageAspectRatio = trickplayResolution.Width / trickplayResolution.Height;
if (currentChapter?.[0]?.Name) { if (currentChapter?.[0]?.Name) {
return ( return (
<div className="flex flex-column video-osb-bubble glass"> <div className="flex flex-column video-osb-bubble">
<div <div
className="video-osd-trickplayBubble" className="video-osd-trickplayBubble"
style={{ style={{
background: `url(${api?.basePath}/Videos/${item?.Id}/Trickplay/${trickplayResolution.Width}/${index}.jpg?${imgUrlParams})`, background: `url(${api?.basePath}/Videos/${item?.Id}/Trickplay/${trickplayResolution.Width}/${index}.jpg?${imgUrlParams})`,
backgroundPositionX: `${backgroundOffsetX}px`, backgroundPositionX: `${backgroundOffsetX}px`,
backgroundPositionY: `${backgroundOffsetY}px`, backgroundPositionY: `${backgroundOffsetY}px`,
width: `${trickplayResolution.Width}px`, width: "100%",
height: `${trickplayResolution.Height}px`, aspectRatio: imageAspectRatio,
}} }}
/> />
<Typography variant="h6" px={2} pt={1}> <Typography variant="h6" px="12px" pt={1}>
{currentChapter?.[0]?.Name} {currentChapter?.[0]?.Name}
</Typography> </Typography>
<Typography px={2} pb={1}> <Typography px="12px" pb={1}>
{ticksDisplay(value)} {ticksDisplay(value)}
</Typography> </Typography>
</div> </div>
); );
} }
return ( return (
<div className="flex flex-column video-osb-bubble glass"> <div className="flex flex-column video-osb-bubble">
<div <div
className="video-osd-trickplayBubble" className="video-osd-trickplayBubble"
style={{ style={{
background: `url(${api?.basePath}/Videos/${item?.Id}/Trickplay/${trickplayResolution.Width}/${index}.jpg?${imgUrlParams})`, background: `url(${api?.basePath}/Videos/${item?.Id}/Trickplay/${trickplayResolution.Width}/${index}.jpg?${imgUrlParams})`,
backgroundPositionX: `${backgroundOffsetX}px`, backgroundPositionX: `${backgroundOffsetX}px`,
backgroundPositionY: `${backgroundOffsetY}px`, backgroundPositionY: `${backgroundOffsetY}px`,
width: `${trickplayResolution.Width}px`, width: "100%",
height: `${trickplayResolution.Height}px`, aspectRatio: imageAspectRatio,
}} }}
/> />
<Typography variant="h6" px={2} py={1}> <Typography variant="h6" px="12px" py={1}>
{ticksDisplay(value)} {ticksDisplay(value)}
</Typography> </Typography>
</div> </div>
@@ -607,8 +604,8 @@ function VideoPlayer() {
if (currentChapter?.[0]?.Name) { if (currentChapter?.[0]?.Name) {
return ( return (
<div className="flex flex-column video-osb-bubble glass"> <div className="flex flex-column video-osb-bubble">
<Typography variant="h6" px={2} pt={1}> <Typography variant="h6" px="12px" pt={1}>
{currentChapter?.[0]?.Name} {currentChapter?.[0]?.Name}
</Typography> </Typography>
<Typography px={2} pb={1}> <Typography px={2} pb={1}>
@@ -618,8 +615,8 @@ function VideoPlayer() {
); );
} }
return ( return (
<div className="flex flex-column video-osb-bubble glass"> <div className="flex flex-column video-osb-bubble ">
<Typography variant="h6" px={2} py={1}> <Typography variant="h6" px="12px" py={1}>
{ticksDisplay(value)} {ticksDisplay(value)}
</Typography> </Typography>
</div> </div>
@@ -704,6 +701,27 @@ function VideoPlayer() {
player.current?.seekTo(ticksToSec(next?.StartPositionTicks ?? 0)); player.current?.seekTo(ticksToSec(next?.StartPositionTicks ?? 0));
}, [progress, playsessionId]); }, [progress, playsessionId]);
const positionRef = React.useRef<{ x: number; y: number }>({
x: 0,
y: 0,
});
const popperRef = React.useRef<Instance>(null);
const areaRef = React.useRef<HTMLDivElement>(null);
const [hoverProgress, setHoverProgress] = useState(0);
const handleSliderHover = (event: React.MouseEvent) => {
positionRef.current = { x: event.clientX, y: event.clientY };
const rect = areaRef.current!.getBoundingClientRect();
const width = rect.width;
const distX = event.clientX - rect.left;
const percentageCovered = distX / width;
setHoverProgress(percentageCovered * itemDuration);
if (popperRef.current != null) {
popperRef.current.update();
}
};
return ( return (
<div className="video-player"> <div className="video-player">
<AnimatePresence> <AnimatePresence>
@@ -904,54 +922,89 @@ function VideoPlayer() {
</Typography> </Typography>
<div className="video-player-osd-controls"> <div className="video-player-osd-controls">
<div className="video-player-osd-controls-progress"> <div className="video-player-osd-controls-progress">
<Slider <Tooltip
value={isSeeking ? sliderProgress : progress} // title={sliderDisplayFormat(
max={itemDuration} // positionRef.current.x - areaRef.current!.getBoundingClientRect().x,
step={1} // )}
onChange={(_, newValue) => { key={`${positionRef.current}`}
setIsSeeking(true); title={sliderDisplayFormat(hoverProgress)}
Array.isArray(newValue) placement="top"
? setSliderProgress(newValue[0]) slotProps={{
: setSliderProgress(newValue); popper: {
}} popperRef,
onChangeCommitted={(_, newValue) => { anchorEl: {
setIsSeeking(false); getBoundingClientRect: () => {
Array.isArray(newValue) return new DOMRect(
? setProgress(newValue[0]) positionRef.current.x,
: setProgress(newValue); areaRef.current!.getBoundingClientRect().y,
if (Array.isArray(newValue)) { 0,
player.current?.seekTo( 0,
ticksToSec(newValue[0]), );
"seconds", },
); },
} else { disablePortal: true,
player.current?.seekTo(ticksToSec(newValue), "seconds"); },
} tooltip: {
}} className: "glass",
sx={{ style: {
"& .MuiSlider-thumb": { width: "34em",
width: 14, overflow: "hidden",
height: 14, padding: "12px",
transition: "0.1s ease-in-out", borderRadius: "20px",
opacity: 0,
"&.Mui-active": {
width: 20,
height: 20,
opacity: 1,
}, },
}, },
"&:hover .MuiSlider-thumb": {
opacity: 1,
},
"& .MuiSlider-rail": {
opacity: 0.28,
background: "white",
},
}} }}
marks={chapterMarks} >
valueLabelDisplay="auto" <Slider
valueLabelFormat={sliderDisplayFormat} value={isSeeking ? sliderProgress : progress}
/> max={itemDuration}
step={1}
onChange={(_, newValue) => {
setIsSeeking(true);
Array.isArray(newValue)
? setSliderProgress(newValue[0])
: setSliderProgress(newValue);
}}
onChangeCommitted={(_, newValue) => {
setIsSeeking(false);
Array.isArray(newValue)
? setProgress(newValue[0])
: setProgress(newValue);
if (Array.isArray(newValue)) {
player.current?.seekTo(
ticksToSec(newValue[0]),
"seconds",
);
} else {
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,
},
"& .MuiSlider-rail": {
opacity: 0.28,
background: "white",
},
}}
marks={chapterMarks}
valueLabelDisplay="off"
ref={areaRef}
onMouseMove={handleSliderHover}
/>
</Tooltip>
<div className="video-player-osd-controls-progress-text"> <div className="video-player-osd-controls-progress-text">
<Typography> <Typography>
{ticksDisplay(isSeeking ? sliderProgress : progress)} {ticksDisplay(isSeeking ? sliderProgress : progress)}
+12 -3
View File
@@ -17,9 +17,9 @@
filter: drop-shadow(0 0 10px black); filter: drop-shadow(0 0 10px black);
} }
} }
&-trick-bubble { &-trickplayBubble {
overflow: hidden; overflow: hidden;
border-radius: $border-radius-default; border-radius: 8px;
} }
} }
&-osd-visible { &-osd-visible {
@@ -98,11 +98,20 @@ video {
align-items: stretch; align-items: stretch;
justify-content: center; justify-content: center;
margin-bottom: 0.5em; margin-bottom: 0.5em;
&-text { &-text {
display: flex; display: flex;
align-items: stretch; align-items: stretch;
justify-content: space-between; justify-content: space-between;
} }
&-bubble{
width: 14em;
top: 0;
left: 0;
transform-origin:bottom center;
transform: translate(var(--left, 0), var(--top, 0));
position: fixed;
}
} }
&-buttons { &-buttons {
display: flex; display: flex;