我正在尝试播放声音文件,例如 /Users/NEO/Library/Developer/CoreSimulator/Devices/D21A7767-E6F6-4B43-A76B-DC6E0F628B16/data/Containers/Data/Application/3F8A82F6-739F-40EA-BEA9-DF3560D0D8BB/Documents/Remember-When.mp3
我正在使用AudioKit / Swift 3,这是我的代码:
do {
debugPrint(sound.filePath)
let audioFile = try AKAudioFile(forReading: URL(fileURLWithPath: sound.filePath))
player = try AKAudioPlayer(file: audioFile)
player.play()
}catch let exception {
}
Xcode崩溃和控制台说: 因未捕获的异常'com.apple.coreaudio.avfaudio'而终止应用程序,原因:'必需条件为false:_engine-> IsRunning()'
我尝试使用AVAudioFoundation,因此效果很好。
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)
}
你能给我一个建议吗?
答案 0 :(得分:4)
我相信当你收到"'要求的条件是假的:_engine-> IsRunning()'" AudioKit引擎尚未启动。因此,在玩游戏之前调用AudioKit.start()
可以解决您的问题