I'd like some help with implementing these headphone hardware button functionalities with playing music:
- Double tap: next track
- Triple tap: previous track
- Single tap: play/pause
I'd like some help with implementing these headphone hardware button functionalities with playing music:
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 = )