Game Development Community

Alxplay callback when done?

by Shai Perry · in Torque Game Engine · 06/26/2006 (3:26 pm) · 4 replies

Hi,

I was wondering if there is a way to get a callback when alxplay is finished playing a sound.. ?

Thanks,

#1
06/27/2006 (9:03 am)
I don't believe there is in the stock engine. Either through ignorance or impatience, I used to use a schedule loop to check if the sound was still playing. I don't have the code, but it was something like this:

function Foo::PlayIt( %this) {
   %this.audiofile = alxPlay(...);
   %this.Cycle();
};
	
function Foo::Cycle( %this) {
   if (alxisPlaying( %this.audiofile))
      %this.schedule( 100, Cycle);
   else
      %this.schedule( 1000, Cue);
}
#2
06/27/2006 (12:03 pm)
A callback when a sound is finished playing is an interesting idea. Of course it would never be completely accurate as the callback could delay as long as a single engine tick (32ms).
#3
06/27/2006 (12:35 pm)
...not to mention the fact that openal processes seperate thread, potentially delaying the callback even further.

Implementing such a callback mechanism should be simple enough, provided you have access to the source. I'd suggest calling a console function in the audio update loop, e.g. alxHandleFinished(). From there, you can determine which handle has stopped playing, and then, what to do next.
#4
06/27/2006 (6:49 pm)
Thanks guys