Check if the given audio format is supported on the browser, and return the compatibility level as a number


A client-side library to check if the given audio format is supported on the browser. It returns the compatibility level as a number (0 - 2).

// On Google Chrome 
audioSupportLevel('aiff'); //=> 0 
audioSupportLevel('mp4'); //=> 1 
audioSupportLevel('mp4', 'mp4a.40.5'); //=> 2 
audioSupportLevel({subtype: 'mp4', codecs: 'mp4a.40.5'}); //=> 2 


npm i --save audio-support-level


bower i --save audio-support-level


component install shinnn/audio-support-level.js

Download the script file directly and install the dependency.

AMD support

This repository includes the AMD-friendly build but the package managers doesn't include it. If you want to use it, download it and its dependency directly.

subtype: String (e.g. 'ogg', 'mp3')
codecs: String (e.g. 'vorbis', 'mp4a.40.5')
Return: Number (0 - 2)

It evaluates .canPlayType() of an audio element, passing a MIME Type with the given subtype and codecs. Then it returns a number (0 - 2) according to the API of can-play-type-to-number.

// On Google Chrome 
audioSupportLevel('ogg'); //=> 1 
audioSupportLevel('ogg', 'vorbis'); //=> 2 

options: Object
Return: Number (0 - 2)

Instead of String, it can take an Object with subtype property (required) and codecs property (optional).

// On Google Chrome 
audioSupportLevel({subtype: 'ogg'}); //=> 1 
audioSupportLevel({subtype: 'ogg', codecs: 'vorbis'}); //=> 2 

Copyright (c) 2014 Shinnosuke Watanabe

Licensed under the MIT LIcense.