AVAudioPlayer not playing audio in Swift
I have this code in a very simple, single view Swift application in my ViewController : var audioPlayer = AVAudioPlayer() @IBAction func playMyFile(sender: AnyObject) { let fileString = NSBundle.mainBundle().pathForResource("audioFile", ofType: "m4a") let url = NSURL(fileURLWithPath: fileString) var error : NSError? audioPlayer = AVAudioPlayer(contentsOfURL: url, error: &error) audioPlayer.delegate = self audioPlayer.prepareToPlay() if (audioPlayer.isEqual(nil)) { println("There was an error: (er)") } else { audioPlayer.play() NSLog("working") } I have added import AVFoundation and audioPlayer