├── .gitignore ├── package.json ├── index.js ├── README.md └── lib ├── audio-object.js ├── audio-tag-player.js └── web-audio-player.js /.gitignore: -------------------------------------------------------------------------------- 1 | test -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "browser-audio", 3 | "version": "1.0.2", 4 | "description": "Browser audio player", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/yyx990803/browser-audio" 12 | }, 13 | "keywords": [ 14 | "audio", 15 | "browser" 16 | ], 17 | "author": "Evan You", 18 | "license": "MIT", 19 | "bugs": { 20 | "url": "https://github.com/yyx990803/browser-audio/issues" 21 | }, 22 | "homepage": "https://github.com/yyx990803/browser-audio" 23 | } 24 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var AudioObject = require('./lib/audio-object') 2 | 3 | module.exports = { 4 | 5 | create: function (url) { 6 | return new AudioObject(url) 7 | }, 8 | 9 | whenLoaded: function (objects, cb) { 10 | var loaded = 0 11 | if (!Array.isArray(objects)) { 12 | objects = [objects] 13 | } 14 | objects.forEach(function (o) { 15 | if (o.state === 'loaded') { 16 | check() 17 | } else { 18 | o.once('load', check) 19 | } 20 | }) 21 | function check () { 22 | loaded++ 23 | if (loaded === objects.length) { 24 | cb() 25 | } 26 | } 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Browser Audio 2 | 3 | A simple cross-browser audio player. Uses Web Audio when possible (except in Firefox where HTML5 `