Reputation: 101
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...)
}
Upvotes: 1
Views: 1891
Reputation:
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:
dispatch_time_t delay;
dispatch_queue_t queue;
dispatch_block_t block;
uint64_t audio_length_ns = 10000000000; // 10 seconds
delay = dispatch_time(DISPATCH_TIME_NOW, audio_length_ns);
queue = dispatch_get_main_queue();
block = ^{
// Do whatever you need to after the delay
// Maybe check to see if the audio has actually
// finished playing and queue up the block again
// if it hasn't.
};
// Queue up the block for the time after
dispatch_after(delay, queue, block);
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.
Upvotes: 3