javascript - 有没有办法指定 HTML5 视频元素的超时?

标签 javascript html video video-streaming html5-video

我正在寻找一种在 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/

相关文章:

javascript - 修改或替换 Facebook 点赞按钮弹出框

javascript - 如何让菜单边栏消失并使用变换调整内容

java - 是否可以检测页面抓取?

video - ffprobe 获取最后一个音频/视频数据包的 pts

javascript - jquery 阻止重定向直到动画之后

javascript - 将重复的 JQuery 代码转换为干净的代码

javascript - 窗口打开问题

c++ - 获取 IAMStreamConfig 接口(interface)失败

javascript - 使用上一个/下一个按钮扩展youtube视频的下拉菜单的 View 屏幕

javascript - jQuery:思考 on() 而不是 live() ,在动态生成的东西上传播