From b335164a583d6b3155e94de6b9afed41e6f84cf3 Mon Sep 17 00:00:00 2001 From: dwindown Date: Thu, 1 Jan 2026 01:33:22 +0700 Subject: [PATCH] Fix overlay to use Plyr's built-in poster element MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of custom overlay, use Plyr's .plyr__poster element which: - Naturally covers the iframe when paused/initial load - Allows Plyr controls to receive clicks (z-index hierarchy) - Hides (opacity: 0) when playing, shows (opacity: 1) when paused - Blocks YouTube UI interactions when visible This matches the reference implementation behavior. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- src/components/VideoPlayerWithChapters.tsx | 58 ++++++++++++++-------- 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/src/components/VideoPlayerWithChapters.tsx b/src/components/VideoPlayerWithChapters.tsx index b2516c9..f1c04a0 100644 --- a/src/components/VideoPlayerWithChapters.tsx +++ b/src/components/VideoPlayerWithChapters.tsx @@ -34,6 +34,7 @@ export const VideoPlayerWithChapters = forwardRef(null); const wrapperRef = useRef(null); const playerRef = useRef(null); + const posterRef = useRef(null); const [currentChapterIndex, setCurrentChapterIndex] = useState(-1); const [isPlaying, setIsPlaying] = useState(false); @@ -93,12 +94,32 @@ export const VideoPlayerWithChapters = forwardRef setIsPlaying(true)); - player.on('pause', () => setIsPlaying(false)); - player.on('ended', () => setIsPlaying(false)); + // Get poster element + posterRef.current = player.elements.wrapper.querySelector('.plyr__poster') as HTMLDivElement; - // Apply custom accent color + // Track play/pause state to show/hide poster overlay + player.on('play', () => { + setIsPlaying(true); + if (posterRef.current) { + posterRef.current.style.opacity = '0'; + } + }); + + player.on('pause', () => { + setIsPlaying(false); + if (posterRef.current) { + posterRef.current.style.opacity = '1'; + } + }); + + player.on('ended', () => { + setIsPlaying(false); + if (posterRef.current) { + posterRef.current.style.opacity = '1'; + } + }); + + // Apply custom accent color and poster styles if (accentColor) { const style = document.createElement('style'); style.textContent = ` @@ -114,6 +135,11 @@ export const VideoPlayerWithChapters = forwardRef {youtubeId && ( - <> - {/* CSS Overlay to block YouTube UI interactions - shows when paused */} -
-