Flash XML Music Player in ActionScript 3
Flash Showcase March 22nd, 2008Okay, I realize I posted the ActionScript 2 version of this music player just yesterday, but I had a little bit of time on my hands, so I decided to go ahead and update it with ActionScript 3. You can view the new version here.
And here are the files for download: jukebox.zip








March 23rd, 2008 at 6:10 am
Thanks for creating this in AS3. I am sure it will be useful to a lot of people.
March 24th, 2008 at 4:57 pm
[...] example, file, Flash, jukebox, music player, Source, webdesign, xml Craig Campbell just posted a nice jukebox example with source file available, demonstrating how you can do it using xml and as3. No Comments [...]
March 24th, 2008 at 6:03 pm
Übersicht: Mit Flash erstellte MP3-Player für die eigene Website…
Oftmals will man eine MP3-Datei oder ganze Songlisten in eine Website integrieren. Hier eine Übersicht über größtenteils kostenlose MP3-Player, die mit Flash oder Flex erstellt worden sind.
Easylistener Flash Music Player
Von Yahoo! kann man einen…
March 26th, 2008 at 10:38 pm
Thanks for posting the source Craig! This will be great to learn a few things from
March 29th, 2008 at 9:54 pm
[...] Flash XML Music Player in ActionScript 3 [...]
March 31st, 2008 at 7:57 am
Is there a way to set this so that it doesn’t automatically load all the songs when the player loads? It’s a huge drain on server resources to load megabytes worth of music that might not even get played each time a user visits me site.
March 31st, 2008 at 8:13 am
@Shan: Great question! This particular music player only loads one song at a time. The songs are pulled in externally using an XML file. The song then streams as it plays so the user doesn’t have to wait for the entire song to load before hearing it. The code for this is included in the jukebox.zip source file linked to above.
I’ll be posting a tutorial for this in the near future in case the code in the file doesn’t make sense.
April 3rd, 2008 at 11:46 am
Craig, I changed the xml file to point to my mp3 files and when I view the site, my songs play in slow mode (like slow motion). I change the xml to point to your 3 songs and it works just fine. Was wondering if you or anyone else had experienced this enigma.
Robert
April 22nd, 2008 at 9:44 pm
Hello Craig, first of all thanks for this tutorial and files. I do have a problem though and hope you can kindly help me solve it. I get the following error message:
***************
Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL: jukebox.xml at jukebox_fla::MainTimeline/jukebox_fla::frame1()
******************
The player is visible on the page and the player’s screen says “Loading…”
Hope you can guide me to solving this issue. Thanks a lot mate and have a great week.
April 26th, 2008 at 9:58 pm
@Rod Gibson thats a very simple error, for some reson the .xml file is not were it should be just make shure you didn’t rename it or put it some were else ans chek the sript to see if its pointing to it
April 28th, 2008 at 3:42 pm
I’m heartbroken. This is precisely what I was looking for - and thank you for doing this, Craig - but it would seem that, ah, it’s a Mac .fla. And I’m on Windows. Anyone have any advice?
April 28th, 2008 at 4:10 pm
Heh. Never mind. Operator error.
May 3rd, 2008 at 2:33 pm
Great little player — I’ve been struggling with only one little thing though! Once the list loads, how do I change the autoPlay to no! I’d like the it to be ready to go, but just not start playing automatically.
May 5th, 2008 at 10:35 am
Awesome post, thanks for the player
May 8th, 2008 at 5:48 pm
I figured out how to load the player stopped on the first song. duh. well i’m learning…
I just copied the code from the stop btn section and dropped it in up top after the load section:
pos = sc.position;
sc.stop();
songPlaying = false;
play_btn.addEventListener(MouseEvent.CLICK,playSong);
May 13th, 2008 at 10:06 am
I was wondering if anyone could help with this:
If you have mp3s in this jukebox that are quite larger (say 3mb) and you decide to click next song before the mp3 has fully loaded the file still loads in the background. If you pressed next again all three files would be downloading. Is there a way to stop the first song from completing its loading when you press next?
May 29th, 2008 at 2:39 pm
I love this player too! But, I am having one small problem. I have loaded it onto my site, and I click play. Everything will play fine. If I click FWD, it will skip to the next song just fine. But, when I click FWD to go to the third song, it won’t play. It will only play 2 files at the most before it stops playing. I have checked my XML file, and all of the code is correct. Any tips?
May 30th, 2008 at 12:23 pm
Also, I am using this player as a separate movie on my SWF. It remains stationary on the bottom of the page, while the rest of the page is interactive. When the file opens up everything is fine. But, when I click a button (and change frames), the buttons and text get slightly distorted. It’s like they move slightly. Any idea why this is happening?
July 15th, 2008 at 12:48 pm
Hi
i was wondering is there a way to create the playlist from a radio station. something like a rss blog reader. so the xml is coming from the web?
best regards
ron
August 6th, 2008 at 10:08 pm
Hi
I found a bug. The volume and the pause/play not works correctly. For example turn down the volume to minimum, press pause then press play. Do u hear it?
schwarz
August 22nd, 2008 at 5:35 pm
schwarz is correct, the volume slider setting does not persist as expected.
I’m interested if what Neil Perryman commented is true - does it load multiple MP3s simultaneously if a user is skipping through the playlist?
I have used FlashLoaded.com’s SoundPlayerPro for Actionscript 1.0 and 2.0, but need to have something ready to use when I have the need to do an Actionscript 3.0 project. I was hoping this would work, unless someone knows of a component already created that doesn’t have some of the glitches this one has.
August 23rd, 2008 at 11:38 pm
> when I view the site, my songs play in slow mode (like slow motion).
Your MP3 files are probably encoded with variable bit rate, which is not part of the MP3 specification. If so, you should re-encode the files with constant bit rate and they will play reliably in more players.
August 25th, 2008 at 10:52 pm
to stop a streaming sound from loading use the Sound.close() method instead of Sound.stop()
September 13th, 2008 at 3:17 pm
Hello craig. Im love the design on this and everything about it!
1 problem though.
When i attempt to change to songs (jukebox.xml) i get this error message:
ReferenceError: Error #1065: Variable sof_mc is not defined.
at jukebox_fla::MainTimeline/jukebox_fla::frame1()
Error #2044: Unhandled IOErrorEvent:. text=Error #2032: Stream Error.
at jukebox_fla::MainTimeline/jukebox_fla::frame1()
The songs are saved in the same file as the default songs you put with it. Ive kept all the files in the same place (you said about this earlier) and it still comes up. Could anyone help me fix this problem?
September 15th, 2008 at 3:47 am
Ok i fixed that issue. So simple mistake on my behalf.
But i got a new one now. When i put the player onto my site to test it, it will show up on load but then vanish as soon as i scrool down or go to a diffrent tab/window for a secound. But the buttons will still work.
October 3rd, 2008 at 1:44 am
As someone else said on here, I stopped the autoplay by copying the stop function commands
pos = sc.position;
sc.stop();
songPlaying = false;
play_btn.addEventListener(MouseEvent.CLICK,playSong);
to the end of the whenLoaded function.
Now to fix the volume changing, I added the adjustVolume function commands
var vol:Number = volume_mc.slider_mc.x * .02;
var st:SoundTransform = new SoundTransform(vol,0);
sc.soundTransform = st;
to the end of the nextSong, prevSong, and playSong functions. It would probably be more efficient to just set those functions to set the volume on sound start, but as a newb to this, I don’t know how.
Finally, as of writing this, I got it to start off at a preset volume (rather than full) by going into the library and editing the volume item. You can slide the circular object from left to right and that is what the player will start the slider at. Note that, I’m pretty sure, you need to use the autoplay stop mod or add the adjustvolume code to the end of the whenLoaded function. Otherwise, it will start off full volume. I’m going to try theming it later. Hope this helps people.
October 5th, 2008 at 1:32 am
I noticed I forgot to say anything to the actual developer. Well after messing around with it for a decent amount of hours, I have modded it into a fairly decent custom player for my site. I would like to leave my thanks and appreciation for this core that gave me a strong jumpstart into flash.
October 11th, 2008 at 7:50 pm
Hi all !
I integrated this player in page(button like craig did the learnflash “building a website flash cs3″ video series). And when I move to another page, the player just continue to play…
Can someone help solving this?Because I would like the player to stop all songs playing when I move to another page(which here is also a movie clip)in my main timeline.
Thank you for your answers!
October 12th, 2008 at 10:33 pm
Spikelly, if I understand you right, and you have the music player as a movie clip in another flash file, you would need to have the master flash file (website?) tell the music player to run the stop function before navigating away from it. How exactly, I’m not sure. I don’t know what your setup is.
October 16th, 2008 at 12:31 pm
Yes it’s exactly what I want.
So what I did is that, my web pages are imbedded into differents movie clips. e.g: for my Home page, I have a movie clip called homePage, and inside that movie clip I have several movie clips with texts,images,and also the player created above.And I would when moving from one page to another to stop the player from playing since the problem now it that it continues playing!
So could you help me stopping the player(movie clip) inside my HomePage movie clip.
Thank you for yours answers !!!
October 31st, 2008 at 2:36 pm
Hey, this is a great tutorial! I have a question, is there a way to password protect the mp3 files used in the xml document? I tried using an .htaccess and .htpasswd file to password protect the mp3 files, but it required the password in order to start playing the songs. Anyone know how to keep people from downloading the mp3 files?
November 5th, 2008 at 10:42 am
@Neal: If you can, just place your mp3’s out of the webroot. It’ll make direct downloads a bunch harder. However you can’t stop people for monitoring the traffic and saving the streaming-cache to their HDD
November 27th, 2008 at 5:43 am
I am having trouble opening the flash file. I have tried with Flash MX 2004 and Flash 8 Professional..I also use Vista…has anyone else had this problem and does anyone have any suggestions? Thanks!
November 30th, 2008 at 12:44 am
How do you enter external MP3 files in the XML?
December 1st, 2008 at 7:05 pm
Great player, however when I deploy the flash player to my server, I cannot get the audio to play at all. I’ve definitely uploaded the files properly, including the xml file, and it plays fine on my localdev.
Any suggestions?
January 6th, 2009 at 2:50 pm
Im having the same problem as david (post 17), when i skip one song it works fine, but if i skip 2 it doesnt play.After this point no song plays even if i click the back button.
Any help much appreciated
January 8th, 2009 at 10:40 am
To Mike (post 36),
The problem you are most likely running into is that you are still streaming the first two mp3’s from the web server. Most browsers only allow 2 simultaneous connections to one server. The best way to get around this is to make sure you close the connection to the current song before you move to the next one.
Building upon what webon (post 23) said, try adding the following code to the beginning of the nextSong(e:Event) and prevSong(e:Event) functions:
if(currentSound.bytesLoaded < currentSound.bytesTotal)
{
currentSound.close();
}
January 13th, 2009 at 9:45 am
HI. great file, very usefull, just one thing, does anyone knows how to make this, selectable song, for examle i have three songs in my xml file, an i need three buttons that play a specific song. Hope any one can help me
January 13th, 2009 at 6:54 pm
Error #2044: Unhandled IOErrorEvent:. text=Error #2032: Stream Error.
at MKEEntPlayer_fla::MainTimeline/frame1()
When published to my website from dreamweaver cs4, i need help with this error, not that experienced in action script
January 18th, 2009 at 3:44 pm
I just did a site using your tutorial “Building a simple website” which worked amazingly well. I’ve also used this tutorial to build a music player which is also working amazingly well. The problem I’m having (due to my novice knowledge of Flash) is how to incorporate the music player into my simple website. They work perfectly on their own, but when I insert the player into the website everything goes haywire. Is there any action script info I may be needing?
Thanks so much for your help and your brilliantly done tutorials.
January 28th, 2009 at 3:44 am
Can Anybody help me please? My question is Similar to Geoff (40.) I know the question that Im asking may be a little too ‘beginner’, since I am just starting to meddle with Dreamweaver’s XML and Actionscript, I do not know how to make the player functionable ONLINE.
I have uploaded the player online, also, I have edited the xml file to direct the Songs destination to my specified URL’s mp3 link. Also, after editing the xml, I have upload the xml file together with the player on FileDen (a free file hosting website). HOWEVER, when I click on the player to preview, it does not play any files at all!
Do I need to change or add any codes in AS3 or inside XML files in order for the player to actually stream music from my specified url? So far, I could not find Craig’s guide to how to upload his player online and let the player works fine online.
Many thanks to those who have helped. Blessing to thee!
February 3rd, 2009 at 9:22 pm
Hello,
I tried using your coding, I already had coding for the play and pause buttons and I used what you had for the previous and next buttons. I cant figure out where my coding is wrong.. when I text movie I get 17 errors all saying 1120: access of undefined property (isPlaying, songPlaying, songList, musicrequest, etc etc. What am i missing? or is there a way I can show you my files? I’m having a really hard time with this.
February 5th, 2009 at 9:54 pm
Hello,
I got rid of the old play and pause button coding and copy/pasted everything you had in your flash jukebox.fla. I deleted the display titles and volume adjusters since my player only has the buttons but I think i deleted something that is necessary but I cant figure out what. When i test movie inside FLASH, nothing happens. no sound. when i put it in the FTP to test it, the first song starts playing automatically (which is what I want) but none of the buttons function and the song just continues to play.
what am i missing? My coding is too long so I don’t want to post it in here… let me know if you need to see it.
February 12th, 2009 at 10:06 pm
Hello I figured out how to make the player work but once i transfer my codes to my other pages, it doesnt work because its saying i need the ad_mc and the sof_mc but I’m not using them in my mp3 player so im not sure what the problem is. Can someone please please help me or direct me to someplace where I can get help?
thanks
February 19th, 2009 at 10:54 am
Craig, is there a problem with the size of the mp3?
The player shows the music name and title but it simply dont play it.
I saw your songs are very short but i wanted to play a full song there,
Can you help me please!?
Tks,
manoel
February 20th, 2009 at 12:29 am
Hi Craig,
Just wanted to say thanks! I was able to customize this exactly for the site I’m working on, with no problems and my interface was totally different from yours and I had been making flash crash for about an hour, trying to use the same button for play/pause and once I separated that and made the overlap and toggle between visibility, I had to figure out how the audio loop… YIKES! This article saved me.
Thank you for sharing your brilliance,
Ms.Lee
February 21st, 2009 at 11:31 am
Great code. Thanks its work. If we update xml (url-> song) with some URL(ration Station)its still work.. THANKS Again.
February 21st, 2009 at 7:32 pm
Hey guys I also have been having the major issue of STOPPING SOUND (both from video and music) when ever i leave an swf using external nav buttons.
All you have to do is add this little snippet of code to the end of you main swf navigation button functions, or any internal button within your music/video swf.
HERE’S THE CODE!:SoundMixer.stopAll();
Eg of placement:
///////Your buttont listener and function/////////
artists_btn.addEventListener(MouseEvent.CLICK,loadArtist);
function loadCompany(evt){
//trace(”clicked”);//see if clicked or not
var loadit=new Loader();
loader_mc.addChild(loadit);
loader_mc.removeChildAt(1); //remove current pic
loadit.load(new URLRequest(”subpgs/company.swf”));
///STOP CODE HERE///
SoundMixer.stopAll();
}
PS. Could have slapped my MAMA how easy this was, lol!
Hope this helps fam!
February 21st, 2009 at 8:08 pm
Wazup guys, today is a day of revelations!
I’ve also figured out the easiest/quickest way to make sure all of the music plays at a default volume. (It would be ideal to set the parameter in one place but i couldn’t figure it out)
Just take this peice of code and add it to the END of your (last set of brackets, place in all three functions):
playSong Function
prevSong Function
nextSong Function
THIS IS THE CODE(from the adjustVolume function):
sc.addEventListener(Event.SOUND_COMPLETE,nextSong);
var vol:Number = volume_mc.slider_mc.x * .01;
var st:SoundTransform = new SoundTransform(vol,0);
sc.soundTransform = st;
///Thanks to JUSTIN & CRAIG///
Here’s an EG of how it was used:
function playSong(e:Event):void
{
if(songPlaying == false)
{
sc = currentSound.play(pos);
sc.addEventListener(Event.SOUND_COMPLETE, nextSong);
songPlaying = true;
play_btn.removeEventListener(MouseEvent.CLICK,playSong);
////Heres the inserted code///////////////////////
var vol:Number = volume_mc.slider_mc.x * .01;
var st:SoundTransform = new SoundTransform(vol,0);
sc.soundTransform = st;
//////////////////////////////////////////////////
}
}
PS. LOOK ON THE LINE IN THE FUNCTION THAT SAYS:
“var vol:Number = volume_mc.slider_mc.x * .01;”
I changed the .01 from .02 to mak it a little bit lower in volume. Use this to adjust the starting volume.
Again cheers all! GOod luck.
February 22nd, 2009 at 4:55 pm
That is that I had wanted. BUT…
–> Is there a way to add a list of songs? I want about 50 songs. So it may be tiring to jump to the next song by pressing the buttons continuously.
February 22nd, 2009 at 10:16 pm
Hello I figured out how to make the player work but once i transfer my codes to my other pages, it doesnt work because its saying i need the ad_mc and the sof_mc but I’m not using them in my mp3 player so im not sure what the problem is. Can someone please please help me or direct me to someplace where I can get help?
thanks
February 24th, 2009 at 5:59 am
hai there, i have the same problem as post no.8…i loaded my own song and the song goes slow motion…is there any solution for this problem? or is it the file size that matters? pls i really need to get this code moving…XD
March 7th, 2009 at 8:51 pm
hey. my players made into a movie clip in my webstie project.
everything works fine.
BUT
when i try to switch tracks while previewing. the song schanges but the text does NOT.
any idea on how to fix this. i tried to copy paste the original songs and xml too into my site but just says “undefined”
i just want my text to switch to the next track.
March 11th, 2009 at 5:34 pm
as for the volume adjustment described in #26, you can also do it like this:
1.) change the function adjustVolume(e:Event) to adjustVolume(e:Event = null)
2.) now just call adjustVolume() in play, next etc..
March 13th, 2009 at 5:55 pm
Hey!
I love this player, but when I browse the pages of my website and go back to home page, the first song starts allover again, overlapping with what is already playing… any ideas why?
I changed the script to: var songPlaying:Boolean = true;
so the song starts automatically.
any idea how I can stop it from repeating itself?
March 19th, 2009 at 8:14 am
I have yet to really use this yet, but I was wondering about something… is there anyway to make this play REMAIN playing which skipping from page to page. See I have a record label website and need the player to continue playing even when I navigate away to another page under the same domain… Any help?
March 25th, 2009 at 8:36 am
Maybe someone can help me. I tried to add a new category to be shown in the text (album title). I edited the xml file and went through the action script and copied code for artist_txt and simply pasted and changed to album_txt. Unfortunately whenever I test the player I get the following message:
ReferenceError: Error #1065: Variable album_txt is not defined.
at test_fla::MainTimeline/whenLoaded()
at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/flash.net:URLLoader::onComplete()
March 26th, 2009 at 9:13 am
Nice player thanks, but if you click the play button more than once another version plays over the first, the more times you click play the more versions of the song play at the same time anyway to stop this ?
Thanks
March 27th, 2009 at 11:34 am
Hi, great tutorial, helped me out a lot. Ok my question is how to I get this working on my site I made in Dreamweaver, It works fine in Flash when I preview it, but when I loaded the SWF into Dreamweaver it just says loading and never plays a song. So My question is how to I get it to read the .XML file in the server where I have this site stored ??? I have everything in the server, and on my desktop when I load it in Dreamweaver but nothing plays. Only plays when I load it in Flash as a preview test.
April 2nd, 2009 at 6:26 am
How do you enter external MP3 files in the XML?
Thanks
htttp://www.sahibimolurmusun.com
April 3rd, 2009 at 5:00 pm
Anyone having the same problem as Spikelly (28) there is an easy fix. just paste this code:
jukebox.stop();
paused = true;
}
after your on(release) command for whatever button is moving you off the page with the music player.
Awesome player, thanks Craig! easy to use and mod.
April 16th, 2009 at 2:01 pm
I’m having the same problem as Byron (post #35). Has anyone come up with a solution to this problem? It works fine locally, but when I put the files out on the server (and I am doing this correctly - I do this for a living) the player just reads: “loading” but it never loads.
Please help.
April 17th, 2009 at 2:51 pm
Im not very good with coding, I change the songs in teh file and also at the XML page but now I get this problem I love the player and I want to be able to use, please help.
Error #2044: Unhandled IOErrorEvent:. text=Error #2032: Stream Error.
at jukebox_fla::MainTimeline/frame1()
thank you
April 23rd, 2009 at 8:52 am
Hi, first I have to say that your player works very well. Thanks!!!!!
I just have a question:
How can I set it to play the songs aleatory?
April 23rd, 2009 at 11:05 am
What I would love to know is if anyone has figured out how to make the player pull songs from the playlist randomly?