feat: increase and decrease volume using scrollwheel
This commit is contained in:
1 parent
94a69faded
commit
0e73ece9b5
1 file changed
+23
@@ -69,6 +69,7 @@ const ticksDisplay = (ticks: number) => {
|
|||||||
})}`;
|
})}`;
|
||||||
return formatedTime;
|
return formatedTime;
|
||||||
};
|
};
|
||||||
|
const VOLUME_SCROLL_INTERVAL = 0.05
|
||||||
|
|
||||||
const VideoPlayer = () => {
|
const VideoPlayer = () => {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
@@ -264,6 +265,28 @@ const VideoPlayer = () => {
|
|||||||
};
|
};
|
||||||
}, [handleKeyPress]);
|
}, [handleKeyPress]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const handleMouseWheel = (event: WheelEvent) => {
|
||||||
|
console.log(event.deltaY);
|
||||||
|
|
||||||
|
if (event.deltaY < 0) {
|
||||||
|
// increase volume
|
||||||
|
setVolume((state) => Math.min(1, state + VOLUME_SCROLL_INTERVAL))
|
||||||
|
} else if (event.deltaY > 0) {
|
||||||
|
// decrease volume
|
||||||
|
setVolume((state) => Math.max(0, state - VOLUME_SCROLL_INTERVAL))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// attach the event listener
|
||||||
|
document.addEventListener("wheel", handleMouseWheel);
|
||||||
|
|
||||||
|
// remove the event listener
|
||||||
|
return () => {
|
||||||
|
document.removeEventListener("wheel", handleMouseWheel);
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function fetchFonts() {
|
async function fetchFonts() {
|
||||||
const font = await fetch(subtitleFont).then((r) => r.arrayBuffer());
|
const font = await fetch(subtitleFont).then((r) => r.arrayBuffer());
|
||||||
|
|||||||
Reference in new issue
Block a user