title: Playing audio file in Swift using AVPlayer
body: <p>I have a very simple method for playing an mp3 audio file in Swift using <code>AVPlayer</code>.</p>
  
  <p>The problem is, it seems too simple. For example, in cases where there is an issue with the playback, an issue with the file, an issue with the device audio, how can the playback fail gracefully instead of the app crashing?</p>
  
  <p>Or is the below playback code safe?</p>
  
  <pre><code>import UIKit
  
  import AVFoundation
  
  var audioPlayer:AVPlayer!
  
  class ViewController: UIViewController {
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          audioPlayer = AVPlayer(URL: NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("myResourceFileName", ofType: "mp3")!))
          audioPlayer.play()
  
      }
  
  }
  </code></pre>