Xcode stops on prepareToPlay

后端 未结 2 961
悲哀的现实
悲哀的现实 2021-02-02 11:53

Using AVAudioPlayer to add sound to a working application, it stops / hangs on prepareToPlay. Note it also stops / hangs on play. Hitting \"Continue program execution\" severa

相关标签:
2条回答
  • 2021-02-02 12:26

    I had this problem too. The solution above works, but I think there's a better way to fix it.

    The errors the author suggests ignoring are indicating that the mac is trying to send audio to a device that isn't working. I'm guessing the code is written in C, so turning the exceptions to "objective-c only" does silence the exception.

    The real fix is to get the audio device working again. For me, the reason for the failure was that I was switching around some audio input and output, but (it seems) IOS simulator had remembered the old settings. So when I tried the various steps in this thread:

    Error '!dat' trying to set the (null) audio devices' sample rate

    I got the audio to work again, and it stopped throwing any exceptions.

    0 讨论(0)
  • 2021-02-02 12:30

    The problem was I normally develop with a breakpoint set to "All Exceptions", and the actual exception thrown was __cxa_throw. Which apparently turns out to be in C++ libraries that are used to implement AVAudioPlayer. By changing the breakpoint to "All Objective-C Exceptions" the program ran fine. (This can be done by editing the breakpoint and changing the Exception field to Objective-C.

    0 讨论(0)
提交回复
热议问题