feat hls错误自动修复
This commit is contained in:
@@ -5,6 +5,10 @@
|
||||
"ComputedRef": true,
|
||||
"DirectiveBinding": true,
|
||||
"EffectScope": true,
|
||||
"ElLoading": true,
|
||||
"ElMessage": true,
|
||||
"ElMessageBox": true,
|
||||
"ElNotification": true,
|
||||
"ExtractDefaultPropTypes": true,
|
||||
"ExtractPropTypes": true,
|
||||
"ExtractPublicPropTypes": true,
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user