https://github.com/rono23/GlovePod
国外牛人的开源工程,其说明如下
You can control music without taking off your gloves!
To use, double-tap home in the lock screen to show the media player.
Then, you can switch to the next/previous track by pressing the increase/decrease volume button.
Additionally, you can play/stop a tune by holding the power button
其中有一些很有用的函数
static BOOL isLocked()
{
return [[objc_getClass("SBAwayController") sharedAwayController] isLocked];
}
static BOOL isDimmed()
{
return [[objc_getClass("SBAwayController") sharedAwayController] isDimmed];
}
static BOOL isVisible()
{
return [[objc_getClass("SBAwayController") sharedAwayController] isShowingMediaControls];
}
static BOOL isPlaying()
{
return [[objc_getClass("SBMediaController") sharedInstance] isPlaying];
}
static BOOL isCalling()
{
return [[objc_getClass("SBTelephonyManager") sharedTelephonyManager] inCall];
}
static BOOL isPowerButtonEnabled()
{
return ((isLocked() && !isCalling()) &&
((LSiPodVisiblePowerButtonEnabled && isVisible()) ||
(LSScreenOnPowerButtonEnabled && !isDimmed() && !isVisible()) ||
(LSScreenOffPowerButtonEnabled && isDimmed())));
}
static BOOL useDefaultVolumeAction(BOOL enabled)
{
return (!isLocked() || (isLocked() && !isPlaying()) || !enabled);
}
/*==============================================================================
==============================================================================*/
static void $SpringBoard$invokeGPPowerButton(SpringBoard *self, SEL sel)
{
invocationGPPowerButtonTimerDidFire = YES;
[[objc_getClass("SBMediaController") sharedInstance] togglePlayPause];
}
static void startInvocationGPPowerButtonTimer()
{
invocationGPPowerButtonTimerDidFire = NO;
SpringBoard *springBoard = (SpringBoard *)[objc_getClass("SpringBoard") sharedApplication];
invocationGPPowerButtonTimer = [[NSTimer scheduledTimerWithTimeInterval:0.7f
target:springBoard selector:@selector(invokeGPPowerButton) userInfo:nil repeats:NO] retain];
}
static void cancelInvocationGPPowerButtonTimer()
{
[invocationGPPowerButtonTimer invalidate];
[invocationGPPowerButtonTimer release];
invocationGPPowerButtonTimer = nil;
}