添加AKMicrophone时崩溃

时间:2018-02-02 06:07:45

标签: ios avaudioengine audiokit

我正在使用AudioKit开发一个音频应用程序,它涉及定期停止AudioKit,重新安排或替换service firebase.storage { match /b/{bucket}/o { match /storyImages { // Cascade read to any image type at any path match /{allImages=**} { allow read; } // Allow write files, subject to the constraints: // 1) File is less than 1MB // 2) Content type is an image // 3) Uploaded content type matches existing content type // 4) File name (stored in imageId wildcard variable) is less than 120 characters // 5) UserId should be the same as folder name where user writes match /{userId}/{storyId}/{imageId} { allow write: if request.resource.size < 1 * 1024 * 1024 && request.resource.contentType.matches('image/.*') && request.resource.contentType == resource.contentType && imageId.size() < 120 && request.auth != null && request.auth.uid == userId } } } } 子类链,然后重新启动AudioKit。这一直顺利进行,直到我使用AKNode进行了尝试。

如果初始声链中存在AKMicrophone,即当我第一次调用AKMicrophone时),它可以正常工作。但是,如果我在之前的呼叫AudioKit.start(之后的某个时刻将AKMicrophone放入声音链中,则应用会在下一次AudioKit.start()呼叫时崩溃,从而产生以下错误消息:

AudioKit.start()

为了说明,以下代码顺利运行:

...[avae] AVAudioEngine.mm:149:-[AVAudioEngine prepare]: Engine@0x1c0007170: could not initialize, error = -10875
...[mcmx] 338: input bus 0 sample rate is 0
...[avae] AVAEInternal.h:103:_AVAE_CheckNoErr: [AVAudioEngineGraph.mm:1266:Initialize: 
(err = AUGraphParser::InitializeActiveNodesInOutputChain(ThisGraph, kOutputChainOptimizedTraversal, *GetOutputNode(), isOutputChainActive)): error -10875

但如果之前是 let mic = AKMicrophone() if let input = AudioKit.inputDevice { try! mic.setDevice(input) } AudioKit.output = mic AudioKit.start() 的调用,则会崩溃:

AudioKit.start()

有什么方法可以避免这种情况吗?甚至帮助理解错误消息也会有所帮助。感谢。

编辑:我注意到相同的行为 AudioKit.output = AKOscillator() AudioKit.start() AudioKit.stop() let mic = AKMicrophone() if let input = AudioKit.inputDevice { try! mic.setDevice(input) } AudioKit.output = mic AudioKit.start() - 在相同条件下的相同错误消息

1 个答案:

答案 0 :(得分:0)

之后

AudioKit.output = AKOscillator()
AudioKit.start()

尝试;

do{
   try AudioKit.stop()
   try AudioKit.shutdown()
   AudioKit.output = nil
}catch{
   print(error)
}