Skip to content

Commit 64c72b1

Browse files
committed
Allowing up to 5.0x toggle playback speed. Changes to the toggle speed / auto-apply settings should now apply without resetting the video player. Changing the default toggle speed to 2.0x for new installations.
1 parent e4adb6b commit 64c72b1

5 files changed

+33
-23
lines changed

YTHFSPrefsManager.h

+13-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,19 @@ typedef enum YTHFSPlaybackRateOption : NSInteger {
2828
kYTHFSPlaybackRateOption125,
2929
kYTHFSPlaybackRateOption150,
3030
kYTHFSPlaybackRateOption175,
31-
kYTHFSPlaybackRateOption200
31+
kYTHFSPlaybackRateOption200,
32+
kYTHFSPlaybackRateOption225,
33+
kYTHFSPlaybackRateOption250,
34+
kYTHFSPlaybackRateOption275,
35+
kYTHFSPlaybackRateOption300,
36+
kYTHFSPlaybackRateOption325,
37+
kYTHFSPlaybackRateOption350,
38+
kYTHFSPlaybackRateOption375,
39+
kYTHFSPlaybackRateOption400,
40+
kYTHFSPlaybackRateOption425,
41+
kYTHFSPlaybackRateOption450,
42+
kYTHFSPlaybackRateOption475,
43+
kYTHFSPlaybackRateOption500
3244
} YTHFSPlaybackRateOption;
3345

3446
// manager that manages the preferences for the tweak

YTHFSPrefsManager.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#define kYTHFSDefaultHoldGestureEnabled NO
2323
#define kYTHFSDefaultDisableStockGesturesEnabled NO
2424
#define kYTHFSDefaultAutoApplyRateEnabled NO
25-
#define kYTHFSDefaultTogglePlaybackRate 1.5
25+
#define kYTHFSDefaultTogglePlaybackRate 2.0
2626
#define kYTHFSDefaultHoldDuration 1.0
2727

2828
// create static variables that will be determined once
@@ -110,7 +110,7 @@ + (YTHFSPlaybackRateOption)playbackRateOptionForValue:(CGFloat)value
110110
if (value > 1.00) {
111111
++playbackRateOptionOffset;
112112
}
113-
return MAX(MIN((NSInteger)(value / 0.25) - playbackRateOptionOffset, kYTHFSPlaybackRateOption200), kYTHFSPlaybackRateOption025);
113+
return MAX(MIN((NSInteger)(value / 0.25) - playbackRateOptionOffset, kYTHFSPlaybackRateOption500), kYTHFSPlaybackRateOption025);
114114
}
115115

116116
// return the appropriate string representation of the hold duration for the given value

