[英]Launch or appear a UIViewController when receiving a phone call with iOS CallKit
[英]iOS - AudioKit Crashes when receiving a phone call
音頻套件 4.9.3 iOS 11+
我正在做一個項目,用戶使用麥克風在設備上錄音,即使應用程序在后台,它也會繼續錄音。 這工作正常但是當接到電話時我收到 AudioKit 錯誤。 我認為這與手機接管麥克風或其他東西有關。 這是錯誤:
[avae] AVAEInternal.h:109
[AVAudioEngineGraph.mm:1544:Start: (err = PerformCommand(*ioNode, kAUStartIO, NULL, 0)): error 561017449 AudioKit+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
]
如何確保即使在接到電話時也能獲得正確的錄音? 一旦您接到電話,錯誤就會發生 - 無論您選擇接聽還是拒絕。
有什么想法嗎?
AudioKit 僅處理音頻播放應用程序的基本路由更改處理。 我們發現,當應用程序變得足夠復雜時,框架無法在發生中斷時有效地預先確定適當的操作過程。 所以,我建議關閉 AudioKit 的路由更改處理並自己響應通知。
另外,我會將 AudioKit 激活碼放在一個按鈕中。
我已經完成了這方面的工作,恐怕您在通話或 VOIP 通話過程中無法訪問麥克風。
這是 iOS 出於不言而喻的原因強制執行的一項基本隱私措施。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.