Add slider to videoPlayer #10

This commit is contained in:
prayag17 committed 2023-05-11 18:56:04 +05:30
1 parent 092a1c74ab
commit 027cf93492
2 files changed
+38 -7

No files matched your search

+1 -1
View File
@@ -189,7 +189,7 @@ function App() {
); );
} }
try { try {
const api = sdk.createApi(best.address); const api = jellyfin.createApi(best.address);
const { data } = await getSystemApi( const { data } = await getSystemApi(
api, api,
).getPublicSystemInfo(); ).getPublicSystemInfo();
+37 -6
View File
@@ -7,6 +7,7 @@ import Box from "@mui/material/Box";
import Stack from "@mui/material/Stack"; import Stack from "@mui/material/Stack";
import IconButton from "@mui/material/IconButton"; import IconButton from "@mui/material/IconButton";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import Slider from "@mui/material/Slider";
import ReactPlayer from "react-player"; import ReactPlayer from "react-player";
@@ -33,16 +34,22 @@ export const VideoPlayer = () => {
const [isMuted, setIsMuted] = useState(false); const [isMuted, setIsMuted] = useState(false);
const [isReady, setIsReady] = 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(() => { const onReady = useCallback(() => {
if (!isReady) { if (!isReady) {
const timeToStart = ticksToSec(startPosition); const timeToStart = ticksToSec(startPosition);
playerRef.current.seekTo(timeToStart, "seconds"); playerRef.current.seekTo(timeToStart, "seconds");
setDuration(playerRef.current.getDuration());
setIsReady(true); setIsReady(true);
} }
}, [isReady]); }, [isReady]);
const startTime = new Date(0);
const onProgress = async (e) => { const onProgress = async (e) => {
console.log(e);
await getPlaystateApi(window.api).reportPlaybackProgress({ await getPlaystateApi(window.api).reportPlaybackProgress({
playbackProgressInfo: { playbackProgressInfo: {
ItemId: itemId, 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( const [url, startPosition, itemId, itemName] = usePlaybackStore(
(state) => [ (state) => [
state.url, state.url,
@@ -109,23 +121,42 @@ export const VideoPlayer = () => {
</Typography> </Typography>
</Toolbar> </Toolbar>
</AppBar> </AppBar>
<Stack padding={2} direction="row"> <Stack direction="column" padding={2} width="100%">
<Stack width="100%">
<Slider
value={currentTime}
step={0.01}
max={100}
onChange={(e, newVal) => {
playerRef.current.seekTo(
(newVal / 100) *
playerRef.current.getDuration(),
);
setCurrentTime(newVal);
}}
/>
</Stack>
<Stack direction="row">
<IconButton <IconButton
onClick={() => onClick={() =>
playerRef.current.seekTo( playerRef.current.seekTo(
playerRef.current.getCurrentTime() - 15, playerRef.current.getCurrentTime() -
15,
) )
} }
> >
<MdiRewind /> <MdiRewind />
</IconButton> </IconButton>
<IconButton onClick={() => setIsPlaying(!isPlaying)}> <IconButton
onClick={() => setIsPlaying(!isPlaying)}
>
{isPlaying ? <MdiPause /> : <MdiPlay />} {isPlaying ? <MdiPause /> : <MdiPlay />}
</IconButton> </IconButton>
<IconButton <IconButton
onClick={() => onClick={() =>
playerRef.current.seekTo( playerRef.current.seekTo(
playerRef.current.getCurrentTime() + 15, playerRef.current.getCurrentTime() +
15,
) )
} }
> >
@@ -133,13 +164,13 @@ export const VideoPlayer = () => {
</IconButton> </IconButton>
</Stack> </Stack>
</Stack> </Stack>
</Stack>
<ReactPlayer <ReactPlayer
ref={playerRef} ref={playerRef}
width="100vw" width="100vw"
height="100vh" height="100vh"
playing={isPlaying} playing={isPlaying}
url={url} url={url}
// controls={true}
onProgress={onProgress} onProgress={onProgress}
onReady={onReady} onReady={onReady}
muted={isMuted} muted={isMuted}