13
13
// the long press gesture that will be created and added to the player view
14
14
@property (nonatomic , retain ) UILongPressGestureRecognizer *YTHFSLongPressGesture;
15
15
16
+ // boolean that determines if the auto-apply feature needs to be invoked for the current video
17
+ @property (nonatomic , assign ) BOOL YTHFSNeedsAutoApply;
18
+
16
19
// switch between the user-selected playback rate and the normal playback rate, invoked either via the hold gesture or
17
20
// automatically when the video starts (dependent on settings)
18
21
- (void )YTHFSSwitchPlaybackRate ;
39
42
#define kYTHFSNumTouchesRequired 1
40
43
#define kYTHFSAllowableMovement 50
41
44
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
-
47
45
// enum to define the direction of the playback rate feedback indicator
48
46
typedef enum YTHFSFeedbackDirection : NSInteger {
49
47
kYTHFSFeedbackDirectionForward ,
@@ -56,12 +54,8 @@ typedef enum YTHFSFeedbackDirection : NSInteger {
56
54
- (void )watchController:(YTWatchController *)watchController didSetPlayerViewController:(YTPlayerViewController *)playerViewController
57
55
{
58
56
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
-
63
57
// check to see if the toggle rate should automatically be applied when the video starts
64
- sYTHFSAutoApplyRateEnabled = [YTHFSPrefsManager autoApplyRateEnabled ];
58
+ playerViewController. YTHFSNeedsAutoApply = [YTHFSPrefsManager autoApplyRateEnabled ];
65
59
66
60
// add a long press gesture to configure the playback rate
67
61
if ([YTHFSPrefsManager holdGestureEnabled ]) {
@@ -111,6 +105,9 @@ typedef enum YTHFSFeedbackDirection : NSInteger {
111
105
// the long press gesture that will be created and added to the player view
112
106
%property (nonatomic, retain) UILongPressGestureRecognizer *YTHFSLongPressGesture;
113
107
108
+ // boolean that determines if the auto-apply feature needs to be invoked for the current video
109
+ %property (nonatomic, assign) BOOL YTHFSNeedsAutoApply;
110
+
114
111
%new
115
112
- (void )YTHFSHandleLongPressGesture:(UILongPressGestureRecognizer *)longPressGestureRecognizer
116
113
{
@@ -128,11 +125,12 @@ typedef enum YTHFSFeedbackDirection : NSInteger {
128
125
NSString *feedbackTitle = nil ;
129
126
YTHFSFeedbackDirection feedbackDirection = kYTHFSFeedbackDirectionForward ;
130
127
CGFloat currentPlaybackRate = [self currentPlaybackRateForVarispeedSwitchController: self .varispeedController];
131
- if (currentPlaybackRate != sYTHFSTogglePlaybackRate ) {
128
+ CGFloat togglePlaybackRate = [YTHFSPrefsManager togglePlaybackRate ];
129
+ if (currentPlaybackRate != togglePlaybackRate) {
132
130
// 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 ) {
136
134
feedbackDirection = kYTHFSFeedbackDirectionBackward ;
137
135
}
138
136
} else {
@@ -157,7 +155,7 @@ typedef enum YTHFSFeedbackDirection : NSInteger {
157
155
}
158
156
159
157
// 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 ] ) {
161
159
UINotificationFeedbackGenerator *feedbackGenerator = [[UINotificationFeedbackGenerator alloc ] init ];
162
160
[feedbackGenerator notificationOccurred: UINotificationFeedbackTypeSuccess];
163
161
feedbackGenerator = nil ;
@@ -169,14 +167,14 @@ typedef enum YTHFSFeedbackDirection : NSInteger {
169
167
{
170
168
%orig ;
171
169
172
- if (sYTHFSAutoApplyRateEnabled && [self .contentVideoPlayerOverlay isKindOfClass: objc_getClass (" YTMainAppVideoPlayerOverlayViewController" )]) {
170
+ if ([YTHFSPrefsManager autoApplyRateEnabled ] && self. YTHFSNeedsAutoApply && [self .contentVideoPlayerOverlay isKindOfClass: objc_getClass (" YTMainAppVideoPlayerOverlayViewController" )]) {
173
171
YTMainAppVideoPlayerOverlayViewController *overlayViewController = (YTMainAppVideoPlayerOverlayViewController *)self.contentVideoPlayerOverlay ;
174
172
if (overlayViewController.isVarispeedAvailable ) {
175
173
// 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 ;
177
175
178
176
// 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 ] ) {
180
178
dispatch_after (dispatch_time (DISPATCH_TIME_NOW, (int64_t )(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue (), ^{
181
179
[self YTHFSSwitchPlaybackRate ];
182
180
});
0 commit comments