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 aSoundobject. Otherwise, load a //.swfcontaining ADCP sound into a nested movie clip. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access