Jump to content
Search Community

Having trouble playing loaded MP3 from TimelineMax??

cerulean test
Moderator Tag

Recommended Posts

I have a function set up to play a loaded MP3 by name string:

protected function playSoundByName($name:String):void {
	//	trace("play sound by name ", $name, LoaderMax);
		_currentSound = LoaderMax.getContent($name);
	//	trace("current sound is ",_currentSound);
		if (_currentSoundChannel) _currentSoundChannel.stop();
	//	trace("the sound is ", _currentSound,_currentSound.length,_currentSound.url);
		_currentSoundChannel = _currentSound.play(0);
		_currentSound.addEventListener(Event.SOUND_COMPLETE,soundComplete,false,0,true);
}

Which works fine when I call it directly, but not when I call it from a callback in a TimelineMax (see below -- the first call works fine, the one from inside the TLM does not).  I'm sure I'm missing the obvious, but it's a big problem…Thanks…

var introSoundsTL:TimelineMax = new TimelineMax({ease:Linear.easeNone});
playSoundByName("jsTexasSurf"); // works!
				
introSoundsTL.addCallback(playSoundByName,0,["jsTexasSurf"]); // the sound from LoaderMax.getContent() in called function is null!

(The loaded xml is in this form:

<?xml version="1.0"?>
<content>
<timelimit limit="45"  />
	<MP3Loader url="music/jetski/321go.mp3" name="js321Go" autoPlay="false" load="true" />
	<MP3Loader url="music/jetski/pg3-300beachs.mp3" name="js300beaches" autoPlay="false" load="true" />
	<MP3Loader url="music/jetski/pg5-texassurf.mp3" name="jsTexasSurf" autoPlay="false" load="true" />
	
</content>

)

Link to comment
Share on other sites

UPDATE:

 

If I load the sounds using LoaderMax.getContent() into an object soon after I load the xml and then grab them by name when I do the TimelineMax callback, all works perfectly.  That is, I can't use LoaderMax.getContent() from within the TimelineMax callback, but if I do it first, and use the saved sounds, it works fine.  Why??

 

Does this have something to do with the note in the API that the sounds that are loaded may get garbage collected and you need to make local copies?  Or am I reading that wrong?

 

The way my class structure is set up, I can't load the sounds immediately after loading the xml, but only when I instantiate a class that will use that xml (shortly thereafter).  If there's a GC issue how much time do I have, if any, before the sounds are at risk?

Link to comment
Share on other sites

No, I highly doubt it has anything to do with gc. Are you 100% sure the file is loaded when that method gets called? Also, try tracing some stuff inside your method to ensure that the scope is intact. If none of that helps, please post a very simple FLA (and sound) file so that we can publish on our end and see what's happening. 

Link to comment
Share on other sites

Thanks. Yes, all the sounds are loaded. In fact I'm able to grab them from the LoaderMax before I can't grab them from LoaderMax from within the timeline callback! (I also get reports that they're loaded from within the main progress report of my xmlloader — the progress of an xmlloader loading xml that contains MP3Loader nodes will report the percentage of all things loaded? Or will the complete for the XMLLoader fire before the MP3s are fully loaded?).

 

 

I'm working in AS3 -- what would I be looking for in terms of scope? I don't know what I'd be looking for, the difference between a call called external to a timeline, and a call called as a callback from within a timeline that is played immediately…

 

UPDATE:

 

Banging my head on this one. The call to LoaderMax.getContent works in my function and then if I put in a delayed call, (forget about the timeline, just a TweenMax delayedCall) stops working. A number of class instantiations happen in between, i.e. a lot of stuff going on but nothing that should affect LoaderMax internals. Why would a call to LoaderMax.getContent('mysound') work and then not work? Could it be GC? I know that an FLA is called for, but this is a two-month project and I don't think I can pull it apart at this point — and the devil seems to be in the details. So, to summarize, LoaderMax works fine, then something I'm doing is making it not return the Sound anymore.

Link to comment
Share on other sites

The only thing I can think of that might cause that behavior is if you're destroying the MP3Loader at some point or calling unload(). Again, GC should NOT be a problem because it's shielded internally. Or maybe you're loading something else and naming that other type of loader (like an ImageLoader) the exact same name, so that when you use getContent() and pass in the name, it's finding the other loader that hasn't loaded yet or something odd like that. I'm grasping at straws here :)

 

As far as the FLA, no need to send your whole project - you can literally just create the most basic possible thing that shows the order that you're doing things and causes it to break. If it works fine in your example FLA, chances are that you've got something else going on in your code that's causing the issue (not necssarily, just a probability).

Link to comment
Share on other sites

Thanks. I'll try to see if I can get an FLA together.  I'm quite certain it will work, and that the error lies in my code, though.  I don't call unload() anywhere, and I'm actually not using LoaderMax in many places, only to load xml really.  And they asked me on a rush to add a lot of voiceovers -- the somewhat rushed code which resulted from their rush is causing me headaches.  I don't think I'm using similar names for images, etc -- the names are quite unique.  My uncertainty stems from the fact that I seem to affecting something internal to LM with my code, but I don't know how to monitor LM to see what's going on -- I was looking to see if there were a list of loaded assets I could get statically to see "what's in there", but couldn't find it --

 

My point regarding GC wasn't that there was a bug in LoaderMax, or anything like that, but was in reference to this note in the API.  I seem to have misread it -- it refers only to canceled or unloaded MP3Loaders...

 

 

 

NOTE: To avoid garbage collection issues in the Flash player, the Sound object that MP3Loader employs must get recreated internally anytime the MP3Loader is unloaded or its loading is cancelled, so it is best to access the content after the COMPLETE event has been dispatched. Otherwise, if you store a reference to the MP3Loader's content before or during a load and it gets cancelled or unloaded for some reason, the Sound object won't be the one into which the MP3 is eventually loaded.

 

Link to comment
Share on other sites

Solved: in the XMLLoader that I was using to auto-magically auto-load the MP3Loaders, I was setting autoDipose:true.  The MP3Loaders were getting disposed out from under me…

 

Thanks Jack and everyone for their help!

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.
×
×
  • Create New...