当声音做过的OpenAL打入门通知 [英] Getting notified when a sound is done playing in OpenAL
问题描述
我使用iPhone上的OpenAL可以同时播放多个音频样本。
I'm using OpenAL on iPhone to play multiple audio samples simultaneously.
我可以当单个样品做打的OpenAL来通知我?
Can I get OpenAL to notify me when a single sample is done playing?
我想避免硬编码的样品长度和设定一个计时器。
I'd like to avoid hardcoding the sample length and setting a timer.
推荐答案
如果您有抽象成一个类的OpenAL源,我想你可以简单地调用 performSelector:afterDelay:
当您启动声音:
If you have the OpenAL source abstracted into a class, I guess you can simply call performSelector:afterDelay:
when you start the sound:
- (void) play
{
[delegate performSelector:@selector(soundHasFinishedPlaying)
afterDelay:self.length];
…
}
(如果你在此期间手动停止的声音,回调可以取消,请参阅<一个href=\"http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSObject%5FClass/Reference/Reference.html#//apple%5Fref/occ/clm/NSObject/cancel$p$pviousPerformRequestsWithTarget:\"相对=nofollow> NSObject类参考),或者你可以查询 AL_SOURCE_STATE
:
- (void) checkStatus
{
ALint state;
alGetSourcei(source, AL_SOURCE_STATE, &state);
if (state == AL_PLAYING)
return;
[timer invalidate];
[delegate soundHasFinishedPlaying];
}
我不知道如何获得的OpenAL叫你回来。你到底要回调呢?有些东西可以不用回调来解决更好。
I don’t know how to have OpenAL call you back. What exactly do you want the callback for? Some things can be solved better without a callback.
这篇关于当声音做过的OpenAL打入门通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!