Jump to content
Search Community

MP3Loader Best Practices

jhakooz test
Moderator Tag

Recommended Posts

I'm feeling kind of dumb for asking, but...

 

I'm building a multimedia player. For now I'm only concerned with the MP3Loader portion.

Basically, I could have hundreds of MP3s which I only want to load on demand and one at a time. What is the best way to go about this?

 

I thought about creating a single MP3Loader and simply re-use it.

 

private var _mp3Loader:MP3Loader;

public function playMP3(audiofilename:String):void{
stopPrevAudio();
_mp3Loader = new MP3Loader(audiofilename, {name:"mp3", autoPlay:true, estimatedBytes:9500, onComplete:completeHandler});
_mp3Loader.addEventListener(MP3Loader.PLAY_PROGRESS, playProgress);
_mp3Loader.load();
}
private function stopPrevAudio():void{
_mp3Loader.unload(); // No sound ever plays when I do this. And still needs to remove event listeners, etc...
}
private function completeHandler(event:LoaderEvent):void{
// 
}
private function playProgress(event:LoaderEvent):void{
// 
}

The "unload" seems to kill the object. And creating potentially hundreds of MP3Loader objects seems like bad practice. Can someone please point me in the right direction?

I'll provide more code if needed, but wanted to keep it simple for now.

 

Thanks in advance...!

Link to comment
Share on other sites

Ok, adding a conditional before unloading the object helps. You can't unload an object that is null... duh right?

For now, it seems I'm heading in the right direction. I'll post if I hit a hiccup...

 

Thanks

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...