Skip to content

Commit

Permalink
Seek buttons, long taps
Browse files Browse the repository at this point in the history
  • Loading branch information
dayanch96 committed Sep 6, 2023
1 parent a1e1083 commit 6cc5c69
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 43 deletions.
14 changes: 12 additions & 2 deletions Source/SeekButtons.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
#import <UIKit/UIKit.h>

@interface UIView (NearestViewController)
- (UIViewController *)nearestViewController;
@end

@interface YTMNowPlayingViewController : UIViewController
- (void)didTapPrevButton;
- (void)didTapNextButton;
@end

@interface YTMPlayerControlsView : UIView
@property (nonatomic, strong) UIButton *prevButton;
@property (nonatomic, strong) UIButton *nextButton;
- (void)didTapPrevButton;
- (void)didTapNextButton;
- (UIViewController *)nearestViewController;
- (void)didTapSeekBackwardButton;
- (void)didTapSeekForwardButton;
- (void)longPressPrev:(UILongPressGestureRecognizer *)gesture;
- (void)longPressNext:(UILongPressGestureRecognizer *)gesture;
@end
82 changes: 50 additions & 32 deletions Source/SeekButtons.x
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ static NSInteger currentSeekTime() {
}

%group gSeekButtons
@implementation UIView (NearestViewController)
- (UIViewController *)nearestViewController {
UIResponder *responder = self.nextResponder;
while (responder) {
if ([responder isKindOfClass:[UIViewController class]]) {
return (UIViewController *)responder;
} responder = responder.nextResponder;
} return nil;
}
@end

%hook YTMPlayerControlsView
- (void)layoutSubviews {
%orig;
Expand Down Expand Up @@ -34,21 +45,23 @@ static NSInteger currentSeekTime() {
}
}

UILongPressGestureRecognizer *longPressPrev = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressPrev:)];
[longPressPrev setMinimumPressDuration:0.5];
[prevButton addGestureRecognizer:longPressPrev];

UILongPressGestureRecognizer *longPressNext = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressNext:)];
[longPressNext setMinimumPressDuration:0.5];
[nextButton addGestureRecognizer:longPressNext];


NSString *backValue = @"10";
NSString *forwardValue = @"30";

