Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if the browser can play mp4 via html5 video tag?

How to check if the browser can play mp4 via html5 video tag?

like image 868
Coepr Avatar asked Aug 26 '10 04:08

Coepr


People also ask

Can MP4 play on HTML5?

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.

Which method check if the browser can play the specified video type?

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.

Which tag is used for video in HTML5?

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.


2 Answers

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> 
like image 196
Alex Polo Avatar answered Sep 18 '22 09:09

Alex Polo


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 :)

like image 20
badfur Avatar answered Sep 19 '22 09:09

badfur