[iOS- 接听电话时,AudioKit崩溃

问题描述 投票:3回答:2

AudioKit 4.9.3iOS 11 +

我正在一个项目中,用户正在使用麦克风在设备上进行录音,并且即使应用程序在后台,它仍会继续录制。效果很好,但是接听电话时出现AudioKit错误。我认为这与手机接管麦克风有关。这是错误:

[avae] AVAEInternal.h:109[AVAudioEngineGraph.mm:1544:Start:(err = PerformCommand(* ioNode,kAUStartIO,NULL,0)):错误561017449AudioKit + StartStop.swift:restartEngineAfterRouteChange(_ :):198:错误更改路线后重新启动引擎

基本上,直到现在为止我所录制的所有内容都丢失了。

这是我设置的AudioKit代码:

func configureAudioKit() {
        AKSettings.audioInputEnabled = true
        AKSettings.defaultToSpeaker = true
        do {
            try try audioSession.setCategory((AVAudioSession.Category.playAndRecord), options: AVAudioSession.CategoryOptions.mixWithOthers)
            try audioSession.setActive(true)
            audioSession.requestRecordPermission({ allowed in
                DispatchQueue.main.async {
                    if allowed {
                        print("Audio recording session allowed")
                        self.configureAudioKitSession()
                    } else {
                        print("Audio recoding session not allowed")
                    }
                }
            })
        } catch let error{
            print("Audio recoding session not allowed: \(error.localizedDescription)")
        }
    }


func configureAudioKitSession() {
        isMicPresent = AVAudioSession.sharedInstance().isInputAvailable
        if !isMicPresent {
            return
        }
        print("mic present and configuring audio session")
        mic = AKMicrophone()
        do{
        let _ = try AKNodeRecorder(node: mic)
        let recorderGain = AKBooster(mic, gain: 0)
        AudioKit.output = recorderGain
        //try AudioKit.start()
        }
        catch let error{
            print("configure audioKit error: ", error)
        }
}

以及点击录制按钮代码:

    do {
         audioRecorder = try AVAudioRecorder(url: actualRecordingPath, settings: audioSettings)
         audioRecorder?.record()
         //print("Recording: \(isRecording)")
         do{
           try AudioKit.start()
          }
          catch let error{
            print("Cannot start AudioKit", error.localizedDescription)
          }
}

当前音频设置:

private let audioSettings = [
        AVFormatIDKey : Int(kAudioFormatMPEG4AAC),
        AVSampleRateKey : 44100,
        AVNumberOfChannelsKey : 2,
        AVEncoderAudioQualityKey : AVAudioQuality.medium.rawValue
    ]

即使在接听电话时,我该怎么做才能确保获得正确的录音?接听电话后即会发生错误-无论您选择接听还是拒绝。

有什么想法吗?

ios swift avaudiosession audiokit avaudiorecorder
2个回答
0
投票

AudioKit仅处理音频播放应用程序的基本路由更改处理。我们发现,当应用变得足够复杂时,当发生中断时,框架将无法有效地预先确定适当的操作步骤。因此,我建议您关闭AudioKit的路线更改处理并自己响应通知。

此外,我将AudioKit激活代码放在一个按钮中。


0
投票

我已经完成了这方面的工作,恐怕在通话或VOIP通话过程中,您无法访问麦克风。

这是不言而喻的iOS强制执行的基本隐私措施。

© www.soinside.com 2019 - 2024. All rights reserved.