完成与 finch 的音频回调播放

发布于 2024-09-15 07:17:44 字数 90 浏览 14 评论 0原文

是否有与芬奇一起完成播放的回调?类似于 avaudioplayer 中的 -audioPlayerDidFinishPlaying?查看代码我找不到任何引用它的内容。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

撩人痒 2024-09-22 07:17:44

Finch 中没有这样的回调,因为 OpenAL 不支持。 (或者至少当我上次查看时它不支持它。)您可以像这样伪造它:

- (void) playSoundWithCallback {
    [someSound play];
    [someDelegate performSelector:@selector(soundDidFinishPlaying:)
        withObject:someSound afterDelay:someSound.duration];
}

我没有尝试过,但它是一个简单的代码,它应该可以正常工作。好吧……至少在你开始扰乱音调和声速之前:)

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:

- (void) playSoundWithCallback {
    [someSound play];
    [someDelegate performSelector:@selector(soundDidFinishPlaying:)
        withObject:someSound afterDelay:someSound.duration];
}

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 :)

何以畏孤独 2024-09-22 07:17:44

@zoul:我知道这是一个很晚的回复。但我注意到答案不正确。如果我暂停声音或系统中断怎么办?在这种情况下,即使声音尚未完成,您也会收到回调。请阅读 openAL 规范中的“4.3.6. 管理源执行”段落以进行正确处理。

@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.

夏の忆 2024-09-22 07:17:44

如果您不关心中断,这里有一个解决音调问题的技巧。

OpenAL 更改音调不是 1.0 时播放的声音的播放长度。
(似乎不可能从 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) ]; 
} 

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) ]; 
} 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文