VLCAppDelegate.m 25 KB

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