Detecting the Audio Device Capabilities using Flash Scripting

by Duncan Murray.

Share
|
Homepage | Submit your article | Contact | TOS
More articles on flash  

You are here: Categories » Computers and technology » Flash

You want to determine the audio capabilities of the device on which the Player is running.

Use the hasAudio and hasMP3 properties of the System.capabilities object.

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

Leave a comment or ask a question
Total comments: 0

Flash Disclaimer

  • The e-articles directory is not responsible for any and all copyright infringements by writers and authors. If you suspect the information contained by this page for any copyright infringements, please contact us to investigate the issue
Targeting Flash Movie Clips - The simplest way to target a movie clip is to use its name, followed by a dot, followed by the command you want to send. However, there are plenty of other ways to target a movie clip as we (more...)
Using Mathematical Operators in ActionScript - You want to modify something over time, such as the rotation or position of a movie clip. Use the compound assignment operators to change a variable or property in increments. Or, if increm (more...)
How to build an animated button using Flash - Time: 15 Minutes. Difficulty Level: Intermediate Requirements: Flash 8 Assumed Knowledge: Basic action (more...)
Enhancing Standalone Projector - You want to create an enhanced Standalone Projector with features such as borderless playback, custom titles, no Flash menus, and so on. Use a third-party tool such as SWF Studio or SWFKit to c (more...)
Creating Flash Buttons - Buttons are one of the three main types of symbols that you use in Flash. The others are movie clips and graphics. Making a New Button There are many ways to create a button. One (more...)
Bouncing Ball Script - Start a new Flash movie. Create a movie clip that has a ball graphic inside it. You can name the instance of the movie clip, myClip, but our code will not depend on the name of the clip. (more...)
ActionScript: Creating Reusable Code - You want to perform a series of actions at various times without duplicating code unnecessarily throughout your movie. Create a function and then call (i.e., invoke) it by name whenever you (more...)
3D Scaling with ActionScript - Although Flash is not capable of real 3D graphics, the kind seen in popular computer games, you can create the illusion of 3D by using scaling. Scaling an object is a great way to give your (more...)
The Dot Syntax - Something else that you will be seeing a lot of as you learn ActionScript is dot syntax. Dot syntax is a way of grouping objects and functions that is used in many object-oriented programming (more...)
Movie Clip Scripts - Movie clip scripts, like button scripts, use handlers. Instead of using the on keyword that button scripts use, we will use the onClipEvent keyword. Here is an example of a movie clip script: (more...)

 
free content
    Copyright © 2006 - 2012 e-articles.info.
The texts, articles and tutorials in the directory are property of their respective owners and authors.