【问题标题】:Two NSTimers with one governing the activity of the other?两个 NSTimer,一个控制另一个的活动?
【发布时间】:2013-07-16 17:05:18
【问题描述】:

我一直在看线程:语音检测 (http://mobileorchard.com/tutorial-detecting-when-a-user-blows-into-the-mic/)。

我希望通过以下变体实现类似的东西。

该示例中的 levelTimer 每 0.03 秒连续触发一次。我基本上需要围绕这个包装另一个计时器,以便语音检查过程只运行(比如说)10 秒。

我发现有类似的东西:

outerTimer = [NSTimer scheduledTimerWithTimeInterval:10.0
                                              target:self
                                            selector:@selector(outerTimerFinished:)
                                            userInfo:nil
                                             repeats:NO];

levelTimer = [NSTimer scheduledTimerWithTimeInterval:0.03
                                              target:self
                                            selector:@selector(listenForSounds:)
                                            userInfo:nil
                                             repeats:YES];

outerTimerFinished 方法调用 [levelTimer invalidate] 不起作用 - 可能是由于线程阻塞?

那么有人可以帮我确定 levelTimer 的工作方式,但仅限于特定的时间吗?

谢谢。

【问题讨论】:

  • 我已经发布了另一种方法,但我测试了你的方法,它对我有用。你在 ListeningForSounds: 里面做什么?

标签: ios nstimer voice-recording


【解决方案1】:

在listenForSounds: 方法中放置一个计数器,并在每次调用该方法时递增。如果您想运行 levelTimer 10 秒,请检查计数器何时 > 333,然后使计时器无效。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-20
    • 1970-01-01
    • 1970-01-01
    • 2014-09-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多