簡體   English   中英

ios Chirp.io SDK和AVSoundEngine如何一起使用?

[英]ios Chirp.io SDK and AVSoundEngine how to use together?

我正在開發一個使用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()中沒有得到異常,它可以正常執行...

當然可以將AVAudioEngine與Chirp iOS SDK結合使用。

出現此問題是因為Chirp SDK與音頻播放器在相同的共享AVAudioSession實例上運行,因此當您設置類別時,您將覆蓋Chirp SDK設置的設置。

我建議您刪除調用setCategory的行,這行將起作用setCategory SDK設置的設置就足夠了,如果我錯了,請糾正我。

其他人報告說在日志中看到“未知選定數據源”警告,我相信這是iOS 12的問題。請參閱https://forums.developer.apple.com/thread/108785

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM