Allow changing volume #10

This commit is contained in:
prayag17 committed 2023-05-15 14:04:35 +05:30
1 parent 5b2968b5bf
commit 25ac859efd
5 files changed
+227 -64

No files matched your search

-14
View File
@@ -275,20 +275,6 @@ function App() {
return ( return (
<SnackbarProvider maxSnack={5}> <SnackbarProvider maxSnack={5}>
<ThemeProvider theme={theme}> <ThemeProvider theme={theme}>
{pingServer.isLoading && (
<Box
sx={{
display: "flex",
width: "100%",
height: "100vh",
justifyContent: "center",
alignItems: "center",
}}
>
<CircularProgress />
</Box>
)}
<Kon resetDelay={1000} action={sixtyNine}></Kon> <Kon resetDelay={1000} action={sixtyNine}></Kon>
<Dialog <Dialog
open={easterEgg} open={easterEgg}
@@ -0,0 +1,12 @@
/** @format */
import SvgIcon from "@mui/material/SvgIcon";
import { mdiPictureInPictureBottomRight } from "@mdi/js";
export const MdiPictureInPictureBottomRight = (props) => {
return (
<SvgIcon {...props}>
<path d={mdiPictureInPictureBottomRight}></path>
</SvgIcon>
);
};
+13
View File
@@ -0,0 +1,13 @@
/** @format */
import SvgIcon from "@mui/material/SvgIcon";
import { mdiVolumeHigh } from "@mdi/js";
export const MdiVolumeHigh = (props) => {
return (
<SvgIcon {...props}>
<path d={mdiVolumeHigh}></path>
</SvgIcon>
);
};
+13
View File
@@ -0,0 +1,13 @@
/** @format */
import SvgIcon from "@mui/material/SvgIcon";
import { mdiVolumeOff } from "@mdi/js";
export const MdiVolumeOff = (props) => {
return (
<SvgIcon {...props}>
<path d={mdiVolumeOff}></path>
</SvgIcon>
);
};
+189 -50
View File
@@ -8,6 +8,8 @@ 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 Slider from "@mui/material/Slider";
import { theme } from "../../theme";
import Grow from "@mui/material/Grow";
import ReactPlayer from "react-player"; import ReactPlayer from "react-player";
@@ -27,6 +29,9 @@ import { MdiFastForward } from "../../components/icons/mdiFastForward";
import { MdiRewind } from "../../components/icons/mdiRewind"; import { MdiRewind } from "../../components/icons/mdiRewind";
import { MdiFullscreen } from "../../components/icons/mdiFullscreen"; import { MdiFullscreen } from "../../components/icons/mdiFullscreen";
import { MdiFullscreenExit } from "../../components/icons/mdiFullscreenExit"; import { MdiFullscreenExit } from "../../components/icons/mdiFullscreenExit";
import { MdiPictureInPictureBottomRight } from "../../components/icons/mdiPictureInPictureBottomRight";
import { MdiVolumeHigh } from "../../components/icons/mdiVolumeHigh";
import { MdiVolumeOff } from "../../components/icons/mdiVolumeOff";
export const VideoPlayer = () => { export const VideoPlayer = () => {
const navigate = useNavigate(); const navigate = useNavigate();
@@ -43,12 +48,14 @@ export const VideoPlayer = () => {
const [isPlaying, setIsPlaying] = useState(true); const [isPlaying, setIsPlaying] = useState(true);
const [isMuted, setIsMuted] = useState(false); const [isMuted, setIsMuted] = useState(false);
const [isReady, setIsReady] = useState(false); const [isReady, setIsReady] = useState(false);
const [isPIP, setIsPIP] = useState(false);
const [volume, setVolume] = useState(0.75);
const [showVolume, setShowVolume] = useState(false);
const [duration, setDuration] = useState(0); const [duration, setDuration] = useState(0);
const [progress, setProgress] = useState(0); const [progress, setProgress] = useState(0);
const [currentTime, setCurrentTime] = useState( const [currentTime, setCurrentTime] = useState(startPosition);
(startPosition / itemDuration) * 100,
);
const onReady = useCallback(() => { const onReady = useCallback(() => {
if (!isReady) { if (!isReady) {
@@ -67,6 +74,7 @@ export const VideoPlayer = () => {
IsMuted: isMuted, IsMuted: isMuted,
PositionTicks: secToTicks(e.playedSeconds), PositionTicks: secToTicks(e.playedSeconds),
PlaybackStartTimeTicks: startPosition, PlaybackStartTimeTicks: startPosition,
VolumeLevel: volume * 100,
}, },
}); });
}; };
@@ -89,8 +97,8 @@ export const VideoPlayer = () => {
})}`; })}`;
}; };
const handleDisplayItemDuration = () => { const handleDisplayTime = (ticks) => {
let time = ticksToSec(itemDuration); let time = ticksToSec(ticks);
let hr = Math.floor(time / 3600); let hr = Math.floor(time / 3600);
time -= hr * 3600; time -= hr * 3600;
let min = Math.floor(time / 60); let min = Math.floor(time / 60);
@@ -127,7 +135,7 @@ export const VideoPlayer = () => {
document document
.querySelector(".video") .querySelector(".video")
.classList.remove("video-osd-visible"); .classList.remove("video-osd-visible");
}, 2000); }, 3000);
}} }}
> >
<Stack <Stack
@@ -161,7 +169,15 @@ export const VideoPlayer = () => {
</Typography> </Typography>
</Toolbar> </Toolbar>
</AppBar> </AppBar>
<Stack direction="column" padding={2} width="100%"> <Stack
direction="column"
padding={2}
width="100%"
sx={{
background:
"linear-gradient(to top, rgb(0 0 0 / 0.75), transparent)",
}}
>
<Stack <Stack
width="100%" width="100%"
direction="row" direction="row"
@@ -175,59 +191,180 @@ export const VideoPlayer = () => {
<Slider <Slider
value={currentTime} value={currentTime}
step={0.01} step={0.01}
max={100} max={itemDuration}
onChange={(e, newVal) => { onChange={(e, newVal) => {
playerRef.current.seekTo( playerRef.current.seekTo(
(newVal / 100) * ticksToSec(newVal),
playerRef.current.getDuration(),
); );
setCurrentTime(newVal); setCurrentTime(newVal);
}} }}
valueLabelDisplay="auto"
valueLabelFormat={(value) =>
handleDisplayTime(value)
}
sx={{
"& .MuiSlider-valueLabel": {
lineHeight: 1.2,
fontSize: 24,
background: "rgb(0 0 0 / 0.5)",
backdropFilter: "blur(30px)",
padding: 1,
borderRadius: "10px",
transform:
"translatey(-120%) scale(0)",
"&:before": { display: "none" },
"&.MuiSlider-valueLabelOpen": {
transform:
"translateY(-120%) scale(1)",
},
"& > *": {
transform: "rotate(0deg)",
},
},
}}
/> />
<Typography variant="h6"> <Typography variant="h6">
{handleDisplayItemDuration()} {handleDisplayTime(itemDuration)}
</Typography> </Typography>
</Stack> </Stack>
<Stack direction="row"> <Stack
<IconButton direction="row"
onClick={() => justifyContent="space-between"
playerRef.current.seekTo( alignItems="center"
playerRef.current.getCurrentTime() - >
15, <Stack direction="row" gap={1}>
) <IconButton
} onClick={() =>
playerRef.current.seekTo(
playerRef.current.getCurrentTime() -
15,
)
}
>
<MdiRewind />
</IconButton>
<IconButton
onClick={() => setIsPlaying(!isPlaying)}
>
{isPlaying ? <MdiPause /> : <MdiPlay />}
</IconButton>
<IconButton
onClick={() =>
playerRef.current.seekTo(
playerRef.current.getCurrentTime() +
15,
)
}
>
<MdiFastForward />
</IconButton>
</Stack>
<Stack
direction="row"
gap={1}
alignItems="center"
justifyContent="center"
> >
<MdiRewind /> <Stack
</IconButton> direction="row"
<IconButton width="15em"
onClick={() => setIsPlaying(!isPlaying)} alignItems="center"
> justifyContent="center"
{isPlaying ? <MdiPause /> : <MdiPlay />} gap={1}
</IconButton> sx={{
<IconButton transition: "250ms background",
onClick={() => borderRadius: 20,
playerRef.current.seekTo( "&:hover": {
playerRef.current.getCurrentTime() + background:
15, theme.palette.background
) .paper,
} },
> }}
<MdiFastForward /> onMouseOver={() => setShowVolume(true)}
</IconButton> onMouseOut={() => setShowVolume(false)}
<IconButton padding="0.25em 1em"
onClick={async () => { >
let fstate = <Grow in={showVolume}>
await appWindow.isFullscreen(); <Slider
setAppFullScreen(fstate); value={volume * 100}
await appWindow.setFullscreen(!fstate); step={1}
}} max={100}
> onChange={(e, newVal) =>
{appFullscreen ? ( setVolume(newVal / 100)
<MdiFullscreen /> }
) : ( valueLabelDisplay="auto"
<MdiFullscreenExit /> valueLabelFormat={(value) =>
)} Math.floor(value)
</IconButton> }
sx={{
"& .MuiSlider-valueLabel":
{
lineHeight: 1.2,
fontSize: 24,
background:
"rgb(0 0 0 / 0.5)",
backdropFilter:
"blur(30px)",
padding: 1,
borderRadius:
"10px",
transform:
"translatey(-120%) scale(0)",
"&:before": {
display: "none",
},
"&.MuiSlider-valueLabelOpen":
{
transform:
"translateY(-120%) scale(1)",
},
"& > *": {
transform:
"rotate(0deg)",
},
},
}}
/>
</Grow>
<IconButton
sx={{
ml: 0.1,
}}
onClick={() =>
setIsMuted(!isMuted)
}
>
{isMuted ? (
<MdiVolumeOff />
) : (
<MdiVolumeHigh />
)}
</IconButton>
</Stack>
<IconButton
onClick={() => {
setIsPIP(!isPIP);
}}
>
<MdiPictureInPictureBottomRight />
</IconButton>
<IconButton
onClick={async () => {
let fstate =
await appWindow.isFullscreen();
setAppFullScreen(!fstate);
await appWindow.setFullscreen(
!fstate,
);
}}
>
{appFullscreen ? (
<MdiFullscreenExit />
) : (
<MdiFullscreen />
)}
</IconButton>
</Stack>
</Stack> </Stack>
</Stack> </Stack>
</Stack> </Stack>
@@ -240,6 +377,8 @@ export const VideoPlayer = () => {
onProgress={onProgress} onProgress={onProgress}
onReady={onReady} onReady={onReady}
muted={isMuted} muted={isMuted}
pip={isPIP}
volume={volume}
/> />
</Box> </Box>
); );