02-04-2011 12:34 PM
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.
02-04-2011 12:45 PM
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.
02-04-2011 12:52 PM
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.
02-05-2011 07:13 PM
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.