Jump to content
Search Community

MP3Loader.soundTime trigger custom event

bonassus test
Moderator Tag

Recommended Posts

I want to check the MP3Loader.soundTime property and have it trigger an event at 3 seconds but I'm not sure how to do it. Help appreciated thanks.

 

IntroMp3.playSound();

if (IntroMp3.soundTime == 3){
//customEvent here...
}

Link to comment
Share on other sites

Ok I got it to work with an enterframe and an if statment that checks if IntroMp3.soundTime is between 3 and 3.1 so that the loop doesn't run forever. Is there a better way to do this?

Thanks.

 

 

IntroMp3.playSound();

addEventListener(Event.ENTER_FRAME,myFunction);

function myFunction(event:Event) {
addEventListener( CustomEvents.IntroSound, firstMenuOpen, false, 0, true );

if(IntroMp3.soundTime >= 3 && IntroMp3.soundTime < 3.1)
{
dispatchEvent( new CustomEvents( CustomEvents.IntroSound ) );
}
}

Link to comment
Share on other sites

Yep, that's the right general idea. Your code is pretty generic and doesn't accommodate situations where a processor load causes the time to skip from 2.95 to 3.15 or something, but that shouldn't be too difficult to tweak. Feel free to look at the _playProgressHandler() method inside VideoLoader if you want to see the technique I used to fire off cue points events.

Link to comment
Share on other sites

Yeah,

I ended up using PLAY_PROGRESS for the event and then removed the event listener on the the function called by the custom event. Thanks for your response.

 

IntroMp3.playSound();
IntroMp3.addEventListener(MP3Loader.PLAY_PROGRESS,myFunction);

}
function myFunction(event:Event) {
addEventListener( CustomEvents.IntroSound, firstMenuOpen, false, 0, true );
if(IntroMp3.soundTime >= 15 && IntroMp3.soundTime < 15.1)
{
dispatchEvent( new CustomEvents( CustomEvents.IntroSound ) );
}
}
function firstMenuOpen(e:CustomEvents){
IntroMp3.removeEventListener(MP3Loader.PLAY_PROGRESS,myFunction);			
}

Link to comment
Share on other sites

  • 7 months later...

Hi!

 

Thanks for the great work!

 

I'm trying to implement audio cue points using LoaderMax' MP3Loader. I'm currently intenting to use the classes described in this page: http://www.adobe.com/devnet/actionscrip ... audio.html .

 

The idea is to have a SoundSync class extending Sound, and to add cue points and trigger a CuePointEvent when it's reached.

 

I didn't have much success until now. The problem is that I can't find a way to pass the MP3Loader.content to SoundSync. SoundSync extends Sound, so it has a .load(URLRequest) method, but that's about it: I can't pass a Sound object to it.

 

Would you have any idea on how to do that?

 

Is there any way to assign a class to the loaded content? For instance, MP3Loader.content would return an instance of SoundSync instead of Sound?

 

Did you think about implementing cue points functionality for audio as you did for video?

 

Thank you very much for any help that you can provide!

Stéphane

Link to comment
Share on other sites

Well, it is certainly possible to add cue point functionality in MP3Loader, but I haven't done so thus far for 2 primary reasons:

 

1) Lack of interest from users (you're the first person I can remember ever requesting it)

 

2) The file size and slight performance cost that would be imposed on all users (even those who have no interest in cue points).

 

It made more sense with VideoLoader (in my opinion) because it is more common for folks to want cue points and because VideoLoader was already a relatively large class (to work around all the bugs and inconsistencies in NetStream), so the overall percentage of kb added was pretty minor. But MP3Loader is less than half the size, so the ratios are different. See what I mean?

 

To integrate the SoundSync class into MP3Loader, you'd need to actually edit the class itself. Either edit the SoundSync class so that it uses composition instead of inheritance or edit MP3Loader so that it uses a SoundSync instance instead of a Sound instance internally. Or just add the cue point functionality in MP3Loader directly using VideoLoader as a template (if you want).

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