fix pause bugs and stuff

This commit is contained in:
mrjvs 2023-10-11 23:36:46 +02:00
parent f3084d37a8
commit d07a611c35
4 changed files with 38 additions and 35 deletions

View File

@ -64,9 +64,7 @@ function BaseContainer(props: { children?: ReactNode }) {
return ( return (
<div ref={containerEl}> <div ref={containerEl}>
<OverlayDisplay> <OverlayDisplay>
<div className="relative overflow-hidden h-screen select-none"> <div className="h-screen select-none">{props.children}</div>
{props.children}
</div>
</OverlayDisplay> </OverlayDisplay>
</div> </div>
); );
@ -80,11 +78,13 @@ export function Container(props: PlayerProps) {
return ( return (
<div className="relative"> <div className="relative">
<VideoContainer />
<BaseContainer> <BaseContainer>
<VideoContainer />
<div className="relative h-screen overflow-hidden">
<VideoClickTarget /> <VideoClickTarget />
<HeadUpdater /> <HeadUpdater />
{props.children} {props.children}
</div>
</BaseContainer> </BaseContainer>
</div> </div>
); );

View File

@ -1,7 +1,7 @@
import { PlayerHoverState } from "@/stores/player/slices/interface"; import { PlayerHoverState } from "@/stores/player/slices/interface";
import { usePlayerStore } from "@/stores/player/store"; import { usePlayerStore } from "@/stores/player/store";
export function useShouldShowControls(opts?: { touchOnly: boolean }) { export function useShouldShowControls() {
const hovering = usePlayerStore((s) => s.interface.hovering); const hovering = usePlayerStore((s) => s.interface.hovering);
const lastHoveringState = usePlayerStore( const lastHoveringState = usePlayerStore(
(s) => s.interface.lastHoveringState (s) => s.interface.lastHoveringState
@ -9,12 +9,18 @@ export function useShouldShowControls(opts?: { touchOnly: boolean }) {
const isPaused = usePlayerStore((s) => s.mediaPlaying.isPaused); const isPaused = usePlayerStore((s) => s.mediaPlaying.isPaused);
const hasOpenOverlay = usePlayerStore((s) => s.interface.hasOpenOverlay); const hasOpenOverlay = usePlayerStore((s) => s.interface.hasOpenOverlay);
const showTouchControls = const isUsingTouch = lastHoveringState === PlayerHoverState.MOBILE_TAPPED;
lastHoveringState === PlayerHoverState.MOBILE_TAPPED; const isHovering = hovering !== PlayerHoverState.NOT_HOVERING;
const notNotHovering = hovering !== PlayerHoverState.NOT_HOVERING;
if (opts?.touchOnly) // when using touch, pause screens can be dismissed by tapping
return (showTouchControls && notNotHovering) || isPaused || hasOpenOverlay; const showTargetsWithoutPause = isHovering || hasOpenOverlay;
const showTargetsIncludingPause = showTargetsWithoutPause || isPaused;
const showTargets = isUsingTouch
? showTargetsWithoutPause
: showTargetsIncludingPause;
return notNotHovering || isPaused || hasOpenOverlay; return {
showTouchTargets: isUsingTouch && showTargets,
showTargets,
};
} }

View File

@ -19,6 +19,7 @@ export function VideoClickTarget() {
const togglePause = useCallback( const togglePause = useCallback(
(e: PointerEvent<HTMLDivElement>) => { (e: PointerEvent<HTMLDivElement>) => {
setTimeout(() => {
// pause on mouse click // pause on mouse click
if (e.pointerType === "mouse") { if (e.pointerType === "mouse") {
if (e.button !== 0) return; if (e.button !== 0) return;
@ -31,6 +32,7 @@ export function VideoClickTarget() {
if (hovering !== PlayerHoverState.MOBILE_TAPPED) if (hovering !== PlayerHoverState.MOBILE_TAPPED)
updateInterfaceHovering(PlayerHoverState.MOBILE_TAPPED); updateInterfaceHovering(PlayerHoverState.MOBILE_TAPPED);
else updateInterfaceHovering(PlayerHoverState.NOT_HOVERING); else updateInterfaceHovering(PlayerHoverState.NOT_HOVERING);
}, 10); // TODO this is dirty workaround, without this, tapping on something where a button will be will trigger it immediately
}, },
[display, isPaused, hovering, updateInterfaceHovering] [display, isPaused, hovering, updateInterfaceHovering]
); );

View File

@ -7,20 +7,15 @@ import { AutoPlayStart } from "@/components/player/atoms";
import { usePlayer } from "@/components/player/hooks/usePlayer"; import { usePlayer } from "@/components/player/hooks/usePlayer";
import { useShouldShowControls } from "@/components/player/hooks/useShouldShowControls"; import { useShouldShowControls } from "@/components/player/hooks/useShouldShowControls";
import { ScrapingPart } from "@/pages/parts/player/ScrapingPart"; import { ScrapingPart } from "@/pages/parts/player/ScrapingPart";
import { PlayerHoverState } from "@/stores/player/slices/interface";
import { import {
PlayerMeta, PlayerMeta,
metaToScrapeMedia, metaToScrapeMedia,
playerStatus, playerStatus,
} from "@/stores/player/slices/source"; } from "@/stores/player/slices/source";
import { usePlayerStore } from "@/stores/player/store";
export function PlayerView() { export function PlayerView() {
const { status, setScrapeStatus, playMedia, setMeta } = usePlayer(); const { status, setScrapeStatus, playMedia, setMeta } = usePlayer();
const { lastHoveringState } = usePlayerStore((s) => s.interface); const { showTargets, showTouchTargets } = useShouldShowControls();
const desktopControlsVisible = useShouldShowControls();
const touchControlsVisible = useShouldShowControls({ touchOnly: true });
const meta = useMemo<PlayerMeta>( const meta = useMemo<PlayerMeta>(
() => ({ () => ({
@ -70,7 +65,7 @@ export function PlayerView() {
/> />
) : null} ) : null}
<Player.BlackOverlay show={desktopControlsVisible} /> <Player.BlackOverlay show={showTargets} />
<Player.CenterControls> <Player.CenterControls>
<Player.LoadingSpinner /> <Player.LoadingSpinner />
@ -79,14 +74,14 @@ export function PlayerView() {
<Player.CenterMobileControls <Player.CenterMobileControls
className="text-white" className="text-white"
show={touchControlsVisible} show={showTouchTargets}
> >
<Player.SkipBackward iconSizeClass="text-3xl" /> <Player.SkipBackward iconSizeClass="text-3xl" />
<Player.Pause iconSizeClass="text-5xl" /> <Player.Pause iconSizeClass="text-5xl" />
<Player.SkipForward iconSizeClass="text-3xl" /> <Player.SkipForward iconSizeClass="text-3xl" />
</Player.CenterMobileControls> </Player.CenterMobileControls>
<Player.TopControls show={desktopControlsVisible}> <Player.TopControls show={showTargets}>
<div className="grid grid-cols-[1fr,auto] xl:grid-cols-3 items-center"> <div className="grid grid-cols-[1fr,auto] xl:grid-cols-3 items-center">
<div className="flex space-x-3 items-center"> <div className="flex space-x-3 items-center">
<Player.BackLink /> <Player.BackLink />
@ -103,7 +98,7 @@ export function PlayerView() {
</div> </div>
</Player.TopControls> </Player.TopControls>
<Player.BottomControls show={desktopControlsVisible}> <Player.BottomControls show={showTargets}>
<Player.ProgressBar /> <Player.ProgressBar />
<div className="flex justify-between"> <div className="flex justify-between">
<Player.LeftSideControls className="hidden lg:flex"> <Player.LeftSideControls className="hidden lg:flex">