From a27b0ac7f241b68833d7dc41670c9e5bd6ea7c24 Mon Sep 17 00:00:00 2001 From: Ironsp <1522278303@qq.com> Date: Fri, 26 Jun 2026 11:07:29 +0800 Subject: [PATCH] =?UTF-8?q?feat=20hls=E9=94=99=E8=AF=AF=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .eslintrc-auto-import.json | 4 ++++ src/utils/video.ts | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/.eslintrc-auto-import.json b/.eslintrc-auto-import.json index 2ca3adf..d979925 100644 --- a/.eslintrc-auto-import.json +++ b/.eslintrc-auto-import.json @@ -5,6 +5,10 @@ "ComputedRef": true, "DirectiveBinding": true, "EffectScope": true, + "ElLoading": true, + "ElMessage": true, + "ElMessageBox": true, + "ElNotification": true, "ExtractDefaultPropTypes": true, "ExtractPropTypes": true, "ExtractPublicPropTypes": true, diff --git a/src/utils/video.ts b/src/utils/video.ts index 6380c60..2dce39b 100644 --- a/src/utils/video.ts +++ b/src/utils/video.ts @@ -26,6 +26,28 @@ export const initHls = (monitorVideoUrl, monitorVideoRef) => { video.play().catch(() => {}); } catch (e) {} }); + + // ★ 错误自动恢复:hls.js 拿到空 m3u8 或 ts 加载失败时自动重试 + hls.on(Hls.Events.ERROR, (event, data) => { + if (data.fatal) { + switch (data.type) { + case Hls.ErrorTypes.NETWORK_ERROR: + // 网络错误(m3u8 404 / ts 404)→ 重新开始加载 + hls.startLoad(); + break; + case Hls.ErrorTypes.MEDIA_ERROR: + // 媒体解码错误 → 尝试恢复 + hls.recoverMediaError(); + break; + default: + // 其他致命错误 → 销毁,让下一次 initHls 重建 + hls.destroy(); + hlsInstance = null; + break; + } + } + }); + hlsInstance = hls; } else if (video.canPlayType('application/vnd.apple.mpegurl')) { // Safari/原生支持 HLS