Skip to main content
New Participant
March 24, 2009
Question

Creating a music play button to play an mp3 file

  • March 24, 2009
  • 2 replies
  • 1740 views
I am creating a music site in flash. I would like to have it list out our clients music files for people to stream simply by clicking a button. Just the corresponding file, not a list of mp3.s - just one. When they click it a second time it will stop playing. No volume control needed. Can someone help me with this command? For some reason I can't find any documentation for mp3 files here or on the web - instead they point me to 'create your mp3 player in flash here' and it's branded or more than I need.

A good example is from this site: http://terrorbird.com/ under the Jukebox column. Those play buttons are what I need.
This topic has been closed for replies.

2 replies

xchanin
Participating Frequently
March 24, 2009
This works for me:

package
{
import flash.display.MovieClip;
import flash.events.*;
import flash.media.*;
import flash.net.URLRequest;

public class SoundLoader extends MovieClip
{
private var isPlaying:Boolean = false;
private var snd:Sound = new Sound();
private var channel:SoundChannel = new SoundChannel();
private var pos:Number = 0;
private var soundVolume:Number = 1;

public function SoundLoader()
{
snd.load(new URLRequest("something.mp3"));
btn_Stop.addEventListener(MouseEvent.CLICK, stopMusic);
btn_Stop.buttonMode = true;

btn_Play.addEventListener(MouseEvent.CLICK, playMusic);
btn_Play.buttonMode = true;
}

private function stopMusic(evt:Event):void
{
channel.stop();
pos = 0;
isPlaying = false;
}

private function playMusic(evt:Event):void
{
if(!isPlaying)
{
channel = snd.play(pos);
btn_Play.visible = false;
btn_Pause.visible = true;
isPlaying = true;
}
}
}
}
April 19, 2009

Do you add this to the button or on an empty frame? I am newbie.. please can anyone point to me a tutorial, because I have the same problem

Inspiring
April 19, 2009

This actually refers to a class file (external flash file).

for example if the class name was: Myclass.as

Store the file in the same directory as your swf and fla. Then in frame one enter:

//first import the class file

import game.SoundLoader;

// create an instance

var myCoolSound:SoundLoader = new SoundLoader();

// now you can use it in your AS

Let us know if you still have a problem.

Message was edited by: >Vee<

xchanin
Participating Frequently
March 24, 2009
Here is a basic tutorial that will help get you started, building out your own music player in AS3:
http://flashspeaksactionscript.com/create-a-mini-music-player-in-as3/
New Participant
March 24, 2009
Too bad I can't get that script to work.

On the flash page I will have - say - 5 bands listed. By each will be a song title and then the option to click play or stop. That script didn't seem to work (i posted my issues with it on their page). Any other suggestions?