Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check for html5 video support?

Tags:

html

flash

video

Is there any JavaScript or any other way of checking for html5 video support?

like image 449
Forelic Avatar asked Aug 25 '10 21:08

Forelic


People also ask

How can you tell if a video is HTML5?

Answer: On the page with the video, press Ctrl+U to View the source. Now, look for a tag like <object> that is used by the flash video player or <video> tag used by HTML5, and accordingly, it can be known if the video is using Flash or HTML5.

How can I tell if HTML5 is supported?

The getContext method is checked by accessing it on the created input object. The result of this expression is checked with an if-statement. If the result is true, it means that HTML5 is supported by the browser.

Does HTML5 support video?

The HTML5 video format capabilities include three options to play: MP4, WebM, and Ogg. You should note that the Safari browser does not support Ogg, WebM is supported by only 58% of browsers, and MP4 is disabled by default in Firefox 24.

Why does my browser not support HTML5 video?

If your browser error "HTML5 video file not found", it means that your browser is not up to date or website pages does not have a suitable video codec. It would help if you communicated with the developer to solve the issue and install all the required codecs.


3 Answers

I use a slight variation of @sweets-BlingBling's answer, which is:

var hasVideo = !!document.createElement('video').canPlayType &&
               !!document.createElement('video').canPlayType('video/mp4')

This also checks whether the media type 'video/mp4' is actually playable (change this if your video has another media type, like 'video/webm' or 'video/ogg'). The method returns an empty String if the video definitely cannot be played and 'probably' or 'maybe' (actually, both results mean yes in most instances) otherwise. I had to add this for Chrome 41 (seemingly used in google crawler), which has canPlayType, but cannot play mp4 videos.

like image 134
Remigius Stalder Avatar answered Sep 26 '22 04:09

Remigius Stalder


use:

<script>
alert(!!document.createElement('video').canPlayType);
</script>

if it alerts true implies that your browser supports HTML5 video tag

Here is the url to check HTML5 Browser compatibility http://www.html5test.com/ Open the url in your browser to test how well your browser supports html5

like image 28
sweets-BlingBling Avatar answered Sep 23 '22 04:09

sweets-BlingBling


Just a little refinement of sweets-BlingBling's answer : sorry - I can't comment yet :(

var isHTML5Video = (typeof(document.createElement('video').canPlayType) != 'undefined') ? true : false;

or even simpler (thanks digitalBath - as always I can't see the wood for the trees :) )

var isHTML5Video = (typeof(document.createElement('video').canPlayType) != 'undefined');
like image 43
Anthony De Souza Avatar answered Sep 26 '22 04:09

Anthony De Souza