From 96c6f1a4abdd2fb0be169027aee5efffcb7f718c Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Wed, 7 Jan 2026 23:42:25 +0100 Subject: [PATCH] Enhance VideoPlayer component with autoplay, mute handling, and replay functionality --- client/src/components/VideoPlayer.tsx | 67 ++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/client/src/components/VideoPlayer.tsx b/client/src/components/VideoPlayer.tsx index 65a3ad4..3f11877 100644 --- a/client/src/components/VideoPlayer.tsx +++ b/client/src/components/VideoPlayer.tsx @@ -1,14 +1,77 @@ +import { useEffect, useRef, useState } from 'react'; +import { Link } from 'react-router-dom'; + interface Props { src: string; variant?: 'compact' | 'wide'; + quizLink?: string; } -export default function VideoPlayer({ src, variant = 'wide' }: Props) { +export default function VideoPlayer({ src, variant = 'wide', quizLink }: Props) { + const videoRef = useRef(null); + const [muted, setMuted] = useState(true); + const [ended, setEnded] = useState(false); + + useEffect(() => { + setEnded(false); + const video = videoRef.current; + if (!video) return; + + const tryPlay = async () => { + try { + video.muted = false; + setMuted(false); + await video.play(); + } catch { + video.muted = true; + setMuted(true); + try { + await video.play(); + } catch (err) { + console.warn('Autoplay failed', err); + } + } + }; + + tryPlay(); + }, [src]); + if (!src) return null; const className = variant === 'compact' ? 'video-shell compact' : 'video-shell'; + + const handleReplay = () => { + const video = videoRef.current; + if (!video) return; + video.currentTime = 0; + setEnded(false); + video.play().catch(() => {}); + }; + return (
-
); }