2.1.0 • Published 7 years ago

sound-fx v2.1.0

Weekly downloads
435
License
-
Repository
github
Last release
7 years ago

SoundFX

NPM version

SoundFX is a sound effect manager with support for Chrome, Firefox, Safari, Edge & IE9+, using the HTML5 Web Audio API where available, and falls back to <audio> elements.

Using it

// Create an instance of SoundFX
var SoundFX = require('sound-fx');
var sfx = new SoundFX();

// load some files by passing it a url and a name
sfx.load('taps.mp3', 'taps');
sfx.load('rocket.wav', 'rocket');

// then play the sounds like so:
sfx.play('rocket');

// or play a sound in looping mode:
sfx.play('taps', true);

// and to stop a loop:
sfx.stop('taps');

// that's it!

API

load (url, name, delay, callback)

  • <String> url - URI or data-encoded string of audio file to load
  • <String> name - Name to save sound against
  • <Number> delay - Delay before loading the file (ms)
  • <Function (err, data)> callback - Callback once the file has been loaded

play (name, loop, callback)

  • <String> name - Name of sound to play
  • <Boolean> loop - Play the sound on a loop
  • <Function (err, data)> callback - Callback once the sound has been played

stop (name)

  • <String> name - Name of sound to stop playing

has (name)

  • <String> name - Check if a sound has been loaded

remove (name)

  • <String> name - Name of sound to remove

License

MIT

Credits

Originally built by @HenrikJoreteg as SoundEffectManager. Extended by @munkyjunky

2.1.0

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago