Hey,
starting macOS 10.12.2 there is the MediaPlayer framework for macOS.
With MPRemoteCommandCenter you can receive actions for multimedia keys, headphones etc. (https://developer.apple.com/documentation/mediaplayer/mpremotecommandcenter?language=objc).
Unfortunately, events from these actions aren't received by a sandboxed app. Is there any magical entitlement to support it?