about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorHailey <me@haileyok.com>2024-08-12 16:49:17 -0700
committerGitHub <noreply@github.com>2024-08-12 16:49:17 -0700
commit99d1a881f2f5c16dddfc10550b39e379690c8135 (patch)
tree8bee511c2076438bcb0e9a6b03b6eb86d01280ea /src
parent134fcd35d84788659effd3a9d0b9e8952b85e0da (diff)
downloadvoidsky-99d1a881f2f5c16dddfc10550b39e379690c8135.tar.zst
[Video] Fix crash when switching tabs (#4925)
Diffstat (limited to 'src')
-rw-r--r--src/view/com/util/post-embeds/VideoEmbedInner/VideoEmbedInnerNative.tsx23
1 files changed, 4 insertions, 19 deletions
diff --git a/src/view/com/util/post-embeds/VideoEmbedInner/VideoEmbedInnerNative.tsx b/src/view/com/util/post-embeds/VideoEmbedInner/VideoEmbedInnerNative.tsx
index 5722ba73d..5cbe01872 100644
--- a/src/view/com/util/post-embeds/VideoEmbedInner/VideoEmbedInnerNative.tsx
+++ b/src/view/com/util/post-embeds/VideoEmbedInner/VideoEmbedInnerNative.tsx
@@ -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') {
-        player.play()
-      }
-    }
-  }, [isAppFocused, player])
-
-  // pause the video when the screen is not focused
-  useEffect(() => {
-    if (!isScreenFocused) {
-      let wasPlaying = player.playing
+    if (isAppFocused === 'active' && isScreenFocused && !player.playing) {
+      player.play()
+    } else if (player.playing) {
       player.pause()
-
-      return () => {
-        if (wasPlaying) player.play()
-      }
     }
-  }, [isScreenFocused, player])
+  }, [isAppFocused, player, isScreenFocused])
 
   const enterFullscreen = useCallback(() => {
     ref.current?.enterFullscreen()