NSTimer准确度 [英] NSTimer Accuracy

查看:124
本文介绍了NSTimer准确度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一款应用程序,该应用程序需要以精确的间隔播放声音文件,其持续时间可变。

I am currently working on an app that requires a sound file to be played at exact intervals, which are variable in duration.

我似乎记得被告知NSTimer只是在指定的持续时间之后将操作放入堆栈,而不是在指定的持续时间之后运行的操作。这意味着如果在它之前堆栈上有很多其他操作,则不会按时调用它。

I seem to remember being told that NSTimer simply places an operation onto the stack after the specified duration, rather than the operation being run after the specified duration. This would mean that if there were lots of other operations on the stack before it, it would not be called on time.

我想知道这是否确实是正确的,如果是的话,是否有任何方法可以保证在指定的持续时间后运行。

I would like to know if this is indeed correct, and if so, is there any way of getting an operation to be guaranteed to run after a specified duration.

在任何评论声音文件可能第一次被延迟之前,它们已经预先加载以避免这种情况。

推荐答案

Apple的NSTimer文档的第一段你会发现:


计时器不是实时机制;它仅在已添加计时器的
运行循环模式之一运行时才会触发,并且能够检查计时器的触发时间是否已经过去
。由于典型的运行循环管理各种
输入源,因此定时器的时间间隔
的有效分辨率限制在50-100
毫秒的量级。如果在长调出期间发生计时器的触发时间或
而运行循环处于不监视计时器的模式,则
计时器在下次运行循环检查计时器之前不会触发。
因此,计时器触发的实际时间可能是预定开火时间后很长一段时间内的
a。

所以你肯定会在你的预定开火时间之后运行(或在你的情况下播放你的声音),但不一定完全 at 你的时间。

So you will definitely run (or play your sound, in your case) after your scheduled firing time, but not necessarily exactly at your time.

这篇关于NSTimer准确度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