Jump to content
GreenSock

DagShot

MP3Loader and imported MP3 files

Recommended Posts

Hey There,

 

i wonder if there is any way to use the MP3Loader Methods with Mp3 files that are imported in the

.flas library.

 

The admin wants a single .swf rather than over a hundret files.

its such a shame, because it realy works well.

 

i tried to, but it didnt work. maybe im doing it wrong, or maybe its just not meant to be.

 

It would be very nice if you could help me out.

Link to comment
Share on other sites

MP3Loader is for loading assets external to the swf. Keeping the mp3s external is usually the best thing for the developer and end-user.

 

If your mp3s are really big it will effect compile time and download time.

 

If you absolutely have to embed the mp3s, look into the GreenSock SelfLoader which allows a swf to monitor its own loading.

 

http://www.greensock.com/as/docs/tween/com/greensock/loading/SelfLoader.html

Link to comment
Share on other sites

yeah i know, thanks for your reply.

 

the loadiing itself isnt the problem,

 

its about the onprogress Event, duration, time, progress propertys witch i use in the program to monitor and dispatch certain actions. Working with these functions is very intuitive and practical.

 

if i know have to embed everything i somehow have to rewrite all the functions.

is there an equivalent to these very features, somehow, somewhere?

 

thx.

Link to comment
Share on other sites

This is what works for me.

Define Loaders in xml. Set autoPlay to false so we don't hear them play as soon as they are loaded

 

?xml version="1.0" encoding="iso-8859-1"?>
<data>
<LoaderMax name="sampleQueue" load="true">
  <MP3Loader  url="H_Drums_AirVentOpen.mp3" name="H_Drums_AirVentOpen" autoPlay="false"/>
  <MP3Loader  url="H_Drums_FuelCapOpen.mp3" name="H_Drums_FuelCapOpen" autoPlay="false"/>
  <MP3Loader  url="H_Drums_HandbrakeOn.mp3" name="H_Drums_HandbrakeOn" autoPlay="false"/>
  <MP3Loader  url="H_Drums_hi-hat.mp3" name="H_Drums_hi-hat" autoPlay="false"/>
  <MP3Loader  url="H_Drums_kickdrum.mp3" name="H_Drums_kickdrum" autoPlay="false"/>
  <MP3Loader  url="H_Drums_snare.mp3" name="H_Drums_snare" autoPlay="false"/>
  <MP3Loader  url="H_Drums_Tap.mp3" name="H_Drums_Tap" autoPlay="false"/>
  <MP3Loader  url="H_ClassicBass_01.mp3" name="H_ClassicBass_01" autoPlay="false"/>
  <MP3Loader  url="H_ClassicBass_02.mp3" name="H_ClassicBass_02" autoPlay="false"/>
  <MP3Loader  url="H_ClassicBass_03.mp3" name="H_ClassicBass_03" autoPlay="false"/>
  <MP3Loader  url="H_ClassicBass_04.mp3" name="H_ClassicBass_04" autoPlay="false"/>
  <MP3Loader  url="H_ClassicBass_05.mp3" name="H_ClassicBass_05" autoPlay="false"/>
  <MP3Loader  url="H_ClassicBass_06.mp3" name="H_ClassicBass_06" autoPlay="false"/>
  <MP3Loader  url="H_ClassicBass_07.mp3" name="H_ClassicBass_07" autoPlay="false"/>
  <MP3Loader  url="H_ClassicBass_08.mp3" name="H_ClassicBass_08" autoPlay="false"/>
  <MP3Loader  url="H_ClassicBass_09.mp3" name="H_ClassicBass_09" autoPlay="false"/>
  <MP3Loader  url="H_ClassicBass_10.mp3" name="H_ClassicBass_10" autoPlay="false"/>
  <MP3Loader  url="H_ClassicBass_11.mp3" name="H_ClassicBass_11" autoPlay="false"/>
  <MP3Loader  url="H_ClassicBass_12.mp3" name="H_ClassicBass_12" autoPlay="false"/>
  <MP3Loader  url="H_ClassicBass_13.mp3" name="H_ClassicBass_13" autoPlay="false"/>
  <MP3Loader  url="H_ClassicBass_14.mp3" name="H_ClassicBass_14" autoPlay="false"/>
  <MP3Loader  url="H_ClassicBass_15.mp3" name="H_ClassicBass_15" autoPlay="false"/>
  <MP3Loader  url="H_ClassicBass_16.mp3" name="H_ClassicBass_16" autoPlay="false"/>
</LoaderMax>
</data>

 

 

 

Load the XML with the MP3 loaders defined. I'm Using a couble of inner functions to keep tabs on progress, errrors etc

 

 

  public function loadStuff() : void {
  LoaderMax.activate([MP3Loader]);
  // only necessary once - allows XMLLoader to recognize MP3Loader's in the XML
  try {
loader = new XMLLoader(_cs_samplesPath + "samples.xml", {prependURLs:_cs_samplesPath, onProgress:sampleLoadProgressHandler, onComplete:sampleLoadCompleteHandler, onError:sampleLoadErrorHandler, estimatedBytes:50000});
loader.load();
  } catch(error : Error) {
trace("Load Stuff has ");
  }
  function sampleLoadProgressHandler(event : LoaderEvent) : void {
// trace("progress: " + event.target.progress);
  }
  function sampleLoadErrorHandler(event : LoaderEvent) : void {
trace("error occured with " + event.target + ": " + event.text);
  }
  function sampleLoadCompleteHandler(event : LoaderEvent) : void {
createSamples();
  }
 }

 

 

 

Once they are loaded I use their names from the XML and the content of the MP3Loader to do what I need

 

  private function createSamples() : void {
  var sampleXML : XML = loader.content;
  var sampleloaders : XMLList = sampleXML.child("LoaderMax").child("MP3Loader");
  for (var i : int = 0; i < sampleloaders.length(); i++) {
var sampleName : String = sampleloaders[i].@name;
var voiceSound : Sound = LoaderMax.getContent(sampleName);
var newPCMVoice : SiONVoice = new SiONVoice();
newPCMVoice.setPCMVoice(voiceSound);
samplerVoices.push(newPCMVoice);
samplerVoicesNames.push(String(i) + "-" + sampleName);
  }
  getStarted();
 }

Link to comment
Share on other sites

thank you for your reply.

i will check out if this is what i was looking for, tomorrow!

i don't have time today.

thanks a lot.

 

*EDIT

 

Are all these mp3s located inside your swf?

this is important

Link to comment
Share on other sites

Hi Jobbies,

 

I was interested to understand your code and have a question.

What is the prependURLs:_cs_samplesPath .?

Is that (_cs_samplePath) just that a example path location to where your mp3 files are located?

I was trying your code in my project and got errors, that the following properties are undefined

For example: say my mp3 files are located in 2 sub folders so my location is prependURLs:folder1/folder2

 

Not sure how I should resolve this.

Ben

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×