Topic: Embed MP3 using FlashDveleop?

Hello,

I'd like to embed an MP3 in a widget and play it as a background loop.  I'm trying to do this in FlashDevelop (I'm new to Flash development).

I know it can be done dynamically via Sound.loadSound(...) and Sound.start(...) but I can only get this working with external MP3s.  Is there a way to access an mp3 in the 'library' and loop it?

Thanks!

wayn3w

2 (edited by wayn3w 2008-02-24 13:35:42)

Re: Embed MP3 using FlashDveleop?

I figured this out... and learned alot about FlashDevelop and swfmill.  In short:

* You cannot add an MP3 directly into a Flashdevelop project; you need to create a separate swf using swfmill and add the new swf to the library.  Then you can access the MP3 via the ID using attachMovies().  It helps to make a 'pre-build' command to build the new swf.

* swfmill only supports a limited set of MP3 bit rates: stereo (not joint stereo) 56, 64, 128, 192, 256 kbps.  I only found success with the 128kbps rate.

* for some reason, I cannot get onSoundComplete to work on the Chumby to make a loop; it works on my PC.

wayn3w

Re: Embed MP3 using FlashDveleop?

Could you please post the XML file that is used by swfmill to create the swf file and also post the corresponding lines of ActionScript that access the sound file? Thanks.

Re: Embed MP3 using FlashDveleop?

Following up on the guidance above, here are some detailed instructions for embedding sounds using FlashDevelop.

The version of FlashDevelop I’m using (3.0.0 Beta 7) cannot directly import a sound as a library element like the png and fonts mentioned here. However, FlashDevelop can import an swf file that contains the sound. So here are the steps.

1.    Find the sound. I needed a click or beep to indicate a button push and so searched the Internet for public domain sounds. I ended up using a sound from this web site http://www.partnersinrhyme.com/soundfx/ … beep.shtml entitled “beep pure”. You may find sounds such as this one in a variety of formats, but they need to be converted to mp3 format with 128kbps encoding.
2.    Convert the format using a free audio editing tool called Audacity which you can download from here http://audacity.sourceforge.net/download/windows. You can use this tool to clip out dead space, adjust volume, and many other things. In order for Audacity to produce mp3 format output, you must also download a dll utility called lame. There is a link to lame from the same Audacity web site. The first time you run Audacity and try to export to mp3, you will be asked to locate the lame dll file. Export to mp3 using this lame dll automatically chooses 128kbps. In my case, I exported to a file named BEEPPURE128kbps.mp3
3.    You need to use swfmill to create an swf file that contains the sound file. The swfmill program is guided by an XML file. Use a text editor to create an XML file called sounds.xml similar to this:

<?xml version="1.0" encoding="iso-8859-1" ?>
<movie width="320" height="240" framerate="12">
  <background color="#ffffff"/>
<frame>
  <library>
    <sound id="beep2ID" import="BEEPPURE128kbps.mp3"/>
  </library>
</frame>
</movie>

Note that the string after “sound id” above will be how you refer to the sound in your ActionScript code and the string after the “import” above is the name of the file you created as an export from Audactiy using lame.
4.    Because FlashDevelop uses swfmill, you have probably already downloaded it. I found it in C:\Program Files\FlashDevelop\FirstRun\Tools\swfmill\swfmill.exe. From there run it from a DOS command line like this:
    swfmill simple sounds.xml sounds.swf
This should produce the sounds.swf file that you will use in your FlashDevelop project. At this step, I had problems with many sound files where swfmill would complain that the mp3 file referred to in the XML file was invalid. I’m not sure why, but if you are willing to find the swfmill source code, apply patches, and compile it, here is a link to a site that has a patch that purports to fix some of the shortcomings with sound import with swfmill.
http://www.mindless-labs.com/blog/archi … ile_import
I just kept trying until I found a sound file that worked with the existing swfmill.
5.    Move the resulting swf file into the folder with your FlashDevelop source. Then within FlashDevelop, find this file name in the panel on the right side. Note that the filename is black. Next right click on the file name and from the pop-up menu, select Add to Library. Then the filename will turn blue.
6.    In your ActionScript code, you would put something like the following:

static var _beep2: Sound = new Sound();

static function Main(mainMc:MovieClip){
    _beep2.attachSound("beep2ID");
    _beep2.setVolume(10);  // Because otherwise its too loud
    ...
    // Upon push of a button...
    beep2.start();
}

7.    Compile and run. The sounds did not work on the Flash player integrated with the FlashDevelop environment, but they worked fine on the Chumby.