# A JavaScript Sound API supporting MP3, MPEG4 and HTML5 Audio.

## Discussion / Support

Get Satisfaction support network

SM2 options: +html5 | -html5 | +debug

## SoundManager 2 makes it easier to play audio using JavaScript. Get SoundManager 2

Using HTML5 and Flash, SoundManager 2 provides reliable cross-platform audio under a single JavaScript API.

### Speak and be heard

#### More sound, in more places

Despite being one of the senses, sound has largely been missing from the web due to inconsistent technology support. SoundManager 2 bridges this gap, making it easier to use audio across a growing variety of devices and platforms, both desktop and mobile.

A few live examples:

Office lobby sound
Random
Water Drop
360° UI »
coins.mp3 glass0.mp3 glass1.mp3
mp3 buttons »

### HTML5 + flash hybrid

#### Complexity, reduced

Supporting HTML5 audio can be tedious in modern browsers, let alone legacy ones. With real-world visitors using browsers ranging from mobile Safari to IE 6 across a wide range of devices, there can be many support cases to consider.

SoundManager 2 gives you a single, powerful API that supports both new and old, using HTML5 audio where supported and optional Flash-based fallback where needed. Ideally when using SoundManager 2, audio "just works."

- Desktop support: Windows, Mac OS, Linux
- Laptop/tablet support: Windows, Mac OS, Linux / Blackberry Playbook, Kindle Fire + other HTML5/Flash devices
- iPhone support: iOS 4.0 and newer
- iPad support: Version 1.0 (iOS 3.2) and newer
- Android platforms supporting HTML5 and/or Flash

The details: how it works »

### The ginsu knife: 11 KB*

#### Big features, small footprint

But wait, there's more!

Performance is an important metric, too. SoundManager 2 packs a comprehensive, feature-rich API into as little as 11 KB over the wire when optimized; that's less than 8% of the original, uncompressed file size.

The source code is BSD-licensed and is provided in fully-commented, non-debug and compiler-optimized "minified" versions appropriate for development and production use.

* Gzip-compressed file size on a typical set-up is 11 KB. And was it supposed to be the Swiss Army kind? I forget.

### Basic

#### Playable links and playlists

These demos use unordered lists with MP3 links that play in-place; the UI is easily customized via CSS.

- Rain
- Walking
- Rain On Car Roof (AAC)

play MP3 links »

A richer playlist theme with optional time, seekable progress bar and a VU meter where supported:

- Armstrong Beat
- Untitled Groove
- BC Quail (HE-AAC)
- Ghosts+Goblins Reconstructed (OGG)
- A corked beer bottle (WAV)

muxtape-style UI »

### Shiny

#### Data visualization features

The 360° player UI demo uses <canvas> and includes options for waveform and spectrum analysis data via Flash 9, adding beautiful visual feedback to the interface.

Graffiti Sex courtesy of The Fugitives, from the album In Streetlight Communion.

The Fugitives - Graffiti Sex
360° + spectrum UI »

### Experimental

#### Advanced prototypes

No audio API is complete without at least one crazy demo. The "Wheels Of Steel" started as a simple CSS prototype, and evolved to replicate most of the UI and functionality of a traditional DJ set-up. Pitch bending, scratch and EQ effects are present where supported.

The Wheels Of Steel, a browser-based DJ turntable prototype. For the tech details, read An Ode To Turntables (in HTML.)

### Bonus

#### Additional demos

#### MPC (sampler/drum machine) + Smashable Christmas Lights

Examples showing multi-track playback, progress and combining sound with animation:

#### "Audio sprites" (sound segments / samples) demo

With sound playback options like `from` and `to`, you can play portions of a larger, single-file "sprite" of many sounds.

For more live examples, see the API Demos.

### Elsewhere

#### As heard on TV the internets

A few nifty places SoundManager 2 has been seen in use on the Wild World Web:

- SoundCloud / The Cloud Player
- last.fm
- Opera Software ASA
- 8tracks
- Discogs
- The Hype Machine
- NON-STOP NYAN CAT!
- Turntable.fm
- Audiogalaxy
- baroque.me
- freesound.org

#### Articles and presentations

Some other words, pictures and video on the subject of HTML5 and web audio:

- Video presentation: Adding Sound To HTML (slides) (12/2011)
- 24ways.org article, The State Of HTML5 Audio (12/2010)
- Video: Probably, Maybe, No: The State of HTML5 Audio + turntable demo (05/2011)

#### Credits and thank-yous

- Icons: Desktop / mobile / iOS device iconography via glyphish.com (CC)
- Music: Graffiti Sex courtesy of The Fugitives, from the album In Streetlight Communion.
  Blue Belle Lament courtesy of Adrian Glynn.
  I Tried and People Asking courtesy of SonReal.
- Homepage header typeface: Chunk (Five) by Meredith Mandel (OFL)

### Technical overview

#### HTML5 audio + optional Flash fallback

- 100% Flash-free audio on iPad, iPhone (iOS4) and other HTML5-enabled devices + browsers
- Invisible Flash SWF provides HTML5 fallback as needed
- API is consistent whether using HTML5 or Flash
- See useHTML5Audio for implementation details

### API specifics

#### Basic API features (HTML5, Flash 8*)

- Load, stop, play, pause, mute, seek, pan*, volume control from JavaScript
- Events: `onload()`, `whileloading()`, `whileplaying()`, `onfinish()` and more
- ID3V1 + ID3V2 tag support for MP3s (title, artist, genre etc.)*

#### Additional Flash 9-based API features

- RTMP / Flash Media Server streaming support (experimental) - see serverURL
- MPEG-4 (AAC, HE-AAC, H.264) audio support
- "MultiShot" play (layered/chorusing effects)
- Waveform/frequency spectrum data
- Peak (L/R channel volume) data
- Audio buffering state/event handling

### Everything else

#### Documentation, tools and demos

- Extensive API Documentation with examples and notes
- Built-in debugging and troubleshooting tools
- Community-based discussion/support
- BSD licensed

#### Not only do you get the ginsu knife...

Even more demos and examples using the SoundManager 2 API...

- Playable MP3 links
- MPC sampler/drum machine
- Basic animation + sound
- Smashable christmas lights
- Live API + code examples

### Getting started

#### Basic SoundManager 2 set-up

Including the script, configuring `soundManager.url` (SWF file path) and registering an `onready()` callback:

    <script src="soundmanager2.js"></script>
    <script>
    // where to find flash SWFs, if needed...
    soundManager.url = '/path/to/swf-files/';

    soundManager.onready(function() {
      // SM2 is ready to play audio!
    });
    </script>

Upon execution of soundmanager2.js, SM2 will determine what Flash SWF to load (if any) based on the path defined in `soundManager.url`.

After successful initialization, `soundManager.onready()` will fire and sounds can be played.

By default, SM2 uses a Flash 8-based SWF build. Some additional features are available when using the Flash 9-based build.

For a live example, see the basic template demo.

### Playing audio

#### Basic playback control

Once `soundManager.onready()` has fired, sounds can be loaded and played.

#### Creating and playing a sound object

    // create "mySound"...
    soundManager.createSound({
      id: 'mySound',
      url: '/path/to/an.mp3'
    });

    // ...and play it
    soundManager.play('mySound');

Additional options and events can be specified when loading and playing sounds. For more examples of playback features, see API Demos.