2.7. Detecting the Device’s Audio Capabilities
Problem
You want to determine the audio capabilities of the device on which the Player is running.
Solution
Use the hasAudio
and hasMP3
properties
of
the System.capabilities
object.
Discussion
Desktop versions of Flash Player 6 and later support MP3 playback and
the ability to encode audio from a microphone or similar device.
However, Flash Players for other devices do not necessarily support
all, or possibly any, audio capabilities. The
System.capabilities.hasAudio
property returns
true
if the Player has any audio capabilities and
false
otherwise. This is extremely important for
playing movies on multiple devices. If a device has no audio support,
you should avoid forcing users to download something they cannot hear
(especially because audio can be quite large):
// Load a .swf
containing sound only if the Player can play audio.
if (System.capabilities.hasAudio) {
mySoundHolder.loadMovie("sound.swf");
} else {
mySoundHolder.loadMovie("silent.swf");
}
Just because a Player has audio capabilities, however, does not
necessarily mean that it can play back MP3 sounds. Therefore, if
publishing MP3 content, you should test for MP3 capabilities using
the System.capabilities.hasMP3
property. MP3
sounds are preferable, if supported, because they offer better
sound-quality-to-file-size ratios than ADCP sounds.
// If the Player can play MP3s, load an MP3 using aSound
object. Otherwise, load a //.swf
containing ADCP sound into a nested movie clip. ...
Get Actionscript Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.