Browse Source

fix: stabilize LivePlayer for normal HLS live

Disable lowLatencyMode, widen fragment retries, extend startup 404
window to 30s, and recover media fatals once before bubbling.
main
xiaosi 2 weeks ago
parent
commit
5eda25a2fb
  1. 25
      src/components/LivePlayer.vue

25
src/components/LivePlayer.vue

@ -44,8 +44,8 @@
<script setup>
import { computed, onBeforeUnmount, ref, watch } from 'vue'
const STARTUP_RETRY_DELAYS_MS = [500, 1000, 2000, 4000]
const STARTUP_WINDOW_MS = 15_000
const STARTUP_RETRY_DELAYS_MS = [500, 1000, 2000, 4000, 6000, 8000]
const STARTUP_WINDOW_MS = 30_000
const props = defineProps({
playUrl: { type: String, default: '' },
@ -321,10 +321,13 @@ async function attachPlayer(url, { seq: existingSeq } = {}) {
// 退 404
hls = new Hls({
enableWorker: true,
lowLatencyMode: true,
manifestLoadingMaxRetry: 0,
levelLoadingMaxRetry: 0,
fragLoadingMaxRetry: 1,
lowLatencyMode: false,
manifestLoadingMaxRetry: 2,
manifestLoadingRetryDelay: 1000,
levelLoadingMaxRetry: 2,
levelLoadingRetryDelay: 1000,
fragLoadingMaxRetry: 4,
fragLoadingRetryDelay: 1000,
})
hls.on(Hls.Events.ERROR, (_event, data) => {
if (seq !== attachSeq) return
@ -367,6 +370,16 @@ async function attachPlayer(url, { seq: existingSeq } = {}) {
return
}
if (data.type === Hls.ErrorTypes.MEDIA_ERROR) {
try {
console.warn('[live-player] hls media fatal, recover once', data)
hls.recoverMediaError()
return
} catch (recoverErr) {
console.warn('[live-player] hls recover failed', recoverErr)
}
}
console.warn('[live-player] hls fatal', data)
emitFatal(buildPlayError({
message: detail || 'hls fatal',

Loading…
Cancel
Save