feat: add autoplay switch

This commit is contained in:
codytseng
2025-05-08 23:24:57 +08:00
parent aa24ad83e5
commit 7b882c72cb
21 changed files with 228 additions and 81 deletions

View File

@@ -1,4 +1,5 @@
import { cn, isInViewport } from '@/lib/utils'
import { useAutoplay } from '@/providers/AutoplayProvider'
import videoManager from '@/services/video-manager.service'
import { useEffect, useRef } from 'react'
import NsfwOverlay from '../NsfwOverlay'
@@ -12,10 +13,13 @@ export default function VideoPlayer({
className?: string
isNsfw?: boolean
}) {
const { autoplay } = useAutoplay()
const videoRef = useRef<HTMLVideoElement>(null)
const containerRef = useRef<HTMLDivElement>(null)
useEffect(() => {
if (!autoplay) return
const video = videoRef.current
const container = containerRef.current
@@ -41,7 +45,7 @@ export default function VideoPlayer({
return () => {
observer.unobserve(container)
}
}, [])
}, [autoplay])
return (
<div ref={containerRef} className="relative">