How to check if the browser can play mp4 via html5 video tag?
The minimum for HTML5 video is MP4 + WebM or Ogg (or both), using the MP4 version for Flash fallback. 2. For mobile support, one H. 264/MP4 output can take you a long way.
The Video canPlayType() method is used for checking if the browser can play the specified video type or not. The Video canPlayType method returns a string which represents the level of support.
The <video> tag is used to embed video content in a document, such as a movie clip or other video streams. The <video> tag contains one or more <source> tags with different video sources. The browser will choose the first source it supports.
This might help you:
<script type="text/javascript">'. var canPlay = false; var v = document.createElement('video'); if(v.canPlayType && v.canPlayType('video/mp4').replace(/no/, '')) { canPlay = true; } alert(canPlay); </script>
Alex Polo's reply is not bad but incomplete try this to check if the codec is supported too:
var mp4Supported = (!!document.createElement('video').canPlayType('video/mp4; codecs=avc1.42E01E,mp4a.40.2'));
Likewise for ogg, webm and so on ... Works with audio too :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With