- Notifications
You must be signed in to change notification settings - Fork38
waud/waud
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
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 ofWeb 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.
- Base64 Pack
- Audio Sprites
- iOS Audio Unlock1
- Auto Mute2
- Simple API
- Zero Dependencies
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).
Available via npm, cdn and haxelib (for haxe users).
- NPM:https://www.npmjs.com/package/waud.js
- CDN:https://cdnjs.com/libraries/waud.js
- Haxelib:http://lib.haxe.org/p/waud
Example:
varsnd=newWaudSound("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.
Usewaudbase64 to generate base64 encoded JSON file.
npm install -g waudbase64
varbase64pack=newWaudBase64Pack("assets/sounds.json",_onLoad);function_onLoad(snds){snds.get("assets/beep.mp3").play();}
Waud also supports passing data URI string toWaudSound
.
//Note that the data URI used below is a sample string and not a valid soundvarbase64Snd=newWaudSound("data:audio/mpeg;base64,//uQxAAAAAAAAAAAAASW5mbwAAAA8AAABEAABwpgADBwsLDxISF");
Usewaudsprite to generate audio sprite.
npm install -g waudsprite
varaudSprite=newWaudSound("assets/sprite.json");audSprite.play("glass");
Waud supports live audio streams, but make sure to disable web audio as live streams can only be played through HTML5 Audio.
varsnd=newWaudSound("http://ice-sov.musicradio.com/SmoothUKMP3",{autoplay:true,webaudio:false});
Tested on all major browsers.
Latest ✓ | Latest ✓ | Latest ✓ | Latest ✓ | 9-11 ✓ | Latest ✓ |
Browser & Device Testing provided by:
Found any bug? Please create a newissue.
// Initialize Waud. Make sure to call this before loading sounds.Waud.init();// To automatically unlock audio on iOS devices by playing a blank sound.// The parameter is a callback function that can be used to start playing sounds like background music.Waud.enableTouchUnlock(touchUnlock);// Use if you want to mute audio when the window is not in focus like switching tabs, minimising window,// etc in desktop and pressing home button, getting a call, etc on devices.Waud.autoMute();// Load and play looping background sound with autoPlay and loop set to true.// Note that this will not play automatically on iOS devices without touching the screen.varbgSnd=newWaudSound("loop.mp3",{"autoplay":true,"loop":true});// Touch unlock callback for iOS devices to start playing bgSnd if it's not already playingfunctiontouchUnlock(){if(!bgSnd.isPlaying())bgSnd.play();}
- It is recommended to use samesample rate for all the audio files. Playing differentsample rate files can cause issues on some devices.
- By default,Waud uses44100 sample rate. If your audio files have a different sample rate then specify it using
Waud.preferredSampleRate
property.
This content is released under theMIT License.
Code of Conduct is adapted fromContributor Covenant, version 1.4
About
Web Audio Library