about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEric Bailey <git@esb.lol>2025-03-06 21:14:00 -0600
committerGitHub <noreply@github.com>2025-03-06 19:14:00 -0800
commitfd8ac1da7df24543d175adc0d5e2b5d2cc9455af (patch)
tree21adfebc10d20edb447ecd20ded348e4b594ca44
parentbeb0fce56c9dc031503311d4f061ba947e36e33c (diff)
downloadvoidsky-fd8ac1da7df24543d175adc0d5e2b5d2cc9455af.tar.zst
Catch thrown error for autoplay in Safari (#7921)
-rw-r--r--src/view/com/util/post-embeds/VideoEmbedInner/web-controls/utils.tsx12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/view/com/util/post-embeds/VideoEmbedInner/web-controls/utils.tsx b/src/view/com/util/post-embeds/VideoEmbedInner/web-controls/utils.tsx
index 60ee33f45..108814ea2 100644
--- a/src/view/com/util/post-embeds/VideoEmbedInner/web-controls/utils.tsx
+++ b/src/view/com/util/post-embeds/VideoEmbedInner/web-controls/utils.tsx
@@ -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
       }
     }