Browse Source

fix: mute LivePlayer so live autoplay can start

Chrome/Edge block unmuted autoplay after async join;
silent play() failures left a black LIVE frame.
main
xiaosi 2 weeks ago
parent
commit
ad7e29dd5d
  1. 21
      src/components/LivePlayer.vue

21
src/components/LivePlayer.vue

@ -9,6 +9,7 @@
ref="videoEl" ref="videoEl"
controls controls
autoplay autoplay
muted
playsinline playsinline
/> />
<div v-else class="camera-scene"> <div v-else class="camera-scene">
@ -92,14 +93,29 @@ async function attachPlayer(url) {
const video = videoEl.value const video = videoEl.value
if (!video || seq !== attachSeq) return if (!video || seq !== attachSeq) return
video.muted = true
video.defaultMuted = true
video.setAttribute('muted', '')
video.addEventListener('error', () => { video.addEventListener('error', () => {
if (seq !== attachSeq) return if (seq !== attachSeq) return
emit('error') emit('error')
}, { once: true }) }, { 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')) { if (video.canPlayType('application/vnd.apple.mpegurl')) {
video.src = url video.src = url
try { await video.play() } catch (_) {}
await tryPlay()
return return
} }
@ -120,7 +136,8 @@ async function attachPlayer(url) {
hls.attachMedia(video) hls.attachMedia(video)
hls.on(Hls.Events.MANIFEST_PARSED, () => { hls.on(Hls.Events.MANIFEST_PARSED, () => {
if (seq !== attachSeq) return if (seq !== attachSeq) return
video.play().catch(() => {})
video.muted = true
tryPlay()
}) })
} catch (_) { } catch (_) {
if (seq === attachSeq) emit('error') if (seq === attachSeq) emit('error')

Loading…
Cancel
Save