Javascript examples for DOM HTML Element:Video
The canPlayType() method checks if the browser can play the specified video type.
The canPlayType() method can return one of the following values:
Value | Meaning |
---|---|
"probably" | the browser most likely supports this video type |
"maybe" | the browser might support this video type |
"" | the browser does not support this video type |
Value | Description |
---|---|
type | Specifies the video type (and optional codecs) to test support for. |
Common values:
Common values, including codecs:
A String, representing the level of support.
The following code shows how to Check if your browser can play different types of video:
<!DOCTYPE html> <html> <body> <p>Can my browser play MP4 videos? <span> <button onclick="supportType(event,'video/mp4','avc1.42E01E, mp4a.40.2')" type="button">Test</button> </span></p> <p>Can my browser play OGG videos? <span> <button onclick="supportType(event,'video/ogg','theora, vorbis')" type="button">Test</button> </span></p> <script> function supportType(e,vidType,codType) { var x = document.createElement("VIDEO"); isSupp = x.canPlayType(vidType+';codecs="'+codType+'"'); if (isSupp == "") { isSupp = "No"; }//from w ww. j a v a 2 s . co m e.target.parentNode.innerHTML = "Answer: " + isSupp; } </script> </body> </html>