Convert Figma logo to code with AI

CreateJS logoSoundJS

A Javascript library for working with Audio. It provides a consistent API for loading and playing audio on different browsers and devices. Currently supports WebAudio, HTML5 Audio, Cordova / PhoneGap, and a Flash fallback.

4,430
835
4,430
97

Top Related Projects

23,743

Javascript audio library for the modern web.

13,373

A Web Audio framework for making interactive music in the browser.

1,184

Band.js - Music composer interface for the Web Audio API.

Quick Overview

SoundJS is a JavaScript library that provides a simple API for working with audio on the web. It is part of the CreateJS suite of tools and offers a unified interface for loading and controlling audio across different browsers and devices.

Pros

  • Cross-browser compatibility, handling various audio formats and fallbacks
  • Easy-to-use API for loading, playing, and controlling audio
  • Supports advanced features like audio sprites and Web Audio API
  • Integrates well with other CreateJS libraries

Cons

  • Limited documentation and examples compared to some other audio libraries
  • May be overkill for simple audio needs
  • Hasn't seen frequent updates in recent years
  • Dependency on CreateJS ecosystem might be unnecessary for some projects

Code Examples

Loading and playing a sound:

createjs.Sound.registerSound("path/to/sound.mp3", "soundID");
createjs.Sound.addEventListener("fileload", handleFileLoad);

function handleFileLoad(event) {
    createjs.Sound.play("soundID");
}

Using audio sprites:

var spriteData = {
    src: "audioSprite.mp3",
    data: {
        audioSprite: [0, 1000],
        audioSprite2: [2000, 1500]
    }
};
createjs.Sound.registerSound(spriteData, "spriteID");
createjs.Sound.play("spriteID|audioSprite");

Controlling volume and loop:

var instance = createjs.Sound.play("soundID", {loop: -1});
instance.volume = 0.5;

Getting Started

  1. Include the SoundJS library in your HTML:
<script src="https://code.createjs.com/1.0.0/soundjs.min.js"></script>
  1. Register and load your sounds:
createjs.Sound.registerSound("path/to/sound.mp3", "mySound");
createjs.Sound.addEventListener("fileload", handleFileLoad);

function handleFileLoad(event) {
    console.log("Sound loaded successfully");
}
  1. Play the sound when needed:
createjs.Sound.play("mySound");

Competitor Comparisons

23,743

Javascript audio library for the modern web.

Pros of Howler.js

  • Lighter weight and more focused on audio functionality
  • Better support for mobile devices and handling mobile-specific audio issues
  • More active development and frequent updates

Cons of Howler.js

  • Less integrated with other multimedia libraries compared to SoundJS
  • Fewer advanced features for complex audio manipulation and sequencing
  • Steeper learning curve for developers new to audio programming

Code Comparison

SoundJS:

createjs.Sound.registerSound("path/to/sound.mp3", "soundID");
createjs.Sound.play("soundID");

Howler.js:

var sound = new Howl({
  src: ['path/to/sound.mp3']
});
sound.play();

Both libraries offer straightforward ways to play audio, but Howler.js provides a more object-oriented approach. SoundJS integrates well with other CreateJS libraries, making it suitable for complex multimedia projects. Howler.js, on the other hand, focuses solely on audio and offers a simpler API for basic audio tasks.

While SoundJS is part of the larger CreateJS ecosystem, Howler.js is a standalone library that excels in handling audio across various platforms and devices. The choice between the two depends on project requirements, integration needs, and the developer's familiarity with audio programming concepts.

13,373

A Web Audio framework for making interactive music in the browser.

Pros of Tone.js

  • More comprehensive audio synthesis and processing capabilities
  • Better suited for complex musical applications and compositions
  • Extensive documentation and examples for advanced audio programming

Cons of Tone.js

  • Steeper learning curve for beginners
  • Larger file size and potentially higher resource usage
  • May be overkill for simple audio playback tasks

Code Comparison

SoundJS example:

createjs.Sound.registerSound("path/to/sound.mp3", "soundID");
createjs.Sound.play("soundID");

Tone.js example:

const player = new Tone.Player("path/to/sound.mp3").toDestination();
Tone.loaded().then(() => {
  player.start();
});

Summary

SoundJS is more straightforward for basic audio playback and is part of the larger CreateJS suite, making it a good choice for simple audio integration in web projects. Tone.js, on the other hand, offers more advanced audio manipulation features and is better suited for complex musical applications. The choice between the two depends on the specific requirements of your project and your level of audio programming expertise.

1,184

Band.js - Music composer interface for the Web Audio API.

Pros of band.js

  • Focuses specifically on music generation and sequencing
  • Provides a more intuitive API for creating musical compositions
  • Includes built-in instruments and effects

Cons of band.js

  • Less actively maintained (last update in 2017)
  • More limited in scope compared to SoundJS's broader audio capabilities
  • Smaller community and fewer resources available

Code Comparison

band.js example:

var conductor = new BandJS();
conductor.setTimeSignature(4, 4);
conductor.setTempo(120);

var piano = conductor.createInstrument();
piano.note('quarter', 'C4');
piano.note('quarter', 'E4');
piano.note('half', 'G4');

SoundJS example:

createjs.Sound.registerSound("path/to/sound.mp3", "sound");
createjs.Sound.addEventListener("fileload", handleFileLoad);

function handleFileLoad(event) {
    createjs.Sound.play("sound");
}

Summary

SoundJS is a more comprehensive audio library with broader capabilities, active maintenance, and a larger community. It's suitable for various audio tasks in web applications. band.js, on the other hand, specializes in music generation and sequencing, offering a more intuitive API for creating musical compositions but with a narrower focus and less active development.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

SoundJS

SoundJS is a library to make working with audio on the web easier. It provides a consistent API for playing audio in different browsers, including using a target plugin model to provide an easy way to provide additional audio plugins like a Flash fallback (included, but must be used separately from the combined/minified version).

A mechanism has been provided for easily tying in audio preloading to PreloadJS.

Example

createjs.Sound.on("fileload", handleLoadComplete);
createjs.Sound.alternateExtensions = ["mp3"];
createjs.Sound.registerSound({src:"path/to/sound.ogg", id:"sound"});
function handleLoadComplete(event) {
	createjs.Sound.play("sound");
}

License

Built by gskinner.com, and released for free under the MIT license, which means you can use it for almost any purpose (including commercial projects). We appreciate credit where possible, but it is not a requirement.

Support and Resources

Classes

Sound

The core API for playing sounds. Call createjs.Sound.play(sound, ...options), and a sound instance is created that can be used to control the audio, and dispatches events when it is complete, loops, or is interrupted.

SoundInstance

A controllable sound object that wraps the actual plugin implementation, providing a consistent API for audio playback, no matter what happens in the background. Sound instances can be paused, muted, and stopped; and the volume, pan (where available), and position changed using the simple API.

WebAudioPlugin

The default, built-in plugin, which uses Web Audio APIs to playback sounds. Note that WebAudio will fail to load when run locally, and the HTML audio plugin will be used instead.

HTMLAudioPlugin

The fallback built-in plugin, which manages audio playback via the HTML5

CordovaAudioPlugin

An additional plugin which will playback audio in a Cordova app and tools that utilize Cordova such as PhoneGap or Ionic. You must manually register this plugin. Currently available on github since SoundJS-0.6.1.

FlashAudioPlugin

An additional plugin which uses a flash shim (and SWFObject) to playback audio using Flash. You must manually set up and register this plugin.

Documentation and examples

Have a look at the included examples and API documentation for more in-depth information.