title: Swift - How to pause a playing audio by clicking the same button?
body: <p>So I have a list of audio files and when a cell is pressed it plays the audio. This works fine but I am not able to pause it by clicking the same cell again.</p>
  
  <p>My code for the table view:</p>
  
  <pre><code>override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
  {
      let a = indexPath.section;
      let b = indexPath.row;
  
      var path = NSBundle.mainBundle().pathForResource(musicArray[b], ofType: "mp3")
      var error:NSError?
  
      do{
          audioPlayer = try AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: path!))
      }
      catch
      {
          print("Something bad happened")
      }
  
      if (audioPlayer.playing)
      {
          audioPlayer.pause();
      }
      else
      {
          audioPlayer.play();
      }
  }
  </code></pre>
  
  <p>musicArray has the titles of the audio files</p>