Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
Developer
Posts: 119
Registered: ‎03-10-2010
My Device: Bold 9000
My Carrier: Rogers

Playing sound effects over animation

Since I'm assuming qnx.media Mediaplayer doesn't work yet on the simulator (based on advices from this forum), I'm keeping using the AS Sound object to play a sound effect in my application.

 

So basically, I'm doing this to play the sound:

 

 

 

var soundplayer:Sound = new Sound();
var url:URLRequest = new URLRequest(audiofile.name);
soundplayer.load(url);
soundplayer.play();

 

 

Just after that, I call a function that starts an animation (using Five3d library Tweener object).

 

The problem is that the sound doesn't synchronize properly with the animation. Actually, it is played with a certain delay *after* the animation starts, despite the fact the play() is called *before*.

 

Because of that behavior, I'm assuming play() works asynchronously, but I cannot see how to control its timing.

 

Is there another way to deal with that?

 

Any help or reference will be appreciated.

 

Regards

 

 

Paulo Garcia



(*) Kudo-me if you really think I helped you!
My plug: I'm doing a Mobile Experiment, reported on my Blog: Check it out!.
---------------------------
Paulo Garcia
http://www.mobilecreators.com - Twitter: http://twitter.com/mobilecreators
Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Playing sound effects over animation

Possibly this has something (bug in simulator) to do with the time delay I discovered when generating audio directly.

 

If it's related, one guess is that it's using the sample rate stored in your audio file, and that you've used a relatively low sample rate.  As noted in my post, I had to use 22kHz or 44kHz to avoid the time lag.

 

There will also be a small delay in any case, I think, simply because the sound is not synchronized... generally you ought to be able to minimize this by starting the play earlier, but there are obviously issues with that.  It would have a different latency on real hardware, not to mention it would depend on what other code was running at the same time.


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: Playing sound effects over animation

There will be a delay because the app has to load the sound file to start playing it.  If the sould file is not too large, you could embed it so the sound would start right away.  Short audio effects that might be used on page transitions or button pushes, it is better to embed.  The trade off is that the application size is larger and might be slower to load, but at least your s/fx would be fast.  If you have lots of these, this would be a good use of a Module that has the embedded assets like sound effects.  Application starts up, shown the user, a second later the Module gets loaded and would have direct access to embeded sounds.  Just a suggestion.

Highlighted
Developer
Posts: 439
Registered: ‎10-25-2010
My Device: Not Specified

Re: Playing sound effects over animation

There's always been a bug in AIR 2.5 on Android, with delayed sound effects. I'm not sure if it ever got fixed or not, might be worth looking into... 

Developer
Posts: 119
Registered: ‎03-10-2010
My Device: Bold 9000
My Carrier: Rogers

Re: Playing sound effects over animation

I tried both suggestions here. First, I changed the audio file sample rate, but I didn't notice any change. The second attempt was embed the audio file. This time, it seems better, but I'm still not happy. Maybe it has also to do with the way I'm starting my animation later on.

 

Since my audio file has only 10k, I'll keep the embed solution.

 

Thanks

 

 



(*) Kudo-me if you really think I helped you!
My plug: I'm doing a Mobile Experiment, reported on my Blog: Check it out!.
---------------------------
Paulo Garcia
http://www.mobilecreators.com - Twitter: http://twitter.com/mobilecreators