Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Zap! is an audio manager for html 5 applications with a focus on real time and interactive applications such as games.
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
examples
LICENSE
Readme.md
Zap.js
Zap.min.js

Readme.md

Zap! HTML 5 Game Audio

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+

Documentation

init(options)

Init should be run before anything else to setup configuration and create dom elements

Arguments

  • options - Optional configuration object

Example

    Zap.init({
        console: true,
        container: 'sound-holder'
    });

on(event, callback)

There are currently three events that can be bound using the 'on' function; 'success', 'update' and 'error'. Multiple callbacks may also be bound.

Arguments

  • ref - An event (success, update or error)
  • callback - A function to be called whenever the above event occurs

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
    });

addSound(ref, sources, channels, time)

Add a sound to be loaded, this method can be chained.

Arguments

  • ref - A unique string reference for this sound
  • sources - An array of possible sources in the order they should be checked
  • channels - The maximum number of channels available for this sample
  • time - Time to wait until giving up on the sound loading

Example

    Zap.addSound('beat', ['beat.mp3', 'beat.ogg', 'beat.wav'])
       .addSound('laser', ['shoot.mp3', 'shoot.ogg'], 5);

addGroup(ref, sounds)

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

  • ref - A unique string reference for this group
  • sounds - An array of possible sound references

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(ref, volume, loops, callback)

Play a sound by reference, this method can be chained.

Arguments

  • ref - The sound reference
  • volume - A number between 0-1
  • loops - The number of times the sample should loop
  • callback - An optional callback to be run once the sample finishes

Example

    Zap.play('mysound', 1, 10, function(){

        alert('My sound has finished');
    });

stop(ref)

Stop a sound by reference, this method can be chained.

Arguments

  • ref - The sound reference

Example

    Zap.stop('mysound');

stopAllSounds

Stop every loaded sound

Example

    Zap.stopAllSounds();

supported

Utility method to find out which formats and codecs are supported in the current browser

Example

    Zap.supported();

Download

Releases are available for download from GitHub.

Development: zap.js

Production: zap.min.js

Something went wrong with that request. Please try again.