我正在开发一个应用程序,用AVFoundation framework生成声音。现在我想添加Chirp.io SDK来将一些信息编码成声音,作为代码的补充。
如果我单独使用我的声音代码或Chirp sdk,一切正常。当我用我的代码发出声音,然后运行Chirp时,它只工作一次,然后在第二次尝试时失败并出现错误:
2018-10-23 19:32:55.188460+0300 FieldApp[2243:1408580] [avae] AVAEInternal.h:70:_AVAE_Check: required condition is false: [AVAudioPlayerNode.mm:536:StartImpl: (_engine->IsRunning())]
2018-10-23 19:32:55.191931+0300 FieldApp[2243:1408580] *** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: _engine->IsRunning()'
是否可以结合使用AVAudioEngine和Chirp.io SDK?
以下是我的代码示例:
// ... init part of my sound code ....
let engine: AVAudioEngine = AVAudioEngine()
let playerNode: AVAudioPlayerNode = AVAudioPlayerNode()
let audioFormat = AVAudioFormat(standardFormatWithSampleRate: 44100.0, channels: 2)
engine.attach(playerNode)
engine.connect(playerNode, to: engine.mainMixerNode, format: audioFormat)
// ... Chirp init code ...
let connect: ChirpConnect! = ChirpConnect(appKey: "xXx", andSecret: "xXx")
connect.setConfig("xXxxx")
connect.start()
// ... do this in a loop ....
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, mode: AVAudioSessionModeDefault)
try AVAudioSession.sharedInstance().setActive(true)
try engine.start()
started = true
}
catch {
LogManager.shared.post("Error starting sound engine: \(error.localizedDescription)")
}
playerNode.play()
//.... wait until playing ends ....
playerNode.stop()
engine.stop()
//.... Chirp SDK sounds ....
let buf: Data = ..... some data to send
connect.send(buf)
//... end of pseudo-loop
所以,当我第二次在循环中运行代码时,我得到了异常,但在engine.start()中没有得到异常,它会正常执行。。。
最佳答案
当然可以将AVAudioEngine与Chirp iOS SDK结合起来。
出现此问题是因为Chirp SDK与音频播放器在同一个共享AVAudioSession实例上运行,当您设置类别时,将覆盖Chirp SDK设置的设置。
我建议您删除调用setCategory
的线路,这样就可以了-Chirp SDK设置的设置就足够了,如果我在这里错了,请纠正我。
其他人报告在日志中看到“未知选定数据源”警告,我相信这是iOS 12的问题。见https://forums.developer.apple.com/thread/108785
关于ios - ios Chirp.io SDK和AVSoundEngine如何一起使用?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52954253/