Why this isn't working? I searched to ways of adding sound into a Xcode and I saw so many different ways. I thought I figured it out how the system's working but something is going wrong but I can't see the problem.
import AVFoundation
var audioPlayer = AVAudioPlayer!
func playSound(sound: String){
let url = Bundle.main.url(forResource: sound, withExtension: "mp3")
audioPlayer = try! AVAudioPlayer(contentsOf: url!)
audioPlayer.play()
}
if userGotItRight{
//true answer
playSound(sound: "CorrectAnswer")
}else{
//false answer
playSound(sound: "WrongAnswer")
}
if you want to play a sound which is in your local, you can use this:
then you can call that function like this: