latency when pressing headset button in iphone
Asked Answered
T

1

13

I'm trying to trigger different actions inside only my own app using buttons of plugged headset (something similar what pressy does). I noticed however that no matter if I use MPRemoteCommandCenter or remoteControlReceivedWithEvent delegate, I receive events with a noticable lag. What makes matter worse is that if I try double press button fast I will only get one UIEventTypeRemoteControl.

Does anyone experience similar issue, know the reason of this or even better know some workaround? Tested under ios8 and ios9.

Transportation answered 14/10, 2015 at 5:27 Comment(2)
Double-press actions on many platforms are handled as a single user event. Does UIEventTypeRemoteControl contain any properties that indicate how many times the button was pressed?Hewe
What kind of time delay "lag" are you getting? Between half a second and a second? A few seconds? Can you please provide a sample project or reproducible test case?Leonardo
S
1

A quick double-press is indeed a single user action, as this is the desired behaviour in almost any application which uses the headset control for input. It saves developers having to debounce, queue and parse incoming control events manually and is a Good Thing(tm)!

For this to work the system will introduce a small amount of lag while it waits for further user input. It should only take a few hundred milliseconds for this to complete, after which you'll receive the event in your code.

A long, painful, but hopefully useful example of double-press detection:

  1. User presses down on headset control
  2. System notices press, waits for release
  3. User releases headset control
  4. System notices release, detects time button was held down (long press vs short press) and queues single-press event
  5. System waits 200ms in case it is a double-press
  6. It is! User presses down on headset control
  7. System notices press, waits for release
  8. User releases headset control
  9. System converts queued single-press event into double-press event
  10. System waits 200ms in case it is a triple-press
  11. No user input within 200ms
  12. System fires double-press event and clears the queue

See how the delay is necessary for single/double/triple-press detection.

When the event reaches your application it will have a subtype which describes what type of click the user made:

let rc = event!.subtype
print("received remote control \(rc.rawValue)") // 101 = pause, 100 = play

switch rc {
    case .RemoteControlTogglePlayPause:
        // ..
    case .RemoteControlPlay:
        // ..
    case .RemoteControlPause:
        // ..
    default:break
}

An answer on a similar question pointed out these event code integers will be something like;

100 = play
101 = pause
103 = single mic click
104 = double mic click
105 = triple mic click
etc ...
Sylvia answered 4/8, 2016 at 15:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.