SoundManager 2 / "Page as a playlist"

Muxtape.com-style UI, MP3/AAC Player Example

This page uses Flash 9-based effects where supported. The default config uses Flash 8.

You can also try enabling experimental visualization features.

MPEG4 / H.264 + HE-AAC (Flash "MovieStar" 9.0r115+) format support - audio-only example

A subset of MPEG4 is supported including AAC, FLV, MP4, M4A, MOV, MP4V, 3GP and 3G2 files.

Basics

Don't want a Flash 9 requirement, EQ/waveform, perhaps less CPU? See Flash 8-based basic demo.

Clicking a title will start loading + playing, or pause, a sound.

Once loading, click (or click and drag) on the loading/position bar to seek within the sound.

The document title reflects the currently-playing sound, and by default the list will play sequentially if left alone. (This is configurable.)

Themes

Just for fun, a few color schemes (visible when playing/paused):

Experimental (Alpha) Variant: MP3 "Metadata": Annotations / notes / sub-tracks

A potential approach to noting interesting moments in sounds, scene changes, new tracks in seamless DJ mixes etc. Keep in mind this is a single MP3 being loaded, but annotations are placed along the timeline as shown.

A "metadata" element contains a nested list of data (UL/LI combination) - in this case, a summary of each scene - and the time at which this item occurs/begins. In order to help with positioning, the total length of the sound is also specified up-front. View the source code of this page for the details.

How It Works

This example uses SoundManager 2 to find links to MP3 files within an unordered list, and makes them playable "in-place" on a page. The script assigns CSS classes to links' parent LI nodes to indicate their state (playing/paused, etc.)

Progressive Enhancement

This provides a nice HTML base for all browsers and user agents, and enhances progressively for those with Javascript and Flash. Links pointing to MP3s are assigned an onclick handler which intercepts the click (preventing the browser from following the link and unloading the page. SM2 will then create sound objects as needed to play the MP3s. In the event there is an error at runtime or a lack of support (no JS/Flash etc.), the browser will simply load the MP3s directly as it normally would. This includes iPhones, etc.

HTML Fragments (UI Element Templates)

Each item in the playlist has its own set of controls and progress indicators, etc. This content is defined once as a hidden template of HTML in the player JavaScript file, separate from the playlist markup, and is cloned for each item as needed. This can be easily styled with CSS as well, of course.

I'd like to use this.

See this basic demo for reference.

The basic demo uses the default Flash 8 configuration, but you can easily change this to use Flash 9 features. The only difference in code is the configuration.

A reminder that if loading from the local filesystem, Flash will deny access to remote (network/internet) URLs by default unless whitelisted via the Flash Player Global Security Settings Page. Some URLs in this example are remote to demonstrate this.

Configuration + Options

Default configuration

Behaviours such as auto-start and UI elements like VU meters and spectrum graphs are easy configurable, using an object literal format as shown below.

The page player config (see related page-player.js file) as below.

The custom parameters used to make this demo page are highlighted in red.

  // ( within page-player.js )

  soundManager.setup({
    // If you need flash 9, include this line.
    flashVersion: 9
  });

  this.config = {
    usePeakData: true,     // [Flash 9 only] show peak (VU-meter) data
    useFavIcon: true,      // try to show peakData in address bar (Firefox + Opera) - requires usePeakData = true too, of course.
    useWaveformData: true, // [Flash 9 only] true: show raw waveform data - WARNING: CPU-intensive
    useEQData: false,      // [Flash 9 only] show EQ (frequency spectrum) data - WARNING: CPU-intensive
    fillGraph: false,      // [Flash 9 only] draw full lines instead of only top (peak) spectrum points
    allowRightClick:true,  // let users right-click MP3 links ("save as...", etc.) or discourage (can't prevent.)
    useThrottling: false,  // try to rate-limit potentially-expensive calls (eg. dragging position around)
    autoStart: false,      // begin playing first sound when page loads
    playNext: true,        // stop after one sound, or play through list until end
    updatePageTitle: true, // change the page title while playing sounds
    emptyTime: '-:--'      // null/undefined timer values (before data is available)
  }

Per-page configuration override

Alternately, you may override the defaults on a per-page basis by defining an "alternate configuration" object before the page-player.js file has been included in your source code:

  // ( before soundManager.onready() has fired )

  soundManager.setup({
    // If you need flash 9, include this line.
    flashVersion: 9
  });

  var PP_CONFIG = {
    usePeakData: true,     // [Flash 9 only] whether or not to show peak data (no notable CPU cost)
    useWaveformData: true  // [Flash 9 only] show raw waveform data. WARNING: Experimental, likely CPU-heavy
  }

Any options specified in PP_CONFIG will override the defaults defined in page-player.js.

Basic CSS

 If you want to make your own UI from scratch, here is the base:

 ul.playlist {}

 Default + hover state, "click to play":

 li.sm2_link {}
 li.sm2_link:hover {}

 Playing + hover state, "click to pause":

 li.sm2_playing {}
 li.sm2_playing:hover {}

 Paused + hover state, "click to resume":

 li.sm2_paused {}
 li.sm2_paused:hover {}

The positioning (load status / control bar) template is also applied after each MP3 link, from an element named "control-template"

"loading" and "position" have background colors applied, and have their width adjusted dynamically by SM2 as the sound(s) load/play. "timing" is replaced with the current time / duration, eg. 1:23 / 4:20

The class names applied can be edited within the source JS also, for convenience.

The controls are shown and hidden via the same dynamic CSS updates. See the source CSS for the timing / status bar layout.

Performance Considerations

Experimental Flash 9 features

More CSS comments


 SoundManager 2: "page as playlist" example
 ------------------------------------------

 Clicks on links to MP3s are intercepted via JS, calls are
 made to SoundManager to load/play sounds. CSS classes are
 appended to the LI parent, which are used to highlight the
 current play state and so on.

 Class names are applied in addition to "sm2_link" base.

 Default:

 sm2_link

 Additional states:

 sm2_playing
 sm2_paused

 eg.

 <!-- default -->
 <li class="sm2_link"><a href="some.mp3">some.mp3</a></li>

 <!-- playing -->
 <li class="sm2_link sm2_playing"><a href="some.mp3">some.mp3</a></li>

 The script also injects an HTML template containing control bar
 and timing elements, which can also be targeted with CSS.


 Note you don't necessarily require ul.playlist for your use
 if only using one style on a page. You can just use .sm2_link
 and so on, but isolate the CSS you want.

 Side note: Would do multiple class definitions eg.

 li.sm2_default.sm2_playing{}

 .. except IE 6 has a parsing bug which may break behaviour,
 applying sm2_playing {} even when the class is set to sm2_default.


 If you want to make your own UI from scratch, here is the base:

 Default + hover state, "click to play":

 li.sm2_link {}
 li.sm2_link:hover {}

 Playing + hover state, "click to pause":

 li.sm2_playing {}
 li.sm2_playing:hover {}

 Paused + hover state, "click to resume":

 li.sm2_paused {}
 li.sm2_paused:hover {}

SoundManager 2 project home