iOS 流音频和录制音频

标签 ios swift avaudiorecorder avaudiosession

我有一个应用程序,当我按下按钮时,它应该录制音频。 在我的 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)
}

有没有办法让录音机准备录音,并继续在后台播放音频? (录制音频时闪避)

最佳答案

Apple's documentation for AVAudio​Session​Category​​Record ,“此类别使播放音频静音”。您是否尝试过将类别设置为AVAudio​Session​Category​Play​And​Record

关于iOS 流音频和录制音频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38083629/

相关文章:

swift - UICollectionViewCell alpha 在使用 '.reloadItems' 时没有改变

ios - 如何从 decodeIntegerForKey 中获取可选值而不是 0?

ios - trackWithMediaType 有时返回 0 首轨道

objective-c - 在 Mac 上使用 AVAudioRecorder

ios - 使用图表框架加载第二个图表时,我收到 exc_bad_access

IOS 13 自动化要求运行

iphone - GLSL:iPhone应用程序无法访问内置属性?

ios - 如何在 cellForRowAtIndexPath 方法中判断滚动方向(右上左下)

swift - 如何扩展 Decodable 以从字典初始化?

swift - AVAudioRecorder 和 AVAudioPlayer 音频长度不同