测试实际视频文件是否可以播放

Testing actual video file can play

JavaScript 有 canPlayType 方法来测试浏览器是否可以播放视频文件。但是为了获得更准确的结果,它需要一个字符串,例如 "video/mp4; codecs="avc1.66.13, mp4a.40.2"。有没有办法让 JavaScript 到 运行 直接在视频文件上进行测试以检查它将播放,或者使用 JavaScript 或什至 PHP?

检索更准确的编解码器信息

有这样的东西,叫做canplaythrough

The canplaythrough event is fired when the user agent can play the media, and estimates that enough data has been loaded to play the media up to its end without having to stop for further buffering of content.

https://developer.mozilla.org/en-US/docs/Web/Events/canplaythrough

还有一个 error 事件会在视频加载失败或浏览器无法播放时触发

var v = document.createElement('video'),
    s = document.createElement('source');

v.appendChild(s);

s.src  = "simpsons.mp4";
s.type = "video/mp4";

s.addEventListener('error', function(ev) {
    // catch errors
}, false);