title: How to play a sound using Swift?
body: <p>I would like to play a sound using Swift.</p>
  
  <p>My code worked in Swift 1.0 but now it doesn't work anymore in Swift 2 or newer.</p>
  
  <pre><code>override func viewDidLoad() {
    super.viewDidLoad()
  
    let url:NSURL = NSBundle.mainBundle().URLForResource("soundName", withExtension: "mp3")!
  
    do { 
      player = try AVAudioPlayer(contentsOfURL: url, fileTypeHint: nil) 
    } catch _{
      return
    }
  
    bgMusic.numberOfLoops = 1
    bgMusic.prepareToPlay()
  
    if (Data.backgroundMenuPlayed == 0){
      player.play()
      Data.backgroundMenuPlayed = 1
    }
  }
  </code></pre>