is there a finished playing callback with finch? similar to - audioPlayerDidFinishPlaying in the avaudioplayer stuff? looking through the code i could not find anything that referenced it.
finished playing audio callback with finch
454 Views Asked by zachron AtThere are 3 best solutions below

@zoul: I know this is a vey late reply. But I noticed that the answer is not correct. What if I pause the sound or if there is an interruption from system. In such case, you will receive a callback even if the sound is not completed yet. Please read paragraph "4.3.6. Managing Source Execution" from openAL specs for correct handling.

Here's a hack with a pitch fix if you don't care about interrupts.
OpenAL changes the playing length of the sound played when pitch is not 1.0. (it doesn't seem possible to query this new length from OpenAL, as the AL parameters return the same values as before)
Pitch ranges from 0.5 to 2.0f. So, if we assume pitch at 0.5 is exactly twice as long, and pitch at 2.0 is exacty half as long, we should be able to use pitch as a multipler:
- (void) playSoundWithCallback {
[someSound play];
[someDelegate performSelector:@selector(soundDidFinishPlaying:)
withObject:someSound afterDelay: someSound.duration * (1.0/someSound.pitch) ];
}
There is no such callback in Finch, because OpenAL does not support it. (Or at least it did not support it when I last looked.) You can fake it like this:
I did not try it, but it’s a simple code, it should work fine. Well… at least until you start messing with the pitch and therefore the sound speed :)