0

我正在开发一个使用 AVFoundation 框架生成声音的应用程序。现在我想添加 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()中没有得到异常,它正常执行......

4

1 回答 1

3

当然可以将 AVAudioEngine 与 Chirp iOS SDK 结合起来。

出现问题是因为 Chirp SDK 与您的音频播放器在同一个共享 AVAudioSession 实例上运行,当您设置类别时,您将覆盖由 Chirp SDK 设置的设置。

我建议您删除您调用的线路,setCategory这将起作用 - Chirp SDK 设置的设置就足够了,如果我在这里错了,请纠正我。

其他人报告说在日志中看到“未知选定数据源”警告,我相信这是 iOS 12 的问题。请参阅https://forums.developer.apple.com/thread/108785

于 2018-10-30T17:34:38.553 回答