【问题标题】:Videojs custom error message when error code is 401错误代码为 401 时的 Videojs 自定义错误消息
【发布时间】:2015-06-24 16:22:31
【问题描述】:

我正在使用 videojs 。它是自托管的,并且要获取视频,它正在使 http 命中。 我已经放置了与 src 一起使用的身份验证。 我得到的状态码是 401。如何打印用户可以理解的错误消息。

目前我收到“无法加载视频,原因可能是服务器或网络出现故障,或者格式不受支持。” .但我想根据状态码显示错误。

需要帮助。

提前致谢

【问题讨论】:

    标签: javascript jquery ajax html5-video video.js


    【解决方案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);
    });
    

    【讨论】:

      猜你喜欢
      • 2020-05-29
      • 1970-01-01
      • 2011-09-05
      • 2011-08-28
      • 1970-01-01
      • 2016-08-06
      • 1970-01-01
      • 2021-07-31
      • 1970-01-01
      相关资源
      最近更新 更多