W3cubDocs

/Web APIs

HTMLMediaElement: canPlayType() method

The HTMLMediaElement method canPlayType() reports how likely it is that the current browser will be able to play media of a given MIME type.

Note: This feature is not available in Web Workers.

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:

"" (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

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
canPlayType
3["codecs string can contain any subset of optional parameters (should be all or none).", "Errors if codecs string contains unexpected characters (should evaluate string up to character)."]
12["codecs string can contain any subset of optional parameters (should be all or none).", "Errors if codecs string contains unexpected characters (should evaluate string up to character)."]
3.5["Before Firefox 28, canPlayType() returned probably when asked about WebM audio or video files without the codecs parameter. Since multiple codecs are supported, this is not enough information to determine if a file can be played, so maybe is now correctly returned.", "Before Firefox 101, canPlayType() ignored codecs parameter options for av01 codecs (treating them as av1)."]
9
≤12.1["codecs string can contain any subset of optional parameters (should be all or none).", "Errors if codecs string contains unexpected characters (should evaluate string up to character)."]
4
≤37["codecs string can contain any subset of optional parameters (should be all or none).", "Errors if codecs string contains unexpected characters (should evaluate string up to character)."]
18["codecs string can contain any subset of optional parameters (should be all or none).", "Errors if codecs string contains unexpected characters (should evaluate string up to character)."]
4["Before Firefox 28, canPlayType() returned probably when asked about WebM audio or video files without the codecs parameter. Since multiple codecs are supported, this is not enough information to determine if a file can be played, so maybe is now correctly returned.", "Before Firefox 101, canPlayType() ignored codecs parameter options for av01 codecs (treating them as av1)."]
≤12.1["codecs string can contain any subset of optional parameters (should be all or none).", "Errors if codecs string contains unexpected characters (should evaluate string up to character)."]
3
1.0["codecs string can contain any subset of optional parameters (should be all or none).", "Errors if codecs string contains unexpected characters (should evaluate string up to character)."]

See also

© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/canPlayType