Video canPlayType()Method

Video 对象参考手册Video Object

Examples

Check whether your browser can play different types of video:

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

Try it Yourself »

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 the audio/video type
  • "maybe" - The browser might support the audio/video type
  • "" - (empty string) The browser does not support the audio/video type

Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

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 Values

Value Description
type Specifies the audio/video type to be detected.

Usually can be:

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

Usually refers to including a 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, this 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


Video 对象参考手册Video Object Other Extensions