[Video] Fix crash when switching tabs (#4925)
parent
134fcd35d8
commit
99d1a881f2
|
@ -23,29 +23,14 @@ export function VideoEmbedInnerNative() {
|
|||
const ref = useRef<VideoView>(null)
|
||||
const isScreenFocused = useIsFocused()
|
||||
const isAppFocused = useAppState()
|
||||
const prevFocusedRef = useRef(isAppFocused)
|
||||
|
||||
// resume video when coming back from background
|
||||
useEffect(() => {
|
||||
if (isAppFocused !== prevFocusedRef.current) {
|
||||
prevFocusedRef.current = isAppFocused
|
||||
if (isAppFocused === 'active') {
|
||||
if (isAppFocused === 'active' && isScreenFocused && !player.playing) {
|
||||
player.play()
|
||||
}
|
||||
}
|
||||
}, [isAppFocused, player])
|
||||
|
||||
// pause the video when the screen is not focused
|
||||
useEffect(() => {
|
||||
if (!isScreenFocused) {
|
||||
let wasPlaying = player.playing
|
||||
} else if (player.playing) {
|
||||
player.pause()
|
||||
|
||||
return () => {
|
||||
if (wasPlaying) player.play()
|
||||
}
|
||||
}
|
||||
}, [isScreenFocused, player])
|
||||
}, [isAppFocused, player, isScreenFocused])
|
||||
|
||||
const enterFullscreen = useCallback(() => {
|
||||
ref.current?.enterFullscreen()
|
||||
|
|
Loading…
Reference in New Issue