i'm trying to run this swift code but it outputs the following error: "fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)". This is the code:
//
// PlaySoundsViewController.swift
// Revoice
//
// Created by Leonardo Barazza on 16/04/15.
// Copyright (c) 2015 Leonardo Barazza. All rights reserved.
//
import UIKit
import AVFoundation
class PlaySoundsViewController: UIViewController {
var audioPlayer: AVAudioPlayer!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
if var filePath = NSBundle.mainBundle().pathForResource("movie_quote", ofType: "mp3") {
var filePathUrl = NSURL.fileURLWithPath(filePath)
audioPlayer = AVAudioPlayer(contentsOfURL: filePathUrl, error: nil)
} else {
println("the filePath is empty")
}
}
@IBAction func playSlowly(sender: UIButton) {
audioPlayer.play()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
Can you help me?
Thanks in advance.