fix(video): 优化 HLS 流加载失败的错误处理机制,解决跨域及 403 导致无限重试的问题

This commit is contained in:
wangjing
2026-04-24 01:17:56 +08:00
parent e6cde5973a
commit 1a1ddcf8a1
+12 -2
View File
@@ -283,8 +283,18 @@ export class VideoPlayer {
switch (data.type) {
case Hls.ErrorTypes.NETWORK_ERROR:
// fatal network error, 多数是因为 CORS 跨域被拦截
console.error('致命网络错误 (非常可能是 CORS 跨域拦截),尝试重启加载...');
this.hls.startLoad();
if (data.details === Hls.ErrorDetails.MANIFEST_LOAD_ERROR || data.details === 'manifestLoadError') {
console.error('M3U8 文件加载失败,通常由于 CORS、403 防盗链或链接失效。');
// 延迟一下提示,避免阻断 UI
setTimeout(() => {
alert(`视频源加载失败:当前流不可用 (防盗链/跨域/已失效)。`);
}, 100);
this.hls.destroy();
this.showWelcome();
} else {
console.error('致命网络错误 (非常可能是 CORS 跨域拦截),尝试重启加载...');
this.hls.startLoad();
}
break;
case Hls.ErrorTypes.MEDIA_ERROR:
console.error('致命媒体错误,尝试恢复...');