O'Reilly logo

Actionscript Cookbook by Joey Lott

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 a Sound object. Otherwise, load a 
// .swf containing ADCP sound into a nested movie clip. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required