Jit*_*ngh 9 iphone audio recording avaudiorecorder
我正在研究录音机应用程序,它工作得非常好.
但我坚持中断的问题.来电时,
- (void)audioRecorderBeginInterruption:(AVAudioRecorder *)recorder
Run Code Online (Sandbox Code Playgroud)
然后调用此方法并暂停录制.
如果用户拒绝来电:
- (void)audioRecorderEndInterruption:(AVAudioRecorder *)recorder
Run Code Online (Sandbox Code Playgroud)
然后在这里,我想从中断的那一刻开始重新录制.但是当我再次调用记录方法时,录制以新文件开始.
问题已经解决了!
我重新编写了录制代码以避免此问题.我使用了AudioQueues,基本上后端代码与SpeakHere应用程序相同,但有一些细微的变化.还提供了两个api:
-(void)resume
{
AudioQueueStart(queueObject, NULL);
}
-(void)pause
{
AudioQueuePause(queueObject);
}
Run Code Online (Sandbox Code Playgroud)
在AudioRecorder类中.基本目的是避免在记录方法中完成的记录设置.
设置中断回调,然后在回调中使用此暂停并适当地恢复方法.还要注意根据您的应用程序是否需要来激活音频会话.
希望这有助于那里的人.
编辑:
音频中断监听器回调:
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];
}
}
Run Code Online (Sandbox Code Playgroud)
听取音频中断:
AudioSessionInitialize(NULL, NULL, interruptionListenerCallback, self);
Run Code Online (Sandbox Code Playgroud)
操作系统可能在中断期间停止 AVAudioRecorder。您可以将两个或多个文件作为单个录音呈现给用户,也可以使用 AudioQueue 编写代码来处理中断(以及将音频数据保存到文件中)。
| 归档时间: |
|
| 查看次数: |
4933 次 |
| 最近记录: |