http://www./projects/soundmanager2/doc/getstarted/#basic-inclusionHow SoundManager WorksIt starts out easy, but you can go down the rabbit hole if you want. SoundManager 2 Tutorial: What, Why, HowProblem: Browsers lack good, consistent native audio support. (HTML 5's Solution: Javascript API using HTML5 Audio() + headless Flash via ExternalInterface, works almost everywhere. If HTML5 is supported but "non-free" MP3/MP4 formats are not, flash can be used as a fallback. SoundManager 2 wraps and extends both the HTML Audio and Flash Audio APIs, providing a single, unified sound API to Javascript; the API is consistent regardless of the technology working under the hood to play sound. (The flash portion is hidden, transparent to both developers and end users.) Including SoundManager 2The soundmanager2.js core can get down to 11 KB over the wire, depending on what version you use. A few versions of the SM2 script are available, balancing code size between commented, debug-enabled and production-optimized builds. Regardless of which build you use, take advantage of gzip compression on your server for big savings. As shown below, SoundManager 2 compresses quite well with gzip; the full debug-enabled version served with gzip is smaller than even the minified, no-debug version served without.
You then need to tell SM2 where to find the flash .SWF it will need (depending on HTML5 support), and optionally what version of Flash (~2.8 KB for flash 8, and ~8.5 KB for flash 9) depending on what API features you want:
If you plan to eventually use the flash block handling feature (disabled in this example), you'll want to look at the flash block demo and include the relevant CSS it uses. Basic SoundManager TemplateFor a live example of a page including SoundManager 2, check the bare-bones template. SoundManager File StructureOr, "What you get when you download SM2." The core audio API bits require
How SoundManager 2 Really WorksSoundManager 2 is the result of Javascript talking to a hidden Flash movie. The Flash layer is not something you have to work with directly, but it is the component which makes audio control possible behind the scenes. soundmanager2.js <- Flash + ExternalInterface, and/or HTML5 Audio() -> <- HTTP -> audio file Flash can expose methods to Javascript via ExternalInterface, allowing bi-directional calls to be made and thus providing additional functionality to Javascript. For the real gory details on the behind-the-scenes action of JS + Flash, see How SoundManager 2 Works on . Startup / InitializationIn brief, here is now SM2 starts up:
A single Javascript include will link in all of the required code for the library, which will automatically begin loading either at Once initialised, SM2 will call event handlers/listeners registered via If you want to lazy-load or defer SM2, see Lazy-loading and SM2_DEFER. SoundManager onready() / ontimeout() Event Handlers
Lazy-loading / Dynamically-loading SM2 on-the-flyLet's say you wanted to load and start SM2 after your page has loaded, using JavaScript to insert a script node etc., or otherwise only start SM2 conditionally. You can load the library dynamically (at or after Example:
For a live demo, check out the deferred loading example. Sound Options Object FormatObject Literal, JSON-style data passed to Object Literal FormatSounds can be created with instance-specific parameters in an object literal (JSON-style) format, where omitted parameters inherit default values as defined in soundManager.
This object can also be passed as an optional argument to the For a full list of available options, see Sound Properties Object "Use Responsibly"Only you can prevent audio pollution? A Word Of ViceNot every button, link, element or paragraph on the web needs to zoom, move, change colour and be noisy, repetitive and annoying all at the same time. Use your own discretion! Sites which automatically start playing background sound, and/or don't have volume or mute controls are the kind of things you should avoid building. As a developer, gentle reader, you may eventually find yourself in such a situation. Please do your part in enhancing the web with sound if you use SM2, while at the same time keeping it audibly usable. :) TroubleshootingConsole-style messaging, useful for troubleshooting start-up and runtime issues. SoundManager 2 Start-up and Debug ToolsThis troubleshooting tool can come in handy for debugging SM2 start-up problems, when Flash support is required. Flash options: Flash 8 (default), Flash 9 (normal) or Flash 9 + highPerformance + fastPolling modes.
Flash detection code from Flash Detect () Flash Movie Debug OutputWhen You can also specify ?debug=1 in the URL to the SWF, and it will write debug output. Try soundmanager2_debug.swf?debug=1, or soundmanager2_flash9_debug.swf?debug=1. Live Debug OutputSoundManager 2 relies on Javascript and Flash communicating via ExternalInterface, and this is subject to a number of timing, loading and browser security conditions. Because of this complexity, debug information is essential for troubleshooting start-up, loading, initialization and error conditions between Flash and Javascript. With debug mode enabled via If loading from the local filesystem (offline eg. file://, not over HTTP), Flash security is likely preventing SM2 from talking to Javascript. You will need to add this project's directory to the trusted locations in the Flash global security settings panel, or simply view this page over HTTP. Below is a live example of debug output. sm2TestSound: ended sm2TestSound: playing sm2TestSound: onload() sm2TestSound: canplay sm2TestSound: loadeddata sm2TestSound: loadedmetadata sm2TestSound: suspend sm2TestSound: loadstart sm2TestSound: waiting sm2TestSound: load (http://www./projects/soundmanager2/demo/_mp3/mouseover.mp3) sm2TestSound: play(): Attempting to load sm2TestSound: Using HTML5 sm2TestSound: Merged options: soundManager.createSound(): sm2TestSound (http://www./projects/soundmanager2/demo/_mp3/mouseover.mp3) SoundManager 2: Ready. SoundManager 2 HTML5 support: mp3 = true, mp4 = true, ogg = true, opus = true, wav = true SoundManager V2.97a.20131201 (HTML5-only mode) For more examples of live debug output, see the Basic Template, API demo and other demos in the top navigation. Standalone version of troubleshooting toolFor debugging your development/production environment with this widget, see the troubleshooting subdirectory of the SoundManager 2 package. |
|