Video canPlayType() Method

Definition and Usage

canPlayType() Method checks if the browser can play the specified video type.

canPlayType() The method can return one of the following values:

  • "probably" - The browser is most likely to support this video type
  • "maybe" - The browser may support this video type
  • "" - (empty string) The browser does not support this video type

Example

Check if your browser can play different types of video:

var x = document.createElement("VIDEO");
isSupp = x.canPlayType(vidType+';codecs="'+codType+'"');

Try it yourself

Syntax

videoObject.canPlayType(type)

Parameter

Parameter Description
type

Define the video types (and optional codecs) to be tested.

Common values:

  • video/ogg
  • video/mp4
  • video/webm

Common values, including codecs:

  • video/ogg; codecs="theora, vorbis"
  • video/mp4; codecs="avc1.4D401E, mp4a.40.2"
  • video/webm; codecs="vp8.0, vorbis"

Note:If the codec is included, this method can only return "probably".

Technical Details

Return value:

String values representing support levels. Possible return values:

  • "probably" - Most likely supported
  • "maybe" - May be supported
  • "" (empty string) - Not supported

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support 9.0 Support Support Support