|
|
@ -60,7 +60,9 @@ export async function openVideoStream(container, { camId, url } = {}) { |
|
|
|
player.load(); |
|
|
|
player.play(); |
|
|
|
|
|
|
|
player.on(flvJs.Events.ERROR, (e) => {}); |
|
|
|
player.on(flvJs.Events.ERROR, (errorType, errorDetails, errorInfo) => { |
|
|
|
console.error('video errorInfo', errorInfo); |
|
|
|
}); |
|
|
|
|
|
|
|
return player; |
|
|
|
} |
|
|
@ -98,6 +100,8 @@ export class HttpLivePlayer { |
|
|
|
|
|
|
|
// 解码 帧
|
|
|
|
lastDecodedFrames; |
|
|
|
retryCount = 0; |
|
|
|
maxRetries = 3; // 最大重试次数
|
|
|
|
|
|
|
|
constructor(container, options) { |
|
|
|
this.container = container; |
|
|
@ -106,6 +110,9 @@ export class HttpLivePlayer { |
|
|
|
getUrl(options).then((url) => { |
|
|
|
this.url = url; |
|
|
|
this.initLiveVideo(); |
|
|
|
}).catch(error => { |
|
|
|
console.error('获取URL失败:', error); |
|
|
|
Message.error('无法获取视频流URL'); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
@ -118,11 +125,18 @@ export class HttpLivePlayer { |
|
|
|
this.player.destroy(); |
|
|
|
this.player = null; |
|
|
|
} |
|
|
|
|
|
|
|
clearMediaElementErrors() { |
|
|
|
if (this.container.error) { |
|
|
|
console.error('Media element is in an error state:', this.container.error); |
|
|
|
this.container.error = null; // 清除错误状态
|
|
|
|
} |
|
|
|
} |
|
|
|
initLiveVideo() { |
|
|
|
this.destroy(); |
|
|
|
this.clearMediaElementErrors(); // 清除媒体元素的错误状态
|
|
|
|
this.player = null; |
|
|
|
this.lastDecodedFrames = null; |
|
|
|
this.retryCount = 0; |
|
|
|
|
|
|
|
if (!this.url) return; |
|
|
|
|
|
|
@ -170,10 +184,13 @@ export class HttpLivePlayer { |
|
|
|
// Message.warning(
|
|
|
|
// `视频流加载失败, ${ErrorTypesCn[errorType] || "其他错误"}`
|
|
|
|
// );
|
|
|
|
let self = this; |
|
|
|
setTimeout(() => { |
|
|
|
self.initLiveVideo(); |
|
|
|
}, 300000); |
|
|
|
if (this.retryCount < this.maxRetries) { |
|
|
|
this.retryCount++; |
|
|
|
this.initLiveVideo(); |
|
|
|
} else { |
|
|
|
Message.error(`视频流加载失败,已达到最大重试次数。${ErrorTypesCn[errorType] || "其他错误"}`); |
|
|
|
this.destroy(); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
// 视频断流
|
|
|
@ -182,6 +199,7 @@ export class HttpLivePlayer { |
|
|
|
this.lastDecodedFrames = res.decodedFrames; |
|
|
|
} else { |
|
|
|
this.lastDecodedFrames = 0; |
|
|
|
this.initLiveVideo(); // 重置解码帧计数器,防止假死
|
|
|
|
// this.destroy();
|
|
|
|
// this.initLiveVideo();
|
|
|
|
} |
|
|
|