mirror of
https://github.com/vndangkhoa/purestream.git
synced 2026-04-05 17:37:59 +07:00
Add loading spinner to prevent black screen while video buffers
This commit is contained in:
parent
929df62342
commit
dc3caed430
1 changed files with 16 additions and 1 deletions
|
|
@ -42,6 +42,7 @@ export const VideoPlayer: React.FC<VideoPlayerProps> = ({
|
||||||
const [localMuted, setLocalMuted] = useState(true);
|
const [localMuted, setLocalMuted] = useState(true);
|
||||||
const isMuted = externalMuted !== undefined ? externalMuted : localMuted;
|
const isMuted = externalMuted !== undefined ? externalMuted : localMuted;
|
||||||
const [hearts, setHearts] = useState<HeartParticle[]>([]);
|
const [hearts, setHearts] = useState<HeartParticle[]>([]);
|
||||||
|
const [isLoading, setIsLoading] = useState(true); // Show loading spinner until video is ready
|
||||||
const lastTapRef = useRef<number>(0);
|
const lastTapRef = useRef<number>(0);
|
||||||
|
|
||||||
// Full proxy URL (yt-dlp, always works but heavier)
|
// Full proxy URL (yt-dlp, always works but heavier)
|
||||||
|
|
@ -105,9 +106,10 @@ export const VideoPlayer: React.FC<VideoPlayerProps> = ({
|
||||||
return () => window.removeEventListener('keydown', handleKeyDown);
|
return () => window.removeEventListener('keydown', handleKeyDown);
|
||||||
}, [isActive]);
|
}, [isActive]);
|
||||||
|
|
||||||
// Reset fallback when video changes
|
// Reset fallback and loading state when video changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setUseFallback(false);
|
setUseFallback(false);
|
||||||
|
setIsLoading(true); // Show loading for new video
|
||||||
}, [video.id]);
|
}, [video.id]);
|
||||||
|
|
||||||
// Progress tracking
|
// Progress tracking
|
||||||
|
|
@ -309,8 +311,21 @@ export const VideoPlayer: React.FC<VideoPlayerProps> = ({
|
||||||
muted={isMuted}
|
muted={isMuted}
|
||||||
className="w-full h-full"
|
className="w-full h-full"
|
||||||
style={{ objectFit }}
|
style={{ objectFit }}
|
||||||
|
onCanPlay={() => setIsLoading(false)}
|
||||||
|
onWaiting={() => setIsLoading(true)}
|
||||||
|
onPlaying={() => setIsLoading(false)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
{/* Loading Spinner Overlay */}
|
||||||
|
{isLoading && (
|
||||||
|
<div className="absolute inset-0 flex items-center justify-center bg-black/60 z-20">
|
||||||
|
<div className="flex flex-col items-center gap-4">
|
||||||
|
<div className="w-12 h-12 border-4 border-white/20 border-t-cyan-400 rounded-full animate-spin" />
|
||||||
|
<span className="text-white/60 text-sm">Loading...</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* Heart Animation Particles */}
|
{/* Heart Animation Particles */}
|
||||||
{hearts.map(heart => (
|
{hearts.map(heart => (
|
||||||
<div
|
<div
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue