如何使用 NStimer 同步 iphone sdk 中的音频?
我正在运行一个倒计时器,它会更新标签上的时间。我想每秒播放一次滴答声。我有声音文件,但它与时间不完全同步。我如何将时间与音频同步?如果我使用 uiimagepicker声音停止了如何处理?如果有人能发出像时钟一样的滴答声,那就太好了。
I am running a countdown timer which updates time on a label.i want to play a tick sound every second.i have the sound file but it is not sync perfectly with time.how do i sync time with audio?also if i use uiimagepicker the sound stops how to manage this? if someone have tick sound like a clock has it would be great.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
同步声音和时间的最佳方法是在 TTimer 触发时每秒实际播放一次短(不到一秒长)的声音文件(滴答声)。它听起来不像真正的时钟或天文钟的滴答声那么好,但很容易做到。如果声音那么小,那么您不必太担心延迟。我认为为了现实,你需要每秒播放两次滴答声,第一次和第二次滴答声相距约 0.3 秒,下一次滴答声从下一秒开始,第四次滴答声也仅在约 0.3 秒后开始。等等。
为了更紧密地集成声音和 GUI,您应该阅读 音频工具箱:
The best way to sync up your sound and time would be to actually play short - less than a second long - sound files (tick sound) once per second as TSTimer fires. It won't sound as nice as a real clock or chronometer ticking, but it would be easy to do. And if the sounds are that small, then you don't have to worry too much about latency. I think to be realistic you need to play two ticks per second, with the first and second ticks about 0.3 seconds apart, and the next one starting at the next second, with the fourth, again only about 0.3 seconds later. And so on.
For even tighter integration of sounds and GUI, you should read up on Audio Toolbox: