Skip to content
Check if the given audio format is supported on the browser, and return the compatibility level as a number
JavaScript
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
dist
src
test
.editorconfig
.gitattributes
.gitignore
.jscs.json
.jshintrc
.npmignore
.travis.yml
LICENSE
README.md
bower.json
component.json
gulpfile.js
package.json

README.md

audio-support-level.js

Bower version NPM version Build Status Dependency Status devDependency Status

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

Duo

var audioSupportLevel = require('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.

Something went wrong with that request. Please try again.