Recipe 2.7 Detecting the Device's Audio Capabilities
2.7.1 Problem
You want to determine
the audio
capabilities of the device on
which the Player is running.
2.7.2 Solution
Use the hasAudio and hasMP3
properties
of
the System.capabilities object.
2.7.3 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 a Sound object. Otherwise, load a
// .swf containing ADCP sound into a nested movie clip.
if (System.capabilities.hasMP3) {
mySound = new Sound(mySoundHolder);
mySound.load("sound.mp3", false);
} else {
mySoundHolder("adcpSound.swf");
}
It is important to understand that the hasAudio
and hasMP3 property settings are based on the
capabilities of the Player and not of the system on which the Player
is running. The desktop system players (for Windows, Mac OS, and
Linux) always return true for both properties
regardless of whether the system actually has the hardware (i.e.,
soundcard and speakers) to play back sounds. However, players for
other devices may return false if the device does
not support the audio or MP3 features.
|