finch 有没有完成播放回调?类似于 - avaudioplayer 中的 audioPlayerDidFinishPlaying?浏览代码我找不到任何引用它的东西。
3 回答
Finch 中没有这样的回调,因为 OpenAL 不支持。(或者至少我上次看时它不支持它。)你可以像这样伪造它:
- (void) playSoundWithCallback {
[someSound play];
[someDelegate performSelector:@selector(soundDidFinishPlaying:)
withObject:someSound afterDelay:someSound.duration];
}
我没有尝试过,但它是一个简单的代码,它应该可以正常工作。好吧……至少在你开始弄乱音高和音速之前:)
@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.
如果您不关心中断,这是一个带有音高修复的技巧。
当音高不是 1.0 时,OpenAL 会更改播放声音的播放长度。(似乎无法从 OpenAL 查询这个新长度,因为 AL 参数返回与以前相同的值)
间距范围从 0.5 到 2.0f。因此,如果我们假设 0.5 处的音高正好是两倍长,而 2.0 处的音高正好是一半长,我们应该能够将音高用作倍数:
- (void) playSoundWithCallback {
[someSound play];
[someDelegate performSelector:@selector(soundDidFinishPlaying:)
withObject:someSound afterDelay: someSound.duration * (1.0/someSound.pitch) ];
}