diff --git a/Source/Settings.xm b/Source/Settings.xm index 3d7293f..8be7b15 100644 --- a/Source/Settings.xm +++ b/Source/Settings.xm @@ -47,6 +47,8 @@ static int appVersionSpoofer() { @interface YTSettingsSectionItemManager (YTLitePlus) - (void)updateYTLitePlusSectionWithEntry:(id)entry; +- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray *)urls; +- (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller; @end extern NSBundle *YTLitePlusBundle(); @@ -197,6 +199,29 @@ static const NSInteger YTLiteSection = 789; ]; [sectionItems addObject:pasteSettings]; + YTSettingsSectionItem *videoPlayer = [%c(YTSettingsSectionItem) + itemWithTitle:LOC(@"VIDEO_PICKER") + titleDescription:LOC(@"VIDEO_PICKER_DESC") + accessibilityIdentifier:nil + detailTextBlock:nil + selectBlock:^BOOL (YTSettingsCell *cell, NSUInteger arg1) { + // Access the current view controller + UIViewController *settingsViewController = [self valueForKey:@"_settingsViewControllerDelegate"]; + if (settingsViewController) { + // Present the video picker + UIDocumentPickerViewController *documentPicker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:@[(NSString *)kUTTypeMovie, (NSString *)kUTTypeVideo] inMode:UIDocumentPickerModeImport]; + documentPicker.delegate = (id)self; + documentPicker.allowsMultipleSelection = NO; + [settingsViewController presentViewController:documentPicker animated:YES completion:nil]; + } else { + NSLog(@"settingsViewController is nil"); + } + + return YES; // Return YES to indicate that the action was handled + } + ]; + [sectionItems addObject:videoPlayer]; + /* YTSettingsSectionItem *appIcon = [%c(YTSettingsSectionItem) itemWithTitle:LOC(@"CHANGE_APP_ICON") @@ -479,4 +504,31 @@ static const NSInteger YTLiteSection = 789; } %orig; } + +// Implement the delegate method for document picker +%new +- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray *)urls { + NSURL *pickedURL = [urls firstObject]; + + if (pickedURL) { + // Use AVPlayerViewController to play the video + AVPlayer *player = [AVPlayer playerWithURL:pickedURL]; + AVPlayerViewController *playerViewController = [[AVPlayerViewController alloc] init]; + playerViewController.player = player; + + UIViewController *settingsViewController = [self valueForKey:@"_settingsViewControllerDelegate"]; + if (settingsViewController) { + [settingsViewController presentViewController:playerViewController animated:YES completion:^{ + [player play]; + }]; + } + } +} + +%new +- (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller { + // Handle cancellation if needed + NSLog(@"Document picker was cancelled"); +} + %end diff --git a/YTLitePlus.h b/YTLitePlus.h index 82d6ac1..f737d46 100644 --- a/YTLitePlus.h +++ b/YTLitePlus.h @@ -6,6 +6,9 @@ #import #import #import +#import // For AVPlayer and AVPlayerViewController +#import // For kUTTypeMovie and kUTTypeVideo + #import "Tweaks/FLEX/FLEX.h" #import "Tweaks/YouTubeHeader/YTAppDelegate.h"