Allow changing volume #10
This commit is contained in:
5 files changed
+227
-64
No files matched your search
-14
@@ -275,20 +275,6 @@ function App() {
|
||||
return (
|
||||
<SnackbarProvider maxSnack={5}>
|
||||
<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>
|
||||
<Dialog
|
||||
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>
|
||||
);
|
||||
};
|
||||
@@ -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>
|
||||
);
|
||||
};
|
||||
@@ -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>
|
||||
);
|
||||
};
|
||||
@@ -8,6 +8,8 @@ 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 { theme } from "../../theme";
|
||||
import Grow from "@mui/material/Grow";
|
||||
|
||||
import ReactPlayer from "react-player";
|
||||
|
||||
@@ -27,6 +29,9 @@ import { MdiFastForward } from "../../components/icons/mdiFastForward";
|
||||
import { MdiRewind } from "../../components/icons/mdiRewind";
|
||||
import { MdiFullscreen } from "../../components/icons/mdiFullscreen";
|
||||
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 = () => {
|
||||
const navigate = useNavigate();
|
||||
@@ -43,12 +48,14 @@ export const VideoPlayer = () => {
|
||||
const [isPlaying, setIsPlaying] = useState(true);
|
||||
const [isMuted, setIsMuted] = 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 [progress, setProgress] = useState(0);
|
||||
const [currentTime, setCurrentTime] = useState(
|
||||
(startPosition / itemDuration) * 100,
|
||||
);
|
||||
const [currentTime, setCurrentTime] = useState(startPosition);
|
||||
|
||||
const onReady = useCallback(() => {
|
||||
if (!isReady) {
|
||||
@@ -67,6 +74,7 @@ export const VideoPlayer = () => {
|
||||
IsMuted: isMuted,
|
||||
PositionTicks: secToTicks(e.playedSeconds),
|
||||
PlaybackStartTimeTicks: startPosition,
|
||||
VolumeLevel: volume * 100,
|
||||
},
|
||||
});
|
||||
};
|
||||
@@ -89,8 +97,8 @@ export const VideoPlayer = () => {
|
||||
})}`;
|
||||
};
|
||||
|
||||
const handleDisplayItemDuration = () => {
|
||||
let time = ticksToSec(itemDuration);
|
||||
const handleDisplayTime = (ticks) => {
|
||||
let time = ticksToSec(ticks);
|
||||
let hr = Math.floor(time / 3600);
|
||||
time -= hr * 3600;
|
||||
let min = Math.floor(time / 60);
|
||||
@@ -127,7 +135,7 @@ export const VideoPlayer = () => {
|
||||
document
|
||||
.querySelector(".video")
|
||||
.classList.remove("video-osd-visible");
|
||||
}, 2000);
|
||||
}, 3000);
|
||||
}}
|
||||
>
|
||||
<Stack
|
||||
@@ -161,7 +169,15 @@ export const VideoPlayer = () => {
|
||||
</Typography>
|
||||
</Toolbar>
|
||||
</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
|
||||
width="100%"
|
||||
direction="row"
|
||||
@@ -175,59 +191,180 @@ export const VideoPlayer = () => {
|
||||
<Slider
|
||||
value={currentTime}
|
||||
step={0.01}
|
||||
max={100}
|
||||
max={itemDuration}
|
||||
onChange={(e, newVal) => {
|
||||
playerRef.current.seekTo(
|
||||
(newVal / 100) *
|
||||
playerRef.current.getDuration(),
|
||||
ticksToSec(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">
|
||||
{handleDisplayItemDuration()}
|
||||
{handleDisplayTime(itemDuration)}
|
||||
</Typography>
|
||||
</Stack>
|
||||
<Stack direction="row">
|
||||
<IconButton
|
||||
onClick={() =>
|
||||
playerRef.current.seekTo(
|
||||
playerRef.current.getCurrentTime() -
|
||||
15,
|
||||
)
|
||||
}
|
||||
<Stack
|
||||
direction="row"
|
||||
justifyContent="space-between"
|
||||
alignItems="center"
|
||||
>
|
||||
<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 />
|
||||
</IconButton>
|
||||
<IconButton
|
||||
onClick={() => setIsPlaying(!isPlaying)}
|
||||
>
|
||||
{isPlaying ? <MdiPause /> : <MdiPlay />}
|
||||
</IconButton>
|
||||
<IconButton
|
||||
onClick={() =>
|
||||
playerRef.current.seekTo(
|
||||
playerRef.current.getCurrentTime() +
|
||||
15,
|
||||
)
|
||||
}
|
||||
>
|
||||
<MdiFastForward />
|
||||
</IconButton>
|
||||
<IconButton
|
||||
onClick={async () => {
|
||||
let fstate =
|
||||
await appWindow.isFullscreen();
|
||||
setAppFullScreen(fstate);
|
||||
await appWindow.setFullscreen(!fstate);
|
||||
}}
|
||||
>
|
||||
{appFullscreen ? (
|
||||
<MdiFullscreen />
|
||||
) : (
|
||||
<MdiFullscreenExit />
|
||||
)}
|
||||
</IconButton>
|
||||
<Stack
|
||||
direction="row"
|
||||
width="15em"
|
||||
alignItems="center"
|
||||
justifyContent="center"
|
||||
gap={1}
|
||||
sx={{
|
||||
transition: "250ms background",
|
||||
borderRadius: 20,
|
||||
"&:hover": {
|
||||
background:
|
||||
theme.palette.background
|
||||
.paper,
|
||||
},
|
||||
}}
|
||||
onMouseOver={() => setShowVolume(true)}
|
||||
onMouseOut={() => setShowVolume(false)}
|
||||
padding="0.25em 1em"
|
||||
>
|
||||
<Grow in={showVolume}>
|
||||
<Slider
|
||||
value={volume * 100}
|
||||
step={1}
|
||||
max={100}
|
||||
onChange={(e, newVal) =>
|
||||
setVolume(newVal / 100)
|
||||
}
|
||||
valueLabelDisplay="auto"
|
||||
valueLabelFormat={(value) =>
|
||||
Math.floor(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)",
|
||||
},
|
||||
},
|
||||
}}
|
||||
/>
|
||||
</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>
|
||||
@@ -240,6 +377,8 @@ export const VideoPlayer = () => {
|
||||
onProgress={onProgress}
|
||||
onReady={onReady}
|
||||
muted={isMuted}
|
||||
pip={isPIP}
|
||||
volume={volume}
|
||||
/>
|
||||
</Box>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user