SoundManager 2: Flashblock / "click to flash" handling demos

Flash blockers (and related ad blockers) can intercept or otherwise prevent flash movies and SWF URLs from loading, sometimes with the option to "click to start". For SM2 this means the flash may not load at all due to being blocked, or may be eventually allowed to run by the user when they click the SWF.

In this case, we assume the user has a flash blocker of some sort installed which will prevent the flash movie from loading, and will cause a timeout/failure in SM2 as it waits for a response from Flash.

For most use cases, it's best to try to start SM2 normally, and then highlight error/timeout cases as applicable. Alternately if your app absolutely requires sound, you can defer starting of your app until SM2 has successfully loaded. In either case, it is good to set soundManager.flashLoadTimeout = 0 so SM2 waits indefinitely for flash to load, rather than firing soundManager.onerror() and related handlers.

Handling Flash blockers

By default, SM2 places a "hidden" SWF in the DOM and tries to load right away; it will succeed or fail with a time-out typically no later than one second after document load. The one-second case is what happens when flash is either not present, or is blocked on the user's browser. The way to work around this is to show the movie at first where it can be allowed/whitelisted by the user, at which time SM2 will load.

Place SWF inline in document at first, reposition (hide) when SM2 loads

Rather than hide off-screen or in a small space, the SoundManager 2 SWF container is put inline in the document so the user can take action without later interruption after a timeout. In the event SM2 starts without issue, the node can be moved out of view to its regular "hidden" place.

The following demo initially places the movie out of view, but then makes it visible if a timeout is detected. If the user then allows the SWF to load, it loads and SM2 becomes hidden again.

Flashblock demo