Fix touch controls for mobile

This commit is contained in:
Nicolas Mowen 2024-03-12 11:06:11 -06:00
parent 7550ad627c
commit a14198be7e

View File

@ -152,6 +152,19 @@ export default function DynamicVideoPlayer({
onKeyboardShortcut, onKeyboardShortcut,
); );
// mobile tap controls
useEffect(() => {
if (isDesktop || !playerRef) {
return;
}
const callback = () => setControls(!controls);
playerRef.on("touchstart", callback);
return () => playerRef.off("touchstart", callback);
}, [controls, playerRef]);
// initial state // initial state
const initialPlaybackSource = useMemo(() => { const initialPlaybackSource = useMemo(() => {
@ -238,14 +251,6 @@ export default function DynamicVideoPlayer({
} }
: undefined : undefined
} }
onClick={
isMobile
? (e) => {
e.stopPropagation();
setControls(!controls);
}
: undefined
}
> >
<div className={`w-full relative ${isScrubbing ? "hidden" : "visible"}`}> <div className={`w-full relative ${isScrubbing ? "hidden" : "visible"}`}>
<VideoPlayer <VideoPlayer
@ -255,9 +260,8 @@ export default function DynamicVideoPlayer({
sources: [initialPlaybackSource], sources: [initialPlaybackSource],
aspectRatio: wideVideo ? undefined : "16:9", aspectRatio: wideVideo ? undefined : "16:9",
controls: false, controls: false,
nativeControlsForTouch: true, nativeControlsForTouch: false,
}} }}
seekOptions={{ forward: 10, backward: 5 }}
onReady={(player) => { onReady={(player) => {
setPlayerRef(player); setPlayerRef(player);
}} }}