Play an MP3 in Adobe AIR/FLEX

By | March 3, 2011

Often in out applications we need to play sounds , so this code explains how to play, stop and resume an mp3 sound in Adobe AIR/FLEX.
What you have to do is to copy the following code and place it inside your “mx:Script” tag.
After that place three buttons for play, pause and stop and connect it to the three functions coded below.
Make sure that you have the sound file in your applications directory.


import adobe.utils.CustomActions;
import air.net.URLMonitor;
import flash.media.Sound;
import flash.media.ID3Info;
import flash.net.URLRequest;

var sound:Sound = new Sound(new URLRequest("app:/my_sound.mp3"));
var my_channel:SoundChannel;
var pausePos:int = 0;
[Bindable]
private function play():void
{
       my_channel= sound.play();
}
private function stop():void
{
      pausePosition = my_channel.position;
      my_channel.stop();
}
private function resume():void
{
       my_channel = sound.play(pausePos);
}

Please leave your valuable comments.

One thought on “Play an MP3 in Adobe AIR/FLEX

Leave a Reply to mp3 Cancel reply

Your email address will not be published. Required fields are marked *