+65 8180 0424
This tutorial is dedicated to Juan, who wrote to me saying “It may be too much asking but have you thought in loading a songlist from an XML”, which gives me this bright idea to write a tutorial on ‘Mini Audio / MP3 player in flash’.
The credit surely goes to Actionscript 3 for the all their new features including ‘pause’.
We will be covering a lot of topics whilst creating mp3 player, topics include,
For better understanding of ‘list component’ and ‘sound classes’, shall write about the same in different sections.
Let’s begin with ‘List Component’, which is also the first step in creating Flash MP3 player.
List Component –
|
import fl.controls.List; |
Next step is to get the player up and running. To accomplish the above, we will have to provide an EventListerner to our List Componenet ‘tracklist’ to check for song selection, grab the song url / data from tracklist, check if the song is loaded, or if there is an error while loading and to play. There is another very important thing which I HAVE TO mention. As you all are aware, to play a song, we will have to create a ‘Sound Object’ and allot play method to Sound Object for playing select music, but the problem here is, we cannot just finish with this, because there is a ‘Memory leak’ problem with AS3. To overcome this problem, we will have to create a ‘player object’ and then allot sound object to the same.
Functionalities for buttons and sliders are also included
|
var sc:SoundChannel=new SoundChannel(); tracklist.addEventListener(Event.CHANGE, tracklistchange); function tracklistchange(event:Event)
function playSound(url) //sound events for 'complete', 'error' and 'progress' function soundevents():void function musicloaded(event:Event) } function funcOnLoadProgress(event:ProgressEvent):void function onIOError(e:IOErrorEvent) //btns play_btn.addEventListener(MouseEvent.CLICK,playmusic); //play button //pause button function pausemusic(event:Event)
//stop button //mute button
function fwdmusic(event:Event)
function backmusic(event:Event) var rect:Rectangle = new Rectangle(0,-5,100,0); function slideit(event:Event) function stopslide(event:Event) function volumecontrol(event:Event) |
I hope the explanation and script was simpler to understand.
Click here to download the source code
- Downloadable source code file also includes script for slider.
The slider didn't seem to work properly over the net so I removed it from this tutorial and thought of retaining the same in source code file, just in case, if you need it.