Catch thrown error for autoplay in Safari (#7921)

This commit is contained in:
Eric Bailey
2025-03-06 21:14:00 -06:00
committed by GitHub
parent beb0fce56c
commit fd8ac1da7d
@@ -68,14 +68,22 @@ export function useVideoElement(ref: React.RefObject<HTMLVideoElement>) {
setError(true)
}
const handleCanPlay = () => {
const handleCanPlay = async () => {
if (bufferingTimeout) clearTimeout(bufferingTimeout)
setBuffering(false)
setCanPlay(true)
if (!ref.current) return
if (playWhenReadyRef.current) {
ref.current.play()
try {
await ref.current.play()
} catch (e: any) {
if (
!e.message?.includes(`The request is not allowed by the user agent`)
) {
throw e
}
}
playWhenReadyRef.current = false
}
}