我正在开发一个用AVFoundation框架生成声音的应用程序。现在,我想添加Chirp.io SDK,将一些信息编码到声音中,作为代码的补充。
如果我单独使用我的声音代码或Chirp,一切都很好。当我使用我的代码发出声音,然后运行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()中没有异常,它通常会执行.
发布于 2018-10-30 17:34:38
当然可以将AVAudioEngine与Chirp结合起来。
出现此问题是因为Chirp与您的音频播放器在同一个共享AVAudioSession实例上操作,当您设置类别时,您将重写Chirp设置的设置。
我建议您删除调用setCategory的行,这样就可以了-- Chirp设置的设置就足够了,如果我错了,请纠正我。
其他人报告说在日志中看到了“未知的选定数据源”警告,我认为这是iOS 12的一个问题。
https://stackoverflow.com/questions/52954253
复制相似问题