Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

latency when pressing headset button in iphone

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.

like image 915
pzo Avatar asked Oct 14 '15 05:10

pzo


1 Answers

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 ...
like image 114
NoChecksum Avatar answered Oct 22 '22 17:10

NoChecksum