Jump to content
Search Community

Stupid question, I know

Cadfael test
Moderator Tag

Recommended Posts

Hey guys,

I usually parse tons of post and can find enough info for what I need. But what I need is so simple, I can find examples in all the complicated problems people bring here :)

 

What I am looking for is a simple load and play of an MP3. Below is a piece of code I wrote to try MP3Loader. For some reason this isnt playing the sound in the intro.mp3.

 

As a side note I was just using the sound and soundchannel facilities in adobe, but they seem to be somewhat memory leaky. In the past greensock code has helped with Video, I assume audio is cleaner here as well. But the audio I am using is pretty simple, just play serveral times.

 

 

Any suggestions?

 

 

 

 

 

import com.greensock.*;

import com.greensock.easing.*;

import com.greensock.events.LoaderEvent;

import com.greensock.loading.display.ContentDisplay;

import com.greensock.loading.*;

 

LoaderMax.activate([MP3Loader])

 

var myMP3:MP3Loader = new MP3Loader("intro.mp3",{repeat:1, onComplete:playSound} );

myMP3.load();

 

function playSound(event:LoaderEvent)

{

var loadedMP3:Sound = event.target.content;

trace(event.target.content);

loadedMP3.play();

}

Link to comment
Share on other sites

Hi,

 

Your code worked fine for me.

 

Are you getting no sound at all?

 

There are a few things that could change with your code,

 

First, if you want MP3Loader to repeat, you shouldn't be trying to tell the event.target.content to play. MP3Loader will do that for you.

 

this is enough to load the sound, play it and repeat it once:

 

 

var myMP3:MP3Loader = new MP3Loader("intro.mp3",{repeat:1} );
myMP3.load();

'

 

an MP3Loader will autoPlay by default.

 

If you want to load sound but wait for onComplete for the sound to play and repeat do this:

 

 

var myMP3:MP3Loader = new MP3Loader("laser.mp3",{repeat:1, autoPlay:false, onComplete:playSound} );
myMP3.load();

function playSound(event:LoaderEvent)
{
event.target.playSound();
//or myMP3.playSound();
} 

 

if you don't want to use the conveniences (repeat:1) and playback methods (playSound()) of MP3Loader, you can certainly bypass them and use event.target.content to target the Sound() object directly.

 

I really had no problem with your code as-is except:

 

The sound was obviously playing twice at the same time and then there was a single repeat.

 

Since I was testing locally, the MP3Loader was automatically playing the sound while event.target.content.play() was playing the Sound() object directly (via your onComplete callback), and then a single instance of the sound played when the repeat happened.

 

Does this help? If not, I can provide some working files.

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