waud / waud
- понедельник, 5 сентября 2016 г. в 03:13:32
Haxe
Web Audio Library
Web Audio Library with HTML5 audio fallback.
Waud is a simple and powerful web audio library that allows you to go beyond HTML5's <audio>
tag and easily take advantage of Web Audio API. It abstracts Web Audio API making it consistent and reliable across multiple platforms and browsers. It also falls back to HTML5 Audio on non-modern browsers where Web Audio API is not supported.
1 Automatically unlocks audio on iOS devices on first touch.
2 Automatically mutes audio when the window is not in focus (switching tab, minimising window, etc).
For haxe users:
haxelib install waud
Example:
var snd = new WaudSound("assets/loop.mp3", { autoplay: false, loop: true, volume: 0.5, onload: playBgSound });
Waud supports base64 decoding across all browsers including IE 9 and I recommend using this over audio sprites.
Use waudbase64 to generate base64 encoded JSON file.
npm install -g waudbase64
var base64pack = new WaudBase64Pack("assets/sounds.json", _onLoad);
function _onLoad(snds) {
snds.get("assets/beep.mp3").play();
}
Waud also supports passing data URI string to WaudSound
.
//Note that the data URI used below is a sample string and not a valid sound
var base64Snd = new WaudSound("data:audio/mpeg;base64,//uQxAAAAAAAAAAAAASW5mbwAAAA8AAABEAABwpgADBwsLDxISF");
Use waudsprite to generate audio sprite.
npm install -g waudsprite
var audSprite = new WaudSound("assets/sprite.json");
audSprite.play("glass");
Tested on all major browsers.
Latest ✓ | Latest ✓ | Latest ✓ | Latest ✓ | 9-11 ✓ | Latest ✓ |
Browser & Device Testing provided by:
Found any bug? Please create a new issue.
Waud.init();
Waud.enableTouchUnlock(touchUnlock);
Waud.autoMute();
var bgSnd = new WaudSound("assets/loop.mp3", {
"autoplay": false, "loop":true, "volume": 0.5, "onload": playBgSound
});
var snd2 = new WaudSound("assets/sound1.wav", {
"autoplay": false,
"loop":true,
"onload": function (snd) { snd.play(); },
"onend": function (snd) { console.log("ended"); },
"onerror": function (snd) { console.log("error"); }
});
//Touch unlock event for iOS devices
function touchUnlock() {
if (!bgSnd.isPlaying()) bgSnd.play();
}
function playBgSound(snd) {
if (!snd.isPlaying()) snd.play();
}
Waud.preferredSampleRate
property.This content is released under the MIT License.
Code of Conduct is adapted from Contributor Covenant, version 1.4