iOS AudioServicesAddSystemSoundCompletion 回调导致 1 秒延迟
我正在播放几种声音,它们必须按顺序(随机)播放,以便当一个声音结束时,下一个需要开始。
我使用 AudioServicesAddSystemSoundCompletion 回调过程来确定 SystemSoundID 指定的声音文件何时完成播放。此时,静态 C 回调方法被命中,然后回调到实例中以播放另一个声音。
但是,我在音频完成和回调函数被触发之间有 1 秒的延迟。
音频被修剪,末尾没有多余的空间。我已将 NSLog 放在几个关键位置进行确认,并播放第一个声音 - 其余代码什么也不做 - 只是等待“输入”,然后在音频完成后一秒定期触发回调。
我查看了官方文档,但找不到任何原因 - 10 分钟的谷歌搜索也没有提供任何解决方案。
请问有人有什么想法吗?
谢谢
I'm playing several sounds, and they have to be played in sequence (random), so that when one finishes, the next needs to start.
I'm using the AudioServicesAddSystemSoundCompletion callback procedure to determine when a sound file specified by a SystemSoundID has finished playing. At that point the static C callback method gets hit and then calls back into the instance to play another sound.
However, I'm getting a 1 second delay between the audio finishing and the callback function getting hit.
The audio is trimmed with no extra space at the end. I've put NSLog's in a few key places to confirm and the first sound is played - the rest of the code is doing nothing - just waiting for 'input' and then the callback gets hit routinely one second after the audio has finished.
I've looked in the official documentation and I can't find any reason for this - neither has 10 mins of googling offered any solution.
Anyone have any ideas please?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道延迟的情况,我从来没有遇到过这种情况。但也许你可以尝试这个。它是 SystemSoundID 及其一些相关函数(包括完成回调)的 Objective-C 包装器。使用它代替 C 函数应该更容易。
I do not know about the delay, I have never experienced that. But maybe you could try this. It is objective-c wrapper for SystemSoundID and some of its assosiated functionss, including completion callback. It should be easier to use this instead of C functions.
对于那些阅读本文的人,我深表歉意,但由于时间限制,我向 Apple 提出了支持请求,以查明此事的真相,你不会相信这个答案……
没有任何延迟。 (勺子/无论什么;))
问题是由我们用来剪切、修剪和导出音频文件的应用程序的 UI“功能”引起的...GarageBand。
看起来,如果您在 GarageBand 中修剪音轨,直到只有您想要的声音可见并播放(即使在循环时),然后将该音轨导出为 .aif 文件...它会在不显示或警告您的情况下放置所有修剪并剪切部分曲目回来!
因此,即使几天后您在英国重新打开该曲目,您看到和听到的也只是删减后的版本。然而,修剪只是文件上的元数据 - 就像 iTunes 修剪一样......完全没有意义。
因此,所有音频都必须在更准确的音频应用程序中重新编辑和导出 - audacity...
Apple 确实提到这些声音播放的回调线程是低优先级线程,但我们仍然不应该看到这样的情况停顿一下。
感谢那些试图找出原因的人,特别是上面的发帖人花时间尝试提供帮助。
Sorry to those reading this, but I used a support request with Apple to get to the bottom of this due to time constraints and you wouldn't believe the answer...
There is NO delay. ( Spoon / whatever ;) )
The problem was caused by a UI 'feature' of the app we used to cut and trim and export the audio files...GarageBand.
It appears that if you trim an audio track in GarageBand until only the sound you want is visible and plays - even when looping - and then export that track as an .aif file... It puts WITHOUT SHOWING OR WARNING YOU - all of the trimmed and cut parts of the track BACK!!!
So that, even when you reopen the track in GB days later all you see and hear is the cut down trimmed version. However the trimming is just metadata on the file - just like iTunes trimming... Totally pointless.
So all the audio had to be re edited and exported in a more accurate audio app - audacity...
Apple did mention that the callback thread for these sound playbacks is a low priority thread, but that we still shouldn't have been seeing such a pause.
Thanks for those who tried to think of a reason, and in particular the poster above for taking the time to try and help.