YTHFSSettings.x

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
selectBlock:^BOOL (YTSettingsCell *cell, NSUInteger arg1) {
8989
// create a new section item for each toggle rate option that the user can select
9090
NSMutableArray *playbackRateSectionRows = [NSMutableArray array];
91-
for (NSInteger currentRow = kYTHFSPlaybackRateOption025; currentRow <= kYTHFSPlaybackRateOption200; ++currentRow) {
91+
for (NSInteger currentRow = kYTHFSPlaybackRateOption025; currentRow <= kYTHFSPlaybackRateOption500; ++currentRow) {
9292
CGFloat playbackRateForRow = [YTHFSPrefsManager playbackRateValueForOption:currentRow];
9393
YTSettingsSectionItem *rateSection = [YTSettingsSectionItemClass checkmarkItemWithTitle:[YTHFSPrefsManager playbackRateStringForValue:playbackRateForRow]
9494
selectBlock:^BOOL (YTSettingsCell *cell, NSUInteger arg1) {

YTHFSTweak.x

+16-18
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
// the long press gesture that will be created and added to the player view
1414
@property (nonatomic, retain) UILongPressGestureRecognizer *YTHFSLongPressGesture;
1515

16+
// boolean that determines if the auto-apply feature needs to be invoked for the current video
17+
@property (nonatomic, assign) BOOL YTHFSNeedsAutoApply;
18+
1619
// switch between the user-selected playback rate and the normal playback rate, invoked either via the hold gesture or
1720
// automatically when the video starts (dependent on settings)
1821
- (void)YTHFSSwitchPlaybackRate;
@@ -39,11 +42,6 @@
3942
#define kYTHFSNumTouchesRequired 1
4043
#define kYTHFSAllowableMovement 50
4144

42-
// the static variables to keep track of the settings which shall persist until the YTPlayerViewController is recreated
43-
static CGFloat sYTHFSTogglePlaybackRate;
44-
static BOOL sYTHFSHapticFeedbackEnabled;
45-
static BOOL sYTHFSAutoApplyRateEnabled;
46-
4745
// enum to define the direction of the playback rate feedback indicator
4846
typedef enum YTHFSFeedbackDirection : NSInteger {
4947
kYTHFSFeedbackDirectionForward,
@@ -56,12 +54,8 @@ typedef enum YTHFSFeedbackDirection : NSInteger {
5654
- (void)watchController:(YTWatchController *)watchController didSetPlayerViewController:(YTPlayerViewController *)playerViewController
5755
{
5856
if (playerViewController) {
59-
// grab the state of the settings for this instance of the player view controller
60-
sYTHFSTogglePlaybackRate = [YTHFSPrefsManager togglePlaybackRate];
61-
sYTHFSHapticFeedbackEnabled = [YTHFSPrefsManager hapticFeedbackEnabled];
62-
6357
// check to see if the toggle rate should automatically be applied when the video starts
64-
sYTHFSAutoApplyRateEnabled = [YTHFSPrefsManager autoApplyRateEnabled];
58+
playerViewController.YTHFSNeedsAutoApply = [YTHFSPrefsManager autoApplyRateEnabled];
6559

6660
// add a long press gesture to configure the playback rate
6761
if ([YTHFSPrefsManager holdGestureEnabled]) {
@@ -111,6 +105,9 @@ typedef enum YTHFSFeedbackDirection : NSInteger {
111105
// the long press gesture that will be created and added to the player view
112106
%property (nonatomic, retain) UILongPressGestureRecognizer *YTHFSLongPressGesture;
113107

108+
// boolean that determines if the auto-apply feature needs to be invoked for the current video
109+
%property (nonatomic, assign) BOOL YTHFSNeedsAutoApply;
110+
114111
%new
115112
- (void)YTHFSHandleLongPressGesture:(UILongPressGestureRecognizer *)longPressGestureRecognizer
116113
{
@@ -128,11 +125,12 @@ typedef enum YTHFSFeedbackDirection : NSInteger {
128125
NSString *feedbackTitle = nil;
129126
YTHFSFeedbackDirection feedbackDirection = kYTHFSFeedbackDirectionForward;
130127
CGFloat currentPlaybackRate = [self currentPlaybackRateForVarispeedSwitchController:self.varispeedController];
131-
if (currentPlaybackRate != sYTHFSTogglePlaybackRate) {
128+
CGFloat togglePlaybackRate = [YTHFSPrefsManager togglePlaybackRate];
129+
if (currentPlaybackRate != togglePlaybackRate) {
132130
// change to the toggle rate if the current playback rate is any other speed
133-
[self varispeedSwitchController:self.varispeedController didSelectRate:sYTHFSTogglePlaybackRate];
134-
feedbackTitle = [YTHFSPrefsManager playbackRateStringForValue:sYTHFSTogglePlaybackRate];
135-
if (currentPlaybackRate > sYTHFSTogglePlaybackRate) {
131+
[self varispeedSwitchController:self.varispeedController didSelectRate:togglePlaybackRate];
132+
feedbackTitle = [YTHFSPrefsManager playbackRateStringForValue:togglePlaybackRate];
133+
if (currentPlaybackRate > togglePlaybackRate) {
136134
feedbackDirection = kYTHFSFeedbackDirectionBackward;
137135
}
138136
} else {
@@ -157,7 +155,7 @@ typedef enum YTHFSFeedbackDirection : NSInteger {
157155
}
158156

159157
// fire off haptic feedback to indicate that the playback rate changed (only applies to supported devices if enabled)
160-
if (sYTHFSHapticFeedbackEnabled) {
158+
if ([YTHFSPrefsManager hapticFeedbackEnabled]) {
161159
UINotificationFeedbackGenerator *feedbackGenerator = [[UINotificationFeedbackGenerator alloc] init];
162160
[feedbackGenerator notificationOccurred:UINotificationFeedbackTypeSuccess];
163161
feedbackGenerator = nil;
@@ -169,14 +167,14 @@ typedef enum YTHFSFeedbackDirection : NSInteger {
169167
{
170168
%orig;
171169

172-
if (sYTHFSAutoApplyRateEnabled && [self.contentVideoPlayerOverlay isKindOfClass:objc_getClass("YTMainAppVideoPlayerOverlayViewController")]) {
170+
if ([YTHFSPrefsManager autoApplyRateEnabled] && self.YTHFSNeedsAutoApply && [self.contentVideoPlayerOverlay isKindOfClass:objc_getClass("YTMainAppVideoPlayerOverlayViewController")]) {
173171
YTMainAppVideoPlayerOverlayViewController *overlayViewController = (YTMainAppVideoPlayerOverlayViewController *)self.contentVideoPlayerOverlay;
174172
if (overlayViewController.isVarispeedAvailable) {
175173
// regardless of the current playback rate, at this point we know that the toggle rate will be applied
176-
sYTHFSAutoApplyRateEnabled = NO;
174+
self.YTHFSNeedsAutoApply = NO;
177175

178176
// compare whether or not the current playback rate is what the user selected and if not, change to it now
179-
if ([self currentPlaybackRateForVarispeedSwitchController:self.varispeedController] != sYTHFSTogglePlaybackRate) {
177+
if ([self currentPlaybackRateForVarispeedSwitchController:self.varispeedController] != [YTHFSPrefsManager togglePlaybackRate]) {
180178
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
181179
[self YTHFSSwitchPlaybackRate];
182180
});

control

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: com.joshuaseltzer.ytholdforspeed
22
Name: YTHoldForSpeed
3-
Version: 1.1.2
3+
Version: 1.2.0
44
Architecture: iphoneos-arm
55
Description: Tap and hold on the YouTube video player to toggle a selected playback speed. Preferences for the tweak are configured within the YouTube app.
66
Maintainer: Joshua Seltzer <joshua.seltzer90@gmail.com>

0 commit comments

Comments
 (0)