When you're developing Flash audio you need to be aware of the capabilities and requirements of audio in Flash Player. This section covers everything you need to know to get started.
The general workflow for audio production in Flash is the same as with other non-vector media. In most cases the audio asset will be acquired and edited externally from Flash. When the audio file is prepared, it is then imported into Flash or loaded at runtime using ActionScript. This is the first big decision to be made in the process; do you embed the audio or use audio that is external to the Flash movie?
Using embedded audio allows you to import a range of audio formats and has the benefit of visual authoring in the Flash interface (you don't need to use any coding to implement it). Embedded audio also has the advantage of visual synchronization with graphic content. The disadvantages are the incurred larger file size to the SWF file and the lack of flexibility for changes and runtime manipulation.
Using external audio is generally the way to go for more complex projects. External audio has the advantage of remaining flexible for edits and dynamic play list driven content. It also has the advantage of excluding the audio's file size from the SWF file. The primary disadvantage is that it requires some ActionScript knowledge to implement it.
The following list is divided into the three facets of production that should be considered; file preparation, working with embedded audio, and working with external audio.
General steps in the preparation workflow include:
Decide whether to use external audio or audio embedded in a FLA file
General steps in the embedded audio workflow include:
Decide whether to attach the sound to a timeline at authortime or dynamically work with the sound using the Sound object at runtime
General steps in the external audio workflow include:
Before we go further into production techniques, let's take a look at the types of audio formats that Flash can support.
It is important to understand that Flash Player is designed to play audio in a few specific formats. By itself, Flash Player cannot record audio streams. However the player does have access to the microphone object on the end viewer's computer and can be combined with the Flash Media Server to record and store sound files on a server or stream the sound to other Flash application instances. The Flash Media Server greatly expands the possibilities of what can be done with Flash audio, but Flash Player by itself works well for streaming sounds for playback.
Flash supports 8-bit or 16-bit audio at sample rates of 5.512, 11.025, 22.05, or 44.1 kHz. The audio can be converted into lower sample rate during publishing, but it is recommended that you use an audio editing application to resample and edit the audio files—outside of Flash. If you want to add effects to sounds in Flash, it's best to use 16-bit sounds. If you have limited RAM on your system, keep your sounds short and use 8-bit audio.
Tip: Your sound needs to be recorded in a format sampled at 44.1 kHz, or an even factor of 44.1, to assure proper playback in Flash. Working in an audio production tool built to produce "Flash-friendly" audio can save a lot of headaches dealing with subtle details. Later in the article we'll take a look at Soundbooth—a solution designed specifically for Flash audio production and integration with other Adobe tools.
Flash supports a range of audio formats for importing and embedding sounds in a SWF file. You'll need to have QuickTime 4 or higher installed on your computer to take full advantage of the supported formats during authoring (see Table 1).
Table 1. Supported audio formats when importing audio into Flash
| Format | Type | Platform | QuickTime 4 |
|---|---|---|---|
| WAV | Waveform Audio Format | Win & Mac | NA |
| AIFF | Audio Interchange File Format | Win & Mac | NA |
| MP3 | MPEG Layer 3 | Win & Mac | NA |
| SD2 | Sound Designer 2 | Mac | Required |
| MOV | Sound Only QuickTime Movies | Win & Mac | Required |
| AU | Sun File Format | Win & Mac | Required |
| SFIL | System 7 Sounds | Mac | Required |
When you embed the audio, Flash bundles the sound with the SWF file. In most cases the embedded sound will be compressed along with the rest of the assets in the file during publishing. So in the case of embedded audio, you also have to think about the exported audio format as well (see Table 2).
Table 2. Supported audio formats when exporting embedded audio in a SWF
| Format | Type | Platform | QuickTime 4 |
|---|---|---|---|
| ADPCM | Adaptive differential pulse code modulation compression |
Win & Mac | NA |
| MP3 | MPEG Layer 3 compression | Win & Mac | NA |
| Raw | Uncompressed | Win & Mac | NA |
| Speech | ASAO compression | Win & Mac | NA |
Notice that while QuickTime is required for importing the full range of supported audio formats, it is not needed to export them or play the published movie. Flash Player handles the playback of the four export formats. The default and most commonly used audio format is MP3. Also notice that all formats are supported on Mac and Windows regardless of whether the file required a Mac during the authoring process.
The export audio format can be set globally in the Publish Settings dialog box or set per sound file. To adjust audio settings globally, edit the event and streaming fields in the Publish Settings (File > Publish Settings). To adjust audio settings per sound, right-click on the sound in the Library to launch the Sound Settings dialog box (see Figure 1).
Figure 1. Sound Settings dialog box for adjusting compression, bit rate, and quality settings
When you work with embedded audio that is attached to the Timeline, you have to decide whether to handle each sound as "event" audio or "streaming" audio in Flash Player. This is a Flash concept that specifies how the audio relates to the Flash Timeline (or not). Streaming audio signals Flash to synchronize the audio to the Timeline it is attached to and to start playing the sound as it downloads. When you stream audio, you attach the sound to the Timeline and the audio playback is directly synched to the length of that Timeline. This approach is commonly used for synchronization with animated content and for streaming playback of larger content files.
Event audio signals Flash to handle the sound's playback without regard to its Timeline. If the Timeline contains a limited number of frames, such as a button, the sound can play from start to finish. Event audio has to download completely before it can play, and therefore is most commonly used for short sounds, such as button clicks.
Flash Player supports playback of external audio in MP3 and FLV format. The MP3 format has been a mainstay with Flash developers since the Flash 4 era whereas the FLV format became an option in Flash MX (6) when the Flash Media Server implemented the format for Flash video and audio streaming.
Tip: Flash Player 9 Update 3, the latest version of Flash Player as of this writing, supports the HE-AAC audio codecs along with H.264 video.
The MP3 format is commonly used because it is familiar to developers from other areas of web production. MP3 formatted files are relatively easy to produce and easy to share with other web-based applications. While this may be the case, there are some advantages to working with the FLV format. FLV formatted files can hold metadata, such as cue points for synchronization. You can also manipulate FLV audio files using the FLVPlayback component, which allows you to load the sound and create a playback interface with little to no ActionScript knowledge. As audio editing tools such as Soundbooth now export source audio to FLV format, FLV has become a viable option for developers working outside of the Flash Media Server environment.
If you choose to work with the Flash Media Server for live audio recording and playback, you'll work with the FLV format exclusively. MP3 and FLV formats are supported on both Windows and Macintosh systems (see Table 3).
Table 3. Supported audio formats when playing external audio in Flash
| Format | Type | Platform | QuickTime 4 |
|---|---|---|---|
| MP3 | MPEG Layer 3 | Win & Mac | NA |
| FLV | Flash Video | Win & Mac | NA |
Flash Player 6 and higher supports metadata for both the MP3 and FLV formats. MP3 files support the ID3 v1.0 and v1.1 standard. FLV files support Flash video metadata parameters, including cue points for content synchronization and custom parameter entries. In both cases the metadata can be retrieved at runtime using event handler functions in ActionScript.
See the Sound page in the Flash LiveDocs for more information on MP3 metadata.
Also, check out the MetadataEvent page in the Flash LiveDocs to learn more about working with FLV metadata.
Flash Lite is a runtime engine used to display SWF files on consumer electronics and mobile devices. This article focuses on implementing audio for playback in Flash Player; however it's interesting to note that Flash Lite supports the playback of device sounds such as MIDI and SMAF, among others. See the Flash Lite 2.x and 3.0 LiveDocs for more information on working with Flash Lite and deploying audio in mobile devices.