Swift - Stop avaudioplayer
<p>I am trying to build a soundboard into an app and have figured out an efficient way of using tags to control playing the sounds. However I am now trying to integrate a pause button that can be used with the <code>.stop()</code> method on the <code>AVAudioPlayer</code> however I get an error with my current code:</p>

<p><code>EXC_BAD_ACCESS</code></p>

<p>This is what I am using at the moment, any ideas?</p>

<pre><code>import UIKit
import AVFoundation

let soundFilenames = ["sound","sound2","sound3"]
var audioPlayers = [AVAudioPlayer]()

class SecondViewController: UIViewController {

     var audioPlayer = AVAudioPlayer()

    override func viewDidLoad() {
        super.viewDidLoad()

     for sound in soundFilenames {
          do {
               let url = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource(sound, ofType: "mp3")!)
               let audioPlayer = try AVAudioPlayer(contentsOfURL: url)
               audioPlayers.append(audioPlayer)
          } catch {
               //Catch error thrown
               audioPlayers.append(AVAudioPlayer())
          }
     }
     }


     @IBAction func buttonPressed(sender: UIButton) {
          let audioPlayer = audioPlayers[sender.tag]
          audioPlayer.play()
     }
     @IBAction func stop(sender: UIButton) {
          audioPlayer.stop()
     }

}
</code></pre>