From ad7e29dd5d7d0cbf87ef2f954e435a753a17a4ca Mon Sep 17 00:00:00 2001 From: xiaosi <2652281683@qq.com> Date: Wed, 2 Sep 2026 15:03:18 +0800 Subject: [PATCH] fix: mute LivePlayer so live autoplay can start Chrome/Edge block unmuted autoplay after async join; silent play() failures left a black LIVE frame. --- src/components/LivePlayer.vue | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/components/LivePlayer.vue b/src/components/LivePlayer.vue index 7e34fcf..54b020e 100644 --- a/src/components/LivePlayer.vue +++ b/src/components/LivePlayer.vue @@ -9,6 +9,7 @@ ref="videoEl" controls autoplay + muted playsinline />
@@ -92,14 +93,29 @@ async function attachPlayer(url) { const video = videoEl.value if (!video || seq !== attachSeq) return + video.muted = true + video.defaultMuted = true + video.setAttribute('muted', '') + video.addEventListener('error', () => { if (seq !== attachSeq) return emit('error') }, { once: true }) + async function tryPlay() { + if (seq !== attachSeq) return + try { + await video.play() + } catch (error) { + console.warn('[live-player] autoplay blocked', error) + // NotAllowedError: autoplay policy. Do not storm play-url rebuilds. + if (error?.name !== 'NotAllowedError' && seq === attachSeq) emit('error') + } + } + if (video.canPlayType('application/vnd.apple.mpegurl')) { video.src = url - try { await video.play() } catch (_) {} + await tryPlay() return } @@ -120,7 +136,8 @@ async function attachPlayer(url) { hls.attachMedia(video) hls.on(Hls.Events.MANIFEST_PARSED, () => { if (seq !== attachSeq) return - video.play().catch(() => {}) + video.muted = true + tryPlay() }) } catch (_) { if (seq === attachSeq) emit('error')