News & Resources — Articles
Using Sound in Flash Lite 1.1
By Nader Nejat
This article originally appeared in the Macromedia Mobile and Devices Developer Center.
Reprinted with permission.
Imagine watching a favorite movie with the audio muted. Pretty poor experience, isn't it?
Adding sound to a mobile phone project can make a great experience for the user. With the release of Flash Lite 1.1, there is more potential than ever for creating better, more interactive experiences on mobile phones. In this article, I'll be looking at different ways of appealing to a user's sense of sound. I'll examine specific issues relating to sound use on mobile phones and then I'll show you how to prepare sounds and use them in the Macromedia MX 2004 authoring environment. Requirements
To complete this tutorial you will need to install the following software and files:
-
Macromedia Flash Professional 2004
-
Macromedia Flash Lite 1.1 CDK
-
Sample files
-
Intermediate-level Flash knowledge and experience using sound in Flash
Using Sound with Mobile Phones
The appropriate use of sound is essential for effective mobile development. Sound can enrich or aggravate the user's experience. Audible feedback and alerts might be welcome in some cases. However, what happens if someone is using a phone to access data services? They may already be in the middle of a conversation, driving, walking, in a cafe, or on public transport. This user won't have the dedicated attention that they usually have when using a traditional desktop or laptop computer.
Most mobile user applications are going to be put to the test in multiple diverse user-access scenarios. The freedom that mobile devices offer is indisputable. It is also indisputable that your mobile applications require thoughtful sound design.
What's different when you are using sound for a mobile phone versus a traditional desktop-delivered Flash file? For starters, mobile phones support a much smaller range of sounds than desktop machines do. Phones may not support the common WAV, AIF, or MP3 sounds used in Flash. Different mobile phones support different types of audio, but, as a rule, most support various types of MIDI. Sound Formats in Flash Lite 1.1
Flash Lite 1.1 supports MIDI, MFi, SMAF, WAV, and ADPCM sound file formats. This differs from the sound formats Flash supports and affects how you will proceed in authoring your mobile application in Flash.
The best place to start is to understand what sound file formats Flash MX 2004 Professional does and does not support. Flash MX 2004 Professional doesn't natively support all the sound file formats used for mobile devices, including the commonly used MIDI format.
When authoring for mobile devices, you must place a proxy sound in a supported format such as MP3, WAV, or AIFF in the Flash document temporarily. The temporary sound files serve as pointers to the final MIDI files. The conversion from sound file to pointer (or proxy) happens as you publish your Flash Lite movie, as discussed in the following section.
One of the advantages of MIDI sound files is that they can be very small, because MIDI instruments reside on the phone and MIDI files are just the instructions provided to the instruments about the playback of the sounds. A helpful analogy is to consider the old player piano that operated independently of a user. The player piano simply read the paper, which served as its instructions to play the music, much like the MIDI file instructs the mobile device on how to play back the sounds.
File size is critical for mobile phones, because bandwidth often is a very important issue. MIDI files can be extremely lean. MIDI instruments can be very small. MIDI files can just be a few kilobytes and can create some great music depending on the sophistication and MIDI capabilities of the phone.
Another limitation of mobile phones is that they often have small amounts of memory and are therefore incapable of playing back large files. It is common to produce a large file if you are using non-MIDI audio. However, compressed digital non-MIDI audio playback can be processor intensive. This means that a sound you can play on a desktop may play back slowly or even be entirely unusable on a mobile phone.
Different phone manufacturers support different MIDI sound formats. So how do you deal with all these different sound formats when you're unsure of the playback devices? You use Flash Lite Bundler.
Using Flash Lite Bundler is necessary, because different phones support different MIDI formats and Flash isn't doing the playback MIDI. Flash Lite Bundler is a great developer's aid. For example, each DoCoMo phone, which is offered by six manufacturers, reproduces different flavors of MFi. You have two choices:
-
Embed six different kinds of MFi in six different SWF files.
-
Use Flash Lite Bundler and encapsulate six different sounds in a bundled file.
The obvious choice is to use Flash Lite Bundler and embed the SWF files into one comprehensive solution. Preparing Sounds
Flash Lite Bundler makes your job easy as it provides the ability to encapsulate device-specific sounds into a single bundled file. This file can be played on multiple mobile devices, thereby speeding your development process and ensuring your success. A single Flash movie deploys a single sound that's represented in MIDI, MFi, and SMAF formats. This makes the movie incredibly portable to many devices that support only MIDI, MFi, or SMAF files. When you are in development, all you need to do is identify the sound formats that you want to support and bundle them together with Flash Lite Bundler.
Use the FlashLiteSoundBundler.exe application to bundle the desired sound files together. When you create this bundle, it saves as an FLS file. This bundle is played when triggered by an event on the mobile device. When the appropriate event is triggered, Flash Lite 1.1 processes this bundle and plays the sounds in the format supported by the device.
To bundle a sound, download the sample files (Flash_Lite_Exercise) for this article, unzip the archive, and follow these steps:
Note to Mac users: In order to bundle sounds you will need to use a PC. You may skip this part of the tutorial and work with an already bundled sound. Please advance to the next section, "Using Bundled Sounds in the Authoring Environment."
1. Double-click FlashLiteBundler.exe to launch the Flash Lite Bundler program. (You can find this file in the Flash Lite 1.1 CDK.) When the application launches, you should see the window shown in Figure 1.
Figure 1. The Flash Lite Bundler application window
2. Open the Flash_Lite_Exercise folder. This folder includes two subfolders: Blank, which includes the exercise files for this step and Completed, which includes the completed test file for your reference.Go to the Blank/Sounds folder and drag the following sound files into the Flash Lite Bundler window:
-
organ_riff.mid
-
organ_riff-D505i.mld
-
organ_riff-F505i.mld
-
organ_riff-N505i.mld
-
organ_riff-P505i.mld
-
organ_riff-SH505i.mld
-
organ_riff-SO505i.mld
3. A new window will launch showing you all the sounds you are about to bundle along with their file sizes (see Figure 2). Click Save Bundle, name the bundle soundTestBundler.fls, and save it to the Blank/Sounds folder.
Figure 2. The original sound files in the Flash Lite Bundler window
4. Go to your Blank/Sounds folder and drag the soundTestBundler.fls file onto the Drag Sound Files Here window (shown in step 1). You'll get a list of all the names of the bundled sounds along with their types and file sizes (see Figure 3). This information can be very useful if you forgot what you put in a bundle, or you received a sound file from someone else. It's also a great way to analyze the size costs of a bundle.
Figure 3. Verifying the contents of the Flash Lite Bundler file Using Bundled Sounds in the Authoring Environment
At this point of the development of your project, you'll use the temporary (proxy) sound files that I mentioned in the previous section. These proxy sound files are portable. To replace a standard sound file with one that is the optimal format for mobile playback, link the file to the MIDI file or a sound bundle file that you want to publish with your Flash application.
Use the Sound Properties dialog box (select a sound file in your library, right-click [PC] or Control-click [Mac], and choose Properties) and the Flash Publish Settings dialog box (choose File > Publish Settings and select the Flash tab) to link the proxy sound file to an external nonsupported sound file. When you publish your project, Flash replaces the proxy sound with the externally linked sound. The SWF file generated when you publish contains the sounds in the appropriate formats for playback on a mobile device.
When adding device-specific sounds or sound bundles to Flash documents for playback on mobile devices, keep the following in mind:
-
This feature works only with event-driven sounds.
-
The Effect, Sync, and Edit options are not supported when linking a sound.
-
You must specify an external sound file for each sound in the project that you are developing.
-
The device sound file or the sound bundle file must be available during the publishing process. This file isn't needed for playback once you deploy your application on the mobile device.
What's this event sound that I've been talking about? Event sound is the ability to play sound independent of the Timeline; and any event can be used to trigger an event sound. The event sound must download completely before it begins playing, and it continues playing until either the end of the sound buffer has been reached or the triggered sound is stopped. It is also helpful to note that you can loop event sounds within SWF files. This keeps your file size small while providing constant sound.
Place the sounds you processed inside a FLA file.
1. Download and unzip the sample files for this article.
2. Open the blank_flashlite_sound_tests.fla file, located in the Blank folder. (The Completed folder contains the finished test file for your reference.) The majority of this file has been kept generic so that you can easily reuse its architecture in your Flash movies.
3. Double-click the soundTest movie clip on the Stage. Then double-click the mySounds movie clip in order to enter its symbol-editing mode and examine its timeline. Notice that there are temporary audio files under the first three labels. There's a WAV file under the fourth label and an MP3 file on the fifth label (see Figure 4).
Figure 4. The mySounds movie clip Timeline
4. Now return to the parent Timeline. Select the first button, open the Actions panel, and enter the following code:
on (press) {
tellTarget("mySounds") {
gotoAndPlay("sound1");
}
}
Select the second button and enter the following code:
on (press) {
tellTarget("mySounds") {
gotoAndPlay("sound2");
}
}
Select the third button and enter the following code:
on (press) {
tellTarget("mySounds") {
gotoAndPlay("sound3");
}
}
Select the fourth button and enter the following code:
on (press) {
tellTarget("mySounds") {
gotoAndPlay("sound4");
}
}
Select the fifth button and enter the following code:
on (press) {
tellTarget("mySounds") {
gotoAndPlay("sound5");
}
}
5. Now open your library so you can substitute MIDI sounds for the temporary MP3 files. Open your library, expand the sounds folder, and select tempAudio01.mp3. Bring up its properties, click the little folder icon to the right of Device Sound, and go to your sounds folder. Select piano_01.mld and click open. Notice that the sound file name now populates the device sound field (see Figure 5).
Figure 5. The Sound Properties dialog box of tempAudio01.mp3
6. Click OK.
7. Select tempAudio02.mp3 from your library, and then repeat steps 5 and 6, using soundTestBundler.fls as the substituted sound.
8. Select tempAudio03.mp3 from your library, and then repeat steps 5 and 6, using Matilda.kar as the substituted sound.
9. Now you need to make sure that you have the proper publish settings. Select File > Publish Settings. On the Flash tab, select Flash Lite 1.1 from the Version drop-down list and then select the Export Device Sounds check box.
Figure 6. Verify the settings before publishing your Flash Lite 1.1 movie.
10. Publish your movie.
Congratulations—you're finished. Transfer your file to a Flash Lite 1.1-enabled phone to test your file. Summary
In summary, I've taken you through issues relating to the use of sound on mobile phones, discussed how to use sound in Flash Lite 1.1, and how to prepare sounds and use them in the authoring environment. Sound not only provides valuable feedback, but it can help create a great mobile experience. (top^)