Browse Source

fix(video-player): unmute video after play in user gesture task

fix iOS video playback issue where muted was set to bypass autoplay restrictions
lsc 4 days ago
parent
commit
7025563092
1 changed files with 5 additions and 1 deletions
  1. 5 1
      src/views/components/element/VideoElement/VideoPlayer/index.vue

+ 5 - 1
src/views/components/element/VideoElement/VideoPlayer/index.vue

@@ -230,7 +230,11 @@ const play = () => {
     videoRef.value.load()
     videoRef.value.load()
   }
   }
 
 
-  // ③ play() 必须在用户手势任务内
+  // ③ 手动挂 src 时设了 muted=true 绕过 iOS,但 play() 来自用户手势(toggle/控件点击),
+  //    浏览器允许有声播放,立即 unmute 恢复用户预期
+  videoRef.value.muted = false
+
+  // ④ play() 必须在用户手势任务内
   const p = videoRef.value.play()
   const p = videoRef.value.play()
   if (p && (p as Promise<void>).catch) (p as Promise<void>).catch(() => {})
   if (p && (p as Promise<void>).catch) (p as Promise<void>).catch(() => {})
 }
 }