I want to know what’s equivalent to using AVAudioPlayerDelegate‘s audioPlayerDidFinishPlaying:successfully: method in OpenAL. For example:
-(void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag
{
// (code or conditions for when the audio has finished playing...)
}
Generally speaking, OpenAL won’t notify you when audio has finished playing, so there’s no real equivalent to the
AVAudioPlayerDelegate. The easiest way is to simply delay a function/block call by the length of the audio. As an example, you could use libdispatch (aka Grand Central Dispatch) to add a block to a queue after a set amount of time:The slightly harder way is, as mentioned in the comment inside the block, to check if OpenAL is finished in the block and, if it isn’t, to push the block onto the queue again (probably with a shorter delay, especially if you can approximate how much longer it’ll be). In general, though, you probably won’t need to be spot-on and just being in a decent range of the sound’s completion is good enough.
You can also schedule this sort of thing via other methods, like
performSelector:withObject:afterDelay:, but that comes down more to your preference as far as API is concerned. The idea is pretty much the same.