if (currentSeekTime() == 1) {
backValue = @"10";
forwardValue = @"10";
} else if (currentSeekTime() == 2) {
backValue = @"20";
forwardValue = @"20";
} else if (currentSeekTime() == 3) {
backValue = @"30";
forwardValue = @"30";
} else if (currentSeekTime() == 4) {
backValue = @"60";
forwardValue = @"60";
if (currentSeekTime() != 0) {
NSArray *values = @[@"10", @"20", @"30", @"60"];
NSInteger seekTime = currentSeekTime() - 1;
backValue = values[seekTime];
forwardValue = values[seekTime];
}

NSString *appBundle = [[NSBundle mainBundle] bundlePath];
Expand All @@ -68,31 +81,36 @@ static NSInteger currentSeekTime() {
- (void)didTapSeekForwardButton {
[self didTapSeekForwardButton];
}

%new - (void)longPressPrev:(UILongPressGestureRecognizer *)gesture {
if (gesture.state == UIGestureRecognizerStateBegan) {
YTMNowPlayingViewController *parentVC = (YTMNowPlayingViewController *)[self nearestViewController];
if (parentVC) [parentVC didTapPrevButton];
}
}

%new - (void)longPressNext:(UILongPressGestureRecognizer *)gesture {
if (gesture.state == UIGestureRecognizerStateBegan) {
YTMNowPlayingViewController *parentVC = (YTMNowPlayingViewController *)[self nearestViewController];
if (parentVC) [parentVC didTapNextButton];
}
}

%end

%hook YTColdConfig
- (long long)iosPlayerClientSharedConfigTransportControlsSeekForwardTime {
if (currentSeekTime() == 1) {
return 10;
} else if (currentSeekTime() == 2) {
return 20;
} else if (currentSeekTime() == 3) {
return 30;
} else if (currentSeekTime() == 4) {
return 60;
} return %orig;
- (NSInteger)iosPlayerClientSharedConfigTransportControlsSeekForwardTime {
NSArray *values = @[@"%orig", @10, @20, @30, @60];
NSInteger seekTime = currentSeekTime();

return (seekTime == 0) ? [values[0] integerValue] : [values[seekTime] integerValue];
}

- (long long)iosPlayerClientSharedConfigTransportControlsSeekBackwardTime {
if (currentSeekTime() == 1) {
return 10;
} else if (currentSeekTime() == 2) {
return 20;
} else if (currentSeekTime() == 3) {
return 30;
} else if (currentSeekTime() == 4) {
return 60;
} return %orig;
- (NSInteger)iosPlayerClientSharedConfigTransportControlsSeekBackwardTime {
NSArray *values = @[@"%orig", @10, @20, @30, @60];
NSInteger seekTime = currentSeekTime();

return (seekTime == 0) ? [values[0] integerValue] : [values[seekTime] integerValue];
}
%end
%end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"AUDIO" = "Audio";
"VIDEO" = "Video";
"SEEK_BUTTONS" = "Replace like/dislike with forward and backward buttons";
"SEEK_TIME_FOOTER" = "Select a seek time in seconds\n\nDefaults:\nSeek backward = 10 sec.\nSeek forward = 30 sec.";
"SEEK_TIME_FOOTER" = "Select a seek time in seconds\n\nDefaults:\nSeek backward = 10 sec.\nSeek forward = 30 sec.\n\nSkip to the next and previous tracks available by long-pressing the buttons.";
"DEFAULT" = "Default";

"THEME_SETTINGS" = "Theme options";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"AUDIO" = "Audio";
"VIDEO" = "Video";
"SEEK_BUTTONS" = "Replace next/previous with forward and backward buttons";
"SEEK_TIME_FOOTER" = "Select a seek time in seconds\n\nDefaults:\nSeek backward = 10 sec.\nSeek forward = 30 sec.";
"SEEK_TIME_FOOTER" = "Select a seek time in seconds\n\nDefaults:\nSeek backward = 10 sec.\nSeek forward = 30 sec.\n\nSkip to the next and previous tracks available by long-pressing the buttons.";
"DEFAULT" = "Default";

"THEME_SETTINGS" = "Theme options";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"AUDIO" = "Audio";
"VIDEO" = "Video";
"SEEK_BUTTONS" = "Replace next/previous with forward and backward buttons";
"SEEK_TIME_FOOTER" = "Selecciona un tiempo de búsqueda en segundos\n\nValores predeterminados:\nRetroceder = 10 seg.\nAvanzar = 30 seg.";
//Selecciona un tiempo de búsqueda en segundos\n\nValores predeterminados:\nRetroceder = 10 seg.\nAvanzar = 30 seg.
"SEEK_TIME_FOOTER" = "Select a seek time in seconds\n\nDefaults:\nSeek backward = 10 sec.\nSeek forward = 30 sec.\n\nSkip to the next and previous tracks available by long-pressing the buttons.";
"DEFAULT" = "Predeterminado";

"THEME_SETTINGS" = "Opciones de tema";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"AUDIO" = "Аудио";
"VIDEO" = "Видео";
"SEEK_BUTTONS" = "Заменить «След.» и «Пред.» на кнопки перемотки";
"SEEK_TIME_FOOTER" = "Выберите время перемотки в секундах\n\nПо умолчанию:\nПеремотка назад = 10cек.\nПеремотка вперед = 30cек.";
"SEEK_TIME_FOOTER" = "Выберите время перемотки в секундах\n\nПо умолчанию:\nПеремотка назад = 10cек.\nПеремотка вперед = 30cек.\n\nПереходить к следующему и предыдущему трекам можно долгим нажатием по кнопкам.";
"DEFAULT" = "По умолч.";

"THEME_SETTINGS" = "Тема";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"AUDIO" = "Şarkı";
"VIDEO" = "Video";
"SEEK_BUTTONS" = "Önceki ve Sonraki düğmelerini Hızlı ileri ve Geri Sar düğmeleriyle değiştir";
"SEEK_TIME_FOOTER" = "Sarma süresini seçiniz\n\Varsayılanlar:\nGeri Sar = 10 sn.\nHızlı ileri = 30 sn.";
"SEEK_TIME_FOOTER" = "Sarma süresini seçiniz\n\Varsayılanlar:\nGeri Sar = 10 sn.\nHızlı ileri = 30 sn.\n\nButonlara uzun basılarak sonraki ve önceki parçalara geçebilirsiniz.";
"DEFAULT" = "Varsayılan";

"THEME_SETTINGS" = "Tema ayarları";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"AUDIO" = "Audio";
"VIDEO" = "Video";
"SEEK_BUTTONS" = "Replace next/previous with forward and backward buttons";
"SEEK_TIME_FOOTER" = "Select a seek time in seconds\n\nDefaults:\nSeek backward = 10 sec.\nSeek forward = 30 sec.";
"SEEK_TIME_FOOTER" = "Select a seek time in seconds\n\nDefaults:\nSeek backward = 10 sec.\nSeek forward = 30 sec.\n\nSkip to the next and previous tracks available by long-pressing the buttons.";
"DEFAULT" = "Default";

"THEME_SETTINGS" = "Theme options";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"AUDIO" = "歌曲";
"VIDEO" = "视频";
"SEEK_BUTTONS" = "Replace next/previous with forward and backward buttons";
"SEEK_TIME_FOOTER" = "选择跳过时间(秒)\n\n默认:\n快退 = 10秒\n快进 = 30秒";
//选择跳过时间(秒)\n\n默认:\n快退 = 10秒\n快进 = 30秒
"SEEK_TIME_FOOTER" = "Select a seek time in seconds\n\nDefaults:\nSeek backward = 10 sec.\nSeek forward = 30 sec.\n\nSkip to the next and previous tracks available by long-pressing the buttons.";
"DEFAULT" = "默认";

"THEME_SETTINGS" = "主题选项";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"AUDIO" = "歌曲";
"VIDEO" = "影片";
"SEEK_BUTTONS" = "Replace next/previous with forward and backward buttons";
"SEEK_TIME_FOOTER" = "選擇一個「快轉/倒轉」時間/秒\n\n預設值:\n倒轉 = 10秒\n快轉 = 30秒";
//選擇一個「快轉/倒轉」時間/秒\n\n預設值:\n倒轉 = 10秒\n快轉 = 30秒
"SEEK_TIME_FOOTER" = "Select a seek time in seconds\n\nDefaults:\nSeek backward = 10 sec.\nSeek forward = 30 sec.\n\nSkip to the next and previous tracks available by long-pressing the buttons.";
"DEFAULT" = "預設";

"THEME_SETTINGS" = "介面主題";
Expand Down Expand Up @@ -76,4 +77,4 @@
"APPLY_MESSAGE" = "這個操作將關閉YouTube Music以套用變更,您確定要繼續嗎?";
"CANCEL" = "取消";
"YES" = "是";
"REGIONAL_RESTRICTION" = "YouTube Music 似乎在您的國家/地區受到限制,請使用 VPN 後再次執行 YouTube Music";
"REGIONAL_RESTRICTION" = "YouTube Music 似乎在您的國家/地區受到限制,請使用 VPN 後再次執行 YouTube Music";

0 comments on commit 6cc5c69

Please sign in to comment.