From a4640221186905db82e3d9e71c5d28e6f6bf2b5e Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 7 Oct 2018 06:21:58 +0200 Subject: HeadphoneKey: Try using `MPRemoteCommandCenter` to listen for media keys Try to use `MPRemoteCommandCenter` to get Bluetooth button input. Doesn't appear to work. --- DomeKey/AppDelegate.m | 1 + DomeKey/HeadphoneKey.h | 2 ++ DomeKey/HeadphoneKey.m | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/DomeKey/AppDelegate.m b/DomeKey/AppDelegate.m index 318aeee..fab5171 100644 --- a/DomeKey/AppDelegate.m +++ b/DomeKey/AppDelegate.m @@ -14,6 +14,7 @@ { _headphone_key = [[HeadphoneKey alloc] init]; [_headphone_key startMonitoringBluetoothEvents]; + [_headphone_key mpmediaplayerBS]; } @end diff --git a/DomeKey/HeadphoneKey.h b/DomeKey/HeadphoneKey.h index 586c40b..61c4864 100644 --- a/DomeKey/HeadphoneKey.h +++ b/DomeKey/HeadphoneKey.h @@ -7,6 +7,7 @@ // #import +#import #import #import "dome_key_map.h" @@ -30,5 +31,6 @@ static const unsigned int TIMEOUT_MILLISECONDS = 1000; - (void)handleDeadKey:(HeadphoneButton)button; - (void)runAction; - (void)startMonitoringBluetoothEvents; +- (void)mpmediaplayerBS; @end diff --git a/DomeKey/HeadphoneKey.m b/DomeKey/HeadphoneKey.m index 5a062fc..e1588eb 100644 --- a/DomeKey/HeadphoneKey.m +++ b/DomeKey/HeadphoneKey.m @@ -96,6 +96,25 @@ }]; } +- (void)mpmediaplayerBS +{ + MPRemoteCommandCenter *center = [MPRemoteCommandCenter sharedCommandCenter]; + + [[center togglePlayPauseCommand] addTarget:self action:@selector(mpmediaplayerplaypauesss:)]; +// pauseCommand +// playCommand +// togglePlayPauseCommand +// nextTrackCommand +// previousTrackCommand +} + +- (MPRemoteCommandHandlerStatus) mpmediaplayerplaypauesss: (MPRemoteCommandEvent*) event +{ + NSLog(@"Played from MPMediaPlayer"); + + return MPRemoteCommandHandlerStatusSuccess; +} + - (void)handleDeadKey:(HeadphoneButton)button { NSNumber *storable_button = [NSNumber numberWithUnsignedInteger:button]; -- cgit v1.2.3