JavaScript has the canPlayType method to test if the browser can play a video file. But for more accurate results it needs a string such as "video/mp4; codecs="avc1.66.13, mp4a.40.2". Is there any way for JavaScript to run a test directly on a video file to check it will play, or alternatively to retrieve more accurate codec information with JavaScript, or perhaps even PHP?
0
votes
1 Answers
1
votes
There is something like that, it's called 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
There's also an error
event that fires when the video fails to load or can't be played by the browser
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);