-1

I'd like some help with implementing these headphone hardware button functionalities with playing music:

  1. Double tap: next track
  2. Triple tap: previous track
  3. Single tap: play/pause
Eric Aya
  • 69,473
  • 35
  • 181
  • 253
PvDev
  • 791
  • 21
  • 67
  • 1
    And what have you tried so far that you need help with? – TommyBs Mar 02 '18 at 10:51
  • Propose closing. duplicate of question asked by OP https://stackoverflow.com/questions/49024682/how-can-i-control-my-headset-for-my-music-player for which a valid answer was provided. Downvoted – MDB983 Mar 02 '18 at 16:39

1 Answers1

0

For the number of taps. Implement this code in your viewDidload

  override func viewDidLoad() {
    super.viewDidLoad()
     yourButton.addTarget(self, action: #selector(multipleTap(_:event:)), for: UIControlEvents.touchDownRepeat)
}

Then create this function:

  @objc func multipleTap(_ sender: UIButton, event: UIEvent) {
    let touch: UITouch = event.allTouches!.first!
     if (touch.tapCount == numberOfClicks) {

        // do stuff here

}

I hope that helps = )

ASH
  • 9
  • 1
  • 7