Flash MX Audio Player

An in depth look at building a reusable streaming audio preloader for Flash MX that includes media controls.

click here to get more tutorials

01 Introduction
02 What should the media player do? / How should the player be structured? / Useful reading
03 Part 1: Start with some easy audio
04 Putting the sound on the stage / Adding a sample graphic
05 Animating the waveform
06 Part 2: Planning our controls / Getting the sound to play, pause and rewind
07 Adding a load indicator
08 Adding a thumb dragger to the slider
09 Dragger states
10 Limiting the dragger / Setting the sound's playhead position
11 Making the media controls ready for sharing
12 Part 3: Using the media player
13 Anything else? / Conclusion / About the authors / Copyright

Introduction

Multimedia is great. Things move, whiz, bang, beep, explode… well you get the idea. Sounds are one of the coolest things that we can add to a site that elevates what we do above the world of text and animated GIFs.

We will be developing these Flash MX files: media-controller.fla (42kb), sound.fla (1787kb), test.fla (1805kb), and test-audio.fla (10kb). Apologies for the larger files, but they have a largish audio sample imbedded in them. When they are published as SWF files, they come in at 3kb, 24kb, 22kb, and 3kb, respectively.

But how do we implement all of those larger sounds? (The ones that you can't just tag on to a button press.) And how do you make them stream nicely? All too often an otherwise great online multimedia presentation grinds to a halt when audio files are played. It's also annoying that you can't usually scrub back or forward to an interesting bit (or skip over the boring parts).

This time we are going to develop an audio player in Flash MX, allowing your visitors to listen to all the samples you want to publish. Specifically, we will:

  1. Import audio resources and test the compression settings for the audio track.
  2. Generate some waveform images so that we can show people what the sounds look like.
  3. Provide a visual indication of the progress of the playback.
  4. Develop a set of controls for controlling playback.

Here's a big warning: there's a large chunk of tutorial to do bits 2 and 3 first before we get on to developing the controls. And this is a long tutorial. So, if you want to find out if this is worth reading, finish this introduction, check out the "how to use this" bit at the end, and see if you want to read the rest. (That's how I did all my study at University! Ha, hah!)

This tutorial comes in three parts:

  1. Load a sound into Flash and create some animation that plays with the sound. (The animation bit is optional.)
  2. Develop a set of controls to control playback of the sound and prepare the controls for use in any Flash file.
  3. Instructions on how to use the controls we have developed.

What we will not discuss is how to record and mix audio. You will need to supply your own samples to play with.

Before we go any further, I would like to point out that some of the screen shots are from the Western Australian Museum's "Western Australia: Land and People" exhibition. Included in that project were over eighty audio files: mostly commentary by the curators of the exhibition. Now we can all get that "behind the scenes" and "making of" info that is usually reserved for Discovery Channel or the extra audio tracks on DVDs! The Western Australian Museum's great content and our stylish Flash MX work produced an inspiring virtual exhibition.

I am assuming that you have had a glance through the Using Flash help file, and that you have completed the online Flash tutorials "Introduction to Flash MX Tutorial" and "Introduction to ActionScript Tutorial" that come with your copy of Flash MX. You should also be familiar with creating audio files. You may find our other tutorials useful. "Yet Another Flash MX Loader" discusses the creation of the GMG loader. And "Object VR In Flash MX" covers playing back 3D Object VR movies without using the QuickTime player.

Next >> What should the media player do? / How should the player be structured? / Useful reading

01 Introduction
02 What should the media player do? / How should the player be structured? / Useful reading
03 Part 1: Start with some easy audio
04 Putting the sound on the stage / Adding a sample graphic
05 Animating the waveform
06 Part 2: Planning our controls / Getting the sound to play, pause and rewind
07 Adding a load indicator
08 Adding a thumb dragger to the slider
09 Dragger states
10 Limiting the dragger / Setting the sound's playhead position
11 Making the media controls ready for sharing
12 Part 3: Using the media player
13 Anything else? / Conclusion / About the authors / Copyright

© 2003 Glasson Murray Group Pty Ltd (ACN 098 651 542), Western Australia. All rights reserved.