feat hls错误自动修复

This commit is contained in:
Ironsp
2026-06-26 11:07:29 +08:00
parent 4083da42d8
commit a27b0ac7f2
2 changed files with 26 additions and 0 deletions

View File

@@ -5,6 +5,10 @@
"ComputedRef": true,
"DirectiveBinding": true,
"EffectScope": true,
"ElLoading": true,
"ElMessage": true,
"ElMessageBox": true,
"ElNotification": true,
"ExtractDefaultPropTypes": true,
"ExtractPropTypes": true,
"ExtractPublicPropTypes": true,

View File

@@ -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