HTMLMediaElement: canPlayType() method
MDN Web Docs · نسخهٔ df622a2a1c1e · CC BY-SA 2.5 و مجوز جداگانهٔ ناشر برای نمونهکد
{{APIRef("HTML DOM")}}
The {{domxref("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-nolint
canPlayType(type)Parameters
type- : A string specifying the MIME type of the media and (optionally) a [
codecsparameter](/en-US/docs/Web/Media/Guides/Formats/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:
""(empty string)- : The media cannot be played on the current device.
probably- : The media is probably playable on this device.
maybe- : There is not enough information to determine whether the media can play (until playback is actually attempted).
Examples
js
let obj = document.createElement("video");
console.log(obj.canPlayType("video/mp4")); // "maybe"Specifications
{{Specifications}}
Browser compatibility
{{Compat}}
See also
- {{domxref("HTMLMediaElement")}}: Interface used to define the
HTMLMediaElement.canPlayType()method - {{domxref("MediaCapabilities")}}
- Handling media support issues in web content
- Media type and format guide
- Codecs in common media types