From 027cf934926ab7ddd26ff1a110b21ac78cb0d41d Mon Sep 17 00:00:00 2001 From: prayag17 Date: Thu, 11 May 2023 18:56:04 +0530 Subject: [PATCH] Add slider to videoPlayer #10 --- src/App.jsx | 2 +- src/routes/player/videoPlayer.jsx | 79 +++++++++++++++++++++---------- 2 files changed, 56 insertions(+), 25 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index 035f2f3..534164e 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -189,7 +189,7 @@ function App() { ); } try { - const api = sdk.createApi(best.address); + const api = jellyfin.createApi(best.address); const { data } = await getSystemApi( api, ).getPublicSystemInfo(); diff --git a/src/routes/player/videoPlayer.jsx b/src/routes/player/videoPlayer.jsx index 5f35507..f33e803 100644 --- a/src/routes/player/videoPlayer.jsx +++ b/src/routes/player/videoPlayer.jsx @@ -7,6 +7,7 @@ import Box from "@mui/material/Box"; import Stack from "@mui/material/Stack"; import IconButton from "@mui/material/IconButton"; import Typography from "@mui/material/Typography"; +import Slider from "@mui/material/Slider"; import ReactPlayer from "react-player"; @@ -33,16 +34,22 @@ export const VideoPlayer = () => { const [isMuted, setIsMuted] = useState(false); const [isReady, setIsReady] = useState(false); + const [duration, setDuration] = useState(0); + const [progress, setProgress] = useState(0); + const [currentTime, setCurrentTime] = useState(0); + const onReady = useCallback(() => { if (!isReady) { const timeToStart = ticksToSec(startPosition); playerRef.current.seekTo(timeToStart, "seconds"); + setDuration(playerRef.current.getDuration()); setIsReady(true); } }, [isReady]); + const startTime = new Date(0); + const onProgress = async (e) => { - console.log(e); await getPlaystateApi(window.api).reportPlaybackProgress({ playbackProgressInfo: { ItemId: itemId, @@ -53,6 +60,11 @@ export const VideoPlayer = () => { }); }; + const handleSeeking = useCallback((time, offset) => { + playerRef.current.seekTo(time / 100); + setCurrentTime(time / 100); + }, []); + const [url, startPosition, itemId, itemName] = usePlaybackStore( (state) => [ state.url, @@ -109,28 +121,48 @@ export const VideoPlayer = () => { - - - playerRef.current.seekTo( - playerRef.current.getCurrentTime() - 15, - ) - } - > - - - setIsPlaying(!isPlaying)}> - {isPlaying ? : } - - - playerRef.current.seekTo( - playerRef.current.getCurrentTime() + 15, - ) - } - > - - + + + { + playerRef.current.seekTo( + (newVal / 100) * + playerRef.current.getDuration(), + ); + setCurrentTime(newVal); + }} + /> + + + + playerRef.current.seekTo( + playerRef.current.getCurrentTime() - + 15, + ) + } + > + + + setIsPlaying(!isPlaying)} + > + {isPlaying ? : } + + + playerRef.current.seekTo( + playerRef.current.getCurrentTime() + + 15, + ) + } + > + + + { height="100vh" playing={isPlaying} url={url} - // controls={true} onProgress={onProgress} onReady={onReady} muted={isMuted}