VLCAppDelegate.m 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. /*****************************************************************************
  2. * VLCAppDelegate.m
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2013-2015 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Authors: Felix Paul Kühne <fkuehne # videolan.org>
  9. * Gleb Pinigin <gpinigin # gmail.com>
  10. * Jean-Romain Prévost <jr # 3on.fr>
  11. * Luis Fernandes <zipleen # gmail.com>
  12. * Carola Nitz <nitz.carola # googlemail.com>
  13. * Tamas Timar <ttimar.vlc # gmail.com>
  14. * Tobias Conradi <videolan # tobias-conradi.de>
  15. * Soomin Lee <TheHungryBu # gmail.com>
  16. *
  17. * Refer to the COPYING file of the official project for license.
  18. *****************************************************************************/
  19. #import "VLCAppDelegate.h"
  20. #import "VLCMediaFileDiscoverer.h"
  21. #import "NSString+SupportedMedia.h"
  22. #import "UIDevice+VLC.h"
  23. #import "VLCLibraryViewController.h"
  24. #import "VLCHTTPUploaderController.h"
  25. #import "VLCMigrationViewController.h"
  26. #import <BoxSDK/BoxSDK.h>
  27. #import "VLCPlaybackController.h"
  28. #import "VLCPlaybackController+MediaLibrary.h"
  29. #import "VLCPlayerDisplayController.h"
  30. #import <MediaPlayer/MediaPlayer.h>
  31. #import <HockeySDK/HockeySDK.h>
  32. #import "VLCSidebarController.h"
  33. #import "VLCKeychainCoordinator.h"
  34. #import "VLCActivityManager.h"
  35. #import "VLCDropboxConstants.h"
  36. #import <ObjectiveDropboxOfficial/ObjectiveDropboxOfficial.h>
  37. NSString *const VLCDropboxSessionWasAuthorized = @"VLCDropboxSessionWasAuthorized";
  38. #define BETA_DISTRIBUTION 1
  39. @interface VLCAppDelegate () <VLCMediaFileDiscovererDelegate>
  40. {
  41. BOOL _passcodeValidated;
  42. BOOL _isRunningMigration;
  43. BOOL _isComingFromHandoff;
  44. VLCWatchCommunication *_watchCommunication;
  45. }
  46. @end
  47. @implementation VLCAppDelegate
  48. + (void)initialize
  49. {
  50. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  51. NSNumber *skipLoopFilterDefaultValue;
  52. if ([[UIDevice currentDevice] vlcSpeedCategory] < VLCSpeedCategoryThreeDevices)
  53. skipLoopFilterDefaultValue = kVLCSettingSkipLoopFilterNonKey;
  54. else
  55. skipLoopFilterDefaultValue = kVLCSettingSkipLoopFilterNonRef;
  56. NSDictionary *appDefaults = @{kVLCSettingPasscodeAllowTouchID : @(1),
  57. kVLCSettingContinueAudioInBackgroundKey : @(YES),
  58. kVLCSettingStretchAudio : @(NO),
  59. kVLCSettingTextEncoding : kVLCSettingTextEncodingDefaultValue,
  60. kVLCSettingSkipLoopFilter : skipLoopFilterDefaultValue,
  61. kVLCSettingSubtitlesFont : kVLCSettingSubtitlesFontDefaultValue,
  62. kVLCSettingSubtitlesFontColor : kVLCSettingSubtitlesFontColorDefaultValue,
  63. kVLCSettingSubtitlesFontSize : kVLCSettingSubtitlesFontSizeDefaultValue,
  64. kVLCSettingSubtitlesBoldFont: kVLCSettingSubtitlesBoldFontDefaultValue,
  65. kVLCSettingDeinterlace : kVLCSettingDeinterlaceDefaultValue,
  66. kVLCSettingHWDecoding : kVLCSettingHWDecodingDefault,
  67. kVLCSettingNetworkCaching : kVLCSettingNetworkCachingDefaultValue,
  68. kVLCSettingVolumeGesture : @(YES),
  69. kVLCSettingPlayPauseGesture : @(YES),
  70. kVLCSettingBrightnessGesture : @(YES),
  71. kVLCSettingSeekGesture : @(YES),
  72. kVLCSettingCloseGesture : @(YES),
  73. kVLCSettingVariableJumpDuration : @(NO),
  74. kVLCSettingVideoFullscreenPlayback : @(YES),
  75. kVLCSettingContinuePlayback : @(1),
  76. kVLCSettingContinueAudioPlayback : @(1),
  77. kVLCSettingFTPTextEncoding : kVLCSettingFTPTextEncodingDefaultValue,
  78. kVLCSettingWiFiSharingIPv6 : kVLCSettingWiFiSharingIPv6DefaultValue,
  79. kVLCSettingEqualizerProfile : kVLCSettingEqualizerProfileDefaultValue,
  80. kVLCSettingPlaybackForwardSkipLength : kVLCSettingPlaybackForwardSkipLengthDefaultValue,
  81. kVLCSettingPlaybackBackwardSkipLength : kVLCSettingPlaybackBackwardSkipLengthDefaultValue,
  82. kVLCSettingOpenAppForPlayback : kVLCSettingOpenAppForPlaybackDefaultValue,
  83. kVLCAutomaticallyPlayNextItem : @(YES)};
  84. [defaults registerDefaults:appDefaults];
  85. }
  86. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  87. {
  88. BITHockeyManager *hockeyManager = [BITHockeyManager sharedHockeyManager];
  89. [hockeyManager configureWithBetaIdentifier:@"0114ca8e265244ce588d2ebd035c3577"
  90. liveIdentifier:@"c95f4227dff96c61f8b3a46a25edc584"
  91. delegate:nil];
  92. // Configure Dropbox
  93. [DBClientsManager setupWithAppKey:kVLCDropboxAppKey];
  94. // Configure the SDK in here only!
  95. [hockeyManager startManager];
  96. [hockeyManager.authenticator authenticateInstallation];
  97. /* listen to validation notification */
  98. [[NSNotificationCenter defaultCenter] addObserver:self
  99. selector:@selector(passcodeWasValidated:)
  100. name:VLCPasscodeValidated
  101. object:nil];
  102. // Change the keyboard for UISearchBar
  103. [[UITextField appearance] setKeyboardAppearance:UIKeyboardAppearanceDark];
  104. // For the cursor
  105. [[UITextField appearance] setTintColor:[UIColor VLCOrangeTintColor]];
  106. // Don't override the 'Cancel' button color in the search bar with the previous UITextField call. Use the default blue color
  107. [[UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor colorWithRed:0.0 green:122.0/255.0 blue:1.0 alpha:1.0]} forState:UIControlStateNormal];
  108. // For the edit selection indicators
  109. [[UITableView appearance] setTintColor:[UIColor VLCOrangeTintColor]];
  110. [[UISwitch appearance] setOnTintColor:[UIColor VLCOrangeTintColor]];
  111. // Init the HTTP Server and clean its cache
  112. [[VLCHTTPUploaderController sharedInstance] cleanCache];
  113. self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  114. // enable crash preventer
  115. void (^setupBlock)() = ^{
  116. _libraryViewController = [[VLCLibraryViewController alloc] init];
  117. VLCSidebarController *sidebarVC = [VLCSidebarController sharedInstance];
  118. VLCNavigationController *navCon = [[VLCNavigationController alloc] initWithRootViewController:_libraryViewController];
  119. sidebarVC.contentViewController = navCon;
  120. VLCPlayerDisplayController *playerDisplayController = [VLCPlayerDisplayController sharedInstance];
  121. playerDisplayController.childViewController = sidebarVC.fullViewController;
  122. self.window.rootViewController = playerDisplayController;
  123. [self.window makeKeyAndVisible];
  124. [self validatePasscode];
  125. BOOL spotlightEnabled = ![[VLCKeychainCoordinator defaultCoordinator] passcodeLockEnabled];
  126. [[MLMediaLibrary sharedMediaLibrary] setSpotlightIndexingEnabled:spotlightEnabled];
  127. [[MLMediaLibrary sharedMediaLibrary] applicationWillStart];
  128. VLCMediaFileDiscoverer *discoverer = [VLCMediaFileDiscoverer sharedInstance];
  129. NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  130. discoverer.directoryPath = [searchPaths firstObject];
  131. [discoverer addObserver:self];
  132. [discoverer startDiscovering];
  133. };
  134. NSError *error = nil;
  135. if ([[MLMediaLibrary sharedMediaLibrary] libraryMigrationNeeded]){
  136. _isRunningMigration = YES;
  137. VLCMigrationViewController *migrationController = [[VLCMigrationViewController alloc] initWithNibName:@"VLCMigrationViewController" bundle:nil];
  138. migrationController.completionHandler = ^{
  139. //migrate
  140. setupBlock();
  141. _isRunningMigration = NO;
  142. [[MLMediaLibrary sharedMediaLibrary] updateMediaDatabase];
  143. [[VLCMediaFileDiscoverer sharedInstance] updateMediaList];
  144. };
  145. self.window.rootViewController = migrationController;
  146. [self.window makeKeyAndVisible];
  147. } else {
  148. if (error != nil) {
  149. APLog(@"removed persistentStore since it was corrupt");
  150. NSURL *storeURL = ((MLMediaLibrary *)[MLMediaLibrary sharedMediaLibrary]).persistentStoreURL;
  151. [[NSFileManager defaultManager] removeItemAtURL:storeURL error:&error];
  152. }
  153. setupBlock();
  154. }
  155. if ([VLCWatchCommunication isSupported]) {
  156. _watchCommunication = [VLCWatchCommunication sharedInstance];
  157. // TODO: push DB changes instead
  158. // [_watchCommunication startRelayingNotificationName:NSManagedObjectContextDidSaveNotification object:nil];
  159. [_watchCommunication startRelayingNotificationName:VLCPlaybackControllerPlaybackMetadataDidChange object:nil];
  160. }
  161. /* add our static shortcut items the dynamic way to ease l10n and dynamic elements to be introduced later */
  162. if ([UIApplicationShortcutItem class] != nil) {
  163. if (application.shortcutItems == nil || application.shortcutItems.count < 4) {
  164. UIApplicationShortcutItem *localLibraryItem = [[UIApplicationShortcutItem alloc] initWithType:kVLCApplicationShortcutLocalLibrary
  165. localizedTitle:NSLocalizedString(@"SECTION_HEADER_LIBRARY",nil)
  166. localizedSubtitle:nil
  167. icon:[UIApplicationShortcutIcon iconWithTemplateImageName:@"AllFiles"]
  168. userInfo:nil];
  169. UIApplicationShortcutItem *localServerItem = [[UIApplicationShortcutItem alloc] initWithType:kVLCApplicationShortcutLocalServers
  170. localizedTitle:NSLocalizedString(@"LOCAL_NETWORK",nil)
  171. localizedSubtitle:nil
  172. icon:[UIApplicationShortcutIcon iconWithTemplateImageName:@"Local"]
  173. userInfo:nil];
  174. UIApplicationShortcutItem *openNetworkStreamItem = [[UIApplicationShortcutItem alloc] initWithType:kVLCApplicationShortcutOpenNetworkStream
  175. localizedTitle:NSLocalizedString(@"OPEN_NETWORK",nil)
  176. localizedSubtitle:nil
  177. icon:[UIApplicationShortcutIcon iconWithTemplateImageName:@"OpenNetStream"]
  178. userInfo:nil];
  179. UIApplicationShortcutItem *cloudsItem = [[UIApplicationShortcutItem alloc] initWithType:kVLCApplicationShortcutClouds
  180. localizedTitle:NSLocalizedString(@"CLOUD_SERVICES",nil)
  181. localizedSubtitle:nil
  182. icon:[UIApplicationShortcutIcon iconWithTemplateImageName:@"iCloudIcon"]
  183. userInfo:nil];
  184. application.shortcutItems = @[localLibraryItem, localServerItem, openNetworkStreamItem, cloudsItem];
  185. }
  186. }
  187. return YES;
  188. }
  189. - (void)dealloc
  190. {
  191. [[NSNotificationCenter defaultCenter] removeObserver:self];
  192. }
  193. #pragma mark - Handoff
  194. - (BOOL)application:(UIApplication *)application willContinueUserActivityWithType:(NSString *)userActivityType
  195. {
  196. if ([userActivityType isEqualToString:kVLCUserActivityLibraryMode] ||
  197. [userActivityType isEqualToString:kVLCUserActivityPlaying] ||
  198. [userActivityType isEqualToString:kVLCUserActivityLibrarySelection])
  199. return YES;
  200. return NO;
  201. }
  202. - (BOOL)application:(UIApplication *)application
  203. continueUserActivity:(NSUserActivity *)userActivity
  204. restorationHandler:(void (^)(NSArray *))restorationHandler
  205. {
  206. NSString *userActivityType = userActivity.activityType;
  207. NSDictionary *dict = userActivity.userInfo;
  208. if([userActivityType isEqualToString:kVLCUserActivityLibraryMode] ||
  209. [userActivityType isEqualToString:kVLCUserActivityLibrarySelection]) {
  210. VLCLibraryMode libraryMode = (VLCLibraryMode)[(NSNumber *)dict[@"state"] integerValue];
  211. if (libraryMode <= VLCLibraryModeAllSeries) {
  212. [[VLCSidebarController sharedInstance] selectRowAtIndexPath:[NSIndexPath indexPathForRow:libraryMode inSection:0]
  213. scrollPosition:UITableViewScrollPositionTop];
  214. [self.libraryViewController setLibraryMode:libraryMode];
  215. }
  216. [self.libraryViewController restoreUserActivityState:userActivity];
  217. _isComingFromHandoff = YES;
  218. return YES;
  219. } else {
  220. NSURL *uriRepresentation = nil;
  221. if ([userActivityType isEqualToString:CSSearchableItemActionType]) {
  222. uriRepresentation = [NSURL URLWithString:dict[CSSearchableItemActivityIdentifier]];
  223. } else {
  224. uriRepresentation = dict[@"playingmedia"];
  225. }
  226. if (!uriRepresentation) {
  227. return NO;
  228. }
  229. NSManagedObject *managedObject = [[MLMediaLibrary sharedMediaLibrary] objectForURIRepresentation:uriRepresentation];
  230. if (managedObject == nil) {
  231. APLog(@"%s file not found: %@",__PRETTY_FUNCTION__,userActivity);
  232. return NO;
  233. }
  234. [[VLCPlaybackController sharedInstance] openMediaLibraryObject:managedObject];
  235. return YES;
  236. }
  237. return NO;
  238. }
  239. - (void)application:(UIApplication *)application
  240. didFailToContinueUserActivityWithType:(NSString *)userActivityType
  241. error:(NSError *)error
  242. {
  243. if (error.code != NSUserCancelledError){
  244. //TODO: present alert
  245. }
  246. }
  247. - (BOOL)application:(UIApplication *)application
  248. openURL:(NSURL *)url
  249. sourceApplication:(NSString *)sourceApplication
  250. annotation:(id)annotation
  251. {
  252. //Handles Dropbox Authorization flow.
  253. DBOAuthResult *authResult = [DBClientsManager handleRedirectURL:url];
  254. if (authResult != nil) {
  255. if ([authResult isSuccess]) {
  256. return YES;
  257. }
  258. }
  259. //Handles Google Authorization flow.
  260. if ([_currentGoogleAuthorizationFlow resumeAuthorizationFlowWithURL:url]) {
  261. _currentGoogleAuthorizationFlow = nil;
  262. return YES;
  263. }
  264. if (_libraryViewController && url != nil) {
  265. APLog(@"%@ requested %@ to be opened", sourceApplication, url);
  266. if (url.isFileURL) {
  267. NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  268. NSString *directoryPath = searchPaths[0];
  269. NSURL *destinationURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@", directoryPath, url.lastPathComponent]];
  270. NSError *theError;
  271. [[NSFileManager defaultManager] moveItemAtURL:url toURL:destinationURL error:&theError];
  272. if (theError.code != noErr)
  273. APLog(@"saving the file failed (%li): %@", (long)theError.code, theError.localizedDescription);
  274. [[VLCMediaFileDiscoverer sharedInstance] updateMediaList];
  275. } else if ([url.scheme isEqualToString:@"vlc-x-callback"] || [url.host isEqualToString:@"x-callback-url"]) {
  276. // URL confirmes to the x-callback-url specification
  277. // vlc-x-callback://x-callback-url/action?param=value&x-success=callback
  278. APLog(@"x-callback-url with host '%@' path '%@' parameters '%@'", url.host, url.path, url.query);
  279. NSString *action = [url.path stringByReplacingOccurrencesOfString:@"/" withString:@""];
  280. NSURL *movieURL;
  281. NSURL *successCallback;
  282. NSURL *errorCallback;
  283. NSString *fileName;
  284. for (NSString *entry in [url.query componentsSeparatedByString:@"&"]) {
  285. NSArray *keyvalue = [entry componentsSeparatedByString:@"="];
  286. if (keyvalue.count < 2) continue;
  287. NSString *key = keyvalue[0];
  288. NSString *value = [keyvalue[1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  289. if ([key isEqualToString:@"url"])
  290. movieURL = [NSURL URLWithString:value];
  291. else if ([key isEqualToString:@"filename"])
  292. fileName = value;
  293. else if ([key isEqualToString:@"x-success"])
  294. successCallback = [NSURL URLWithString:value];
  295. else if ([key isEqualToString:@"x-error"])
  296. errorCallback = [NSURL URLWithString:value];
  297. }
  298. if ([action isEqualToString:@"stream"] && movieURL) {
  299. VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
  300. vpc.fullscreenSessionRequested = YES;
  301. [vpc playURL:movieURL successCallback:successCallback errorCallback:errorCallback];
  302. }
  303. else if ([action isEqualToString:@"download"] && movieURL) {
  304. [self downloadMovieFromURL:movieURL fileNameOfMedia:fileName];
  305. }
  306. } else {
  307. NSString *receivedUrl = [url absoluteString];
  308. if ([receivedUrl length] > 6) {
  309. NSString *verifyVlcUrl = [receivedUrl substringToIndex:6];
  310. if ([verifyVlcUrl isEqualToString:@"vlc://"]) {
  311. NSString *parsedString = [receivedUrl substringFromIndex:6];
  312. NSUInteger location = [parsedString rangeOfString:@"//"].location;
  313. /* Safari & al mangle vlc://http:// so fix this */
  314. if (location != NSNotFound && [parsedString characterAtIndex:location - 1] != 0x3a) { // :
  315. parsedString = [NSString stringWithFormat:@"%@://%@", [parsedString substringToIndex:location], [parsedString substringFromIndex:location+2]];
  316. } else {
  317. parsedString = [receivedUrl substringFromIndex:6];
  318. if (![parsedString hasPrefix:@"http://"] && ![parsedString hasPrefix:@"https://"] && ![parsedString hasPrefix:@"ftp://"]) {
  319. parsedString = [@"http://" stringByAppendingString:[receivedUrl substringFromIndex:6]];
  320. }
  321. }
  322. url = [NSURL URLWithString:parsedString];
  323. }
  324. }
  325. [[VLCSidebarController sharedInstance] selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]
  326. scrollPosition:UITableViewScrollPositionNone];
  327. NSString *scheme = url.scheme;
  328. if ([scheme isEqualToString:@"http"] || [scheme isEqualToString:@"https"] || [scheme isEqualToString:@"ftp"]) {
  329. VLCAlertView *alert = [[VLCAlertView alloc] initWithTitle:NSLocalizedString(@"OPEN_STREAM_OR_DOWNLOAD", nil) message:url.absoluteString cancelButtonTitle:NSLocalizedString(@"BUTTON_DOWNLOAD", nil) otherButtonTitles:@[NSLocalizedString(@"PLAY_BUTTON", nil)]];
  330. alert.completion = ^(BOOL cancelled, NSInteger buttonIndex) {
  331. if (cancelled)
  332. [self downloadMovieFromURL:url fileNameOfMedia:nil];
  333. else {
  334. VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
  335. [vpc playURL:url successCallback:nil errorCallback:nil];
  336. }
  337. };
  338. [alert show];
  339. } else {
  340. VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
  341. vpc.fullscreenSessionRequested = YES;
  342. [vpc playURL:url successCallback:nil errorCallback:nil];
  343. }
  344. }
  345. return YES;
  346. }
  347. return NO;
  348. }
  349. - (void)applicationWillEnterForeground:(UIApplication *)application
  350. {
  351. [[MLMediaLibrary sharedMediaLibrary] applicationWillStart];
  352. }
  353. - (void)applicationWillResignActive:(UIApplication *)application
  354. {
  355. _passcodeValidated = NO;
  356. [self.libraryViewController setEditing:NO animated:NO];
  357. [self validatePasscode];
  358. [[MLMediaLibrary sharedMediaLibrary] applicationWillExit];
  359. }
  360. - (void)applicationDidBecomeActive:(UIApplication *)application
  361. {
  362. if (!_isRunningMigration && !_isComingFromHandoff) {
  363. [[MLMediaLibrary sharedMediaLibrary] updateMediaDatabase];
  364. [[VLCMediaFileDiscoverer sharedInstance] updateMediaList];
  365. } else if(_isComingFromHandoff) {
  366. _isComingFromHandoff = NO;
  367. }
  368. }
  369. - (void)applicationWillTerminate:(UIApplication *)application
  370. {
  371. _passcodeValidated = NO;
  372. [[NSUserDefaults standardUserDefaults] synchronize];
  373. }
  374. - (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler
  375. {
  376. [[VLCSidebarController sharedInstance] performActionForShortcutItem:shortcutItem];
  377. }
  378. #pragma mark - media discovering
  379. - (void)mediaFileAdded:(NSString *)fileName loading:(BOOL)isLoading
  380. {
  381. if (!isLoading) {
  382. MLMediaLibrary *sharedLibrary = [MLMediaLibrary sharedMediaLibrary];
  383. [sharedLibrary addFilePaths:@[fileName]];
  384. /* exclude media files from backup (QA1719) */
  385. NSURL *excludeURL = [NSURL fileURLWithPath:fileName];
  386. [excludeURL setResourceValue:@YES forKey:NSURLIsExcludedFromBackupKey error:nil];
  387. // TODO Should we update media db after adding new files?
  388. [sharedLibrary updateMediaDatabase];
  389. [_libraryViewController updateViewContents];
  390. }
  391. }
  392. - (void)mediaFileDeleted:(NSString *)name
  393. {
  394. [[MLMediaLibrary sharedMediaLibrary] updateMediaDatabase];
  395. [_libraryViewController updateViewContents];
  396. }
  397. - (void)mediaFilesFoundRequiringAdditionToStorageBackend:(NSArray<NSString *> *)foundFiles
  398. {
  399. [[MLMediaLibrary sharedMediaLibrary] addFilePaths:foundFiles];
  400. [[(VLCAppDelegate *)[UIApplication sharedApplication].delegate libraryViewController] updateViewContents];
  401. }
  402. #pragma mark - pass code validation
  403. - (void)passcodeWasValidated:(NSNotification *)aNotifcation
  404. {
  405. _passcodeValidated = YES;
  406. [self.libraryViewController updateViewContents];
  407. if ([VLCPlaybackController sharedInstance].isPlaying)
  408. [[VLCPlayerDisplayController sharedInstance] pushPlaybackView];
  409. }
  410. - (BOOL)passcodeValidated
  411. {
  412. return _passcodeValidated;
  413. }
  414. - (void)validatePasscode
  415. {
  416. VLCKeychainCoordinator *keychainCoordinator = [VLCKeychainCoordinator defaultCoordinator];
  417. if (!_passcodeValidated && [keychainCoordinator passcodeLockEnabled]) {
  418. [[VLCPlayerDisplayController sharedInstance] dismissPlaybackView];
  419. [keychainCoordinator validatePasscode];
  420. } else {
  421. _passcodeValidated = YES;
  422. [self passcodeValidated];
  423. }
  424. }
  425. #pragma mark - download handling
  426. - (void)downloadMovieFromURL:(NSURL *)url
  427. fileNameOfMedia:(NSString *)fileName
  428. {
  429. [[VLCDownloadViewController sharedInstance] addURLToDownloadList:url fileNameOfMedia:fileName];
  430. [[VLCSidebarController sharedInstance] selectRowAtIndexPath:[NSIndexPath indexPathForRow:2 inSection:1]
  431. scrollPosition:UITableViewScrollPositionNone];
  432. }
  433. #pragma mark - remote events pre 7.1
  434. - (void)remoteControlReceivedWithEvent:(UIEvent *)event {
  435. [[VLCPlaybackController sharedInstance] remoteControlReceivedWithEvent:event];
  436. }
  437. #pragma mark - watch stuff
  438. - (void)application:(UIApplication *)application
  439. handleWatchKitExtensionRequest:(NSDictionary *)userInfo
  440. reply:(void (^)(NSDictionary *))reply
  441. {
  442. if ([VLCWatchCommunication isSupported]) {
  443. [self.watchCommunication session:[WCSession defaultSession] didReceiveMessage:userInfo replyHandler:reply];
  444. }
  445. }
  446. @end