aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2019-03-24 12:36:42 +0100
committerTeddy Wing2019-03-24 12:36:42 +0100
commit519038bde17082020265d5ae5bda80f493f91b20 (patch)
treeaecfc4627093309a5ef14c43bcd36c663d016329
parent8aba8891e027dc1aa5d352fb60240e704e5628d8 (diff)
downloadDomeKey-519038bde17082020265d5ae5bda80f493f91b20.tar.bz2
HeadphoneKeyEventBluetooth: Initial thought with MPRemoteCommandCenter
Turns out that `MPRemoteCommandCenter` seems to work for the 'play' button, but it has no interface for volume buttons. I remember discovering the volume button problem when I last looked into it several months ago, but since forgot. This was an attempt at replicating the method in: https://github.com/russellhancox/btrcd/blob/c3e375f/btrcd/AppDelegate.m by setting up an `MPRemoteCommandCenter` and calling `addTargetWithHandler:` on each button to invoke a custom handler. Committing this for reference. In order to get volume button functionality, we'll have to dive into lower level Bluetooth events with AVRCP. Seems that newer headphones might even use something newer than AVRCP, so I wonder if we'll have to use multiple Bluetooth remote control profiles. A bit of a pain, as there doesn't seem to be a pre-built interface for us to do this, but I'm learning more about interacting with IOBluetooth. Also, `MPRemoteCommandCenter` is an OS X 10.12 Sierra API, so if there's something we can use that's available on earlier OSes, that's a plus.
-rw-r--r--DomeKey/HeadphoneKey.h2
-rw-r--r--DomeKey/HeadphoneKey.m2
-rw-r--r--DomeKey/HeadphoneKeyEventBluetooth.h9
-rw-r--r--DomeKey/HeadphoneKeyEventBluetooth.m22
4 files changed, 34 insertions, 1 deletions
diff --git a/DomeKey/HeadphoneKey.h b/DomeKey/HeadphoneKey.h
index 6670ff5..d5e9e76 100644
--- a/DomeKey/HeadphoneKey.h
+++ b/DomeKey/HeadphoneKey.h
@@ -51,6 +51,7 @@
#import "HeadphoneKeyEventDelegate.h"
#import "HeadphoneKeyEventWired.h"
+#import "HeadphoneKeyEventBluetooth.h"
#import "Mappings.h"
#import "Sounds.h"
#import "dome_key_map.h"
@@ -60,6 +61,7 @@ static const Milliseconds TIMEOUT_DEFAULT = 500;
@interface HeadphoneKey : NSObject <HeadphoneKeyEventDelegate> {
HeadphoneKeyEventWired *_wired_headphone_event;
+ HeadphoneKeyEventBluetooth *_bluetooth_headphone_event;
NSMutableArray *_key_buffer;
Mappings *_mappings;
Milliseconds _timeout;
diff --git a/DomeKey/HeadphoneKey.m b/DomeKey/HeadphoneKey.m
index 3aa79ce..beba94d 100644
--- a/DomeKey/HeadphoneKey.m
+++ b/DomeKey/HeadphoneKey.m
@@ -60,6 +60,8 @@ static BOOL _play_audio;
if (self) {
_wired_headphone_event = [[HeadphoneKeyEventWired alloc]
initWithDelegate:self];
+ _bluetooth_headphone_event = [[HeadphoneKeyEventBluetooth alloc]
+ initWithDelegate:self];
_key_buffer = [[NSMutableArray alloc] initWithCapacity:5];
diff --git a/DomeKey/HeadphoneKeyEventBluetooth.h b/DomeKey/HeadphoneKeyEventBluetooth.h
index 00577c3..86e0ce7 100644
--- a/DomeKey/HeadphoneKeyEventBluetooth.h
+++ b/DomeKey/HeadphoneKeyEventBluetooth.h
@@ -8,6 +8,13 @@
#import <Foundation/Foundation.h>
-@interface HeadphoneKeyEventBluetooth : NSObject
+#import "HeadphoneKeyEventDelegate.h"
+#import "dome_key_map.h"
+
+@interface HeadphoneKeyEventBluetooth : NSObject {
+ id <HeadphoneKeyEventDelegate> _delegate;
+}
+
+- (instancetype)initWithDelegate:(id <HeadphoneKeyEventDelegate>)delegate;
@end
diff --git a/DomeKey/HeadphoneKeyEventBluetooth.m b/DomeKey/HeadphoneKeyEventBluetooth.m
index 3c02486..52e22db 100644
--- a/DomeKey/HeadphoneKeyEventBluetooth.m
+++ b/DomeKey/HeadphoneKeyEventBluetooth.m
@@ -10,4 +10,26 @@
@implementation HeadphoneKeyEventBluetooth
+- (instancetype)initWithDelegate:(id <HeadphoneKeyEventDelegate>)delegate
+{
+ self = [self init];
+ if (self) {
+ _delegate = delegate;
+
+ MPRemoteCommandCenter *cc = [MPRemoteCommandCenter sharedCommandCenter];
+ [cc playCommand];
+ [cc pauseCommand];
+ [cc stopCommand];
+ [cc togglePlayPauseCommand];
+ // [cc nextTrackCommand];
+ // [cc seekForwardCommand];
+ // [cc previousTrackCommand];
+ // [cc seekBackwardCommand];
+ }
+ return self;
+}
+
+MPRemoteCommandHandler key_pressed(HeadphoneButton button) {
+}
+
@end