我使用的blob:HTTPS作为源为我的视频标签,就像这样:检测404:HTTPS源
function mk_bloburl(source_id, url) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'blob'; //important
xhr.onload = function(e) {
if (this.status == 200) {
var blob = this.response;
var source = document.getElementById(source_id);
var video = source;
if (video.tagName=="SOURCE") {
video = source.parentNode;
}
video.oncanplaythrough = function() {
URL.revokeObjectURL(source.src);
};
source.src = URL.createObjectURL(blob);
video.load();
}
};
xhr.send();
}
mk_bloburl('review-video-source', my_video_url);
有了HTML这样的:
<video id="review-video" controls="" width="100%">
<source id="review-video-source" />
</video>
现在,如果我重新加载页面并开始播放,它的工作原理。如果我玩,让它玩,然后重播没有等待时间它的作品。 然而,如果我重新加载页面,然后等待一段时间(如1-2分钟),然后按播放,它会失败。
留言我在Chrome浏览器中得到如下:
GET blob:https://example.com/debeecfe-49b0-4c98-87d6-8ead325b2d75 404 (Not Found)
所以,它就像一滴被自动移除了一段时间后,浏览器内存中。我想在事件被删除或者当我通过开始播放获得404时捕获该事件,因此我可以刷新该Blob。
我曾尝试:
var source = document.querySelector("#review-video-source");
source.addEventListener("error", function(event) {
console.debug("An error accoured");
});
但是,这似乎并没有捕获错误。 我能做什么?