我正在使用videojs。它是自我托管的,并获得视频,它正在使http命中。 我已经提供了与src一起使用的身份验证。 我得到的状态代码是401.如何打印用户可理解的错误消息。
目前我收到“视频无法加载,因为服务器或网络出现故障或者因为格式不受支持。” 。但我想根据状态代码显示错误。
需要帮助。
提前致谢
答案 0 :(得分:1)
您可以尝试使用xmlhttp头请求(在视频错误之后)捕获特定的http状态代码...
function getError(url, callback)
{
var xhr = new XMLHttpRequest();
xhr.open('HEAD', url);
xhr.onreadystatechange = function() {
if (this.readyState == this.DONE) {
callback(this.status);
}
};
xhr.send();
}
/* after your video throws an error, try a simple head request */
getError("https://your.domain.com/video/sample.mp4", function(status) {
/* handle specific codes here... */
console.log(status);
});