Video canPlayType() method
Example
Detect whether your browser can play different types of video:
var x = document.createElement("VIDEO");
isSupp = x.canPlayType(vidType+';codecs="'+codType+'"');
Try it »
Definition and Usage
The canPlayType() method checks whether the browser can play the specified audio/video type.
The canPlayType() method can return one of the following values:
- "probably" - The browser most likely supports this audio/video type
- "maybe" - The browser might support this audio/video type
- "" - (empty string) The browser does not support this audio/video type
Browser support





All major browsers support the canPlayType() method
Note: Internet Explorer 8 and earlier IE versions do not support this method.
Syntax
videoObject
.canPlayType(
type
))
Parameter value
| Value | Description |
|---|---|
| type | Describes the audio/video type to be detected. |
通常可以是:
- video/ogg
- video/mp4
- video/webm
Usually it includes the codec:
- video/ogg; codecs="theora, vorbis"
- video/mp4; codecs="avc1.4D401E, mp4a.40.2"
- video/webm; codecs="vp8.0, vorbis"
Note: If a codec is included, the method can only return "probably".
|Technical Details
| Return value: | Indicates the level of support. Possible values:
- "probably" - Most likely supported
- "maybe" - Possibly supported
- "" - (empty string) Not supported
The Video object