Working with Sounds, Loading Sounds

Must Read

Sources to Discover the Best Refinance Mortgage Rates

Searching around and listening to several different banks can let you to size up the rates that are quoted...

Christmas Shopping Is Different Today Than In The Past

Thanksgiving, in the not too distant past, was the official start of the holiday shopping. Now, as soon as...

Refinance Home Mortgage Loans When The Timing Gives Benefits

When the borrower wants to refinance home mortgage loans it is important to understand, that the loan is a...

Bad Credit Debt Consolidation Loan: Knocks Your Debt

Is debt sending a shiver down your spine?You are looking out to merge your debts together into a consolidated...

Quick Facts About Obama’s Loan Modification Procedures

Federal Loan Modification Program is a smart and innovative program initiated by Obama in order to bring the home...

Refinance Mortgage Home Equity Loan: Consolidate Your Mortgage and Home Equity Loan

If you are a homeowner carrying a home equity loan in addition to your mortgage, refinancing to one monthly...

Now that your sound files are ready, let’s see how we can use them. All sound-related classes belong to the package and will be introduced throughout this chapter.

Loading Sounds

The Sound class gets access to the audio information to load the sound file. It is a subclass of the EventDispatcher class.

As discussed before, your sound can be embedded, it can be loaded as an external file from your application assets directory, or it can be downloaded from a remote server. For the latter, advise your audience to use WiFi over 3G for a better experience.

If you try to play a sound that is not loaded, you will get a runtime error. Create a listener to be notified when the loading is complete, and then play your file:

var sound:Sound = new Sound();
sound.addEventListener(Event.COMPLETE, onLoaded);
var request:URLRequest = new URLRequest(“mySound.mp3”);
// sound fully loaded
function onLoaded(event:Event):void {
sound.removeEventListener(Event.COMPLETE, onLoaded);;

You can inform the user that the file has started to load:

sound.addEventListener(Event.OPEN, onOpen);
function onOpen(event:Event):void {
trace(“sound loading”);

If it is a large file, create a listener to display the progress:

sound.addEventListener(ProgressEvent.PROGRESS, onLoading);
function onLoading(event:ProgressEvent):void {
// display the percentage loaded

On Android devices, it is important to check for errors, particularly if the file is served from a remote server. Inform your user if there is a network issue:

sound.addEventListener(IOErrorEvent.IO_ERROR, onError);
function onError(event:IOErrorEvent):void {
trace(“sound cannot be loaded”, event.text);


Streaming is the process of playing part of a sound file while other parts are loading in the background. The advantage is that you don’t need to wait for the whole file to download before playing. In addition, you can play very long tracks without memory constraints.

The audio files must be located on a streaming server. The quality of the server is an important factor to a good experience: 128 kbps is sufficient for audio, but a musician can detect artifacts in high frequency for MP3 encoding. Encoding your audio at 192 kbps is a good compromise.

Requesting the file is the same process as before.

You can start playing the audio as soon as there is enough data in the buffer. Buffering is the process of receiving and storing audio data before it is played. The default buffer time is 1,000 milliseconds. You can overwrite the default using the SoundLoaderCon text class.

In this example, the buffer time is changed to five seconds:

var sound:Sound = new Sound();
var request:URLRequest = new URLRequest(“myStreamingSound.mp3”);
var context:SoundLoaderContext = new SoundLoaderContext(5000, true);
sound.load(request, context);;

The SoundLoaderContext class is also used for security checks when loading sounds, but it may not be required in AIR.

Streaming MP3 files is buggy when it comes to midstream bit rate changes, a method often used by streaming services such as Internet radios. The audio sounds like it speeds up or is broken in chunks because it uses the bit rate declared at the start of the stream, even after a change.


Please enter your comment!
Please enter your name here

Latest News

Digital Marketing for Beginners

Digital marketing for starter, Let to basic learning about connecting with your audience in the right place...

What are 7 things poor people do that the rich don’t?

1. poor people watch TV in which people read books how many hours you spend in front of the TV and when...

Top 18 best small business ideas for beginners starting

A small business can be frightening and requires plenty of careful planning there are many small business ideas which can be beneficial...

Summer that makes you happy

We saw were already here I've been thinking about some of the things. I used to do with my husband even though...

4 Point to helpful tips specifically for caregivers

What you need to take a vacation. I know it sounds impossible creative and try to make it work for you almost...

More Articles Like This