var engine:AVAudioEngine!
var format = engine.inputNode.inputFormat(forBus: 0)
engine.connect(engine.inputNode, to: engine.mainMixerNode, format: format)
在函数 AVAudioEngine.connect 中使我的应用程序仅在硬件上崩溃
但在模拟器中没问题。
当我在硬件上运行时,会出现错误。
Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: IsFormatSampleRateAndChannelCountValid(format)'
terminating with uncaught exception of type NSException
我明白了。
我只是将 AVAudioSession 类别类型设置错误。
如果您遇到相同的错误,请查看 AVAudioSession 并确保您的 AVAudioSession 类别的麦克风权限设置正确。
例如
AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord, with: .mixWithOthers)
通过此设置将允许应用程序使用麦克风并同时播放声音。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)