audio-support-level
v0.1.1
Published
Check if the given audio format is supported on the browser, and return the compatibility level as a number
Downloads
12
Maintainers
Readme
audio-support-level.js
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
Installation
Install with package manager
npm
npm i --save audio-support-level
Bower
bower i --save audio-support-level
Component
component install shinnn/audio-support-level.js
Install manually
Download the script file directly and install the dependency.
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.
API
audioSupportLevel(subtype [, codecs])
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
audioSupportLevel(options)
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
License
Copyright (c) 2014 Shinnosuke Watanabe
Licensed under the MIT LIcense.