ios - AudioKit 崩溃 - 如何用它播放音频文件?
<p><p>我正在尝试播放声音文件,例如
/Users/NEO/Library/Developer/CoreSimulator/Devices/D21A7767-E6F6-4B43-A76B-DC6E0F628B16/data/Containers/Data/Application/3F8A82F6-739F-40EA-BEA9-DF3560D0D8BB/Documents/Remember-When.mp3</p>
<p>我正在使用 AudioKit/Swift 3,这是我的代码:</p>
<pre><code>do {
debugPrint(sound.filePath)
let audioFile = try AKAudioFile(forReading: URL(fileURLWithPath: sound.filePath))
player = try AKAudioPlayer(file: audioFile)
player.play()
}catch let exception {
}
</code></pre>
<p>Xcode 崩溃和控制台说:
由于未捕获的异常“com.apple.coreaudio.avfaudio”而终止应用程序,原因:“所需条件为 false:_engine->IsRunning()”</p>
<p>我尝试使用 AVAudioFoundation,所以效果很好。</p>
<pre><code>do {
player = try AVAudioPlayer(contentsOf: URL(fileURLWithPath: sound.filePath))
guard let player = player else { return }
player.prepareToPlay()
player.play()
} catch let error {
print(error.localizedDescription)
}
</code></pre>
<p>你能给我一个建议吗?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我相信,当您收到“'required condition is false: _engine->IsRunning()'”时,AudioKit 引擎还没有启动。所以在播放之前调用 <code>AudioKit.start()</code> 应该可以解决你的问题</p></p>
<p style="font-size: 20px;">关于ios - AudioKit 崩溃 - 如何用它播放音频文件?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/40943163/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/40943163/
</a>
</p>
页:
[1]