我正在寻找一种在 HTML5 视频元素报告网络错误 (HTML5 media element error code 2) 之前设置超时的方法
在测试时,我注意到如果我停止互联网连接,视频元素会挂起并且在显示媒体错误代码 2 之前似乎缓冲了很长时间。我可以减少这个时间吗?
也有一些它根本不报告错误并且似乎永远缓冲的情况。这是有原因的吗?
最佳答案
不幸的是,我认为你不能,这取决于每个浏览器 vendor 的实现。根据 HTML5 视频 spec在资源获取算法中,您可以阅读:
The stall timeout is a user-agent defined length of time, which should be about three seconds. When a media element that is actively attempting to obtain media data has failed to receive any data for a duration equal to the stall timeout, the user agent must queue a task to fire a simple event named stalled at the element.
User agents may allow users to selectively block or slow media data downloads. When a media element's download has been blocked altogether, the user agent must act as if it was stalled (as opposed to acting as if the connection was closed). The rate of the download may also be throttled automatically by the user agent, e.g. to balance the download with other connections sharing the same bandwidth.
User agents may decide to not download more content at any time, e.g. after buffering five minutes of a one hour media resource, while waiting for the user to decide whether to play the resource or not, or while waiting for user input in an interactive resource. When a media element's download has been suspended, the user agent must set the networkState to NETWORK_IDLE and queue a task to fire a simple event named suspend at the element. If and when downloading of the resource resumes, the user agent must set the networkState to NETWORK_LOADING.
关于javascript - 有没有办法指定 HTML5 视频元素的超时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40909883/