1687 lines
109 KiB
HTML
1687 lines
109 KiB
HTML
<!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.useFlashBlock = false;
|
|
soundManager.debugMode = false;
|
|
soundManager.url = '../swf/';
|
|
soundManager.onload = function() {
|
|
}
|
|
</script>
|
|
</head>
|
|
|
|
<body id="doc">
|
|
|
|
<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/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° 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>
|
|
<li><a href="../demo/template/">Basic Template</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>
|
|
</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/#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" class="triple">
|
|
|
|
|
|
<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="c1">
|
|
<h2>SoundManager Configuration</h2>
|
|
<p>Flash URLs, version + performance options</p>
|
|
</div>
|
|
<div class="c2">
|
|
|
|
<h3>SoundManager Properties</h3>
|
|
|
|
<div class="f-block f-useconsole f-consoleonly f-waitforwindowload f-allowpolling f-nullurl f-usemoviestar f-allowscriptaccess">
|
|
|
|
<p class="in">SoundManager has properties which configure debug mode, flash movie path and other behaviours. At minimum, the <code>soundManager.url</code> property must be assigned a path used to look for the necessary flash movie.</p>
|
|
|
|
<pre class="small block specialcommentblock"><code><span>allowPolling = true; <span>// enable flash status updates. Required for whileloading/whileplaying.</span>
|
|
consoleOnly = false; <span>// if console is being used, do not create/write to #soundmanager-debug</span>
|
|
debugMode = true; <span>// enable debugging output (div#soundmanager-debug, OR console..)</span>
|
|
debugFlash = false; <span>// enable debugging output inside SWF, troubleshoot Flash/browser issues</span>
|
|
flashLoadTimeout = 1000; <span>// ms to wait for flash movie to load before failing (0 = infinity)</span>
|
|
flashVersion = 8; <span>// version of flash to require, either 8 or 9. Some features require 9.</span>
|
|
nullURL = 'about:blank'; <span>// (Flash 8 only): URL of silent/blank MP3 for unloading/stop request.</span>
|
|
url = '/path/to/swfs/'; <span>// path (directory) where SM2 .SWF files will be found.</span>
|
|
useConsole = true; <span>// use firebug/safari console.log()-type debug console if available</span>
|
|
useMovieStar = true; <span>// enable <a href="http://www.adobe.com/support/documentation/en/flashplayer/9/releasenotes.html#fixes_90115">Flash 9.0r115+</a> MPEG4 audio support</span>
|
|
useFastPolling = false; <span>// fast timer=higher callback frequency, combine w/useHighPerformance</span>
|
|
flashPollingInterval = null; <span>// Frequency for Flash. Default = 50 unless useFastPolling = true.</span>
|
|
useHighPerformance = false;<span>// position:fixed flash movie for faster JS/flash callbacks</span>
|
|
waitForWindowLoad = false; <span>// always delay soundManager.onload() until after window.onload()</span>
|
|
wmode = 'transparent'; <span>// null, transparent, opaque (last two allow HTML on top of flash)</span>
|
|
allowScriptAccess = 'always'; <span>// for scripting SWF (object/embed prop.), 'always' or 'sameDomain'</span>
|
|
useFlashBlock = true; <span>// better handling of SWF if load fails, let user unblock. See <a href="../demo/flashblock/" title="SoundManager 2 flash block demo">demo</a>.</span>
|
|
useHTML5Audio = false; <span>// <a href="#soundmanager-usehtml5audio">beta feature</a>: Use HTML5 Audio() where supported.</span>
|
|
</span></code></pre>
|
|
<p>To modify global SoundManager default parameters for SM2 itself or for all sound objects, edit the main soundmanager2.js file (look for above section in code) or assign new values in your own application script before either <code class="in">onDOMContentLoaded()</code> or <code class="in">window.onload()</code> fire. (Specifically, both external and inline script blocks which immediately execute are OK.)</p>
|
|
<p>Example per-application override:</p>
|
|
<pre class="block"><code><span>soundManager.debugMode = false; <span>// disable debug mode</span>
|
|
soundManager.defaultOptions.volume = 33; <span>// set global default volume for all sound objects</span>
|
|
</span></code></pre>
|
|
|
|
</div>
|
|
|
|
<div class="f-block f-debugmode">
|
|
<h4 id="soundmanager-debugmode">soundManager.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-debugflash">
|
|
<h4 id="soundmanager-debugflash">soundManager.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-url">
|
|
<h4 id="soundmanager-url">soundManager.url</h4>
|
|
<p class="in"><code>soundManager.url</code> specifies the "online", generally HTTP-based path which SM2 will load .SWF movies from. The "local" (current) directory 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.url = '/path/to/swfs/';</code> (Note trailing slash)</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-alturl">
|
|
<h4 id="soundmanager-alturl">soundManager.altURL</h4>
|
|
<p class="in"><code>soundManager.altURL</code> specifies an alternate path to <code>soundManager.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.url</code> will be used for all cases.</p>
|
|
</div>
|
|
|
|
<div class="f-block f-flashversion">
|
|
|
|
<h4 id="soundmanager-flashversion">soundManager.flashVersion</h4>
|
|
|
|
<p class="in">SoundManager 2 started with a Flash 8 base requirement, but can also now use Flash 9 and take advantages of some new 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.flashVersion = 9;</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>New 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">soundManager.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-usefastpolling f-usehighperformance f-flashpollinginterval">
|
|
<h4 id="soundmanager-usefastpolling">soundManager.useFastPolling</h4>
|
|
<p>By default <code>useFastPolling = false</code>, and thus SoundManager uses a 20-milisecond 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 1-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-flashpollinginterval f-usefastpolling f-usehighperformance">
|
|
<h4 id="soundmanager-flashpollinginterval">soundManager.flashPollingInterval</h4>
|
|
<p>Setting this will override <code>useFastPolling</code>. E.g. set this to 200 to have 200ms intervals. This is useful in case your callbacks are CPU intensive.</p>
|
|
</div>
|
|
|
|
<div class="f-block f-usehighperformance f-usefastpolling f-flashpollinginterval">
|
|
<h4 id="soundmanager-highperformance">soundManager.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">soundManager.useHighPerformance</code> is enabled and should 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.useHighPerformance = true;</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-useflashblock">
|
|
<h4 id="soundmanager-useflashblock" title="Recently-added feature" class="recent">soundManager.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="block"><code>#sm2-container {
|
|
<span><span>/* Initial 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 for some reason.
|
|
(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-usehtml5audio">
|
|
|
|
<h4 id="soundmanager-usehtml5audio">soundManager.useHTML5Audio</h4>
|
|
|
|
<p><em><b style="color:#993333">Warning: Beta-ish, in-progress feature</b>; subject to bugs, API changes etc. By default, special check to enable feature for the Apple iPad 3.2+ (which does not support Flash) and Palm Pre, otherwise currently disabled by default. Works on iPhone OS 4.0 / iOS 4.0+.</em></p>
|
|
<p>Determines whether HTML5 <code>Audio()</code> support is used to play sound, if available, with Flash as the fallback for playing MP3/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.)</p>
|
|
|
|
<h5>SoundManager 2 + useHTML5Audio: Init Process</h5>
|
|
|
|
<p>At DOM ready (if useHTML5Audio = true), 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 none of the "required" formats (MP3 + MP4, by default) are supported natively, then Flash is also added as a requirement for SM2 to start.</p>
|
|
<p><code>soundManager.audioFormats</code> currently 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 would not play them inline.</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; by default, SoundManager 2 will only assume a format is supported if a "probably" response is given. You can modify <code>soundManager.html5Test</code> to something like <code>/(probably|maybe)/i</code> if you want to be a bit riskier, but you should consider potential false positives.</p>
|
|
|
|
<p>At this time, only Safari and Chrome (excluding Chromium?) support MP3 and MP4 formats. Other browsers have excluded them because MP3 and MP4 are not "free" formats. For these cases, Flash is used as the fallback support for MP3/MP4 as needed.</p>
|
|
|
|
<h5>Bonus HTML5 formats: OGG, WAV</h5>
|
|
|
|
<p>WAVe (an old standard) and OGG (a MP3-like codec, except free) 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.</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><a></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 < 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&view=article&id=1741&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>
|
|
|
|
|
|
<div id="html5-knownissues">
|
|
|
|
<h5>HTML5 Audio: Notes, bugs, quirks and annoyances</h5>
|
|
|
|
<p>As of the January, 2011 (V2.97a.20110101) and December, 2010 releases of SM2 (V2.97a.20101221):</p>
|
|
<ul>
|
|
<li>The <code>bytesLoaded</code> and <code>bytesTotal</code> properties may become less-relevant under HTML5 due to non-linear HTTP downloading (using ranges and partials), but they are still provided under Firefox at this time.</li>
|
|
<li>Related to bytes loading/total, a sound's <code>onload</code> event may not always be fired (Mozilla currently discourage use of the DOM <code>loaded</code> event), again because of range requests and the ability to arbitrarily seek within a file.</li>
|
|
<li>Basic support for the W3 <code>TimeRanges</code> implementation of sound buffering (ie., loaded data) has been implemented. This gives an idea of "total time loaded", but again, is not necessarily sequential.</li>
|
|
<li>HTML5 audio is disabled for all versions of Safari (4 and 5) on Snow Leopard (OS X 10.6.3 - 10.6.5) until Apple fixes issues with audio loading and playback due to bugs in "underlying frameworks." See <a href="https://bugs.webkit.org/show_bug.cgi?id=32159#c9" title="Safari Snow Leopard HTML5 Audio Bug">Webkit #32159</a>. HTML5 audio in Safari on Windows (provided QuickTime is installed) does not have the same fatal bug.</li>
|
|
</ul>
|
|
|
|
<p>As of the October, 2010 release of SM2 (V2.97a.20101010):</p>
|
|
<ul>
|
|
<li>HTML5 audio is disabled for all versions of Safari (4 and 5) on Snow Leopard (OS X 10.6.3 and 10.6.4) until Apple fixes issues with audio loading and playback due to bugs in "underlying frameworks." See <a href="https://bugs.webkit.org/show_bug.cgi?id=32159#c9" title="Safari Snow Leopard HTML5 Audio Bug">Webkit #32159</a>.</li>
|
|
</ul>
|
|
|
|
<p>As of the August, 2010 release of SM2 (V2.96a.20100822):</p>
|
|
<ul>
|
|
<li>Safari 5.0.1 (533.17.18) on Snow Leopard (10.6.x) continues to show buggy HTML5 audio load/playback behaviour. Apple are aware of the regression, which began with Safari 4.0 on Snow Leopard (perhaps with the new QuickTime.) See <a href="https://bugs.webkit.org/show_bug.cgi?id=32159#c9" title="Safari Snow Leopard HTML5 Audio Bug">Webkit #32159</a>.</li>
|
|
<li>iPad/iPhone iOS4 will now play a sequence of sounds if using <code>onfinish()</code> to create/start the next (eg., the Muxtape-style playlist on the SM2 homepage will play through once the user starts it.) In any event, user interaction is always required to start the first sound.</li>
|
|
</ul>
|
|
|
|
<p>As of the June, 2010 release of SM2 (V2.96a.20100624):</p>
|
|
<ul>
|
|
<li>Safari 5.0 (533.16) on OS X Snow Leopard (10.6.x) continues to show buggy HTML5 audio load/playback behaviour, same as with Safari 4.0.5 on Snow Leopard only - may be related to underlying QuickTime implementation (a guess, at this point.) SM2 will disable HTML5 audio support by default for this specific browser + OS combo. See <a href="https://bugs.webkit.org/show_bug.cgi?id=32159#c9" title="Safari Snow Leopard HTML5 Audio Bug">Webkit #32159</a> for discussion + testcases.</li>
|
|
</ul>
|
|
|
|
<p>As of the May, 2010 release of SM2 (V2.96a.20100520):</p>
|
|
<ul>
|
|
<li>Safari 4.0.5 on OS X Snow Leopard (10.6.x) appears to have an annoying bug where audio inconsistently fails to load / play; SM2 will currently disable or ignore the HTML5 feature on this exact browser + OS version. See <a href="https://bugs.webkit.org/show_bug.cgi?id=32159#c9" title="Safari Snow Leopard HTML5 Audio Bug">Webkit #32159</a> for discussion + testcases. Note that Safari on OS X 10.5 "Leopard" and on Windows <i>do not</i> appear to have this bug; it seems to be limited to Snow Leopard, seen on OS X 10.6.3.</li>
|
|
<li>Some browsers (and iPad 3.2?) do not fire <code>progress</code> events, and/or do not implement bytesLoaded/bytesTotal-style attributes.</li>
|
|
<li>iPad 3.2 appears to be able to only play one sound at a time, and will terminate other sounds.</li>
|
|
<li>iPad 3.2 may also loop AAC+ (HE-AAC) and WAV sounds, perhaps not firing onfinish() and resetting the position to 0 each time, but is fine with MP3s. This has been observed, but not fully-tested.</li>
|
|
<li>Looping in HTML5 is either "infinite" or "none". A wrapper may be created for SM2 so that a number of loops can be specified, as with Flash. This is not yet implemented.</li>
|
|
<li>Panning (left/right channel balance) does not appear to be in HTML5.</li>
|
|
<li>Flash-only features such as ID3 tag reading, waveform and spectrum data will simply be ignored, and their related events will not fire on SMSound objects which are using HTML5.</li>
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
<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">soundManager.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>
|
|
|
|
|
|
</div>
|
|
|
|
<div id="api" class="columnar">
|
|
|
|
<div class="c1">
|
|
<h2>SoundManager Core API</h2>
|
|
<p>Methods for the soundManager object.</p>
|
|
</div>
|
|
|
|
<div class="c2">
|
|
|
|
<div class="f-block">
|
|
|
|
<h3>SoundManager Global Object</h3>
|
|
|
|
<p>This is a collection of methods, collections, 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><a>: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:
|
|
<a id="song1" href="/music/player.php?songID=1" type="audio/mp3">play song 1</a> <span>// type match</span>
|
|
<a id="song2" href="song2.mp3">play song 2</a> <span>// URL match</span>
|
|
*/</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: <a id="song1" href="foo.php?songID=1" type="audio/mp3">play song 1</a></span></span>
|
|
var aLink = document.getElementById('<span>song1</span>');
|
|
if (soundManager.canPlayLink(aLink)) {
|
|
soundManager.play('<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-createsound" class="f-block f-createsound s-autoplay">
|
|
|
|
<dt style="margin-top:2em"><span>object:SMSound </span>createSound(<span>object:options</span>)</dt>
|
|
<dd title="object:options">Creates a sound with an arbitrary number of optional arguments. Returns a <code>SMSound</code> object instance. Requires <code>id</code> and <code>url</code> at a minimum.</dd>
|
|
<dd>
|
|
Example:
|
|
<pre class="block"><code>soundManager.createSound({<span>
|
|
id: 'mySound', <span>// required</span>
|
|
url: '/audio/mysoundfile.mp3', <span>// required</span>
|
|
<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: soundIsLoading
|
|
</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.</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>
|
|
id: 'mySound',
|
|
url: '/audio/mysoundfile.mp3'
|
|
</span>});
|
|
mySoundObject.play(); <span><span>// SMSound object reference, same as soundManager.getSoundById('mySound')</span></span></code></pre>
|
|
|
|
<p>(Note: Code formatting is stylistic, not necessarily recommended.) 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-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>
|
|
</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>Example:
|
|
<pre class="block"><code>soundManager.ontimeout(<span>function() {
|
|
alert('SM2 failed to start. Flash missing, blocked or security error?');
|
|
}</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>
|
|
</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 >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 title="soundID:string">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.onerror = 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="#flashloadtimeout" onclick="resetFilter()">flashLoadTimeout</a>, which can have SM2 wait indefinitely for the flash to load if desired.</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 loading a new, tiny "stub" MP3 file, <code class="in">./null.mp3</code>, which replaces the current one from loading. This is defined in the SM2 global object as <code class="in">nullURL</code>, and can be edited.</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="c1">
|
|
<h2>SMSound (Sound Object) API</h2>
|
|
<p class="in">Each <code>createSound()</code> call generates a matching <code>SMSound</code> (sound instance) object, which lasts for the life of the page or until explicitly destroyed. Each instance stores stateful information (eg. <code>playState</code>) and provides event handlers for state changes (eg. <code>onload()</code>.)</p>
|
|
<p>SoundManager is a convenient wrapper for most sound object methods: It will check for and gracefully exit if a sound object (specified by ID) does not exist, and provides convenient global functionality, eg. muting or pausing of all sounds.</p>
|
|
<p class="in">Nonetheless, each <code>SMSound</code> object can have its methods called directly. eg. <code>mySound.mute()</code> instead of <code>soundManager.mute('mySound')</code>, and so on.</p>
|
|
<p class="in">Note that for code examples, <code>mySound</code> is assumed to be a valid SMSound instance object - eg.,<br /><code>var mySound = soundManager.createSound();</code> or<br /> <code>var mySound = soundManager.getSoundById();</code></p>
|
|
</div>
|
|
|
|
<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-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.sID+' reached '+eventPosition</span>});</code></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 loading a new, tiny "stub" MP3 file, <code class="in">./null.mp3</code>, which replaces the current one from loading. This is defined in the SM2 global object as <code class="in">nullURL</code>, and can be edited.</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="c1">
|
|
<h2 id="soundmanager-sound-events">SMSound Events</h2>
|
|
<p>Event handlers for SMSound objects.</p>
|
|
</div>
|
|
|
|
<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.sID+' <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.sID</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>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>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.sID+' 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.sID+' 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&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>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-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.sID+' 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.sID+' playing, '+this.position+' of '+this.duration</span>);</code></dd>
|
|
</dl>
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
<div id="sound-object-properties" class="columnar">
|
|
|
|
<div class="c1">
|
|
<h2>SMSound Properties</h2>
|
|
<p>Instance Option properties (parameters) can be used with <code>createSound()</code> and <code>play()</code>.</p>
|
|
<p style="margin-bottom:0px">Example:</p>
|
|
<pre class="block"><code>soundManager.createSound({
|
|
id: 'foo',
|
|
url: '/path/to/an.mp3'
|
|
});</code></pre>
|
|
<p>Dynamic Properties can be read to monitor the state of a sound object.</p>
|
|
<p style="margin-bottom:0px">Example:</p>
|
|
<pre class="block"><code>alert(mySound.playState);</code></pre>
|
|
|
|
|
|
</div>
|
|
|
|
<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-sid" class="f-block s-sid">
|
|
<dt>sID</dt>
|
|
<dd>Sound ID string as provided from the <code>id</code> parameter via <code>createSound()</code> or <code>play()</code>. Can be referenced as <code>this.sID</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[sID]</code> on the SoundManager global object.</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>
|
|
</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-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>Boolean indicating whether <code>beforeFinish()</code> condition was reached.</dd>
|
|
</dl>
|
|
|
|
<dl id="smsound-didjustbeforefinish" class="f-block s-didjustbeforefinish">
|
|
<dt>didJustBeforeFinish</dt>
|
|
<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>Once the sound has fully loaded, <code>duration</code> should be referenced as it will contain the final and accurate value.</dd>
|
|
<dd>Note that this method works only with Constant Bitrate (CBR)-encoded MP3s due to the consistent data/time assumption. VBR-encoded MP3s will give inaccurate results.</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<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-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>
|
|
</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<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="c1">
|
|
<h2>SMSound Methods</h2>
|
|
<p>Functions which may be called directly on sound objects.</p>
|
|
</div>
|
|
<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="c1">
|
|
<h2>SoundManager Default Options</h2>
|
|
<p>An optional object specifying event handlers etc., passed to <code>createSound()</code> and <code>play()</code>.</p>
|
|
</div>
|
|
|
|
<div class="c2">
|
|
|
|
<div class="f-block f-defaultoptions s-autoload s-loops s-stream s-onbeforefinish s-onbeforefinishtime s-onjustbeforefinishtime s-multishot s-multishotevents s-pan s-volume s-ismoviestar s-flash9options s-moviestaroptions s-buffertime s-serverurl s-onconnect">
|
|
|
|
<h3 id="sound-properties">SoundManager Global Sound Object Defaults</h3>
|
|
|
|
<p>The <code class="in">soundManager.defaultOptions</code> object contains default parameters inherited by sound objects made via <code class="in">createSound()</code>. They 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>
|
|
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>
|
|
onbeforefinish: null, <span>// callback for "before sound finished playing (at [time])"</span>
|
|
onbeforefinishtime: 5000, <span>// offset (milliseconds) from sound end, call beforefinish..</span>
|
|
onbeforefinishcomplete: null,<span>// function to call when said sound finishes playing</span>
|
|
onjustbeforefinish: null, <span>// callback for [n] msec before end of current sound</span>
|
|
onjustbeforefinishtime: 200, <span>// if unused, set to 0 (or null handler), event will not fire.</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>
|
|
type: null, <span>// MIME-like hint for file pattern / canPlay() tests, eg. audio/mp3</span>
|
|
usePolicyFile: false, <span>// enable crossdomain.xml request for audio on 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>// *** merged soundManager.flash9Options, as applicable ***</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) - Note: May be CPU-intensive, UI redraw/layout etc.</span>
|
|
useEQData: false, <span>// enable sound EQ (frequency spectrum data) - Note: CPU potential also.</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>// *** merged soundManager.movieStarOptions, as applicable ***</span>
|
|
bufferTime: null, <span>// seconds of data to buffer (null = flash default of 0.1 - if AAC gappy, try up to 3 seconds)</span>
|
|
serverURL: null, <span>// rtmp: flash media server to connect to, required for RTMP</span>
|
|
onconnect: null <span>// rtmp: callback for connection to flash media server</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>id: 'mySound',
|
|
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 "without nesting" into <code class="in">soundManager.defaultOptions</code>.</p>
|
|
|
|
<pre class="small block"><code>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>// if applicable, these options are merged into soundManager.defaultOptions at SM2 init.
|
|
// soundManager.flash9Options.isMovieStar -> soundManager.defaultOptions.isMovieStar, etc.</span></span>
|
|
</code></pre>
|
|
|
|
<h4 id="when-to-modify-version-specific" class="flash9" title="Flash 9+ only">defaultOptions.peakData vs. flash9Options.usePeakData</h4>
|
|
|
|
<p>Note that <code class="in">soundManager.defaultOptions.peakData</code> will be undefined until SoundManager 2 has self-initialized, at which point it determines the flash version to use and creates the .SWF, etc. Only then will defaultOptions be populated with optional option parameters, if applicable.</p>
|
|
|
|
<p class="in">Once SM2 has written out the .SWF, it is safe to modify <code>soundManager.defaultOptions.usePeakData</code> directly, for example - but if making changes <em>before</em> initialization, eg., at the time when you are setting <code>soundManager.flashVersion</code>, it is best to modify the source objects as they haven't yet been merged. ie., <code>soundManager.flash9Options.usePeakData = true;</code></p>
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div id="soundmanager2-dynamic-properties" class="columnar">
|
|
<div class="c1">
|
|
<h2>SoundManager Runtime Properties</h2>
|
|
<p>Elements of SoundManager which are set at runtime, intended as read-only.</p>
|
|
</div>
|
|
|
|
<div class="c2">
|
|
|
|
<div class="f-block 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. Currently, <code><a href="#soundmanager-ok" onclick="resetFilter()">ok()</a></code> and <code>features</code> are the only properties that fall in this category.</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 >= 9. This object has been added in anticipation of additional features with future versions of Flash.</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
<div id="soundmanager-events" class="columnar">
|
|
<div class="c1">
|
|
<h2>SoundManager Core Events</h2>
|
|
<p>Events fired by SoundManager at start-up</p>
|
|
</div>
|
|
<div class="c2">
|
|
|
|
<div class="f-block f-onload f-onerror f-oninitmovie">
|
|
|
|
<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>
|
|
<p>For a more flexible queue-based, addListener-style approach to the onload event, see <code><a href="#soundmanager-onready" title="soundManager.onready() event queueing" onclick="resetFilter()">soundManager.onready()</a></code>.</p>
|
|
|
|
<dl>
|
|
|
|
|
|
<dt id="soundmanager-onerror" title="object:function">onerror()</dt>
|
|
<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() { alert('SoundManager failed to load'); }</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 you want multiple listeners for this event, see <a href="#soundmanager-onready" onclick="resetFilter()">soundManager.onready()</a>.</dd>
|
|
|
|
<dt id="soundmanager-oninitmovie" title="object:function">oninitmovie()</dt>
|
|
<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>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>
|
|
|
|
<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>
|
|
|
|
</dl>
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
</div>
|
|
|
|
<div class="columnar">
|
|
<div class="c1">
|
|
<h2>SoundManager Collections</h2>
|
|
<p>Object collections which SoundManager maintains during runtime.</p>
|
|
</div>
|
|
<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="c1">
|
|
<h2>Sound Options Object Format</h2>
|
|
<p>Object Literal, JSON-style form passed to <code>createSound()</code> and <code>play()</code></p>
|
|
</div>
|
|
|
|
<div class="c2">
|
|
|
|
<div class="f-block s-onload"> <!-- f-createsound s-sid 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.sID+' 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>
|
|
|
|
<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/">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>allowPolling</li>
|
|
<li>allowScriptAccess</li>
|
|
<li><a href="#soundmanager-alturl">altURL</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><a href="#soundmanager-flashversion">flashVersion</a></li>
|
|
<li class="flash9" title="Flash 9.0r115+ only"><a href="#sound-properties-flash9">movieStarOptions</a></li>
|
|
<li>nullURL</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 class="flash9" title="Flash 9+ only"><a href="#soundmanager-flashpollinginterval">flashPollingInterval</a></li>
|
|
<li><a href="#soundmanager-useflashblock">useFlashBlock</a></li>
|
|
<li><a href="#soundmanager-highperformance">useHighPerformance</a></li>
|
|
<li class="recent" title="Recently-added, beta feature">useHTML5Audio</li>
|
|
<li class="flash9" title="Flash 9.0r115+ only">useMovieStar</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 class="recent"><a href="#soundmanager-canplaylink" title="Recently-added feature">canPlayLink()</a></li>
|
|
<li class="recent"><a href="#soundmanager-canplaymime" title="Recently-added feature">canPlayMIME()</a></li>
|
|
<li><a href="#soundmanager-canplayurl">canPlayURL()</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" class="new">ok()</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><a href="#soundmanager-resume">resume()</a></li>
|
|
<li><a href="#soundmanager-resumeall">resumeAll()</a></li>
|
|
<li><a href="#soundmanager-setpan">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</h4>
|
|
<ul>
|
|
<li><a href="#soundmanager-onerror">onerror()</a></li>
|
|
<li><a href="#soundmanager-oninitmovie">oninitmovie()</a></li>
|
|
<li><a href="#soundmanager-onload">onload()</a></li>
|
|
<li><a href="#soundmanager-onready">onready()</a></li>
|
|
<li class="new" title="Newly-added feature"><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>Properties (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 title="Flash 9.0r115+ only" class="flash9">isMovieStar</li>
|
|
<li title="Recently-updated feature" class="recent">loops</li>
|
|
<li>multiShot</li>
|
|
<li>multiShotEvents</li>
|
|
<li>onbeforefinishtime</li>
|
|
<li>onjustbeforefinishtime</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, new feature" class="flash9 new"><a href="#smsound-serverurl">serverURL</a></li>
|
|
<li><a href="#smsound-sid">sID</a></li>
|
|
<li>stream</li>
|
|
<li title="Recently-added feature" class="recent"><a href="#smsound-type">type</a></li>
|
|
<li><a href="#smsound-url">url</a></li>
|
|
<li title="New feature" class="new"><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-bytesloaded">bytesLoaded</a></li>
|
|
<li><a href="#smsound-bytestotal">bytesTotal</a></li>
|
|
<li title="Flash 9+" class="flash9"><a href="#smsound-isbuffering">isBuffering</a></li>
|
|
<li title="Flash 9+, new feature" class="flash9 new"><a href="#smsound-connected">connected</a></li>
|
|
<li><a href="#smsound-didbeforefinish">didBeforeFinish</a></li>
|
|
<li><a href="#smsound-didjustbeforefinish">didJustBeforeFinish</a></li>
|
|
<li><a href="#smsound-duration">duration</a></li>
|
|
<li><a href="#smsound-durationestimate">durationEstimate</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+ required, recently-added feature" class="recent"><a href="#smsound-onbufferchange">onbufferchange()</a></li>
|
|
<li title="Flash 9+ required, new feature" class="new"><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 class="new"><a href="#smsound-onposition">onposition()</a></li>
|
|
<li><a href="#smsound-onresume">onresume()</a></li>
|
|
<li><a href="#smsound-onstop">onstop()</a></li>
|
|
<li><a href="#smsound-onbeforefinishcomplete">onbeforefinishcomplete()</a></li>
|
|
<li><a href="#smsound-onbeforefinish">onbeforefinish()</a></li>
|
|
<li><a href="#smsound-onjustbeforefinish">onjustbeforefinish()</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-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>
|
|
|
|
<!-- /main -->
|
|
</div>
|
|
|
|
<!-- /content -->
|
|
</div>
|
|
|
|
<script type="text/javascript">
|
|
init();
|
|
</script>
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|