简体   繁体   English

iOS - 接听电话时 AudioKit 崩溃

[英]iOS - AudioKit Crashes when receiving a phone call

AudioKit 4.9.3 iOS 11+音频套件 4.9.3 iOS 11+

I am working on a project where the user is recording on the device using the microphone and it continues to record, even if the app is in the background.我正在做一个项目,用户使用麦克风在设备上录音,即使应用程序在后台,它也会继续录音。 This works fine but when receiving a phone call I get an AudioKit error.这工作正常但是当接到电话时我收到 AudioKit 错误。 I assume it has something to do with the phone taking over the mic or something.我认为这与手机接管麦克风或其他东西有关。 here is the error:这是错误:

[avae] AVAEInternal.h:109 [avae] AVAEInternal.h:109
[AVAudioEngineGraph.mm:1544:Start: (err = PerformCommand(*ioNode, kAUStartIO, NULL, 0)): error 561017449 AudioKit+StartStop.swift:restartEngineAfterRouteChange(_:):198:error restarting engine after route change [AVAudioEngineGraph.mm:1544:Start: (err = PerformCommand(*ioNode, kAUStartIO, NULL, 0)): error 561017449 AudioKit+StartStop.swift:restartEngineAfterRouteChange(_:):198: 路由更改后重启引擎时出错

basically everything that i have recording up until that point is lost.基本上我在那之前录制的所有内容都丢失了。

here is my set up AudioKit code:这是我设置的 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)
        }
}

and when tapping on the record button code:当点击录制按钮代码时:

    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)
          }
}

Current audio Settings:当前音频设置:

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

What can I do to ensure that I can get a proper recording, even when receiving a phone call?如何确保即使在接到电话时也能获得正确的录音? The error happens as soon as you receive the call - whether you choose to answer it or decline.一旦您接到电话,错误就会发生 - 无论您选择接听还是拒绝。

Any thoughts?有什么想法吗?

AudioKit handles only the basic route change handling for an audio playback app. AudioKit 仅处理音频播放应用程序的基本路由更改处理。 We've found that when an app becomes sufficiently complex, the framework can't effectively predestine the appropriate course of action when interruptions occur.我们发现,当应用程序变得足够复杂时,框架无法在发生中断时有效地预先确定适当的操作过程。 So, I would suggest turning off AudioKit's route change handling and respond to the notifications yourself.所以,我建议关闭 AudioKit 的路由更改处理并自己响应通知。

Also, I would putting AudioKit activation code in a button.另外,我会将 AudioKit 激活码放在一个按钮中。

I've done work in this area, I'm afraid you cannot access the microphone(s) while a call or a VOIP call is in progress.我已经完成了这方面的工作,恐怕您在通话或 VOIP 通话过程中无法访问麦克风。

This is a basic privacy measure that is enforced by iOS for self-evident reasons.这是 iOS 出于不言而喻的原因强制执行的一项基本隐私措施。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM