HTMLMediaElement: canPlayType() method
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The HTMLMediaElement
method canPlayType()
reports how likely it is that the current browser will be able to play media of a given MIME type.
Syntax
js
canPlayType(type)
Parameters
type
-
A string specifying the MIME type of the media and (optionally) a
codecs
parameter containing a comma-separated list of the supported codecs.
Return value
A string indicating how likely it is that the media can be played. The string will be one of the following values:
Examples
js
let obj = document.createElement("video");
console.log(obj.canPlayType("video/mp4")); // "maybe"
Specifications
Specification |
---|
HTML Standard # dom-navigator-canplaytype-dev |
Browser compatibility
BCD tables only load in the browser
See also
HTMLMediaElement
: Interface used to define theHTMLMediaElement.canPlayType()
methodMediaCapabilities
- Handling media support issues in web content
- Media type and format guide
- Codecs in common media types