Latest web development tutorials

HTML Audio / Video DOM canPlayType () method

HTML audio / video Tag Reference HTML Audio / Video DOM Reference

Examples

Detect your browser can play different types of video:

myVid=document.createElement('video');
isSupp=myVid.canPlayType(vidType+';codecs="'+codType+'"');

try it"

Definition and Usage

canPlayType () method to detect whether the browser can play the specified audio / video type.

canPlayType () method returns one of the following values:

  • "Probably" - the most likely to support the browser of the audio / video type
  • "Maybe" - perhaps the browser supports the audio / video type
  • "" - (Null string) browser does not support the audio / video type

Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support canPlayType () method.

Note: 8 and earlier versions of Internet Explorer does not support this method.


grammar

audio|video .canPlayType( type ))

parameter

描述
type 规定要检测的音频/视频类型(和可选的编解码器)。

常用值:

  • video/ogg
  • video/mp4
  • video/webm
  • audio/mpeg
  • audio/ogg
  • audio/mp4

常用值,包括编解码器:

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

注意:如果包含编解码器,则该方法只能返回 "probably"。

return value

类型 描述
String 表示支持的级别。可能的返回值:
  • "probably" - 最有可能支持
  • "maybe" - 可能支持
  • "" - (空字符串)不支持


HTML audio / video Tag Reference HTML Audio / Video DOM Reference