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

What SoundManager 2 does

Audio features, accessible from JavaScript.

About SoundManager 2, Features and Live Demos

SoundManager 2 makes it easier to play audio using JavaScript.

Using HTML5 and Flash, SoundManager 2 provides reliable cross-platform audio under a single API. How It Works »

Audio, just about anywhere.

SoundManager 2 speaker logo

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.

Complexity, reduced.

Supporting HTML5 audio in modern browsers can be tedious, let alone "legacy" HTML4-based ones. With technology ranging from mobile Safari down to IE 6, there's a lot of ground to cover.

SoundManager 2 gives you a simple but powerful API that supports both new and old, using HTML5 audio where supported and an invisible Flash fallback where needed. Ideally when using SoundManager 2, audio "just works."

Big features, small footprint.

SoundManager 2 packs a full-featured API (100 KB of code) into as little as 10 KB over the wire. The source is provided in fully-commented, -no-debug and compiler-optimized "minified" versions appropriate for development and production use.

Technical details

HTML5 Audio Support (Beta-ish)

  • 100% Flash-free MP3 + MP4/AAC where supported. Works on iPad, iPhone iOS 4
  • Seamless flash fallback for MP3/MP4 content, if needed
  • HTML5/Flash API switching is transparent, handled internally
  • WAV + OGG playback possible via HTML5, if supported
  • See useHTML5Audio for implementation details

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 and ID3V2 tag support for MP3s (title, artist, genre etc.)*

Shiny Flash 9-only 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

General Tech Stuff

As Heard On TV The Internets

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

Download!

Get SoundManager 2

 

Playing MP3s with JavaScript

Play audio in one line, or get fancy with multiple options.

How To Play Audio Using SoundManager 2

Simple ID / URL method:

soundManager.play('mySound','/path/to/an.mp3');

And, setting the volume:

soundManager.setVolume('mySound',50);

More flexible method supporting option parameters as an object literal:

var mySound = soundManager.createSound({
  id: 'someSound',
  url: '/path/to/some.mp3',
  volume: 50,
  onload: soundLoadedFunction
});
mySound.play();

See API Demos

Using SM2 on your site

How to include SoundManager 2 from HTML, and some basic event handlers.

Include the SoundManager 2 core script, tell it where to look for the flash .SWF and provide an onload() handler.

<script src="/path/to/soundmanager2.js"></script>
<script>
soundManager.url = '/path/to/swfs/';
soundManager.onload = function() {
  // SM2 is ready to go! 
  // soundManager.createSound(...) calls can now be made, etc.}
</script>

See a basic template demo

Licensing

BSD licensed.

SoundManager 2 is provided under a BSD license.