title: Swift Avplayer - Stop all other tableviewcells from playing, when 'Play' is tapped
body: <p>My home page is a table view and each cell has a play button (when clicked an <code>AVAudioPlayer</code> instance is created). The problem is I can click Play on multiple cells and they will all play simultaneously. I am trying to figure out how to pause the other cells when any Play button is clicked.</p>
  
  <p>Here is my play button code from my <code>TableViewCell</code> file:</p>
  
  <pre><code>@IBAction func playButtonTapped(_ sender: UIButton) {
  
      if self.audioPlayer != nil {
          if self.audioPlayer.isPlaying {
              self.audioPlayer.pause()
              self.playbutton.setImage(#imageLiteral(resourceName: "bluePlay"), for: .normal)
          }
          else {
              self.audioPlayer.play()
              self.playbutton.setImage(#imageLiteral(resourceName: "bluePause"), for: .normal)
          }
          return
      }
      do {
          self.audioPlayer = try AVAudioPlayer(data: self.audioFile!)
          self.audioPlayer.prepareToPlay()
          self.audioPlayer.delegate = self as? AVAudioPlayerDelegate
          self.audioPlayer.play()
          self.playbutton.setImage(#imageLiteral(resourceName: "bluePause"), for: .normal)
  
          let audioSession = AVAudioSession.sharedInstance()
          do {
              try audioSession.overrideOutputAudioPort(AVAudioSession.PortOverride.speaker)
          } catch let error as NSError {
              print("audioSession error: \(error.localizedDescription)")
          }
      } catch {
          print(#line, error.localizedDescription)
      }
      self.timer = Timer.scheduledTimer(timeInterval: 1, target: self,   selector: (#selector(HomeTableViewCell.updateProgress)), userInfo: nil, repeats: true)
  }
  </code></pre>
  
  <p>I have been trying protocols, trying to edit the <code>TableViewVC</code> and the <code>TableViewCellVC</code>, but I can't quite get it.</p>