iphone - iPhone录音中断后如何恢复?

标签 iphone audio avaudiorecorder recording

我正在开发一个录音机应用程序,它工作得很好。

但是我被中断的问题困扰了。当有电话打来时,

- (void)audioRecorderBeginInterruption:(AVAudioRecorder *)recorder

然后调用此方法并暂停录制。

如果用户拒绝调用:

- (void)audioRecorderEndInterruption:(AVAudioRecorder *)recorder

然后我想从中断的地方继续录制。 但是当我再次调用 record 方法时,录音会从一个新文件开始。

最佳答案

问题解决了!

我重新编写了录制代码以避免这个问题。我使用了 AudioQueues,基本上后端代码与 SpeakHere 应用程序相同,但有一些细微的变化。里面又提供了两个api:

-(void)resume
{
    AudioQueueStart(queueObject, NULL);
}

-(void)pause
{
    AudioQueuePause(queueObject);
}

在 AudioRecorder 类中。基本目的是避免在记录方法中完成的记录设置。

设置中断回调,然后在回调中适本地使用此暂停和恢复方法。另请注意根据您的应用程序是否需要 Audio Session 来设置事件 Audio Session 。

希望这对那里的人有帮助。

编辑:

音频中断监听器回调:

void interruptionListenerCallback (void *inUserData, UInt32 interruptionState)
{
    if (interruptionState == kAudioSessionBeginInterruption) 
    {
        [self.audioRecorder pause];
    } 
    else if (interruptionState == kAudioSessionEndInterruption) 
    {
        // if the interruption was removed, and the app had been recording, resume recording
        [self.audioRecorder resume];
    }
}

监听音频中断:

AudioSessionInitialize(NULL, NULL, interruptionListenerCallback, self);

关于iphone - iPhone录音中断后如何恢复?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1706064/

相关文章:

iphone - 方向导航栏问题

ios - 如果应用程序已经有一些其他 pod 依赖项(例如 Almofire、SwiftJSON 等),如何创建我们自己的 Cocoapods

javascript - 如何将此代码应用于我的音频

swift - 无法在本地通知中使用录制的剪辑作为声音

iphone - AVAudioRecorder 不适用于 iPhone 5S

ios - AVAudioRecorder - 展开可选时发现 nil

iOS - 从底部错误地推送 segue

iphone - UIButton setTitleColor 和 setImage 不起作用

c++ - MediaElement捕获麦克风并修改数据

iphone - 在 iOS 应用程序 : audio but no picture 中播放视频