import { useGoBack } from "@/hooks/useGoBack"; import { useVolumeControl } from "@/hooks/useVolumeToggle"; import { forwardRef, useContext, useEffect, useRef } from "react"; import { VideoErrorBoundary } from "./parts/VideoErrorBoundary"; import { useVideoPlayerState, VideoPlayerContext, VideoPlayerContextProvider, } from "./VideoContext"; export interface VideoPlayerProps { autoPlay?: boolean; children?: React.ReactNode; } const VideoPlayerInternals = forwardRef< HTMLVideoElement, { autoPlay: boolean } >((props, ref) => { const video = useContext(VideoPlayerContext); const didInitialize = useRef<{ source: string | null } | null>(null); const { videoState } = useVideoPlayerState(); const { toggleVolume } = useVolumeControl(); useEffect(() => { const value = { source: video.source }; const hasChanged = value.source !== didInitialize.current?.source; if (!hasChanged) return; if (!video.state.hasInitialized || !video.source) return; video.state.initPlayer(video.source, video.sourceType); didInitialize.current = value; }, [didInitialize, video]); // muted attribute is required for safari, as they cant change the volume itself return (