我正在开发一个录音机应用程序,它工作得很好。
但是我被中断的问题困扰了。当有电话打来时,
- (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/