Audio canPlayType() Method

Definition and usage

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

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

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

Example

Check if your browser can play different types of audio:

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

Try it yourself

Syntax

audioObject.canPlayType(type)

Parameter value

Value Description
type

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

Common values:

  • audio/mpeg
  • audio/ogg
  • audio/mp4

Common values, including codecs:

  • audio/ogg; codecs="vorbis"
  • audio/mp4; codecs="mp4a.40.5"

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

Technical Details

Return Value:

String values representing the support level. 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