import { MaterialIcons } from '@expo/vector-icons' import React, { useEffect, useRef, useState } from 'react' import { Pressable, StyleSheet, Text, View } from 'react-native' import { resolveMediaUri } from '../utils/resolveMediaUri' const BackgroundVideo = ({ source, soundButtonStyle = null, silent = false }) => { const videoRef = useRef(null) const [uri, setUri] = useState(null) const [muted, setMuted] = useState(false) useEffect(() => { let isMounted = true if (!source) { setUri(null) return () => { isMounted = false } } const loadSource = async () => { try { const nextUri = await resolveMediaUri(source) if (isMounted) { setUri(nextUri) } } catch { if (isMounted) { setUri(null) } } } loadSource() return () => { isMounted = false } }, [source]) useEffect(() => { const video = videoRef.current if (!video || !uri) { return } const playResult = video.play() playResult?.catch?.((error) => { if (error?.name === 'NotAllowedError') { setMuted(true) video.muted = true video.play()?.catch?.(() => {}) } }) }, [uri]) useEffect(() => { const video = videoRef.current if (!video) { return } video.muted = silent || muted if (video.paused) { video.play()?.catch?.(() => {}) } }, [muted, silent]) if (!uri) { return null } return (