metamaps--metamaps/app/assets/javascripts/librariesForAllPages/soundmanagerv297a-20131201/doc/index.html

1934 lines
124 KiB
HTML
Executable file

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>SoundManager 2: Documentation</title>
<meta name="robots" content="noindex" />
<meta name="description" content="API documentation for SoundManager 2, a JavaScript-based MP3 and MP4 audio API. BSD licensed." />
<meta name="keywords" content="javascript sound, javascript audio, documentation, api documentation, soundmanager 2" />
<meta name="robots" content="all" />
<meta name="author" content="Scott Schiller" />
<meta name="copyright" content="Copyright (C) 1997 onwards Scott Schiller" />
<meta name="language" content="en-us" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" media="screen" href="../demo/index.css" />
<link rel="stylesheet" type="text/css" media="screen" href="../demo/flashblock/flashblock.css" />
<script type="text/javascript" src="../script/soundmanager2.js"></script>
<script type="text/javascript" src="../demo/index.js"></script>
<script type="text/javascript">
soundManager.setup({
useFlashBlock: false,
debugMode: false,
url: '../swf/'
});
</script>
</head>
<body id="doc" class="special">
<div id="content">
<div id="top">
<h1>SoundManager 2: Documentation</h1>
<div id="nav">
<ul>
<li>
<a href="..">Home</a>
</li>
<li>
<a href="#">Demos</a>
<ul>
<li><a href="../demo/template/">Basic Template</a></li>
<li><a href="../demo/api/">API Examples</a></li>
<li><a href="../demo/play-mp3-links/" class="exclude">Playable MP3 links</a></li>
<li><a href="../demo/mp3-player-button/" class="exclude">Basic MP3 Play Button</a></li>
<li><a href="../demo/page-player/">Muxtape-style UI</a></li>
<li><a href="../demo/360-player/">360&deg; Player UI</a></li>
<li><a href="../demo/mpc/">Drum Machine (MPC)</a></li>
<li><a href="../demo/animation/">DOM/Animation Demos</a></li>
<li><a href="../demo/flashblock/">FlashBlock Handling</a></li>
</ul>
</li>
<li>
<a href="getstarted/">Getting Started</a>
<ul>
<li><a href="getstarted/#how-sm2-works">How SoundManager 2 works</a></li>
<li><a href="getstarted/#basic-inclusion">Including SM2 on your site</a></li>
<li><a href="getstarted/#troubleshooting">Troubleshooting</a></li>
</ul>
</li>
<li>
<strong><a href="#">Documentation</a></strong>
<ul>
<li><a href="#sm-config">SoundManager Properties</a></li>
<li><a href="#sound-object-properties">Sound Object Properties</a></li>
<li><a href="#smdefaults">Global Sound Defaults</a></li>
<li><a href="#api">SoundManager Core API</a></li>
<li><a href="#smsoundmethods">Sound Object (SMSound) API</a></li>
<li><a href="generated/soundmanager2.html">Generated Documentation</a></li>
</ul>
</li>
<li>
<a href="download/">Download</a>
<ul>
<li><a href="download/#latest">Get SoundManager 2</a></li>
<li><a href="download/#revision-history">Revision History</a></li>
</ul>
</li>
<li>
<a href="technotes/">Technical Notes</a>
<ul>
<li><a href="technotes/#requirements">System Requirements</a></li>
<li><a href="technotes/#serving-audio">Serving To HTML5 + Flash Clients</a></li>
<li><a href="technotes/#client-requests">How Clients Download Audio</a></li>
<li><a href="technotes/#mobile-device-limitations">Mobile Device Limitations</a></li>
<li><a href="technotes/#debug-output">Debug + Console Output</a></li>
</ul>
</li>
<li>
<a href="resources/">Resources</a>
<ul>
<li><a href="resources/#licensing">Licensing</a></li>
<li><a href="resources/#related">Related Projects</a></li>
<li><a href="http://getsatisfaction.com/schillmania/products/schillmania_soundmanager_2/">SM2 support / discussion</a></li>
<li><a href="http://www.schillmania.com/content/react/contact/">Contact Info @ Schillmania.com</a></li>
</ul>
</li>
</ul>
<div class="clear"></div>
</div>
</div>
<div id="main-wrapper">
<div id="main" class="triple">
<div id="col3" class="c3">
<!--
<div id="get-satisfaction" class="box">
<div id="gsfn_list_widget">
<h2><a href="http://getsatisfaction.com/schillmania/products/schillmania_soundmanager_2/" title="User discussion, FAQs and support for SoundManager 2" rel="nofollow">Discussion / Support</a><span class="l"></span><span class="r"></span></h2>
<div id="gsfn_content"></div>
<div class="powered_by"><a href="http://getsatisfaction.com/" rel="nofollow">Get Satisfaction support network</a></div>
</div>
</div>
-->
<div id="shortcuts">
<!--
<div class="box">
<h2>Shortcuts<span class="l"></span><span class="r"></span></h2>
<ul class="first">
<li onclick="setFilter(event,'c-')" class="ignore">
<ul>
<li>Demos</li>
<li>Getting Started</li>
<li>Basic Use</li>
<li>Download</li>
<li>Requirements</li>
<li>Limitations</li>
<li>Debug Output</li>
<li>Revision History</li>
<li>About</li>
</ul>
</li>
</ul>
</div>
-->
<div class="box">
<h2>API Elements<span class="l"></span><span class="r"></span></h2>
<p>SoundManager and SMSound API</p>
<ul id="shortcuts-list" class="first">
<li onclick="return setFilter(event,'f-')" class="ignore">
<h3 class="wedge">SoundManager<span class="l"></span><span class="r"></span></h3>
<h4>Properties</h4>
<ul>
<li>allowScriptAccess</li>
<li><a href="#soundmanager-alturl">altURL</a></li>
<li><a href="#soundmanager-audioformats">audioFormats</a></li>
<li><a href="#soundmanager-bgcolor">bgColor</a></li>
<li>consoleOnly</li>
<li><a href="#soundmanager-debugflash">debugFlash</a></li>
<li><a href="#soundmanager-debugmode">debugMode</a></li>
<li><a href="#smdefaults">defaultOptions</a></li>
<li class="flash9" title="Flash 9-only"><a href="#sound-properties-flash9">flash9Options</a></li>
<li><a href="#soundmanager-features">features</a></li>
<li><a href="#soundmanager-flashloadtimeout">flashLoadTimeout</a></li>
<li class="flash9" title="Flash 9+ only"><a href="#soundmanager-flashpollinginterval">flashPollingInterval</a></li>
<li><a href="#soundmanager-flashversion">flashVersion</a></li>
<li><a href="#soundmanager-html5only">html5Only</a></li>
<li ><a href="#soundmanager-html5pollinginterval">html5PollingInterval</a></li>
<li class="flash9" title="Flash 9.0r115+ only"><a href="#sound-properties-flash9">movieStarOptions</a></li>
<li><a href="#soundmanager-preferflash">preferFlash</a></li>
<li><a href="#soundmanager-url">url</a></li>
<li>useConsole</li>
<li class="flash9" title="Flash 9+ only"><a href="#soundmanager-usefastpolling">useFastPolling</a></li>
<li><a href="#soundmanager-useflashblock">useFlashBlock</a></li>
<li><a href="#soundmanager-highperformance">useHighPerformance</a></li>
<li title="Beta-ish feature"><a href="#soundmanager-usehtml5audio">useHTML5Audio</a></li>
<li class="flash9" title="Flash 9.0r115+ only"><a href="#soundmanager-wmode">wmode</a></li>
<li>waitForWindowLoad</li>
</ul>
<h4>Methods</h4>
<ul>
<li><a href="#soundmanager-canplaylink">canPlayLink()</a></li>
<li><a href="#soundmanager-canplaymime">canPlayMIME()</a></li>
<li><a href="#soundmanager-canplayurl">canPlayURL()</a></li>
<li><a href="#soundmanager-clearonposition">clearOnPosition()</a></li>
<li><a href="#soundmanager-createsound">createSound()</a></li>
<li><a href="#soundmanager-destroysound">destroySound()</a></li>
<li class="flash9" title="Flash 9.0+ only"><a href="#soundmanager-getmemoryuse">getMemoryUse()</a></li>
<li><a href="#soundmanager-getsoundbyid">getSoundById()</a></li>
<li><a href="#soundmanager-load">load()</a></li>
<li><a href="#soundmanager-mute">mute()</a></li>
<li><a href="#soundmanager-ok">ok()</a></li>
<li><a href="#soundmanager-onposition">onPosition()</a></li>
<li><a href="#soundmanager-pause">pause()</a></li>
<li><a href="#soundmanager-pauseall">pauseAll()</a></li>
<li><a href="#soundmanager-play">play()</a></li>
<li><a href="#soundmanager-reboot">reboot()</a></li>
<li class="new"><a href="#soundmanager-reset" title="New feature">reset()</a></li>
<li><a href="#soundmanager-resume">resume()</a></li>
<li><a href="#soundmanager-resumeall">resumeAll()</a></li>
<li class="recent"><a href="#soundmanager-setup" title="Recently-added feature">setup()</a></li>
<li><a href="#soundmanager-setpan" title="Flash-only feature">setPan()</a></li>
<li><a href="#soundmanager-setposition">setPosition()</a></li>
<li><a href="#soundmanager-setvolume">setVolume()</a></li>
<li><a href="#soundmanager-supported">supported()</a></li>
<li><a href="#soundmanager-stop">stop()</a></li>
<li><a href="#soundmanager-stopall">stopAll()</a></li>
<li><a href="#soundmanager-togglemute">toggleMute()</a></li>
<li><a href="#soundmanager-togglepause">togglePause()</a></li>
<li><a href="#soundmanager-unload">unload()</a></li>
<li><a href="#soundmanager-unmute">unmute()</a></li>
</ul>
<h4>Events (Callbacks)</h4>
<ul>
<li><a href="#soundmanager-onready">onready()</a></li>
<li><a href="#soundmanager-ontimeout">ontimeout()</a></li>
</ul>
</li>
<li onclick="setFilter(event,'s-')" class="ignore">
<h3 class="wedge">SMSound <span class="archive">(Sound Object)</span><span class="l"></span><span class="r"></span></h3>
<h4>Parameters (Instance Options)</h4>
<ul>
<li>autoLoad</li>
<li>autoPlay</li>
<li title="Flash 9.0r115+ only" class="flash9">bufferTime</li>
<li title="Flash 9+ only" class="flash9"><a href="#smsound-eqdata">eqData</a></li>
<li><a href="#smsound-from">from</a></li>
<li><a href="#smsound-id">id</a></li>
<li title="Flash 9.0r115+ only" class="flash9">isMovieStar</li>
<li>loops</li>
<li>multiShot</li>
<li>multiShotEvents</li>
<li>pan</li>
<li title="Flash 9+ only" class="flash9"><a href="#smsound-peakdata">peakData</a></li>
<li><a href="#smsound-position">position</a></li>
<li title="Flash 9+ only" class="flash9"><a href="#smsound-serverurl">serverURL</a></li>
<li>stream</li>
<li><a href="#smsound-to">to</a></li>
<li><a href="#smsound-type">type</a></li>
<li><a href="#smsound-url">url</a></li>
<li><a href="#smsound-usepolicyfile">usePolicyFile</a></li>
<li>volume</li>
<li title="Flash 9+ only" class="flash9"><a href="#smsound-waveformdata">waveformData</a></li>
</ul>
<h4>Dynamic Properties</h4>
<ul>
<li><a href="#smsound-buffered">buffered</a></li>
<li><a href="#smsound-bytesloaded">bytesLoaded</a></li>
<li><a href="#smsound-bytestotal">bytesTotal</a></li>
<li title="Flash 9+ only" class="flash9"><a href="#smsound-isbuffering">isBuffering</a></li>
<li title="Flash 9+ only" class="flash9"><a href="#smsound-connected">connected</a></li>
<li><a href="#smsound-duration">duration</a></li>
<li><a href="#smsound-durationestimate">durationEstimate</a></li>
<li><a href="#smsound-ishtml5">isHTML5</a></li>
<li><a href="#smsound-loaded">loaded</a></li>
<li><a href="#smsound-muted">muted</a></li>
<li><a href="#smsound-paused">paused</a></li>
<li><a href="#smsound-playstate">playState</a></li>
<li><a href="#smsound-position">position</a></li>
<li><a href="#smsound-readystate">readyState</a></li>
</ul>
<h4>Events</h4>
<ul>
<li title="Flash 9+ only" class="flash9"><a href="#smsound-onbufferchange">onbufferchange</a></li>
<li title="Flash 9+ only" class="flash9"><a href="#smsound-onconnect">onconnect</a></li>
<li title="Flash 9.0.r115+" class="flash9"><a href="#smsound-ondataerror">ondataerror</a></li>
<li><a href="#smsound-onfinish">onfinish</a></li>
<li><a href="#smsound-onload">onload</a></li>
<li><a href="#smsound-onpause">onpause</a></li>
<li><a href="#smsound-onplay">onplay</a></li>
<!--
<li><a href="#smsound-onposition-event">onposition</a></li>
-->
<li><a href="#smsound-onresume">onresume</a></li>
<li title="HTML5 only"><a href="#smsound-onsuspend">onsuspend</a></li>
<li><a href="#smsound-onstop">onstop</a></li>
<li><a href="#smsound-onid3">onid3</a></li>
<li><a href="#smsound-whileloading">whileloading</a></li>
<li><a href="#smsound-whileplaying">whileplaying</a></li>
</ul>
<h4>Methods</h4>
<ul>
<li><a href="#smsound-destruct">destruct()</a></li>
<li><a href="#smsound-load">load()</a></li>
<li><a href="#smsound-clearonposition">clearOnPosition()</a></li>
<li><a href="#smsound-onposition">onPosition()</a></li>
<li><a href="#smsound-mute">mute()</a></li>
<li><a href="#smsound-pause">pause()</a></li>
<li><a href="#smsound-play">play()</a></li>
<li><a href="#smsound-resume">resume()</a></li>
<li><a href="#smsound-setpan">setPan()</a></li>
<li><a href="#smsound-setposition">setPosition()</a></li>
<li><a href="#smsound-setvolume">setVolume()</a></li>
<li><a href="#smsound-stop">stop()</a></li>
<li><a href="#smsound-togglemute">toggleMute()</a></li>
<li><a href="#smsound-togglepause">togglePause()</a></li>
<li><a href="#smsound-unload">unload()</a></li>
<li><a href="#smsound-unmute">unmute()</a></li>
</ul>
</li>
</ul>
<!-- /.box -->
</div>
</div>
</div>
<div class="clear"></div>
<div id="filter-box" class="columnar">
<div class="c1">
<div id="reset-filter"></div>
</div>
<div class="c2">
<div id="search-results"><!-- search results for %s --></div>
</div>
</div>
<div id="soundmanager-properties" class="columnar">
<div class="c2">
<h3 id="soundmanager-setup">SoundManager Properties: soundManager.setup()</h3>
<p>
Just getting started? See <a href="getstarted/#basic-inclusion">the basics</a>. For nicely-formatted, annotated source code, see the <a href="generated/soundmanager2.html">pretty-printed version</a>.
</p>
<div class="f-block f-useconsole f-consoleonly f-waitforwindowload f-allowscriptaccess f-bgcolor f-setup">
<p class="in">The soundManager object has many configurable properties which set debug mode, determine the flash movie path and other behaviours.</p>
<p>When configuring soundManager for your use, <code>soundManager.setup()</code> is the method used to assign these options; for example, <code>soundManager.setup({ url: '/path/to/swfs/', flashVersion: 9 });</code></p>
<p>You should call the setup method before "DOM Ready", which is when SM2 applies configuration and starts up.</p>
<p>Below are the <i>default</i> settings for SoundManager 2, which are appropriate for the majority of use cases - you shouldn't need to change them. These parameters are defined and stored in <code>soundManager.setupOptions</code>.</p>
<p><b>Note</b>: The only property requiring customization is <code>url</code> - this defines the path used to look for the appropriate flash SWF for driving audio when HTML5 is not available. (If not specified, the current working path is used.) Aside from flash-specific items like <code>url</code> and <code>flashVersion</code>, most properties can be set after "DOM Ready" without issue.</p>
<div id="sm2-properties" class="small code block">
<ul class="code code-block">
<li>
<div>url: '<em>/path/to/swf-files/</em>',</div>
<span>// the directory where SM2 can find the flash movies (soundmanager2.swf, soundmanager2_flash9.swf and debug versions etc.) Note that SM2 will append the correct SWF file name, depending on flashVersion and debugMode settings.</span>
</li>
<li>
<div>allowScriptAccess: '<em>always</em>',</div>
<span>// for scripting the SWF (object/embed property), 'always' or 'sameDomain'</span>
</li>
<li>
<div>bgColor: '<em>#ffffff</em>',</div>
<span>// SWF background color. N/A when wmode = 'transparent'</span>
</li>
<li>
<div>consoleOnly: <em>true</em>,</div>
<span>// if console is being used, do not create/write to #soundmanager-debug</span>
</li>
<li>
<div>debugMode: <em>true</em>,</div>
<span>// enable debugging output (console.log() with HTML fallback)</span>
</li>
<li>
<div>debugFlash: <em>false</em>,</div>
<span>// enable debugging output inside SWF, troubleshoot Flash/browser issues</span>
</li>
<li>
<div>flashVersion: <em>8</em>,</div>
<span>// flash build to use (8 or 9.) Some API features require 9.</span>
</li>
<li>
<div>flashPollingInterval: <em>null</em>,</div>
<span>// msec affecting whileplaying/loading callback frequency. If null, default of 50 msec is used.</span>
</li>
<li>
<div>html5PollingInterval: <em>null</em>,</div>
<span>// msec affecting whileplaying/loading callback frequency. If null, native HTML5 update events are used.</span>
</li>
<li>
<div>html5Test: <em>/^(probably|maybe)$/i</em>,</div>
<span>// HTML5 Audio() format support test. Use /^probably$/i; if you want to be more conservative.</span>
</li>
<li>
<div>flashLoadTimeout: <em>1000</em>,</div>
<span>// msec to wait for flash movie to load before failing (0 = infinity)</span>
</li>
<li>
<div>idPrefix: <em>'sound'</em>,</div>
<span>// if an id is not provided to createSound(), this prefix is used for generated IDs - 'sound0', 'sound1' etc.</span>
</li>
<li>
<div>noSWFCache: <em>false</em>,</div>
<span>// if true, appends ?ts={date} to break aggressive SWF caching.</span>
</li>
<li>
<div>preferFlash: <em>true</em>,</div>
<span>// overrides useHTML5audio. if true and flash support present, will try to use flash for MP3/MP4 as needed since HTML5 audio support is still quirky in browsers.</span>
</li>
<li>
<div>useConsole: <em>true</em>,</div>
<span>// use console.log() if available (otherwise, writes to #soundmanager-debug element)</span>
</li>
<li>
<div>useFlashBlock: <em>false</em>,</div>
<span>// requires flashblock.css, <a href="../demo/flashblock/" title="SoundManager 2: Flash blocking demos">see demos</a> - allow recovery from flash blockers. Wait indefinitely and apply timeout CSS to SWF, if applicable.</span>
</li>
<li>
<div>useHighPerformance: <em>false</em>,</div>
<span>// position:fixed flash movie can help increase js/flash speed, minimize lag</span>
</li>
<li>
<div>useHTML5Audio: <em>true</em>,</div>
<span>// use <a href="#soundmanager-usehtml5audio">HTML5 Audio()</a> where supported. Some browsers may not support "non-free" MP3/MP4/AAC codecs. Ideally, transparent vs. Flash API where possible.</span>
</li>
<li>
<div>waitForWindowLoad: <em>false</em>,</div>
<span>// force SM2 to wait for window.onload() before trying to call soundManager.onready()</span>
</li>
<li>
<div>wmode: <em>null</em></div>
<span>// flash rendering mode - null, 'transparent', or 'opaque' (last two allow z-index)</span>
</li>
</ul>
</div>
<p><b>Legacy support note:</b> The new approach defines top-level properties in <code>soundManager.setupOptions</code>. The old approach was to assign properties directly to the soundManager instance. Thus, when <code>soundManager.setup({ url: ... });</code> is called, the updated property value is assigned to both <code>soundManager.setupOptions.url</code> <i>and</i> <code>soundManager.url</code>. You can assign <code>soundManager.url</code> directly as with the old method, but it is recommended to use the new <code>setup()</code>-based method for forward compatibility.</p>
<div id="sm2-setup-extra-properties">
<h4>Bonus: Extended soundManager.setup() Parameters</h4>
<p>As it is common to configure soundManager properties and related events all at once, you can also pass <code>onready</code> and <code>ontimeout</code> parameters which will be called as if you had used <code>soundManager.onready()</code> and <code>soundManager.ontimeout()</code>.</p>
<p>You can also provide values from the following top-level soundManager properties:</p>
<ul>
<li><code>defaultOptions: {...}</code> (global defaults for new sound objects)</li>
<li><code>flash9Options: {...}</code> (API feature options specific to Flash 9)</li>
<li><code>movieStarOptions: {...}</code> (Flash 9-only NetStream/RTMP-specific options)</li>
</ul>
<pre class="block"><code>soundManager.setup({
url: <span>'/path/to/swfs/'</span>,
flashVersion: <span>9</span>,
preferFlash: <span>false</span>, <span><span>// prefer 100% HTML5 mode, where both supported</span></span>
onready: function() {
<span><span>// console.log('SM2 ready!');</span></span>
},
ontimeout: function() {
<span><span>// console.log('SM2 init failed!');</span></span>
},
defaultOptions: {
<span><span>// set global default volume for all sound objects</span></span>
volume: <span>33</span>
}
});</code></pre>
</div>
</div>
<div class="f-block f-debugflash">
<h4 id="soundmanager-debugflash">debugFlash</h4>
<p class="in"><code>soundManager.debugFlash</code> configures SM2's flash debugging output, disabled (false) by default. When enabled, the Flash portion of SM2 will write debug statements within the Flash movie. This can be useful for troubleshooting Flash/JS/browser (ExternalInterface) issues and so on.</p>
<p>A CSS class of <code>flash_debug</code> will also be appended to the Flash <code>#sm2-container</code> DIV element when enabled, if you wish to style it differently.</p>
<p>For a live example, see <a href="getstarted/#flashdebug" title="SoundManager 2 flash debug output demo">Flash Movie Debug Output</a> in the Troubleshooting section.</p>
</div>
<div class="f-block f-debugmode">
<h4 id="soundmanager-debugmode">debugMode</h4>
<p class="in"><code>soundManager.debugMode</code> configures SM2's debug behaviour, enabled (true) by default. When enabled, SoundManager 2 will write console-like output to <code>console.log()</code>-style javascript interfaces, and/or an HTML element with the ID <code>soundmanager-debug</code> (will be created if not found in the DOM at runtime.)</p>
<p>For a live example of debug output, see <a href="technotes/#debug-output" title="SoundManager 2 debug output demo">Debug + Console Output</a>.</p>
</div>
<div class="f-block f-flashversion">
<h4 id="soundmanager-flashversion">flashVersion</h4>
<p class="in">SoundManager 2 started with a Flash 8 base requirement, but can also use Flash 9 and take advantages of some unique features Flash 9 offers. By default Flash 8 will be used, but the version can be easily changed by setting <code>flashVersion</code> appropriately.</p>
<p class="in">Example: <code>soundManager.setup({ <span>flashVersion: 9</span> });</code></p>
<p class="in">The Flash 8 version is <code>soundmanager2.swf</code>, and the flash 9 version is <code>soundmanager2_flash9.swf</code>, accordingly. Note that only Flash 8 and Flash 9 are supported at this time; other values will result in errors.</p>
</div>
<div class="f-block f-flashversion">
<p>Flash 9-only features:</p>
<ul>
<li class="in">MPEG-4 (HE-AAC/H.264) audio support</li>
<li class="in">True "multi-shot" sound behaviour. <code>play()</code> can be called multiple times, giving a layered, "chorus" effect. Sound will also fire <code>onfinish()</code> multiple times. (Previous behaviour did not layer sounds, but would re-play a single instance.)</li>
<li class="in"><code>waveformData</code> array: 256 waveform data values available while playing sound</li>
<li class="in"><code>eqData</code> array: 256 EQ spectrum data values available while playing sound</li>
<li class="in"><code>peakData</code> object: Left and right channel peak/volume data available while playing sound</li>
</ul>
</div>
<div class="f-block f-flashloadtimeout">
<h4 id="soundmanager-flashloadtimeout">flashLoadTimeout</h4>
<p class="in">After initializing the flash component during start-up, SM2 will wait for a defined period of time before timing out and calling <code>soundManager.onerror()</code>.</p>
<p>The default value is 1000 (msec.) Setting a value of 0 disables the timeout and makes SM2 wait indefinitely for a call from the flash component. If you want to handle flash block-type situations, see <a href="#soundmanager-useflashblock" onclick="resetFilter()">soundManager.useFlashBlock</a>.</p>
<p>Setting this parameter to 0 may be useful when attempting to gracefully recover from a flashBlock situation, where the user has whitelisted the movie after it was blocked etc.</p>
<p>Note that when the timeout is disabled, soundManager will not fire its onerror() handler if there is an error at the flash loading stage.</p>
</div>
<div class="f-block f-flashpollinginterval f-usefastpolling f-usehighperformance">
<h4 id="soundmanager-flashpollinginterval">flashPollingInterval</h4>
<p>Setting this will override <code>useFastPolling</code>, and defines the interval of the internal flash timer used for callbacks to sound events like <code>whileloading()</code> and <code>whileplaying()</code>. For example, set this to 200 to have 200ms intervals. This is useful in the case where your callbacks are CPU intensive, or you simply wish to throttle your calls to be more CPU-conservative.</p>
</div>
<div class="f-block f-html5pollinginterval">
<h4 id="soundmanager-html5pollinginterval">html5PollingInterval</h4>
<p>Setting this will enable a single interval that will affect the frequency of event callbacks such <code>whileplaying()</code> for HTML5 sounds, with the exclusion of mobile devices. If null, native HTML5 update events are used. The frequency of native events may vary widely across browsers, and may exceed 500 msec on mobile and other resource-limited devices.</p>
<p>By default, Flash uses a 50-msec timer interval and this is a reasonable value to apply to <code>html5PollingInterval</code> for desktop use cases.</p>
</div>
<div class="f-block f-preferflash">
<h4 id="soundmanager-preferflash">preferFlash</h4>
<p>This property handles "mixed-mode" HTML5 + flash cases, and may prevent 100% HTML5 mode when enabled depending on the configuration of <a href="#soundmanager-audioformats">soundManager.audioFormats</a>. In the event HTML5 supports the default "required" formats (presently MP3), and <code>preferFlash</code> is true (and flash is installed), flash will be used for MP3/MP4 content while allowing HTML5 to play OGG, WAV and other supported formats.</p>
<p><em>Important note:</em> Because HTML5 audio has some bugs across various browsers and operating systems, <code>preferFlash</code> is <code>true</code> by default to help ensure MP3/MP4 play consistently. If set to <code>false</code> or flash is not available, "HTML5-only" mode will kick in and will apply to all formats.</p>
<p>To encourage 100% HTML5 mode, call <code>soundMangager.setup({ preferFlash: false })</code> and then Flash will not be used for MP3/MP4 playback, provided that HTML5 supports them.</p>
</div>
<div class="f-block f-url">
<h4 id="soundmanager-url">url</h4>
<p class="in"><code>soundManager.url</code>, applied via <code>soundManager.setup()</code>, specifies the "online", generally HTTP-based path which SM2 will load .SWF movies from. The "local" (current) path of <code>./</code> will be used by default. The appropriate .SWF required (depending on the desired Flash version) will be appended to the URL.</p>
<p class="in">Example: <code>soundManager.setup({ url: '<span>/path/to/swf-directory/</span>' });</code> (Note trailing slash)</p>
<p>For a simple demo of this in action, see the <a href="../demo/template/">basic template</a>.</p>
<p class="in">For cases where SM2 is being used "offline" in non-HTTP cases (eg., development environments), see <code>altURL</code>.</p>
</div>
<div class="f-block f-usefastpolling f-usehighperformance f-flashpollinginterval">
<h4 id="soundmanager-usefastpolling">useFastPolling</h4>
<p>By default <code>useFastPolling = false</code>, and thus SoundManager uses a 50-millisecond timer inside Flash when polling for updated sound properties such as <code>bytesLoaded</code> and data and event callbacks eg. <code>whileloading()</code>, <code>whileplaying()</code> and so on. With <code>useFastPolling = true</code>, a 10-msec timer is used and callback frequency may noticeably increase. This is best combined with <code>useHighPerformance</code> for optimal results.</p>
</div>
<div class="f-block f-useflashblock">
<h4 id="soundmanager-useflashblock">useFlashBlock</h4>
<p>Flash blockers (eg. FlashBlock, "Click To Flash") can prevent the flash portion of SM2 from loading, which will cause a start-up error with a time-out.</p>
<p>SM2 historically has kept the flash movie off-screen and out of view, and thus the user could not click on and unblock it. Now with <code>useFlashBlock = true</code>, the movie positioning can be handled by CSS. The initial state is still off-screen by default, but will change to be in view when a blocking (time-out) situation may be encountered. You can also edit the CSS to taste, of course.</p>
<p>When starting up, CSS classes are appended to the <code>#sm2-container</code> DIV (which you can provide, or SM2 will create and append to the document.) The CSS classes change with the state of SM2's start-up, eg. <code>#sm2-container.swf_timedout { border:1px solid red; }</code> could be used to highlight the movie to the user for unblocking and so on.</p>
<p>Setting <code>useFlashBlock = true</code> will cause SM2 to wait infinitely for the Flash content to load after an initial (non-fatal) timeout, having already waited for <code>flashLoadTimeout</code> to pass. If <code>flashLoadTimeout = 0</code>, SM2 will immediately go into "flash block mode" on start-up.</p>
<p>The relevant CSS is as follows:</p>
<pre class="small block"><code>#sm2-container {
<span><span>/**
* Initial/default state...
* position:absolute/off-screen, or left/top:0
*/</span></span>
}
#sm2-container.swf_timedout {
<span><span>/**
* Didn't load before time-out, show to user.
* Maybe highlight on-screen, red border, etc..?
*/</span></span>
}
#sm2-container.swf_unblocked {
<span><span>/**
* Applied if movie loads successfully
* (flash started, so move off-screen etc.)
*/</span></span>
}
#sm2-container.swf_error {
<span><span>/**
* "Fatal" error case: SWF loaded, but SM2 was unable to start.
* (Flash security or other error case.)
*/</span></span>
}
#sm2-container.high_performance {
<span><span>/**
* Additional modifier for "high performance" mode
* should apply position:fixed and left/bottom 0 to stay on-screen
* at all times (better flash performance)
*/</span></span>
}
#sm2-container.flash_debug {
<span><span>/**
* Additional modifier for flash debug output mode
* should use width/height 100% so you can read debug messages
*/</span></span>
}</code></pre>
<p>For a live example, see the <a href="../demo/flashblock/">FlashBlock Demo</a>.</p>
</div>
<div class="f-block f-usehighperformance f-usefastpolling f-flashpollinginterval">
<h4 id="soundmanager-highperformance">useHighPerformance</h4>
<p>Perhaps intuitively, Flash is given higher priority when positioned within the viewable area of the browser, at least 6px in height (oddly), fully-opaque, visible and displayed on the screen. By default, <code class="in">useHighPerformance</code> is disabled. When enabled, it may noticeably reduce JS/flash lag and increase the frequency of callbacks such as <code class="in">whileplaying()</code> in some circumstances.</p>
<p><code class="in">soundManager.setup({useHighPerformance: <span>true</span>});</code></p>
<p>This has made a noticeable impact in responsiveness on Mac OS X, and Safari on Windows; animation lag is practically non-existent (see <a href="../demo/animation-2b/" title="SoundManager JS + DOM + sound demo 2b" style="display:inline" onclick="checkDomain(this)">demo</a>). Because setting wmode=transparent and fixed position has been reported to cause some issues, the feature is disabled by default.</p>
<p>To be least-obtrusive, SM2 attempts to set position:fixed, and uses bottom/left:0px to stay within view (though using wmode=transparent where possible, to be hidden from view.) It occupies an 8x8px square. If you wish to position the movie yourself or show it inline, have a DIV element with the ID of <code class="in">sm2-container</code> present in the DOM for SM2 to reference and it will write the movie there without positioning.</p>
</div>
<div class="f-block f-usehtml5audio">
<h4 id="soundmanager-usehtml5audio">useHTML5Audio</h4>
<p style="background:#f0f9ff">HTML5 support is in active development. See <a href="download/#revision-history">Revision History</a> for the latest updates on HTML5 playback support.</p>
<p><code>useHTML5Audio</code> determines whether HTML5 <code>Audio()</code> support is used (as available) to play sound, with flash as the fallback for playing MP3 and MP4 (AAC) formats. Browser support for HTML5 Audio varies, and format support (eg. MP3, MP4/AAC, OGG, WAV) can vary by browser/platform.</p>
<p>The SM2 API is effectively transparent, consistent whether using flash or HTML5 <code>Audio()</code> for sound playback behind the scenes. The HTML5 Audio API is roughly equivalent to the flash 8 feature set, minus ID3 tag support and a few other items. (Flash 9 features like waveform data etc. are not available in HTML5 mode.)</p>
<p>By default, "100% HTML5 mode" applies to Apple iPad 3.2+ (iPad version 1.0), iPhone / iOS 4.0+ devices and others without flash. In other cases, HTML5 support is tested and if MP3/MP4 aren't natively supported, flash will be used as a backup method of playing these "required" formats. (It is assumed MP3 playback is required by default, but this is user-configurable via <code><a href="#soundmanager-audioformats">soundManager.audioFormats</a></code>.) HTML5 may also enable support for additional formats such as OGG and WAV.</p>
<p>On the desktop and other devices with flash support, SM2 will still try for 100% HTML5 mode by default. However, you can use <code>soundManager.setup({ preferFlash: true })</code> if you would like to have Flash play MP3 and MP4 (AAC) formats even when they are supported via HTML5.</p>
<h5>SoundManager 2 + useHTML5Audio: Init Process</h5>
<p>At DOM ready (if <code>useHTML5Audio</code> = <code>true</code>), a test for <code>Audio()</code> is done followed by a series of <code>canPlayType()</code> tests to see if MP3, MP4, WAV and OGG formats are supported. If any of the "required" formats (by default, MP3) are <i>not</i> supported via HTML5, or if <code>preferFlash</code> = <code>true</code> and MP3 or MP4 are required, then flash is also added as a requirement for SM2 to start.</p>
<p><code><a href="#soundmanager-audioformats">soundManager.audioFormats</a></code> defines the list of formats to check (MP3, MP4 and so on), their possible <code>canPlayType()</code> strings (long story short, it's complicated) and whether or not they are "required" - that is, whether flash should be loaded if they don't work under HTML5. (Again, only MP3 + MP4 are supported by flash.) If you had a page solely using OGG, you could make MP3/MP4 non-required, but many browsers do not play OGG files natively.</p>
<p>SM2 will indicate its state (HTML 5 support or not, using flash or not) in <code>console.log()</code>-style debug output messages when <code>debugMode = true</code>.</p>
<h5>"My browser does HTML5, why not MP3"?</h5>
<p>Despite best efforts, some browsers eg. Chrome on Windows may only return "maybe" for <code>Audio().canPlayType('audio/mpeg; codecs=mp3')</code> and variants; SoundManager 2 will presently assume a format is supported if a "probably" or "maybe" response is given. You can modify <code>html5Test</code> to be <code>/probably/i</code> if you want to be more strict, for example.</p>
<p>Safari, IE 9, and Chrome (excluding Chromium?) support the "non-free" MP3 and MP4 (including AAC) formats. Firefox, in some cases, does support the MP3 codec where the underlying OS has support for it. This includes Windows Vista (and newer), and as of November 2013, Firefox Aurora (development builds) also on OS X.</p>
<p>For the cases where MP3 is not supported via HTML5, flash is used as the fallback support for MP3/MP4 as needed. Additionally, if flash support is present, <code>soundManager.preferFlash</code> means that MP3/MP4 will be handled by flash even if HTML5 support is present for those formats.</p>
<h5>Additional HTML5 formats: OGG, WAV</h5>
<p>WAVe (uncompressed audio) and OGG (a free/open-source alternative to MP3) are both supported in a majority of browsers via HTML5, so SoundManager 2 will also test for support for these formats. A flash fallback for these formats has not been implemented. In 2011, Adobe suggested they would support OGG audio + video (combined, the "WebM" format) in a future release of flash. As of November 2013, this has yet to materialize.</p>
<p>You may need to make a few server configuration updates given the importance of MIME types and the use of certain HTTP headers when serving audio to HTML5 clients. See <a href="../doc/technotes/#client-requests">Client Requests</a> for more.</p>
<p>HTML5 is not limited to OGG and WAV, of course, as the system is designed to be extensible. Support for other formats may exist, depending on what built-in support exists, and plug-ins or codecs the user has installed on their system.</p>
<h5>Testing audio format support</h5>
<p>Once <code>soundManager.onready()</code> has fired and SM2 has started, you can check for support via a number of methods. Namely, <a href="#soundmanager-canplaylink">soundManager.canPlayLink()</a> will take an <code>&lt;a&gt;</code> element and check its <code>href</code> and <code>type</code> attributes, if available, for hints as to its format or type. You can also pass arbitrary URLs to <a href="#soundmanager-canplayurl">soundManager.canPlayURL()</a>, which will make a "best guess" based on the extension it finds. In any event, SM2 will return a true/false value from canPlay methods based on HTML and/or flash capabilities.</p>
<p>To see what formats are supported by HTML5, watch SM2's debug/console output when debug is enabled, or dump the contents of <code>soundManager.html5</code> to the console; it will show the results of tests for simple items like "mp3", as well as <code>canPlayType()</code> strings such as 'mpeg; codecs=mp3'</p>
<h5>Apple iPad, iPhone, Palm Pre: Special Cases</h5>
<p>The "Big iPhone" doesn't do Flash, and does support HTML5 <code>Audio()</code> pretty decently - so SM2 makes a special exception to enable <code>useHTML5Audio</code> when it detects an iPad, iPhone or Palm Pre user agent string by default. Feel free to disable this if you wish.</p>
<p>iPad and iPhone require user interaction to start a sound, eg. the createSound() and play() call should happen within an onclick() handler on a link, etc. The "security" model here seems to be implemented similarly to the way pop-up blockers work. You may "chain" sounds (eg. create and play a new one) provided it is done via the onfinish() event of a sound initiated by a user, however. The Muxtape-style demo on the SM2 homepage uses this, and will advance the playlist on the iPad/iPhone if allowed.</p>
<p>iPad 3.2 gets hung up on the "BC quail" HE-AAC example sound for some reason, and endlessly loops it rather than finishing and moving on to the next item. May be an iPad playback bug, as other formats are fine. iPhone OS 4 (iOS 4) does not show this issue.</p>
<p>iPhone OS version &lt; 3.1 doesn't work, but 3.1 (and possibly earlier versions, not verified) have a native <code>Audio()</code> object. However, they seem to simply not play sound when <code>play()</code> is called, so SM2 looks for and ignores the iPhone with these OS revisions.</p>
<p>The Palm Pre <a href="http://developer.palm.com/index.php?option=com_content&amp;view=article&amp;id=1741&amp;Itemid=265#using_html_5_audio_objects" title="Palm Developer Center: Audio">supports</a> a number of MP3, MP4 and WAV formats (WebOS 1.4.1 was tested; it didn't seem to like MP3s at 192kbps, but 128kbps was fine.)</p>
<h5>General Disclaimer</h5>
<p>HTML5 audio support may still be in flux, and may not be fully-supported or implemented consistently in modern browsers. Be careful out there.</p>
<h5>Related Reading on HTML5</h5>
<p>For some more backstory on HTML and audio, see the 24ways.org article <a href="http://24ways.org/2010/the-state-of-html5-audio">"Probably, Maybe, No": The State Of HTML5 Audio</a> (published December, 2010.)</p>
</div>
<div class="f-block f-wmode">
<h4 id="soundmanager-wmode">wmode</h4>
<p>The <code>wmode</code> property is applied directly to the flash movie, and can be either <code>null</code>, <code>'window'</code>, <code>'transparent'</code> or <code>'opaque'</code>. By default if <code>useHighPerformance</code> is enabled, transparency will be attempted by SM2 unless there are known issues with the rendering mode.</p>
<p>It appears that non-IE browsers on Windows will not load SWF content "below the fold" (out of scrollable view) when wmode is set to anything other than null (window). This will break SM2 as it expects Flash to load within a reasonably short amount of time - so SM2 by default will reset wmode for this case. If you wish to force retention of your <code>wmode</code>, set <code>soundManager.flashTimeout = 0</code> which will ensure that if the content is below the fold, SM2 will not time out waiting for it to load.</p>
<p>Additionally, <code>soundManager.specialWmodeCase</code> will be set to <code>true</code> if wmode has been reset due to this special condition.</p>
</div>
<div class="f-block">
<h3>SoundManager Top-Level Properties</h3>
<p>A few additional properties that hang off the <code>soundManager</code> instance object</p>
</div>
<div class="f-block f-alturl">
<h4 id="soundmanager-alturl">soundManager.altURL</h4>
<p class="in"><code>soundManager.altURL</code> specifies an alternate path to <code>soundManager.setupOptions.url</code> which SM2 can load its SWF from. It is a simple convenience for when you may need to load SWFs from different paths depending on your hosting environment (eg., offline development vs. production.)</p>
<p class="in">Example: <code>soundManager.altURL = '../';</code> (Load from parent directory - note trailing slash)</p>
<p class="in">For altURL to be used, it must be defined and an "alternate environment" condition must be met:</p>
<p class="in"><code>soundManager.useAltURL = (!document.location.protocol.match(/http/i));</code></p>
<p>By default and as shown above, SM2 will use this property when the hosting page is not being served over HTTP, and thus is assumed to being served "offline" - for example, when loading via file://, from the local file system.</p>
<p>This can easily be adapted to taste, eg., checking the domain matching yourdomain.com vs. localhost:</p>
<p class="in"><code>soundManager.useAltURL = (!document.location.match(/mydomain.com/i));</code></p>
<p class="in">If <code>soundManager.altURL</code> is null (the default), <code>soundManager.setupOptions.url</code> will be used for all cases.</p>
</div>
<div class="f-block f-audioformats">
<h4 id="soundmanager-audioformats">soundManager.audioFormats</h4>
<p><code>soundManager.audioFormats</code> defines a structure listing the audio codecs that will be tested for support under both HTML5 and Flash. Each type is defined by a file extension and MIME types, and optionally, a list of related extensions (eg. MPEG-4 content can be in an .mp4 file, but may also be .aac, or .m4a.)</p>
<p>Additionally, each format can be defined as "required", meaning that SM2 can fail to start if playback support is not found via either HTML5 or Flash. By default, MP3 is a required format.</p>
<pre class="small block"><code>soundManager.audioFormats = {
<span><span>/**
* determines HTML5 support + flash requirements.
* if no support (via flash/HTML5) for "required" format, SM2 will fail to start.
* flash fallback is used for MP3 or MP4 if lacking HTML5 (or preferFlash = true)
* multiple MIME types may be tried looking for positive canPlayType() response.
*/</span></span>
'<span>mp3</span>': {
'type': ['<span>audio/mpeg; codecs="mp3"</span>', '<span>audio/mpeg</span>', '<span>audio/mp3</span>', '<span>audio/MPA</span>', '<span>audio/mpa-robust</span>'],
'required': <span>true</span>
},
'<span>mp4</span>': {
'related': ['<span>aac</span>','<span>m4a</span>'], <span><span>// additional formats under the MP4 container</span></span>
'type': ['<span>audio/mp4; codecs="mp4a.40.2"</span>', '<span>audio/aac</span>', '<span>audio/x-m4a</span>', '<span>audio/MP4A-LATM</span>', '<span>audio/mpeg4-generic</span>'],
'required': <span>false</span>
},
'<span>ogg</span>': {
'type': ['<span>audio/ogg; codecs=vorbis</span>'],
'required': <span>false</span>
},
'<span>wav</span>': {
'type': ['<span>audio/wav; codecs="1"</span>', '<span>audio/wav</span>', '<span>audio/wave</span>', '<span>audio/x-wav</span>'],
'required': <span>false</span>
}
};</code></pre>
</div>
</div>
</div>
<div id="api" class="columnar">
<div class="c2">
<div class="f-block">
<h3>soundManager Global Object</h3>
<p>This is a collection of methods, properties and event handlers available via the <span class="code">soundManager</span> Javascript object. Sound properties and methods can be set on a global (inherited) default, or per-sound basis.</p>
</div>
<dl id="soundmanager-canplaylink" class="f-block f-canplaylink" style="margin-top:2em">
<dt><span>canPlay:boolean</span> canPlayLink(<span>&lt;a&gt;:DOM element</span>)</dt>
<dd>Normalized method which checks <code>canPlayMIME()</code> and <code>canPlayURL()</code> as needed to estimate the playability of an HTML link; this means both the <code>href</code> and <code>type</code> attributes, if provided, are checked for matching file extension and/or MIME type patterns.</dd>
<dd>Example:
<pre class="block"><code><span><span>/**
* example links:
* &lt;a id="song1" href="/music/player.php?songID=1" type="audio/mp3"&gt;play #1&lt;/a&gt;
* &lt;a id="song2" href="song2.mp3"&gt;play song 2&lt;/a&gt;
*/</span></span>
var aLink = document.getElementById('<span>mySong</span>');
if (soundManager.canPlayLink(aLink)) {
soundManager.play('<span>mySongSound</span>', aLink.href);
}</code></pre></dd>
</dl>
<dl id="soundmanager-canplaymime" class="f-block f-canplaymime">
<dt><span>canPlay:boolean</span> canPlayMIME(<span>MIMEtype:string</span>)</dt>
<dd>Returns a boolean indicating whether soundManager can play the given MIME type - eg., <code>audio/mp3</code>. The types supported vary based on Flash version and MPEG4 (MovieStar mode) options.</dd>
<dd>
MIME type patterns are as follows:
<ul>
<li>Defaults: <code>/^audio\/(?:x-)?(?:mp(?:eg|3))\s*;?/i;</code> - eg. <code>audio/mp3</code> or <code>audio/mpeg</code></li>
<li>MovieStar-only formats: <code>/^audio\/(?:x-)?(?:mp(?:eg|3)|mp4a-latm|aac|speex)\s*;?/i; </code> - eg. <code>audio/m4a or audio/aac</code></li>
</ul>
</dd>
<dd>Example:
<pre class="block"><code><span><span>// link example: &lt;a id="song1" href="foo.php?songID=1" type="audio/mp3"&gt;play #1&lt;/a&gt;</span></span>
var aLink = document.getElementById('<span>song1</span>');
if (soundManager.canPlayMIME(aLink.type)) {
soundManager.createSound('<span>song1Sound</span>', aLink.href);
}</code></pre></dd>
<dd>If no <code>type</code> attribute is found, this method will return <code>null</code> instead of <code>false</code>.</dd>
</dl>
<dl id="soundmanager-canplayurl" class="f-block f-canplayurl">
<dt><span>canplay:boolean</span> canPlayURL(<span>mediaURL:string</span>)</dt>
<dd>Returns a boolean indicating whether soundManager can play the given URL. Playability is determined by a matching URL pattern set at runtime, based on Flash version and MPEG4 (MovieStar mode) support.</dd>
<dd>Example:
<pre class="block"><code>var sURL = '<span>/path/to/some.mp3</span>';
if (soundManager.canPlayURL(sURL)) {
soundManager.createSound('<span>fooSound</span>', sURL);
}</code></pre></dd>
<dd>If no <code>href</code> attribute is found, this method will return <code>null</code> instead of <code>false</code>.</dd>
</dl>
<dl id="soundmanager-clearonposition" class="f-block f-clearonposition">
<dt><span>object:SMSound</span> clearOnPosition(<span>id:string, msecOffset:integer, [callback:function]</span>)</dt>
<dd>Clears the event listener set via <code>onPosition()</code>, in the same way it was registered. If the callback is omitted, any and all callbacks registered for the given offset will be cleared.</dd>
<dd>Example: <code>soundManager.clearOnPosition('mySound', 3000, positionHandler);</code></dd>
<dd>Example 2: <code>soundManager.clearOnPosition('mySound', 3000);</code></dd>
</dl>
<dl id="soundmanager-createsound" class="f-block f-createsound s-autoplay">
<dt><span>object:SMSound </span>createSound(<span>object:options</span>)</dt>
<dd title="object:options">Creates a sound object, supporting an arbitrary number of optional arguments. Returns a <code>SMSound</code> object instance. At minimum, a <code>url</code> parameter is required.</dd>
<dd>
Minimal example:
<pre class="block"><code>var someSound = soundManager.createSound({ <span>
url: '/path/to/an.mp3'
</span>});</pre></code>
</dd>
<dd>
With optional parameters:
<pre class="block"><code>var mySoundObject = soundManager.createSound({<span>
<span>// optional id, for getSoundById() look-ups etc. If omitted, an id will be generated.</span>
id: 'mySound',
url: '/audio/mysoundfile.mp3',
<span>// optional sound parameters here, see <a href="#sound-properties" title="SoundManager 2 API Info: Sound Properties Object" onclick="resetFilter()">Sound Properties</a> for full list</span>
volume: 50,
autoPlay: true,
whileloading: function() { console.log(this.id + ' is loading'); }
</span>});</code></pre>
<p>Each <code>createSound()</code> call results in the creation of a <code>SMSound</code> object which stores all properties, methods and events relevant to that particular sound instance. If you keep the <code>SMSound</code> object in scope, you probably don't need to specify an ID. However, if you <i>do</i> provide an <code>id</code>, you can easily get a reference to the given sound via <code>soundManager.getSoundById()</code> (for the above example, you would use <code>mySound</code>.)</p>
<p>When specifying an <code>id</code> you can also use controller-level convenience methods, i.e., <code>soundManager.play('<span>mySound</span>')</code>, <code>soundManager.stop('<span>mySound</span>')</code> and so on.</p>
<p>Individual sound objects can also easily be referenced as returned from <code>createSound()</code>:</p>
<pre class="block"><code>var mySoundObject = soundManager.createSound({<span>
url: '/audio/mysoundfile.mp3'
</span>});
mySoundObject.play(); <span><span>// SMSound object instance</span></span></code></pre>
<p>For more SMSound parameters, see <a href="#object-literal-format" title="SoundManager 2 API Info: Sound Properties Object" onclick="resetFilter()">Object Literal Format</a>.</p>
</dd>
<dd>If <code>createSound</code> is called with the ID of an existing sound, that sound object will be returned "as-is". Any other <code>createSound</code> options passed (eg., <code>url</code> or <code>volume</code>, etc.) will be ignored.</dd>
</dl>
<dl id="soundmanager-createsound-overloaded" class="f-block f-createsound">
<dt><span>object:SMSound </span>createSound(<span>id:string, url:string</span>) - overloaded method</dt>
<dd title="id:string,url:string">Creates a sound with the specified ID and URL (simple two-parameter method.)</dd>
<dd>Example: <code>soundManager.createSound('<span>mySound</span>','<span>/audio/mysoundfile.mp3</span>');</code></dd>
</dl>
<dl id="soundmanager-destroysound" class="f-block f-destroysound">
<dt>destroySound(<span>id:string</span>)</dt>
<dd title="id:string">Stops, unloads and destroys a sound specified by ID.</dd>
<dd>Example: <code>soundManager.destroySound('<span>mySound</span>');</code></dd>
<dd>SMSound equivalent example: <code>mySound.destruct();</code></dd>
</dl>
<dl id="soundmanager-mute" class="f-block f-mute">
<dt><span>object:SMSound </span>mute(<span>[id:string]</span>)</dt>
<dd title="id:string">Mutes the sound specified by ID and returns that sound object. If no ID specified, all sounds will be muted and null is returned. Affects <span>muted</span> property (boolean.)</dd>
<dd>Example: <code>soundManager.mute('<span>mySound</span>');</code></dd>
</dl>
<dl id="soundmanager-onposition" class="f-block f-onposition">
<dt><span>object:SMSound</span> onPosition(<span>id:string, msecOffset:integer, callback:function, [scope]</span>)</dt>
<dd>Registers an event listener, fired when a sound reaches or passes a certain position while playing. Position being "listened" for is passed back to event handler. Will also fire if a sound is "rewound" (eg. via <code>setPosition()</code> to an earlier point) and the given position is reached again. Listeners will be removed if a sound is unloaded. An optional scope can be passed as well.</dd>
<dd>Note that for <code>multiShot</code> cases, only the first play instance's <code>position</code> is tracked in Flash; therefore, subsequent "shots" will not have onPosition() events being fired.</dd>
<dd>Example: <code>soundManager.onPosition('mySound', 3000, function(eventPosition){<span>console.log(this.id+' reached '+eventPosition</span>});</code></dd>
</dl>
<dl id="soundmanager-onready" class="f-block f-onready">
<dt>onready(<span>callback:function, [scope]</span>)</dt>
<dd title="callback:function">Queues an event callback/handler for successful initialization and "ready to use" state of SoundManager 2. An optional scope parameter can be specified; if none, the callback is scoped to the window. If <code>onready()</code> is called after successful initialization, the callback will be executed immediately. The <code>onready()</code> queue is processed before <code>soundManager.onload()</code>.</dd>
<dd>Example:
<pre class="block"><code>soundManager.onready(<span>function() {
alert('Yay, SM2 loaded OK!');
}</span>);</code></pre>
</dd>
<dd>Queueing multiple handlers: <code>soundManager.onready(<span>myOnReadyHandler</span>); soundManager.onready(<span>myOtherHandler</span>);</code></dd>
<dd>The same listener may be added multiple times; there is no duplicate checking. Queue is processed in order of addition.</dd>
<dd>If <code>soundManager.reboot()</code> is called, all listeners' "fired" flags will be reset and they will be eligible to fire again when SM2 starts.</dd>
<dd>This method can also be used via <code><a href="#sm2-setup-extra-properties" onclick="resetFilter()">soundManager.setup</a>({ <span>onready: function() { ... }</span> });</code></dd>
</dl>
<dl id="soundmanager-ontimeout" class="f-block f-ontimeout">
<dt>ontimeout(<span>callback:function, [scope]</span>)</dt>
<dd title="callback:function">Queues an event callback/handler for SM2 init failure, processed at (or immediately, if added after) SM2 initialization has failed, just before <code>soundManager.onerror()</code> is called. An optional scope parameter can be specified; if none, the callback is scoped to the window.</dd>
<dd>Additionally, a <code>status</code> object containing <code>success</code> and <code>error-&gt;type</code> parameters is passed as an argument to your callback.</dd>
<dd>Example:
<pre class="block"><code>soundManager.ontimeout(<span>function(status) {
alert('SM2 failed to start. Flash missing, blocked or security error?');
alert('The status is ' + status.success + ', the error type is ' + status.error.type);
}</span>);</code></pre>
</dd>
<dd>Queueing multiple handlers: <code>soundManager.ontimeout(<span>myOnTimeoutHandler</span>); soundManager.ontimeout(<span>myOtherHandler</span>);</code></dd>
<dd>The timeout event is not necessarily fatal, as SM2 may be rebooted and fire an <code>onready()</code> in the <code>useFlashBlock</code> case (where the user sees, and chooses to unblock the Flash component after a failed init attempt.)</dd>
<dd>The same listener may be added multiple times; there is no duplicate checking. Queue is processed in order of addition.</dd>
<dd>If <code>soundManager.reboot()</code> is called, all listeners' "fired" flags will be reset and they will be eligible to fire again when SM2 starts.</dd>
<dd>This method can also be used via <code><a href="#sm2-setup-extra-properties" onclick="resetFilter()">soundManager.setup</a>({ <span>ontimeout: function() { ... }</span> });</code></dd>
</dl>
<dl id="soundmanager-play" class="f-block f-play">
<dt><span>object:SMSound</span> play(<span>id:string, [options object]</span>)</dt>
<dd title="soundID:string">Starts playing the sound specified by ID. (Will start loading if applicable, and will play ASAP.)</dd>
<dd>Returns an <code>SMSound</code> (sound object) instance.</dd>
<dd>Example: <code>soundManager.play('<span>mySound</span>');</code></dd>
<dd>Note that the second parameter, <code>options object</code>, is not required and can take almost any argument from the object literal format (eg. volume.) It is convenient when you wish to override the sound defaults for a single instance.</dd>
<dd>Example: <code>soundManager.play('<span>mySound</span>',{<span>volume:50,onfinish:playNextSound</span>});</code></dd>
</dl>
<dl id="soundmanager-pause" class="f-block f-pause">
<dt><span>object:SMSound</span> pause(<span>id:string</span>)</dt>
<dd title="soundID:string">Pauses the sound specified by ID. Does not toggle. Affects <span>paused</span> property (boolean.) Returns the given sound object.</dd>
<dd>Example: <code>soundManager.pause('<span>mySound</span>');</code></dd>
</dl>
<dl id="soundmanager-pauseall" class="f-block f-pauseall">
<dt>pauseAll()</dt>
<dd>Pauses all sounds whose playState is &gt;0. Affects <span>paused</span> property (boolean.)</dd>
<dd>Example: <code>soundManager.pauseAll();</code></dd>
</dl>
<dl id="soundmanager-reboot" class="f-block f-reboot">
<dt>reboot()</dt>
<dd>Destroys any created SMSound objects, unloads the flash movie (removing it from the DOM) and restarts the SM2 init process, retaining all currently-set properties.</dd>
<dd>Example:
<pre class="block"><code>soundManager.ontimeout(function() {<span>
<span>// Something went wrong during init - in this example, we *assume* flashblock etc.</span>
soundManager.flashLoadTimeout = 0; <span>// When restarting, wait indefinitely for flash</span>
soundManager.onerror = {}; <span>// Prevent an infinite loop, in case it's not flashblock</span>
soundManager.reboot(); <span>// and, go!</span>
});</span></code></pre>
</dd>
<dd>This method may be helpful when trying to gracefully recover from FlashBlock-type situations where the user has prevented the SWF from loading, but is able to whitelist it. For more ideas, see <a href="../demo/flashblock/">Flashblock demo</a>.</dd>
<dd>When using this method also consider <a href="#soundmanager-flashloadtimeout" onclick="resetFilter()">flashLoadTimeout</a>, which can have SM2 wait indefinitely for the flash to load if desired.</dd>
</dl>
<dl id="soundmanager-reset" class="f-block f-reset">
<dt>reset()</dt>
<dd>Effectively restores SoundManager's original state without rebooting (re-initializing).</dd>
<dd>Similar to <a href="#soundmanager-reboot" onclick="resetFilter()">reboot()</a> which destroys sound objects and the flash movie (as applicable), but also nukes any registered <code>onready()</code> and related callbacks.</dd>
<dd>Once <code>soundManager.reset()</code> has been called, <code>soundManager.beginDelayedInit()</code> (or <code>soundManager.setup()</code> with a <code>url</code> property) may be called to re-init SM2.</dd>
</dl>
<dl id="soundmanager-resume" class="f-block f-resume">
<dt><span>object:SMSound</span> resume(<span>id:string</span>)</dt>
<dd title="soundID:string">Resumes and returns the currently-paused sound specified by ID.</dd>
<dd>Example: <code>soundManager.resume('<span>mySound</span>');</code></dd>
</dl>
<dl id="soundmanager-resumeall" class="f-block f-resumeall">
<dt>resumeAll()</dt>
<dd title="soundID:string">Resumes all currently-paused sounds.</dd>
<dd>Example: <code>soundManager.resumeAll();</code></dd>
</dl>
<dl id="soundmanager-setpan" class="f-block f-setpan">
<dt><span>object:SMSound</span> setPan(<span>id:string,volume:integer</span>)</dt>
<dd title="id:string,volume:integer">Sets the stereo pan (left/right bias) of the sound specified by ID, and returns the related sound object. Accepted values: -100 to 100 (L/R, 0 = center.) Affects <span>pan</span> property.</dd>
<dd>Example: <code>soundManager.setPan('<span>mySound</span>',<span>-80</span>);</code></dd>
</dl>
<dl id="soundmanager-setposition" class="f-block f-setposition">
<dt><span>object:SMSound</span> setPosition(<span>id:string,msecOffset:integer</span>)</dt>
<dd title="id:string,msecOffset:integer">Seeeks to a given position within a sound, specified by miliseconds (1000 msec = 1 second) and returns the related sound object. Affects <span>position</span> property.</dd>
<dd>Example: <code>soundManager.setPosition('<span>mySound</span>',<span>2500</span>);</code></dd>
<dd>Can only seek within loaded sound data, as defined by the <span>duration</span> property.</dd>
</dl>
<dl id="soundmanager-setvolume" class="f-block f-setvolume">
<dt><span>object:SMSound</span> setVolume(<span>id:string, volume:integer</span>)</dt>
<dd title="id:string,volume:integer">Sets the volume of the sound specified by ID and returns the related sound object. Accepted values: 0-100. Affects <span>volume</span> property.</dd>
<dd>Example: <code>soundManager.setVolume('<span>mySound</span>',<span>50</span>);</code></dd>
</dl>
<dl id="soundmanager-stop" class="f-block f-stop">
<dt><span>object:SMSound</span> stop(<span>id:string</span>)</dt>
<dd title="soundID:string">Stops playing the sound specified by ID. Returns the related sound object.</dd>
<dd>Example: <code>soundManager.stop('<span>mySound</span>');</code></dd>
</dl>
<dl id="soundmanager-stopall" class="f-block f-stopall">
<dt>stopAll()</dt>
<dd>Stops any currently-playing sounds.</dd>
<dd>Example: <code>soundManager.stopAll();</code></dd>
</dl>
<dl id="soundmanager-togglemute" class="f-block f-togglemute">
<dt><span>object:SMSound</span> toggleMute(<span>id:string</span>)</dt>
<dd title="soundID:string">Mutes/unmutes the sound specified by ID. Returns the related sound object.</dd>
<dd>Example: <code>soundManager.toggleMute('<span>mySound</span>');</code></dd>
</dl>
<dl id="soundmanager-togglepause" class="f-block f-togglepause">
<dt><span>object:SMSound</span> togglePause(<span>id:string</span>)</dt>
<dd title="soundID:string">Pauses/resumes play on the sound specified by ID. Returns the related sound object.</dd>
<dd>Example: <code>soundManager.togglePause('<span>mySound</span>');</code></dd>
</dl>
<dl id="soundmanager-unload" class="f-block f-unload">
<dt><span>object:SMSound</span> unload(<span>id:string</span>)</dt>
<dd title="soundID:string">Stops loading the sound specified by ID, canceling any current HTTP request. Returns the related sound object.</dd>
<dd>Example: <code>soundManager.unload('<span>mySound</span>');</code></dd>
<dd>Note that for Flash 8, SoundManager does this by pointing the sound object to <code>about:blank</code>, which replaces the current one from loading.</dd>
</dl>
<dl id="soundmanager-unmute" class="f-block f-unmute">
<dt><span>object:SMSound</span> unmute(<span>[id:string]</span>)</dt>
<dd title="id:string">Unmutes the sound specified by ID. If no ID specified, all sounds will be unmuted. Affects <span>muted</span> property (boolean.) Returns the related sound object.</dd>
<dd>Example: <code>soundManager.unmute('<span>mySound</span>');</code></dd>
</dl>
<dl id="soundmanager-load" class="f-block f-load">
<dt><span>object:SMSound</span> load(<span>id:string, [options object]</span>)</dt>
<dd title="soundID:string">Starts loading the sound specified by ID, with options if specified. Returns the related sound object.</dd>
<dd>Example: <code>soundManager.load('<span>mySound</span>');</code></dd>
<dd>Example 2: <code>soundManager.load('<span>mySound</span>',{<span>volume:50,onfinish:playNextSound</span>});</code></dd>
</dl>
<dl id="soundmanager-getsoundbyid" class="f-block f-getsoundbyid">
<dt><span>object:SMSound </span>getSoundById(<span>id:string</span>)</dt>
<dd title="id:string">Returns an <code>SMSound</code> object specified by ID, or null if a sound with that ID is not found.</dd>
<dd>Example: <code>var mySMSound = soundManager.getSoundById('<span>mySound</span>');</code></dd>
</dl>
<dl id="soundmanager-getmemoryuse" class="f-block f-getmemoryuse">
<dt class="flash9" title="Requires Flash 9.0+"><span>number:bytesUsed </span>getMemoryUse()</dt>
<dd>Returns the total number of bytes allocated to the Adobe Flash player or Adobe AIR, or 0 if unsupported (Flash 9+ only.) This number may include memory use across all tabs, browsers etc. See <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/system/System.html#totalMemory" title="System.totalMemory property documentation">system.totalMemory</a> (livedocs.adobe.com)</dd>
<dd>Example: <code>var mbUsed = (soundManager.getMemoryUse()/1024/1024).toFixed(2); <span><span>// eg. 12.05 MB</span></span></code></dd>
</dl>
<dl id="soundmanager-ok" class="f-block f-ok f-supported">
<dt id="soundmanager-supported"><span>isSupported:boolean</span> ok() ( previous name: supported() )</dt>
<dd>Returns a boolean indicating whether soundManager has attempted to and succeeded in initialising. This function will return false if called before initialisation has occurred, and is useful when you want to create or play a sound without knowing SM2's current state.</dd>
<dd>Example: <code>var isSupported = soundManager.ok();</code></dd>
</dl>
</div>
</div>
<div id="smsoundmethods" class="columnar">
<div class="c2">
<div>
<h3>Sound Object Methods</h3>
<p class="in">Each sound under SoundManager 2 is given a <code>SMSound</code> object instance which includes the following events, methods and properties. Note that most methods will return the sound object instance, allowing for method chaining if desired.</p>
<dl id="smsound-clearonposition" class="f-block f-clearonposition">
<dt><span>object:SMSound</span> clearOnPosition(<span>msecOffset:integer, [callback:function]</span>)</dt>
<dd>Clears the event listener set via <code>onPosition()</code>, in the same way it was registered. If the callback is omitted, any and all callbacks registered for the given offset will be cleared.</dd>
<dd>Example: <code>mySound.clearOnPosition(3000, positionHandler);</code></dd>
<dd>Example 2: <code>mySound.clearOnPosition('mySound', 3000);</code></dd>
</dl>
<dl id="smsound-destruct" class="f-block s-destruct">
<dt>destruct()</dt>
<dd>Stops, unloads and destroys a sound, freeing resources etc.</dd>
<dd>Example: <code>mySound.destruct();</code></dd>
</dl>
<dl id="smsound-load" class="f-block s-load">
<dt><span>object:SMSound</span> load(<span>[options object]</span>)</dt>
<dd title="soundID:string">Starts loading the given sound, with options if specified.</dd>
<dd>Example: <code>mySound.load();</code></dd>
<dd>Example 2: <code>mySound.load({<span>volume:50,onfinish:playNextSound</span>});</code></dd>
</dl>
<dl id="smsound-mute" class="f-block s-mute">
<dt><span>object:SMSound</span> mute()</dt>
<dd>Mutes the given sound. Affects <span>muted</span> property.</dd>
<dd>Example: <code>mySound.mute();</code></dd>
</dl>
<dl id="smsound-onposition" class="f-block s-onposition">
<dt><span>object:SMSound</span> onPosition(<span>msecOffset:integer, callback:function, [scope]</span>)</dt>
<dd>Registers an event listener, fired when a sound reaches or passes a certain position while playing. Position being "listened" for is passed back to event handler. Will also fire if a sound is "rewound" (eg. via <code>setPosition()</code> to an earlier point) and the given position is reached again. Listeners will be removed if a sound is unloaded. An optional scope can be passed as well.</dd>
<dd>Note that for <code>multiShot</code> cases, only the first play instance's <code>position</code> is tracked in Flash; therefore, subsequent "shots" will not have onPosition() events being fired.</dd>
<dd>Example: <code>mySound.onPosition(3000, function(eventPosition){<span>console.log(this.id+' reached '+eventPosition</span>});</code></dd>
<dd>If you need to fire an event relative to the true duration of the sound, reference its duration once the sound has fully-loaded - ie., at or after the <code>onload()</code> event - as the duration will not be completely accurate until that time. <code>durationEstimate</code> may be referenced before <code>onload()</code>, but it should not be relied on when "precise" timings of say, &lt; 1 second are desired.</dd>
<dd>Example:<pre class="block"><code>mySound.load({
onload: function() {
this.onPosition(this.duration * 0.5, function(eventPosition) {
console.log(<span>'the sound '</span> + this.id + <span>' is now at position '</span> + this.position + ' (event position: ' + eventPosition + ')');
});
}
});</code></pre>
</dd>
<dd>Again, note that due to the interval / polling-based methods of both HTML5 and flash audio, sound status updates and thus precision can vary between 20 msec to perhaps 0.5 seconds and the sound's position property will reflect this delta when the <code>onPosition()</code> callback fires.</dd>
</dl>
<dl id="smsound-pause" class="f-block s-pause s-paused">
<dt><span>object:SMSound</span> pause()</dt>
<dd>Pauses the given sound. (Does not toggle.) Affects <span>paused</span> property (boolean.)</dd>
<dd>Example: <code>mySound.pause();</code></dd>
</dl>
<dl id="smsound-play" class="f-block s-play">
<dt><span>object:SMSound</span> play(<span>[options object]</span>)</dt>
<dd>Starts playing the given sound, with an optional options object. (Will start loading if applicable, and will play ASAP.)</dd>
<dd>Note that the <code>options object</code> parameter is not required and can take almost any argument from the object literal format (eg. volume.)</dd>
<dd>Example: <code>mySound.play('<span>mySound</span>',{<span>volume:50,onfinish:playNextSound</span>});</code></dd>
</dl>
<dl id="smsound-setposition" class="f-block s-setposition">
<dt><span>object:SMSound</span> setPosition(<span>msecOffset:integer</span>)</dt>
<dd title="msecOffset:integer">Seeks to a given position within a sound, specified by miliseconds (1000 msec = 1 second.) Affects <span>position</span> property.</dd>
<dd>Example: <code>mySound.setPosition(<span>2500</span>);</code></dd>
<dd>Can only seek within loaded sound data, as defined by the <span>duration</span> property.</dd>
</dl>
<dl id="smsound-resume" class="f-block s-resume">
<dt><span>object:SMSound</span> resume()</dt>
<dd>Resumes the currently-paused sound. Does not affect currently-playing sounds.</dd>
<dd>Example: <code>mySound.resume();</code></dd>
</dl>
<dl id="smsound-setpan" class="f-block s-setpan">
<dt><span>object:SMSound</span> setPan(<span>volume:integer</span>)</dt>
<dd title="volume:integer">Sets the stereo pan (left/right bias) of the given sound. Accepted values: -100 to 100 (L/R, 0 = center.) Affects <span>pan</span> property.</dd>
<dd>Example: <code>mySound.setPan(<span>-80</span>);</code></dd>
</dl>
<dl id="smsound-setvolume" class="f-block s-setvolume">
<dt><span>object:SMSound</span> setVolume(<span>volume:integer</span>)</dt>
<dd title="volume:integer">Sets the volume of the given sound. Accepted values: 0-100. Affects <span>volume</span> property.</dd>
<dd>Example: <code>mySound.setVolume(<span>50</span>);</code></dd>
</dl>
<dl id="smsound-togglemute" class="f-block s-togglemute">
<dt><span>object:SMSound</span> toggleMute()</dt>
<dd>Mutes/unmutes the given sound. Affected <span>muted</span> property (boolean.)</dd>
<dd>Example: <code>mySound.toggleMute();</code></dd>
</dl>
<dl id="smsound-togglepause" class="f-block s-togglepause">
<dt><span>object:SMSound</span> togglePause()</dt>
<dd>Pauses/resumes play of the given sound. Will also start a sound if it is has not yet been played.</dd>
<dd>Example: <code>mySound.togglePause();</code></dd>
</dl>
<dl id="smsound-stop" class="f-block s-stop">
<dt><span>object:SMSound</span> stop()</dt>
<dd>Stops playing the given sound.</dd>
<dd>Example: <code>mySound.stop();</code></dd>
</dl>
<dl id="smsound-unload" class="f-block s-unload">
<dt><span>object:SMSound</span> unload()</dt>
<dd>Stops loading the given sound, canceling any current HTTP request.</dd>
<dd>Example: <code>mySound.unload();</code></dd>
<dd>Note that for Flash 8, SoundManager does this by pointing the sound object to <code>about:blank</code>, which replaces the current one from loading.</dd>
</dl>
<dl id="smsound-unmute" class="f-block s-unmute">
<dt><span>object:SMSound</span> unmute()</dt>
<dd>Unmutes the given sound. Affects <span>muted</span> property.</dd>
<dd>Example: <code>mySound.unmute();</code></dd>
</dl>
</div>
</div>
</div>
<div id="smsoundevents" class="columnar">
<div class="c2">
<div>
<h3>Sound Object Events</h3>
<p class="in">Like native javascript objects, each SoundManager <code>SMSound</code> (sound instance) object can fire a number of <code>onload</code>-like events. Handlers cannot be "directly" assigned (eg. someSound.onload), but can be passed as option parameters to several sound methods.</p>
<div>
<pre class="block"><code>soundManager.play('<span>mySound</span>',{
onfinish: function() {
alert('<span>The sound </span>'+this.id+' <span>finished playing.</span>');
}
});</code></pre>
</div>
<p>Event handlers are scoped to the relevant sound object, so the <code>this</code> keyword will point to the sound object on which the event fired such that its properties can easily be accessed - eg. within an <code>SMSound</code> event handler, <code>this.id</code> will give the sound ID.</p>
</div>
<div style="margin-top:2em">
<dl id="smsound-onbufferchange" class="f-block s-onbufferchange">
<dt class="flash9">onbufferchange()</dt>
<dd>Fires when a sound's reported buffering state has changed while playing and/or loading. The current state is reflected in the boolean <code>isBuffering</code> property.</dd>
<dd>Flash 9+ only. Related information on Adobe, <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/media/Sound.html#isBuffering">Sound.isBuffering</a>.</dd>
</dl>
<dl id="smsound-ondataerror" class="f-block s-ondataerror s-waveformdata s-eqdata">
<dt title="Flash 9+ only" class="flash9">ondataerror()</dt>
<dd>Fires at least once per sound play instance when Flash encounters a security error when trying to call computeSpectrum() internally. This typically happens when sounds are 'inaccessible' due to another Flash movie (eg. YouTube) in another tab which has loaded, and may (or may not be) playing sound. Flash attempts to read the "combined" output to the sound card, and must have security permissions for all sounds as a result. See <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/media/SoundMixer.html#areSoundsInaccessible()">areSoundsInaccessible()</a> on Adobe for more info.</dd>
<dd>If the offending resource causing the security error is closed or becomes inactive(?), the data will become available again. Intermittent availability will result in intermittent calls to <code>ondataerror()</code>.</dd>
</dl>
<dl id="smsound-onbeforefinishcomplete" class="f-block s-onbeforefinishcomplete">
<dt>onbeforefinishcomplete()</dt>
<dd class="deprecation-note"><b>This method has been removed.</b> Use the newer <a href="#smsound-onposition" onclick="resetFilter()">SMSound.onPosition()</a> as a replacement.</dd>
<!--
<dd>Fires when a sound has finished, <code>onfinish()</code> has been called, but before the sound play state and other meta data (position, etc.) are reset.</dd>
-->
</dl>
<dl id="smsound-onbeforefinish" class="f-block s-onbeforefinish">
<dt>onbeforefinish()</dt>
<dd class="deprecation-note"><b>This method has been removed.</b> Use the newer <a href="#smsound-onposition" onclick="resetFilter()">SMSound.onPosition()</a> as a replacement.</dd>
<!--
<dd>Fires when a playing, fully-loaded sound has reached <code>onbeforefinishtime</code> (eg. 5000 msec) from its end.</dd>
-->
</dl>
<dl id="smsound-onconnect" class="f-block s-onconnect flash9">
<dt>onconnect()</dt>
<dd>Fires when a sound using an RTMP <code>serverURL</code> property has attempted to connect, and has either succeeded or failed. Affects <code>connected</code> property. Once connected, a stream can be requested from the RTMP server.</dd>
<dd>Example:
<pre class="block"><code>var s = soundManager.createSound({<span>
id: 'rtmpTest',
serverURL: 'rtmp://localhost/test/',
url: 'song.mp3',
onconnect: function(bConnect) {
<span><span>// <b>this.connected</b> can also be used</span></span>
soundManager._writeDebug(this.id+' connected: '+(bConnect?'true':'false'));
}
</span>}).play();<span><span> // will result in connection being made</span></span></code></pre>
</dd>
</dl>
<dl id="smsound-onfinish" class="f-block s-onfinish">
<dt>onfinish()</dt>
<dd>Fires when a playing sound has reached its end. By this point, relevant properties like <code>playState</code> will have been reset to non-playing status.</dd>
</dl>
<dl id="smsound-onid3" class="f-block s-onid3">
<dt id="onid3">onid3()</dt>
<dd>Fires when ID3 data has been received. Relevant property is <code>id3</code>, which is an object literal (JSON)-style object. Only fields with data will be populated.</dd>
<dd>Note that ID3V2 data is located at the beginning (header) of an MP3 file and will load almost immediately, whereas ID3V1 data is at the end and will not be received until the MP3 has fully loaded.</dd>
<dd>
Example handler code:
<div>
<pre class="block"><code>soundManager._writeDebug(<span>'sound '+this.id+' ID3 data received'</span>);
var prop = null;
var data = '';
for (prop in this.id3) {
data += prop+': '+this.id3[prop]+','; <span><span>// eg. title: Loser, artist: Beck</span></span>
}</code></pre>
</div>
</dd>
<dd>Refer to the <a href="http://livedocs.adobe.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&amp;file=00002676.html" title="Flash 8 Sound.id3 property documentation">Flash 8 Sound.id3</a> documentation for a list of ID3 properties.</dd>
<dd>When parsing ID3 data, it is best to check for the existance of ID3V1 data first, and apply ID3V2 if no matching ID3V1 data is defined. (V1 should "inherit" from V2, ideally, if available.)</dd>
<dd>Note that Flash's cross-domain security restrictions may prevent access to ID3 information, even though the MP3 itself can be loaded. (crossdomain.xml files on the remote host can grant Flash permission to access this.)</dd>
<dd>Also note some <a href="#id3-parsing" onclick="resetFilter()">issues with parsing ID3 from iTunes</a>.</dd>
</dl>
<dl id="smsound-onjustbeforefinish" class="f-block s-onjustbeforefinish">
<dt>onjustbeforefinish()</dt>
<dd class="deprecation-note"><b>This method has been removed.</b> Use the newer <a href="#smsound-onposition" onclick="resetFilter()">SMSound.onPosition()</a> as a replacement.</dd>
<!--
<dd>Fires approximately <code>justbeforefinishtime</code> before the end of a fully-loaded, playing sound.</dd>
<dd>This is based on a polling approach given SM2 must track the sound's position, and is approximated (eg. a 200 msec value may fire at 187 msec before the end of the sound.)</dd>
-->
</dl>
<dl id="smsound-onload" class="f-block s-onload">
<dt>onload(<span>boolean:success</span>)</dt>
<dd>Fires on sound load. Boolean reflects successful load (true), or fail/load from cache (false).</dd>
<dd>False value should seemingly only be for failure, but appears to be returned for load from cache as well. This strange behaviour comes from Flash. More detail may be available from the Flash 8 sound object documentation.</dd>
<dd>Failure can occur if the Flash sandbox (security) model is preventing access, for example loading SoundManager 2 on the local file system and trying to access an MP3 on a network (or internet) URL. (Security can be configured in the Flash security panel, [<a href="#fpgss" title="Configure your Flash player security settings" onclick="resetFilter()">see here</a>].)</dd>
<!-- <dd>Example: <code>soundManager.createSound('<span>mySound</span>','<span>/audio/mysoundfile.mp3</span>');</code></dd> -->
</dl>
<dl id="smsound-onpause" class="f-block s-onpause">
<dt>onpause()</dt>
<dd>Fires when a sound pauses, eg. via <code>sound.pause()</code>.</dd>
<dd>Example: <code>soundManager.pause('<span>mySound</span>');</code></dd>
</dl>
<dl id="smsound-onplay" class="f-block s-onplay">
<dt>onplay()</dt>
<dd>Fires when <code>sound.play()</code> is called.</dd>
</dl>
<dl id="smsound-onresume" class="f-block s-onresume">
<dt>onresume()</dt>
<dd>Fires when a sound resumes playing, eg. via <code>sound.resume()</code>.</dd>
<dd>Example: <code>soundManager.resume('<span>mySound</span>');</code></dd>
</dl>
<dl id="smsound-onsuspend" class="f-block s-onsuspend">
<dt>onsuspend()</dt>
<dd>HTML5-only event: Fires when a browser has chosen to stop downloading of an audio file.</dd>
<dd>Per spec: "The user agent is intentionally not currently fetching media data, but does not have the entire media resource downloaded."</dd>
<dd>One use case may be catching the behaviour where mobile Safari (iOS) will not auto-load or auto-play audio without user interaction, and using this event to show a message where the user can click/tap to start audio.</dd>
<dd>The HTML5 <code>stalled</code> event may also fire in desktop cases and might behave differently across browsers and platforms, so careful testing is recommended.</dd>
</dl>
<dl id="smsound-onstop" class="f-block s-onstop">
<dt>onstop()</dt>
<dd>Fires when <code>sound.stop()</code> is explicitly called. For natural "sound finished" <code>onfinish()</code> case, see below.</dd>
</dl>
<dl id="smsound-whileloading" class="f-block s-whileloading s-bytesloaded s-bytestotal">
<dt>whileloading()</dt>
<dd>Fires at a regular interval when a sound is loading and new data has been received. The relevant, updated property is <code>bytesLoaded</code>.</dd>
<dd>Example handler code: <code>soundManager._writeDebug(<span>'sound '+this.id+' loading, '+this.bytesLoaded+' of '+this.bytesTotal</span>);</code></dd>
<dd>Note that the <code>duration</code> property starts from 0 and is updated during <code>whileloading()</code> to reflect the duration of currently-loaded sound data (ie. when a 4:00 MP3 has loaded 50%, the duration will be reported as 2:00 in milliseconds.) However, an estimate of final duration can be calculated using <code>bytesLoaded</code>, <code>bytesTotal</code> and <code>duration</code> while loading. Once fully-loaded, <code>duration</code> will reflect the true and accurate value.</dd>
</dl>
<dl id="smsound-whileplaying" class="f-block s-whileplaying">
<dt>whileplaying()</dt>
<dd>Fires at a regular interval when a sound is playing, and a position (time) change is detected. The relevant, updated property is <code>position</code>.</dd>
<dd>Example handler code: <code>soundManager._writeDebug(<span>'sound '+this.id+' playing, '+this.position+' of '+this.duration</span>);</code></dd>
</dl>
</div>
</div>
</div>
<div id="sound-object-properties" class="columnar">
<div class="c2">
<div class="f-block">
<h3 id="soundmanager-sound-properties">Sound Object Properties</h3>
<p>Each sound object inherits these properties from soundManager.defaultOptions. They can be set individually or at once when enclosed in object literal form to either <code>createSound()</code> or <code>play()</code>.</p>
</div>
<div style="margin-top:2em">
<dl id="smsound-id" class="f-block s-id">
<dt>id</dt>
<dd>Sound ID string as provided from the <code>id</code> parameter via <code>createSound()</code>. Can be referenced as <code>this.id</code> from within sound object event handlers such as <code>onload()</code>, <code>whileloading()</code> or <code>whileplaying()</code>, etc.</dd>
<dd>If an ID is known, the related SMSound object can be retrieved via <code>getSoundById</code> or directly referencing <code>sounds[id]</code> on the SoundManager global object.</dd>
<dd><b>Legacy note:</b> The sound ID property used to be referenced as <b>sID</b> from within the sound object; this name is maintained for backward compatibility.</dd>
</dl>
<dl id="smsound-url" class="f-block s-url">
<dt>url</dt>
<dd>The specified URL from which the sound is loaded, typically over HTTP. Can be referenced as <code>this.url</code> from within sound object event handlers such as <code>onload()</code> or <code>whileplaying()</code>, etc.</dd>
<dd><b>Experimental feature</b>: Multiple formats/encodings can now be applied to the <code>url</code> parameter by specifying an array instead of a single string.</dd>
<dd>Example:
<pre class="block"><code>soundManager.createSound({<span>
id: 'foo',
url: ['bar.ogg','bar.mp3']
});</span></code></pre></dd>
<dd>SoundManager 2 will use the first playable URL it finds (according to <code>canPlayURL()</code> and/or <code>canPlayType()</code>), and the URL property will then reflect the playable URL after that point. Note that this means the original array data will be lost.</dd>
<dd>In this alternate format, the array accepts "type" attributes.</dd>
<dd>
<pre class="block"><code>soundManager.createSound({<span>
id: 'foo',
<span>// useful for URLs without obvious filetype extensions</span>
url: [
{type:'audio/mp3',url:'/path/to/play.php?song=123'},
{type:'audio/mp4',url:'/path/to/play.php?song=256'}
]
});</span></code></pre></dd>
</dl>
<dl id="smsound-serverurl" class="f-block s-serverurl">
<dt>serverURL</dt>
<dd><b>Note: <em>Experimental feature.</em></b> Only for use with RTMP streaming, ie., Flash Media Server and similar servers.</dd>
<dd>The RTMP server address which Flash will connect to using a <a href="http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/net/NetStream.html" title="NetStream documentation">NetStream</a> object. Only the server address is specified here, when RTMP is in use; the <code>url</code> property is used to point to a specific resource on the server.</dd>
<dd>Example:
<pre class="block"><code>soundManager.createSound({<span>
id: 'mySound',
serverURL: 'rtmp://localhost/rtmpDemo/', <span><span>// RTMP server</span></span>
url: 'mysong.mp3' <span><span>// path to stream</span></span>
}</span>).play();</code></pre></dd>
</dl>
<dl id="smsound-usepolicyfile" class="f-block s-usepolicyfile">
<dt>usePolicyFile</dt>
<dd>Boolean value (default: <code>false</code>) which instructs Flash, when loading MP3/MP4 content from remote/third party domains, to request example.com/crossdomain.xml first in order to determine permissions for access to metadata such as ID3 info, waveform, peak and/or spectrum data.</dd>
<dd><code>usePolicyFile</code> will be automagically set to <code>true</code> if your sound options have an <code>onid3()</code> event handler, or uses sound data (peak/wave/spectrum) features. By default, Flash will not have access to this metadata on remote domains unless granted cross-domain security permissions via the crossdomain.xml file.</dd>
<dd>Consider additional HTTP traffic (albeit, perhaps with caching-like behaviour for subsequent checks?) and silent 404s in most cases given few hosts use crossdomain.xml files.</dd>
<dd>See Adobe's knowledge base for <a href="http://kb2.adobe.com/cps/963/50c96388.html" title="Adobe KB: ID3 does not load on cross-domain MP3s">related ID3 + crossdomain.xml</a> documentation.</dd>
</dl>
</div>
<div style="margin-top:2em">
<div class="f-block">
<h3 id="soundmanager-sound-dynamic-properties">Sound Object Dynamic Properties</h3>
<p>Each sound includes a number of properties that are updated throughout the life of a sound - while loading or playing, for example. Many of these properties have related events that fire when they are updated, and should be treated as read-only.</p>
</div>
<dl id="smsound-buffered" class="f-block s-buffered">
<dt>buffered</dt>
<dd>Based loosely on the native HTML5 attribute, SM2 defines <code>buffered</code> as an array of objects which include <b>start</b> and <b>end</b> position (time) values. This property is updated during the SM2 <code>whileloading</code> event; internally, SM2 uses HTML5's <code>progress</code> event to track changes.</dd>
<dd>It is important to note that the buffered values may not always be contiguous and can change, particularly if the user seeks within the file during downloading. With ranges, you can draw highlighted segments on a progress bar UI which would reflect the current "slices" of buffered data.</dd>
<dd>Example: a <code>buffered</code> array of <code>[{ start: 0, end: 2 }, { start: 5, end: 7 }];</code> shows a sound that has buffered data for the ranges 0-2 seconds, and 5-7 seconds.</dd>
<dd>In order to determine the total buffered data and thus "total percent loaded" under HTML5, you can loop through the <code>buffered</code> array and sum the total of <code>(buffered[i].end - buffered[i].start)</code>. If you want to draw ranges, you can use the start and end values of each buffered item and draw that relative to the total <code>duration</code> (normalized as <code>durationEstimate</code> for flash compatibility).</dd>
<dd>Example:
<pre class="block"><code>var i, total = 0;
for (i=0, j=this.buffered.length; i&lt;j; i++) {
<span><span>// draw current range in progress bar UI?</span></span>
drawProgressUI(this.buffered[i].start, this.buffered[i].end);
<span><span>// sum of all ranges vs. whole file duration</span></span>
total += (this.buffered[i].end - this.buffered[i].start);
}</code></pre>
</dd>
<dd>Note that under Flash, downloading is always sequential and thus the buffered array will always be a single item with <code>start: 0</code> and an <code>end</code> value of <code>duration</code> (eg., the amount of currently-downloaded "time").</dd>
<dd>Additional behaviour note: A browser might download additional bytes of a sound in advance under HTML5, but may only update the buffered state to reflect the newly-downloaded range(s) when the "playback head" reaches near the end of the current buffer. This can also be affected if the user seeks within the file.</dd>
</dl>
<dl id="smsound-bytesloaded" class="f-block s-bytesloaded">
<dt>bytesLoaded</dt>
<dd>The number of bytes currently received while loading a sound.</dd>
</dl>
<dl id="smsound-bytestotal" class="f-block s-bytestotal">
<dt>bytesTotal</dt>
<dd>The total number of bytes to be downloaded, while loading a sound.</dd>
</dl>
<dl id="smsound-didbeforefinish" class="f-block s-didbeforefinish">
<dt>didBeforeFinish</dt>
<dd class="deprecation-note"><b>This property has been removed.</b> Use the newer <a href="#smsound-onposition" onclick="resetFilter()">SMSound.onPosition()</a> as a replacement.</dd>
<!--
<dd>Boolean indicating whether <code>beforeFinish()</code> condition was reached.</dd>
-->
</dl>
<dl id="smsound-didjustbeforefinish" class="f-block s-didjustbeforefinish">
<dt>didJustBeforeFinish</dt>
<dd class="deprecation-note"><b>This property has been removed.</b> Use the newer <a href="#smsound-onposition" onclick="resetFilter()">SMSound.onPosition()</a> as a replacement.</dd>
<!--
<dd>Boolean indicating whether <code>justBeforeFinish()</code> condition was reached.</dd>
-->
</dl>
<dl id="smsound-duration" class="f-block s-duration">
<dt>duration</dt>
<dd>The current length of the sound, specified in milliseconds.</dd>
<dd>Note that during loading, this property reflects the length of downloaded data, not the full length, until completely loaded (see <a href="#smsound-whileloading" onclick="resetFilter()">whileloading()</a>.) For an approximate "full duration" value while loading, see <code>durationEstimate</code>.</dd>
</dl>
<dl id="smsound-durationestimate" class="f-block s-durationestimate">
<dt>durationEstimate</dt>
<dd>The estimated duration of the sound, specified in milliseconds.</dd>
<dd>Due to the dynamic nature of <code>duration</code> while loading, this attempts to provide the full duration by calculating <code>parseInt((self.bytesTotal/self.bytesLoaded)*self.duration)</code> and is updated with each <code>whileloading()</code> interval.</dd>
<dd>(Flash-only): Once the sound has fully loaded (<code>onload()</code> has fired), <code>durationEstimate</code> will be updated with the final, Flash-calculated value of <code>duration</code>.</dd>
<dd>Note that the <code>durationEstimate</code> method works only with Constant Bitrate (CBR)-encoded MP3s due to the consistent data/time assumption. VBR-encoded MP3s will give inaccurate results.</dd>
<dd>HTML5 behaviour: Both <code>duration</code> and <code>durationEstimate</code> are updated at regular intervals during loading of HTML5 audio, directly referencing the duration property provided on the native HTML5 object. Unlike Flash, HTML5 typically gets the true and final duration value by the time playback begins.</dd>
</dl>
<dl id="smsound-eqdata" class="f-block s-eqdata">
<dt title="Flash 9+ only" class="flash9">eqData = {<span>left:[], right: []</span>}</dt>
<dd>Object containing two arrays of 256 floating-point (three decimal place) values from 0 to 1, the result of an FFT on the waveform data. Can be used to draw a spectrum (frequency range) graph while playing a sound. See <a href="../demo/page-player/#debug=1" title="Muxtape.com-style page-as-playlist, with debug output" onclick="checkDomain(this,true)">Page-as-playlist demo</a> for example implementation. Requires Flash 9+.</dd>
<dd>A spectrum frequency graph reflects the level of frequencies being played, from left to right, low to high (i.e., 0 to 20,000 Hz.)</dd>
<dd><code>eqData</code> is set and updated during <code>whileplaying()</code>. A simple graph could be drawn by looping through the values and multiplying by a vertical scale value (eg. 32, thus a graph with peaks of 32 pixels.)</dd>
<dd>Example code:
<pre class="block"><code>someSoundObject.whileplaying = function() {<span>
<span>// Move 256 absolutely-positioned 1x1-pixel DIVs, for example (ugly, but works)</span>
var gPixels = document.getElementById('graphPixels').getElementsByTagName('div');
var gScale = 32; <span>// draw 0 to 32px from bottom</span>
for (var i=0; i&lt;256; i++) {
graphPixels[i].style.top = (32-(gScale+Math.ceil(this.waveformData.left[i]*gScale)))+'px';
}
</span>}</code></pre>
</dd>
<dd>Related Adobe technical documentation (Flash 9/AS3 Sound() object): <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/media/SoundMixer.html#computeSpectrum()" title="Adobe Flash 9, sound object documentation">computeSpectrum()</a></dd>
<dd><strong>Note</strong>: Flash security measures may deny access to waveformData when loading MP3s from remote domains.</dd>
<dd><strong>Warning:</strong> This feature can eat up a lot of CPU in some cases. The amount of data passed from Flash to JS is not terribly large, but the JS-DOM updates and browser reflow can be expensive. Use with caution.</dd>
<dd><strong>Backward compatibility note:</strong> Up to SoundManager 2.95a.20090717, eqData was a single array containing one channel of data. In newer versions this is unchanged, except the array now has .left[] and .right[] objects attached to it. To ensure future compatibility, use eqData.left[0] instead of eqData[0] and so on.</dd>
</dl>
<dl id="smsound-id3" class="f-block s-id3">
<dt>id3</dt>
<dd>An object literal populated, if applicable, when ID3 data is received (related handler: <code>onid3()</code>)</dd>
<dd>For property details, see <a href="#onid3" title="onid3() documentation" onclick="resetFilter()">onid3()</a>.</dd>
</dl>
<dl id="smsound-isbuffering" class="f-block s-isbuffering">
<dt class="flash9">isBuffering</dt>
<dd>Boolean value reflecting the buffering state of a playing or loading object. To be notified when this property changes, see <a href="#smsound-onbufferchange" onclick="resetFilter()">onbufferchange()</a>.</dd>
<dd>Flash 9+ only. Related information on Adobe, <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/media/Sound.html#isBuffering">Sound.isBuffering</a>.</dd>
</dl>
<dl id="smsound-ishtml5" class="f-block s-ishtml5">
<dt>isHTML5</dt>
<dd>Boolean property indicating whether a sound object is using HTML5 Audio for playback. Treat as read-only.</dd>
<dd>This should not really be relied on for anything, but it is provided as an indicator of support on a per-sound basis.</dd>
<dd><code>isHTML5</code> is set based on the URL provided to <code>createSound()</code>, and is updated when the URL changes.</dd>
</dl>
<dl id="smsound-connected" class="f-block s-connected">
<dt class="flash9">connected</dt>
<dd>Boolean value reflecting the state of an RTMP server connection (when <code>serverURL</code> is used to connect to a Flash Media Server or similar RTMP service.) Calls to <code>load</code> or <code>play</code> will result in a connection attempt being made, and <code>onconnect()</code> ultimately being called.</dd>
<dd>For example code using <code>connected</code>, see <a href="#smsound-onconnect" onclick="resetFilter()">onconnect()</a>.</dd>
</dl>
<dl id="smsound-loaded" class="f-block s-loaded">
<dt>loaded</dt>
<dd>Boolean value indicating load success as returned from Flash. True indicates success, False is a failure.</dd>
<dd>Because of the potential for false positives, <code>duration</code> and other properties could be checked as a test of whether sound data actually loaded. For more granular state information, see <a href="#readystate" title="SMSound readyState documentation" onclick="resetFilter()">readyState</a>.</dd>
</dl>
<dl id="smsound-muted" class="f-block s-muted">
<dt>muted</dt>
<dd>Boolean indicating muted status. True/False.</dd>
<dd>Treat as read-only; use <code>mute()</code>, <code>unmute()</code> and <code>toggleMute()</code> methods to affect state.</dd>
</dl>
<dl id="smsound-paused" class="f-block s-paused">
<dt>paused</dt>
<dd>Boolean indicating pause status. True/False.</dd>
<dd>Treat as read-only; use <code>pause()</code>, <code>resume()</code> and <code>togglePause()</code> methods to affect state.</dd>
</dl>
<dl id="smsound-peakdata" class="f-block s-peakdata">
<dt title="Flash 9+ only" class="flash9">peakData = {<span>left:0.0, right:0.0</span>}</dt>
<dd>Object literal format including <code>left</code> and <code>right</code> properties with floating-point values ranging from 0 to 1, indicating "peak" (volume) level. Updated during <code>whileplaying()</code>. See <a href="../demo/page-player/#debug=1" title="Muxtape.com-style page-as-playlist, with debug output" onclick="checkDomain(this,true)">Page-as-playlist demo</a> as one example. Requires Flash 9+.</dd>
<dd>Example (within relevant sound object handler):
<pre class="block"><code>someSoundObject.whileplaying = function() {<span>
soundManager._writeDebug('Peaks, L/R: '+this.peakData.left+'/'+this.peakData.right);
</span>}</code></pre></dd>
</dl>
<dl id="smsound-playstate" class="f-block s-playstate">
<dt>playState</dt>
<dd>Numeric value indicating the current playing state of the sound.</dd>
<dd>0 = stopped/uninitialised</dd>
<dd>1 = playing <em>or</em> buffering sound (play has been called, waiting for data etc.)</dd>
<dd>Note that a 1 may not always guarantee that sound is being heard, given buffering and autoPlay status.</dd>
</dl>
<dl id="smsound-position" class="f-block s-position">
<dt>position</dt>
<dd>The current location of the "play head" within the sound, specified in milliseconds (1 sec = 1000 msec).</dd>
</dl>
<dl id="smsound-readystate" class="f-block s-readystate s-onload">
<dt id="readystate">readyState</dt>
<dd>Numeric value indicating a sound's current load status</dd>
<dd>0 = uninitialised</dd>
<dd>1 = loading</dd>
<dd>2 = failed/error</dd>
<dd>3 = loaded/success</dd>
<dd>Under Flash, <code>readyState</code> will move from 0 to 1, and then change to 3 when the sound's <code>onload()</code> event fires (and all bytes have loade.)</dd>
<dd>Under HTML5, <code>readyState</code> will move from 0 to 1 when initializing the HTTP request (from <code>load()</code>), and will quickly change to 3 when the sound is ready to play. Note that HTML5 is buffer-based and <code>onload()</code> means "enough audio data has buffered to begin playback".</dd>
</dl>
<dl id="smsound-type" class="f-block s-type">
<dt>type</dt>
<dd>A MIME type-like string eg. <code>audio/mp3</code>, used as a hint for SM2 to determine playability of a link with methods like <code>canPlayURL()</code>.</dd>
<dd>This can be helpful when you have a sound URL that does not have an .mp3 extension, but serves MP3 data (eg., a PHP or other CGI script.)</dd>
<dd>Example:
<pre class="block"><code>var s = soundManager.createSound({<span>
id: 'aSound',
url: '/path/to/some.php?songID=123',
type: 'audio/mp3' <span><span>// indicates an MP3 link, so SM2 can handle it appropriately</span></span>
</span>});</code></pre></dd>
</dl>
<dl id="smsound-waveformdata" class="f-block s-waveformdata">
<dt title="Flash 9+ only" class="flash9">waveformData = {<span>left:[], right:[]</span>}</dt>
<dd>Array of 256 floating-point (three decimal place) values from -1 to 1, can be used to draw a waveform while playing a sound. See <a href="../demo/page-player/#debug=1" title="Muxtape.com-style page-as-playlist, with debug output" onclick="checkDomain(this,true)">Page-as-playlist demo</a> for example implementation. Requires Flash 9+.</dd>
<dd><code>waveformData</code> is set and updated during <code>whileplaying()</code>. A simple graph could be drawn by looping through the values and multiplying by a vertical scale value (eg. 32, which would make a graph with peaks of -32 and +32 pixels.)</dd>
<dd>Example code:
<pre class="block"><code>someSoundObject.whileplaying = function() {<span>
<span>// Move 256 absolutely-positioned 1x1-pixel DIVs, for example (ugly, but works)</span>
var gPixels = document.getElementById('graphPixels').getElementsByTagName('div');
var gScale = 32; <span>// draw -32 to +32px from "zero" (i.e., center Y-axis point)</span>
for (var i=0; i&lt;256; i++) {
graphPixels[i].style.top = (gScale+Math.ceil(this.waveformData.left[i]*-gScale))+'px';
}
</span>}</code></pre>
</dd>
<dd><strong>SM2 implementation note</strong>: <code>waveformData</code> contains both left and right channels, and the data represents a raw sound wave rather than a frequency spectrum.</dd>
<dd>Related Adobe technical documentation (Flash 9/AS3 Sound() object): <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/media/SoundMixer.html#computeSpectrum()" title="Adobe Flash 9, sound object documentation">computeSpectrum()</a></dd>
<dd><strong>Note</strong>: Flash security measures may deny access to waveformData when loading MP3s from remote domains.</dd>
<dd><strong>Warning:</strong> This feature can eat up a lot of CPU in some cases. The amount of data passed from Flash to JS is not terribly large, but the JS-DOM updates and browser reflow can be expensive. Use with caution.</dd>
</dl>
</div>
</div>
</div>
<div id="smsound-methods" class="columnar">
<div class="c2">
<div class="f-block">
<h3>SMSound Object Methods</h3>
<p class="in">SoundManager provides wrappers for most SMSound methods - eg. <code>soundManager.play('<span>mySound</span>')</code> checks for a valid sound object, and then calls <code>soundManager.sounds['<span>mySound</span>'].play()</code> on that particular object; thus, it is the same as <code>var sound = soundManager.getSoundById('mySound'); mySound.play();</code></p>
<p>The following methods can be called directly on a SMSound instance. The method calls are the same as the SoundManager global methods documented above for existing sound objects, minus the sound ID parameter.</p>
</div>
<div class="f-block"> <!-- s-play s-setposition s-pause s-resume s-togglepause s-mute s-setvolume s-setpan s-stop s-unload s-destruct -->
<dl class="tight">
<dt>destruct() <span class="archive">(also called via <a href="#soundmanager-destroysound" onclick="resetFilter()">soundManager.destroySound()</a>)</span></dt>
<dt><a href="#smsound-load" onclick="resetFilter()">load()</a></dt>
<dt><a href="#smsound-mute" onclick="resetFilter()">mute()</a></dt>
<dt><a href="#smsound-pause" onclick="resetFilter()">pause()</a></dt>
<dt><a href="#smsound-play" onclick="resetFilter()">play(<span>[options object]</span>)</a></dt>
<dt><a href="#smsound-resume" onclick="resetFilter()">resume()</a></dt>
<dt><a href="#smsound-setposition" onclick="resetFilter()">setPosition(<span>msecOffset:integer</span>)</a></dt>
<dt><a href="#smsound-togglepause" onclick="resetFilter()">togglePause()</a></dt>
<dt><a href="#smsound-setvolume" onclick="resetFilter()">setVolume(<span>volume:integer</span>)</a></dt>
<dt><a href="#smsound-setpan" onclick="resetFilter()">setPan(<span>pan:integer</span>)</a></dt>
<dt><a href="#smsound-stop" onclick="resetFilter()">stop()</a></dt>
<dt><a href="#smsound-unload" onclick="resetFilter()">unload()</a></dt>
<dt><a href="#smsound-unmute" onclick="resetFilter()">unmute()</a></dt>
</dl>
</div>
</div>
</div>
<!-- options -->
<div id="smdefaults" class="columnar">
<div class="c2">
<div class="f-block f-defaultoptions s-autoload s-buffertime s-loops s-stream s-onbeforefinish s-onbeforefinishtime s-onjustbeforefinishtime s-multishot s-multishotevents s-from s-to s-pan s-volume">
<h3 id="sound-properties">SoundManager: Default Sound Options</h3>
<p>Sound objects inherit properties from <code>soundManager.defaultOptions</code> when they are created.</p>
<p>Sound parameters can be overridden on a per-sound basis at create time, or changed dynamically in some cases. Note that none of these options are required when calling <code class="in">createSound()</code> except for <code>id</code> and <code>url</code>; the others will inherit the default values if unspecified.</p>
<p><code class="in">soundManager.defaultOptions</code> apply the properties and event handlers as specified above. Defaults are shown below as an example.</p>
<pre class="small block"><code>soundManager.defaultOptions = {<span>
autoLoad: false, <span>// enable automatic loading (otherwise .load() will call with .play())</span>
autoPlay: false, <span>// enable playing of file ASAP (much faster if "stream" is true)</span>
from: null, <span>// position to start playback within a sound (msec), see <a href="../demo/api/#fitter-happier">demo</a></span>
loops: 1, <span>// number of times to play the sound. Related: <a href="../demo/api/#looping">looping</a> (API demo)</span>
multiShot: true, <span>// let sounds "restart" or "chorus" when played multiple times..</span>
multiShotEvents: false, <span>// allow events (onfinish()) to fire for each shot, if supported.</span>
onid3: null, <span>// callback function for "ID3 data is added/available"</span>
onload: null, <span>// callback function for "load finished"</span>
onstop: null, <span>// callback for "user stop"</span>
onfinish: null, <span>// callback function for "sound finished playing"</span>
onpause: null, <span>// callback for "pause"</span>
onplay: null, <span>// callback for "play" start</span>
onresume: null, <span>// callback for "resume" (pause toggle)</span>
position: null, <span>// offset (milliseconds) to seek to within downloaded sound.</span>
pan: 0, <span>// "pan" settings, left-to-right, -100 to 100</span>
stream: true, <span>// allows playing before entire file has loaded (recommended)</span>
to: null, <span>// position to end playback within a sound (msec), see <a href="../demo/api/#fitter-happier">demo</a></span>
type: null, <span>// MIME-like hint for canPlay() tests, eg. 'audio/mp3'</span>
usePolicyFile: false, <span>// enable crossdomain.xml request for remote domains (for ID3/waveform access)</span>
volume: 100, <span>// self-explanatory. 0-100, the latter being the max.</span>
whileloading: null, <span>// callback function for updating progress (X of Y bytes received)</span>
whileplaying: null, <span>// callback during play (position update)</span>
<span>// see optional <a href="#sound-properties-flash9" title="SoundManager 2: Additional Flash 9-based options">flash 9-specific options</a>, too</span>
</span>}
</code></pre>
<p class="in">As a simple example, the following code would override the default <code>autoPlay</code>, <code>pan</code> and <code>volume</code> options for a given sound:</p>
<pre class="block"><code>soundManager.createSound({
<span>url: '/path/to/some.mp3',
autoPlay: true,
pan: -75,
volume: 50</span>
});</code></pre>
<p class="alternate"><em>Note</em>: For live examples, see the code behind the "<a href="../demo/page-player/" title="muxtape-style page as playlist demo" onclick="checkDomain(this)">page as playlist</a>" demo which uses much of this functionality.</p>
</div>
<div class="f-block f-defaultoptions f-flash9options f-moviestaroptions s-ismoviestar s-usepeakdata s-usewaveformdata s-useeqdata">
<h3 id="sound-properties-flash9" title="Flash 9-only" class="flash9">Sound Properties Object: Version-specific Options (Merging)</h3>
<p>Some sound properties object items (eg. <code class="in">usePeakData</code>) are flash version-specific, non-default and are intentionally separated from <code class="in">soundManager.defaultOptions</code>. Flash 9-specific options fall under this category.</p>
<p><code class="in">soundManager.flash9Options</code> and <code class="in">soundManager.movieStarOptions</code> are both defined as separate objects, and if supported according to <code class="in">flashVersion</code> and <code class="in">defaultOptions</code> parameters, are merged at the property level into <code class="in">soundManager.defaultOptions</code>.</p>
<pre class="small block"><code><span><span>// Note: These are merged into soundManager.defaultOptions when <a href="#soundmanager-flashversion" title="soundManager.flashVersion parameter" onclick="resetFilter()">flashVersion</a> = 9.</span></span>
soundManager.flash9Options = {<span>
isMovieStar: null, <span>// "MovieStar" MPEG4 audio mode. Null (default) = auto detect MP4, AAC etc. based on URL. true = force on, ignore URL</span>
usePeakData: false, <span>// enable left/right channel peak (level) data</span>
useWaveformData: false, <span>// enable sound spectrum (raw waveform data) - WARNING: May set CPUs on fire.</span>
useEQData: false, <span>// enable sound EQ (frequency spectrum data) - WARNING: Also CPU-intensive.</span>
onbufferchange: null, <span>// callback for "isBuffering" property change</span>
ondataerror: null <span>// callback for waveform/eq data access error (flash playing audio in other tabs/domains)</span>
</span>}
soundManager.movieStarOptions = {<span>
bufferTime: null <span>// seconds of data to buffer (null = flash default of 0.1 - if AAC gappy, try up to 3 seconds)</span>
</span>}
<span><span>// when merged, soundManager.flash9Options.isMovieStar -&gt; soundManager.defaultOptions.isMovieStar, etc.</span></span></code></pre>
</div>
</div>
</div>
<div id="soundmanager2-dynamic-properties" class="columnar">
<div class="c2">
<div class="f-block f-html5 f-html5only f-features f-waveformdata f-peakdata">
<h3 id="soundmanager-dynamic">SoundManager Dynamic (Runtime) Properties</h3>
<p class="in">Some properties are dynamic, determined at initialisation or later during runtime, and should be treated as read-only.</p>
<h4 id="soundmanager-features">soundManager.features Object</h4>
<p class="in">As certain sound functionality is only available beginning with Flash 9, <code>soundManager.features</code> can provide a consistent way of checking for feature support.</p>
<p>The structure (intended as read-only) is currently as follows:</p>
<pre class="block"><code>soundManager.features = {<span>
buffering: <span>[boolean]</span>,
peakData: <span>[boolean]</span>,
waveformData: <span>[boolean]</span>,
eqData: <span>[boolean]</span>,
movieStar: <span>[boolean]</span>
</span>}</code></pre>
<p class="in">Example (checking for <code>peakData</code> support):</p>
<pre class="block"><code>if (<span>soundManager.features.peakData</span>) {<span>
<span>// do peak data-related things here</span>
</span>}</code></pre>
<p class="in">The features object is populated at initialisation time; the current feature support tests simply check the value of <code>soundManager.flashVersion</code> being &gt;= 9. This object has been added in anticipation of additional features with future versions of Flash.</p>
</div>
<h4 id="soundmanager-html5only">soundManager.html5Only [boolean, read-only]</h4>
<p>This property is set during initialization and reflects whether SM2 is running in "100% HTML5 mode", based on support for required formats defined by <code>soundManager.audioFormats</code>.</p>
</div>
</div>
<div id="soundmanager-events" class="columnar">
<div class="c2">
<div class="f-block f-onload f-onerror f-oninitmovie">
<h3>SoundManager Core Events</h3>
<p class="in">The following events are attached to the <code>soundManager</code> global object and are useful for detecting the success/failure of the API's initialisation.</p>
<p>Keep in mind that these core events are effectively asynchronous (ie., they may fire long before or after <code class="in">window.onload()</code>) and therefore should not be relied on as the "ready" event for starting your application. Use the standard "DOM content loaded" or window load events for your own initialization routines.</p>
<dl>
<dt title="method(object:function)">onready(<span>callback:function(status),[scope]</span>)</dt>
<dd title="callback:function">Queue <code>onload()</code>-style event listener(s), triggered when soundManager has successfully started.</dd>
<dd>Example: <code>soundManager.onready(<span>myOnReadyHandler</span>); soundManager.onready(<span>myOtherHandler</span>);</code></dd>
<dd>For more detail and examples, see <a href="#soundmanager-onready" onclick="resetFilter()">soundManager.onready()</a>.</dd>
<dt title="method(object:function)">ontimeout(<span>callback:function(status),[scope]</span>)</dt>
<dd title="callback:function">Queue <code>onload()</code>-style event listener(s), triggered when soundManager has successfully started.</dd>
<dd>Example: <code>soundManager.ontimeout(<span>myOnTimeoutHandler</span>); soundManager.ontimeout(<span>myOtherHandler</span>);</code></dd>
<dd>For more detail and examples, see <a href="#soundmanager-ontimeout" onclick="resetFilter()">soundManager.ontimeout()</a>.</dd>
<dt id="soundmanager-onerror" title="object:function">onerror(status)</dt>
<dd class="deprecation-note"><b>Deprecation note:</b> Use the newer <a href="#soundmanager-ontimeout" onclick="resetFilter()">soundManager.ontimeout()</a> instead of this method.</dd>
<!--
<dd>Function called when SoundManager fails to successfully initialise after Flash attempts an init call via ExternalInterface.</dd>
<dd>Example: <code>soundManager.onerror = <span>function(status) { alert('SoundManager failed to load: ' + status.type); }</span></code></dd>
<dd>This handler should be called if there is an ExternalInterface problem or other exceptions that fire when the initialisation function is called.</dd>
<dd>If a specific type of error occurred, it will be provided in the status object as a <code>type</code> parameter.</dd>
<dd>If you want multiple listeners for this event, see <a href="#soundmanager-ontimeout" onclick="resetFilter()">soundManager.ontimeout()</a>.</dd>
-->
<dt id="soundmanager-oninitmovie" title="object:function">oninitmovie()</dt>
<dd class="deprecation-note"><b>Deprecation note:</b> Use the newer <a href="#soundmanager-ontimeout" onclick="resetFilter()">soundManager.ontimeout()</a> instead of this method.</dd>
<!--
<dd>Function called immediately after the SWF is either written to (or retrieved from) the DOM as part of the start-up process. This event can be useful if you wish to implement your own start-up time-out, eg. for handling flash blockers, start-up failures or other custom messaging.</dd>
<dd>Example: <code>soundManager.oninitmovie = <span>function(){ alert('SWF init.'); }</span></code></dd>
-->
<dt id="soundmanager-onload" title="object:function">onload()</dt>
<dd class="deprecation-note"><b>Deprecation note:</b> Use the newer <a href="#soundmanager-onready" onclick="resetFilter()">soundManager.onready()</a> instead of this method.</dd>
<!--
<dd>Function called when SoundManager has successfully loaded.</dd>
<dd>Example: <code>soundManager.onload = <span>function() { alert('SoundManager ready to use'); }</span></code></dd>
<dd>Once this function has been called, all core methods will be available to use.</dd>
<dd>Note that <code>onload()</code> is not called when SoundManager fails to load; instead, <code>onerror()</code> is called.</dd>
<dd>If you want multiple listeners for this event, see <a href="#soundmanager-onready" onclick="resetFilter()">soundManager.onready()</a>.</dd>
-->
</dl>
</div>
</div>
</div>
<div class="columnar">
<div class="c2">
<div class="f-block">
<h3>SoundManager Object Collections</h3>
<dl>
<dt title="object:array">soundIDs[]</dt>
<dd>An array of sound ID strings, ordered by creation. Can be used to iterate through <code>sounds{}</code> by ID.</dd>
<dt title="object:array">sounds{}</dt>
<dd>An object literal/JSON-style instance of <code>SMSound</code> objects indexed by sound ID (as in <code>sounds['mySound']</code> or <code>sounds.mySound</code>), used internally by SoundManager. <code>soundManager.getSoundById()</code> may be used as an alternate to directly accessing this object.</dd>
</dl>
</div>
</div>
</div>
<div id="sound-options-object" class="columnar">
<div class="c2">
<div class="f-block s-onload"> <!-- f-createsound s-id s-url s-autoload s-autoplay s-onload -->
<h3 id="object-literal-format">Object Literal Format</h3>
<p>Sounds can be created with instance-specific parameters in an object literal (JSON) format, where omitted parameters inherit default values as defined in soundManager.</p>
<pre class="block"><code>soundManager.createSound({<span>
id: 'mySound',
url: '/path/to/some.mp3',
autoLoad: true,
autoPlay: false,
onload: function() {
alert('The sound '+this.id+' loaded!');
},
volume: 50
</span>});</code></pre>
<p>This object can also be passed as an optional argument to the <code class="in">play</code> method, overriding options set at creation time.</p>
<p>For a full list of available options, see <a href="#sound-properties" title="SoundManager 2 API info: Sound Properties" onclick="resetFilter()">Sound Properties Object</a></p>
</div>
</div>
</div>
<!-- /main -->
</div>
<!-- /main-wrapper -->
</div>
<!-- /content -->
</div>
<script type="text/javascript">
init();
</script>
</body>
</html>