【问题标题】:iPhone AVAudioRecorder pause problem after entering backgroundiPhone AVAudioRecorder 进入后台后暂停问题
【发布时间】:2011-07-07 16:31:26
【问题描述】:

我在进入后台后暂停 AVAudioRecorder 时遇到问题。基本上,它是这样的(_recorder 是我的 AVAudioRecorder 实例):

  1. 开始录制:

    [_recorder record];
    
  2. 按下设备上的主页按钮。

  3. 因为我已经设置了通知这种情况的观察者(在 viewDidLoad 中),所以我的自定义方法 applicationDidEnterBackground 会触发。
  4. 在 applicationDidEnterBackground 我做:

    [_recorder pause];
    
  5. 现在,当我点击应用程序图标时,将应用程序带到前台,立即连续录制,无需执行任何操作。它甚至更奇怪,因为检查属性:

    _recorder.recording == YES
    

返回编号。

我有一个函数,NSTimer 每 0.1 秒调用一次(刷新 UI 等),在那个函数中我有这个:

if(_recorder.recording) {
    NSLog(@"recording");
}
else {
    NSLog(@"not recording");
    NSLog(@"time: %f", _recorder.currentTime);
} 

它在控制台上打印:

    ...
    not recording
    time: 9.404082
    not recording
    not recording
    time: 9.473197
    not recording
    time: 9.531179
    not recording
    time: 9.629206
    not recording
    time: 9.728435
    ...

因此,如您所见,录音机的 currentTime 一直在增加,并且正在录制音频。

有什么办法解决这个问题吗?

【问题讨论】:

    标签: iphone audio background recording


    【解决方案1】:

    您应该添加以下代码:

    <key>UIBackgroundModes</key>
    <array>
        <string>audio</string>
    </array>
    

    到 Info.plist。这将导致后台模式响应管理音频会话,因此您可以手动暂停和恢复录制。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-30
      • 2013-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多