title: Sound through UIButton does not work, swift
body: <p>I have 4 buttons that trigger 4 different sounds. All buttons work, I have a println button 1, button2, etc.. For some reason I am only hearing sounds that come through button 3 and 4. I used the same coding method for all buttons and audio players, So I have no idea what the problem could be. This is my code. </p>
  
  <p>There are no errors or anything and again all buttons and audio players work the same, so I'm not sure why button 1 and 2 don't work.</p>
  
  <p>Any help would be much appreciated.</p>
  
  <pre><code>class MusicPlayer {
  
  var onePlayer : AVAudioPlayer?
  var twoPlayer : AVAudioPlayer?
  var threePlayer : AVAudioPlayer?
  var fourPlayer : AVAudioPlayer?
  
  
  func playOneSound() {
      twoPlayer!.play()
  }
  
  func playTwoSound() {
  
      twoPlayer!.play()
  }
  
  func playThreeSound() {
  
      threePlayer!.play()
  }
  
  func playFourSound() {
  
      fourPlayer!.play()
  }
  
  func stopOneSound() {
      twoPlayer!.stop()
  }
  
  func stopTwoSound() {
  
      twoPlayer!.stop()
  }
  
  func stopThreeSound() {
  
      threePlayer!.stop()
  }
  
  func stopFourSound() {
  
      fourPlayer!.stop()
  }
  
  class var sharedInstance: MusicPlayer {
      struct Static {
          static var instance: MusicPlayer?
          static var token: dispatch_once_t = 0
      }
  
      dispatch_once(&amp;Static.token) {
          Static.instance = MusicPlayer()
      }
  
      return Static.instance!
  }
  
  init() {
  
  
      // Create an NSURL for the correct file
      let oneSound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("Go To Sleep 1", ofType: "mp3")!)
      let twoSound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("Go To Sleep 2", ofType: "mp3")!)
      let threeSound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("Go To Sleep 3", ofType: "mp3")!)
      let fourSound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("Go To Sleep 5", ofType: "mp3")!)
  
      // Create a new AVAudioPlayer with the correct file
      onePlayer = AVAudioPlayer(contentsOfURL: oneSound, error: nil)
      twoPlayer = AVAudioPlayer(contentsOfURL: twoSound, error: nil)
      threePlayer = AVAudioPlayer(contentsOfURL: threeSound, error: nil)
      fourPlayer = AVAudioPlayer(contentsOfURL: fourSound, error: nil)
  
      /*onePlayer!.volume = masterEffectSoundLevel
      twoPlayer!.volume = masterEffectSoundLevel
      threePlayer!.volume = masterEffectSoundLevel
      fourPlayer!.volume = masterEffectSoundLevel*/
  
  
      // Prepare for playback, set loop count to infinite, start playback
      onePlayer!.prepareToPlay()
      twoPlayer!.prepareToPlay()
      threePlayer!.prepareToPlay()
      fourPlayer!.prepareToPlay()
  
  }
  </code></pre>
  
  <p>This is my code for the buttons :</p>
  
  <pre><code> @IBAction func settingOneButton(sender: UIButton) {
      settingOne.hidden = false
      settingTwo.hidden = true
      settingThree.hidden = true
      settingFour.hidden = true
  
  }
  
  @IBAction func settingTwoButton(sender: UIButton) {
      settingOne.hidden = true
      settingTwo.hidden = false
      settingThree.hidden = true
      settingFour.hidden = true
  
  }
  
  @IBAction func settingThreeButton(sender: UIButton) {
      settingOne.hidden = true
      settingTwo.hidden = true
      settingThree.hidden = false
      settingFour.hidden = true
  
  }
  
  @IBAction func settingFourButton(sender: UIButton) {
      settingOne.hidden = true
      settingTwo.hidden = true
      settingThree.hidden = true
      settingFour.hidden = false
  
  }
  
  @IBAction func goToSleepPressed(sender: AnyObject) {
  
      if settingOne.hidden == false {
  
          MusicPlayer.sharedInstance.playOneSound()
          MusicPlayer.sharedInstance.stopTwoSound()
          MusicPlayer.sharedInstance.stopThreeSound()
          MusicPlayer.sharedInstance.stopFourSound()
          println("one")
  
      } else if settingTwo.hidden == false {
          MusicPlayer.sharedInstance.playTwoSound()
          MusicPlayer.sharedInstance.stopOneSound()
          MusicPlayer.sharedInstance.stopThreeSound()
          MusicPlayer.sharedInstance.stopFourSound()
          println("two")
  
      } else if settingThree.hidden == false {
  
          MusicPlayer.sharedInstance.playThreeSound()
          MusicPlayer.sharedInstance.stopOneSound()
          MusicPlayer.sharedInstance.stopTwoSound()
          MusicPlayer.sharedInstance.stopFourSound()
          println("three")
  
      } else if settingFour.hidden == false {
          MusicPlayer.sharedInstance.playFourSound()
          MusicPlayer.sharedInstance.stopOneSound()
          MusicPlayer.sharedInstance.stopTwoSound()
          MusicPlayer.sharedInstance.stopThreeSound()
          println("four")
  
      }
  }
  </code></pre>