@IBAction func cowButton(_ sender: UIButton) {
let soundFileSeleced : String = soundArray[0]
print(soundFileSeleced)
playSound()
}
func playSound() {
let soundURL = Bundle.main.url(forResource: "cowSound", withExtension: ".wav")
do {
audioPlayer = try AVAudioPlayer(contentsOf: soundURL!)
}
catch {
print(error)
}
audioPlayer.play()
}
I can't get my sound to play. What's wrong with my code? I get the message:
"Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value"