Basics of working with sound

Before you can control a sound, you need to load the sound into the Adobe AIR application. There are five ways you can get audio data into AIR:

  • You can load an external sound file such as an mp3 file into the application.

  • You can embed the sound information into a SWF file, load it (using <script src="[swfFile].swf" type="application/x-shockwave-flash"/ >) and play it.

  • You can get audio input using a microphone attached to a user’s computer.

  • You can access sound data that’s streamed from a server.

  • You can dynamically generate sound data.

When you load sound data from an external sound file, you can begin playing back the start of the sound file while the rest of the sound data is still loading.

Although there are various sound file formats used to encode digital audio, AIR supports sound files that are stored in the mp3 format. It cannot directly load or play sound files in other formats like WAV or AIFF.

While you’re working with sound in AIR, you’ll likely work with several classes from the runtime.flash.media package. The Sound class is the class you use to get access to audio information by loading a sound file or assigning a function to an event that samples sound data and then starting playback. Once you start playing a sound, AIR gives you access to a SoundChannel object. An audio file that you’ve loaded can only be one of several sounds that an application plays simultaneously. Each individual sound that’s playing uses its own SoundChannel object; the combined output of all the SoundChannel objects mixed together is what actually plays over the speakers. You use this SoundChannel instance to control properties of the sound and to stop its playback. Finally, if you want to control the combined audio, the SoundMixer class gives you control over the mixed output.

You can also use several other runtime classes to perform more specific tasks when you’re working with sound in AIR. For more information on all the sound-related classes, see Understanding the sound architecture .

The Adobe AIR developer’s center provides a sample application: Using Sound in an HTML-based Application (http://www.adobe.com/go/learn_air_qs_sound_html_en).

// Ethnio survey code removed