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

SoundManager 2 makes it easier to play audio using JavaScript.

Get SoundManager 2 SoundManager 2 provides simple, reliable cross-platform audio under a single JavaScript API. 

Featured demo: Bar UI »

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.

Getting started is pretty easy, too.

A few live examples:

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 OS supporting HTML5 and/or Flash (Version 2.3 or newer)
The details: how it works »

The ginsu knife: 12 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 12 KB over the wire when optimized; that's less than 8% of the original, uncompressed file size.

SM2 is self-contained, having no external dependencies, and is compatible with popular JavaScript frameworks.

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.

Basic

Playable links and playlists

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

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

Shiny

Fancier UI, more features

The Bar UI uses SVG for a resolution-independent UI, with HTML and CSS that makes customization easy.

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.

Seven Or Eight Days courtesy of Adrian Glynn, from the album Bruise. For more, see the music video.

Experimental

Advanced prototypes

The Cassette Tape UI is a skinnable player based on the TDK MA-R90 cassette tape, a classic design from 1982.

Cassette Tape UI Prototype Screenshot

Remember Type IV, Metal & Chromium/CrO2? Those were the days.

Getting started

Basic SoundManager 2 set-up

Including the script, configuring the url and registering an onready() callback:

<script src="soundmanager2.js"></script>
<script>
soundManager.setup({
  // where to find flash audio SWFs, as needed
  url: '/path/to/swf-files/',
  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"...
var mySound = soundManager.createSound({
  url: '/path/to/an.mp3'
});

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

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

Bonus

Additional demos

Examples using multi-track playback, progress and combinations of sound and animation:

Armor Alley: Web Prototype (PC-DOS game remake)

Armor Alley is a side-scrolling, real-time vehicle simulation / strategy game, originally released for the Mac and PC-DOS computers in 1990. This web-based remake is a tribute to the attention to detail shown in the original. Your goal is to defend a convoy as it moves into enemy territory; the game ends when a van reaches the opposing base. See the making-of for more.

SURVIVOR (Commodore 64 game remake)

SURVIVOR is a web-based remake of a Commodore 64 game. The goal is to shoot out turrets and destroy bases, while avoiding contact with basically everything around you. Sound was used creatively in the original, and it has been re-implemented in this modern interpretation. See the making-of for more.

Elsewhere

As heard on TV the internets

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

Articles and presentations

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

Credits and thank-yous

  • Icons: Desktop / mobile / iOS device iconography via glyphish.com (CC). Tile background: "Tiny Grid". Homepage header typeface: Chunk (Five) by Meredith Mandel (OFL).
  • Music: Seven Or Eight Days courtesy of Adrian Glynn. Graffiti Sex courtesy of The Fugitives, from the album In Streetlight Communion. Let Me, LA, I Tried and People Asking courtesy of SonReal.

Additional experimental 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.

wheelsofsteel.net: Online turntable demo (screenshot)

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

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


Not only do you get the ginsu knife...

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