Zap! is an audio manager for html 5 applications with a focus on real time and interactive applications such as games.
MIT License
Zap! is an audio manager for html 5 applications with a focus on real-time uses such as games.
It provides a common interface that works across the individual browser quirks and shortcomings such as multiple channels, looping and callbacks.
Zap! depends on jQuery 1.4+
Init should be run before anything else to setup configuration and create dom elements
Arguments
Example
Zap.init({
console: true,
container: 'sound-holder'
});
There are currently three events that can be bound using the 'on' function; 'success', 'update' and 'error'. Multiple callbacks may also be bound.
Arguments
Example
Zap.on('complete', function(){
// all sounds are loaded
});
Zap.on('update', function(percent){
// sounds are loading
});
Zap.on('error', function(ref){
// there was a problem loading a sound file
});
Add a sound to be loaded, this method can be chained.
Arguments
Example
Zap.addSound('beat', ['beat.mp3', 'beat.ogg', 'beat.wav'])
.addSound('laser', ['shoot.mp3', 'shoot.ogg'], 5);
Allows sounds to be added into groups, groups can then be played back like individual sounds - a random sound from the group will be chosen. This method can be chained.
Arguments
Example
Zap.addGroup('punch', ['thud', 'pow', 'kablam']);
Zap.addSound('thud', ['thud.mp3', 'thud.ogg']),
.addSound('pow', ['pow.mp3', 'pow.ogg']),
.addSound('kablam', ['kablam.mp3', 'kablam.ogg']);
Play a sound by reference, this method can be chained.
Arguments
Example
Zap.play('mysound', 1, 10, function(){
alert('My sound has finished');
});
Stop a sound by reference, this method can be chained.
Arguments
Example
Zap.stop('mysound');
Stop every loaded sound
Example
Zap.stopAllSounds();
Utility method to find out which formats and codecs are supported in the current browser
Example
Zap.supported();
Releases are available for download from GitHub.
Development: zap.js
Production: zap.min.js