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);
关于javascript - 测试实际视频文件能否播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27857355/