开发者

How to check for html5 video support?

Is there any开发者_Go百科 JavaScript or any other way of checking for html5 video support?


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


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');


Have a look at Modernizer: http://www.modernizr.com/

There, you get APIs as easy as

if (Modernizr.video) {
  // html5 video available
}

But many more features and more suitable APIs as well.


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.


One way is to embed the html5 tags, and then put the alternate video viewer within the video tags as a "fallback". The fallback will get displayed if a browser doesnt recognize the tag. Its not strictly 'detecting' html5 video support, but may suit your needs.

<video src='...'>
    <embed flash player instead>
</video>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