我有一个应用程序,当我按下按钮时应该录制音频。 在我的ViewDidLoad中我预先录制了录音机,问题是当调用'self.audioRecorder.prepareToRecord()'行时,流式音频会中断。
我的设置:
do {
recordingSession = AVAudioSession.sharedInstance()
try recordingSession.setCategory(AVAudioSessionCategoryRecord, withOptions: [.DuckOthers, .AllowBluetooth, .MixWithOthers])
recordingSession.requestRecordPermission() { [unowned self] (allowed: Bool) -> Void in
dispatch_async(dispatch_get_main_queue()) {
do {
if allowed {
self.audioRecorder = try AVAudioRecorder(URL: self.tempAudioPath, settings: self.settings)
self.audioRecorder.delegate = self
self.audioRecorder.prepareToRecord()
//self.audioRecorder.record()
} else {
// failed to record!
print("No Access to Micro")
}
}catch{}
}
}
} catch {
print (error)
}
有没有办法预录音录音机进行录音,并继续在后台播放音频? (录制音频时将其丢弃)
答案 0 :(得分:0)
Per Apple's documentation for AVAudioSessionCategoryRecord,"此类别使播放音频静音"。您是否尝试将类别设置为AVAudioSessionCategoryPlayAndRecord
?