From 76e4bc5851ab0ba587ded77820082e3cf80b0439 Mon Sep 17 00:00:00 2001 From: Jelle van Snik Date: Tue, 7 Feb 2023 16:01:05 +0100 Subject: [PATCH] shortcuts, progress saving fix, error handling, airplay, safe are for full screen only Co-authored-by: Jip Frijlink --- __old/VideoPlayer.tsx | 64 -------- src/state/watched/context.tsx | 11 +- src/video/components/VideoPlayer.tsx | 147 ++++++++++-------- src/video/components/VideoPlayerBase.tsx | 46 +++++- .../components/actions/AirplayAction.tsx | 30 ++++ .../actions/KeyboardShortcutsAction.tsx | 90 +++++++++++ .../controllers/SourceController.tsx | 5 +- src/video/components/hooks/useInitialized.ts | 10 ++ .../internal/VideoElementInternal.tsx | 11 +- .../internal/WrapperRegisterInternal.tsx | 2 + .../components/parts/VideoErrorBoundary.tsx | 83 ++++++++++ .../components/parts/VideoPlayerError.tsx | 7 +- .../components/parts/VideoPlayerHeader.tsx | 10 +- src/video/state/events.ts | 4 +- src/video/state/init.ts | 5 +- src/video/state/logic/controls.ts | 3 + src/video/state/logic/error.ts | 38 +++++ src/video/state/logic/misc.ts | 39 +++++ src/video/state/providers/providerTypes.ts | 1 + src/video/state/providers/utils.ts | 3 + .../state/providers/videoStateProvider.ts | 63 ++++++-- src/video/state/types.ts | 9 +- src/views/media/MediaView.tsx | 2 +- 23 files changed, 510 insertions(+), 173 deletions(-) create mode 100644 src/video/components/actions/AirplayAction.tsx create mode 100644 src/video/components/actions/KeyboardShortcutsAction.tsx create mode 100644 src/video/components/hooks/useInitialized.ts create mode 100644 src/video/components/parts/VideoErrorBoundary.tsx create mode 100644 src/video/state/logic/error.ts create mode 100644 src/video/state/logic/misc.ts diff --git a/__old/VideoPlayer.tsx b/__old/VideoPlayer.tsx index 3e064aa1..4642c5ec 100644 --- a/__old/VideoPlayer.tsx +++ b/__old/VideoPlayer.tsx @@ -31,70 +31,6 @@ const VideoPlayerInternals = forwardRef< didInitialize.current = value; }, [didInitialize, video]); - useEffect(() => { - let isRolling = false; - const onKeyDown = (evt: KeyboardEvent) => { - if (!videoState.isFocused) return; - if (!ref || !(ref as any)?.current) return; - const el = (ref as any).current as HTMLVideoElement; - - switch (evt.key.toLowerCase()) { - // Toggle fullscreen - case "f": - if (videoState.isFullscreen) { - videoState.exitFullscreen(); - } else { - videoState.enterFullscreen(); - } - break; - - // Skip backwards - case "arrowleft": - videoState.setTime(videoState.time - 5); - break; - - // Skip forward - case "arrowright": - videoState.setTime(videoState.time + 5); - break; - - // Pause / play - case " ": - if (videoState.isPaused) { - videoState.play(); - } else { - videoState.pause(); - } - break; - - // Mute - case "m": - toggleVolume(); - break; - - // Do a barrel Roll! - case "r": - if (isRolling) return; - isRolling = true; - el.classList.add("roll"); - setTimeout(() => { - isRolling = false; - el.classList.remove("roll"); - }, 1000); - break; - - default: - break; - } - }; - - window.addEventListener("keydown", onKeyDown); - - return () => { - window.removeEventListener("keydown", onKeyDown); - }; - }, [videoState, toggleVolume, ref]); - // muted attribute is required for safari, as they cant change the volume itself return (