我正在尝试播放音频文件。
let url = URL.init(fileURLWithPath: Bundle.main.path(forResource: name, ofType: nil)!)
do {
player = try AVAudioPlayer(contentsOf: url)
player.play()
} catch {
print("error")
}
给出错误消息:
Fatal error: Unexpectedly found nil while unwrapping an Optional value: file.
/Users/hrayr/Desktop/Projects/Подводный бой/Подводный бой/Music/AudioPlayer.swift, line 15
2020-05-06 13:51:49.010761+0400 Подводный бой[947:28055] Fatal error: Unexpectedly found nil
while unwrapping an Optional value: file /Users/hrayr/Desktop/Projects/Подводный бой/.
Подводный бой/Music/AudioPlayer.swift, line 15
怎么修?提前致谢
检查资源名称和类型是否正确。该错误描述了在尝试解包时收到了 nil。