mirror of
https://github.com/SoPat712/YTLitePlus.git
synced 2025-08-21 18:28:47 -04:00
Attempt brightness and volume gestures
This commit is contained in:
@@ -576,17 +576,32 @@ BOOL isTabSelected = NO;
|
|||||||
%new
|
%new
|
||||||
- (void)YTLitePlusHandlePanGesture:(UIPanGestureRecognizer *)panGestureRecognizer {
|
- (void)YTLitePlusHandlePanGesture:(UIPanGestureRecognizer *)panGestureRecognizer {
|
||||||
static float initialVolume;
|
static float initialVolume;
|
||||||
|
static float initialBrightness;
|
||||||
static BOOL isHorizontalPan = NO;
|
static BOOL isHorizontalPan = NO;
|
||||||
|
static NSInteger gestureSection = 0; // 1 for brightness, 2 for volume, 3 for seeking
|
||||||
|
|
||||||
if (panGestureRecognizer.state == UIGestureRecognizerStateBegan) {
|
if (panGestureRecognizer.state == UIGestureRecognizerStateBegan) {
|
||||||
// Store the initial volume at the beginning of the pan gesture
|
// Get the gesture's start position
|
||||||
initialVolume = [[AVAudioSession sharedInstance] outputVolume];
|
CGPoint startLocation = [panGestureRecognizer locationInView:self.view];
|
||||||
|
CGFloat viewHeight = self.view.bounds.size.height;
|
||||||
|
|
||||||
|
// Determine the section based on the start position
|
||||||
|
if (startLocation.y <= viewHeight / 3.0) {
|
||||||
|
gestureSection = 1; // Top third: Brightness
|
||||||
|
initialBrightness = [UIScreen mainScreen].brightness;
|
||||||
|
} else if (startLocation.y <= 2 * viewHeight / 3.0) {
|
||||||
|
gestureSection = 2; // Middle third: Volume
|
||||||
|
initialVolume = [[AVAudioSession sharedInstance] outputVolume];
|
||||||
|
} else {
|
||||||
|
gestureSection = 3; // Bottom third: Seeking
|
||||||
|
}
|
||||||
|
|
||||||
// Reset the horizontal pan flag
|
// Reset the horizontal pan flag
|
||||||
isHorizontalPan = NO;
|
isHorizontalPan = NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (panGestureRecognizer.state == UIGestureRecognizerStateChanged) {
|
if (panGestureRecognizer.state == UIGestureRecognizerStateChanged) {
|
||||||
// Calculate the translation
|
// Calculate the translation of the gesture
|
||||||
CGPoint translation = [panGestureRecognizer translationInView:self.view];
|
CGPoint translation = [panGestureRecognizer translationInView:self.view];
|
||||||
|
|
||||||
// Determine if the gesture is predominantly horizontal
|
// Determine if the gesture is predominantly horizontal
|
||||||
@@ -600,30 +615,42 @@ BOOL isTabSelected = NO;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle the gesture based on the identified section
|
||||||
if (isHorizontalPan) {
|
if (isHorizontalPan) {
|
||||||
float newVolume = initialVolume + (translation.x / 1000.0); // Adjust the divisor to control the sensitivity
|
if (gestureSection == 1) {
|
||||||
|
// Top third: Adjust brightness
|
||||||
// Clamp the volume between 0 and 1
|
float newBrightness = initialBrightness + (translation.x / 1000.0);
|
||||||
newVolume = fmaxf(fminf(newVolume, 1.0), 0.0);
|
newBrightness = fmaxf(fminf(newBrightness, 1.0), 0.0);
|
||||||
|
[[UIScreen mainScreen] setBrightness:newBrightness];
|
||||||
// https://stackoverflow.com/questions/50737943/how-to-change-volume-programmatically-on-ios-11-4/50740074#50740074
|
|
||||||
MPVolumeView *volumeView = [[MPVolumeView alloc] init];
|
} else if (gestureSection == 2) {
|
||||||
UISlider *volumeViewSlider = nil;
|
// Middle third: Adjust volume
|
||||||
for (UIView *view in volumeView.subviews) {
|
float newVolume = initialVolume + (translation.x / 1000.0);
|
||||||
if ([view isKindOfClass:[UISlider class]]) {
|
newVolume = fmaxf(fminf(newVolume, 1.0), 0.0);
|
||||||
volumeViewSlider = (UISlider *)view;
|
|
||||||
break;
|
MPVolumeView *volumeView = [[MPVolumeView alloc] init];
|
||||||
|
UISlider *volumeViewSlider = nil;
|
||||||
|
for (UIView *view in volumeView.subviews) {
|
||||||
|
if ([view isKindOfClass:[UISlider class]]) {
|
||||||
|
volumeViewSlider = (UISlider *)view;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||||
|
volumeViewSlider.value = newVolume;
|
||||||
|
});
|
||||||
|
|
||||||
|
} else if (gestureSection == 3) {
|
||||||
|
// Bottom third: Seek functionality (implement your seeking logic here)
|
||||||
|
// Example: Adjust playback position based on horizontal swipe
|
||||||
|
// (Add your media player's seeking logic here)
|
||||||
}
|
}
|
||||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
||||||
volumeViewSlider.value = newVolume;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (panGestureRecognizer.state == UIGestureRecognizerStateEnded) {
|
if (panGestureRecognizer.state == UIGestureRecognizerStateEnded) {
|
||||||
if (isHorizontalPan) {
|
if (isHorizontalPan) {
|
||||||
// Haptic feedback
|
// Provide haptic feedback upon successful gesture recognition
|
||||||
UINotificationFeedbackGenerator *feedbackGenerator = [[UINotificationFeedbackGenerator alloc] init];
|
UINotificationFeedbackGenerator *feedbackGenerator = [[UINotificationFeedbackGenerator alloc] init];
|
||||||
[feedbackGenerator notificationOccurred:UINotificationFeedbackTypeSuccess];
|
[feedbackGenerator notificationOccurred:UINotificationFeedbackTypeSuccess];
|
||||||
feedbackGenerator = nil;
|
feedbackGenerator = nil;
|
||||||
|
Reference in New Issue
Block a user