首页 > 编程知识 正文

ios 音频录制播放用到什么sdk,ios开发音频录制按钮

时间:2023-05-04 05:02:57 阅读:275289 作者:4332

我正在我的应用程序中录制音频,包括前景和后台.我还处理AVAudioSessionInterruptionNotification以在中断开始时停止录制并在结束时再次开始.虽然在前台它按预期工作,当应用程序在后台录制并且我接到一个呼叫时,它不会在呼叫结束后再次开始录制.我的代码如下:

- (void)p_handleAudioSessionInterruptionNotification:(NSNotification *)notification

{

NSUInteger interruptionType = [[[notification userInfo] objectForKey:AVAudioSessionInterruptionTypeKey] unsignedIntegerValue];

if (interruptionType == AVAudioSessionInterruptionTypeBegan) {

if (self.isRecording && !self.interruptedWhileRecording) {

[self.recorder stop];

self.interruptedWhileRecording = YES;

return;

}

}

if (interruptionType == AVAudioSessionInterruptionTypeEnded) {

if (self.interruptedWhileRecording) {

NSError *error = nil;

[[AVAudioSession sharedInstance] setActive:YES error:&error];

NSDictionary *settings = @{

AVEncoderAudioQualityKey: @(AVAudioQualityMax),

AVSampleRateKey: @8000,

AVFormatIDKey: @(kAudioFormatLinearPCM),

AVNumberOfChannelsKey: @1,

AVLinearPCMBitDepthKey: @16,

AVLinearPCMIsBigEndianKey: @NO,

AVLinearPCMIsFloatKey: @NO

};

_recorder = [[AVAudioRecorder alloc] initWithURL:fileURL settings:settings error:nil];

[self.recorder record];

self.interruptedWhileRecording = NO;

return;

}

}

}

请注意,fileURL指向NSDocumentDirectory子目录中的新caf文件.配置背景模式音频.我也试过voip和沉默,都没有成功.

AVAudioSessionInterruptionTypeEnded块中的NSError是OSStatus错误560557684,我还没有找到解决方法.

任何帮助将非常感激.

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。