VLCAppDelegate.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  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 "VLCHTTPUploaderController.h"
  24. #import "VLCMigrationViewController.h"
  25. #import <BoxSDK/BoxSDK.h>
  26. #import "VLCPlaybackController.h"
  27. #import "VLCPlaybackController+MediaLibrary.h"
  28. #import <MediaPlayer/MediaPlayer.h>
  29. #import <HockeySDK/HockeySDK.h>
  30. #import "VLCActivityManager.h"
  31. #import "VLCDropboxConstants.h"
  32. #import "VLCDownloadViewController.h"
  33. #import <ObjectiveDropboxOfficial/ObjectiveDropboxOfficial.h>
  34. #import "VLCPlaybackNavigationController.h"
  35. #import "PAPasscodeViewController.h"
  36. #import "VLC_iOS-Swift.h"
  37. NSString *const VLCDropboxSessionWasAuthorized = @"VLCDropboxSessionWasAuthorized";
  38. #define BETA_DISTRIBUTION 1
  39. @interface VLCAppDelegate () <VLCMediaFileDiscovererDelegate>
  40. {
  41. BOOL _isRunningMigration;
  42. BOOL _isComingFromHandoff;
  43. VLCKeychainCoordinator *_keychainCoordinator;
  44. AppCoordinator *appCoordinator;
  45. UITabBarController *rootViewController;
  46. }
  47. @end
  48. @implementation VLCAppDelegate
  49. + (void)initialize
  50. {
  51. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  52. NSDictionary *appDefaults = @{kVLCSettingPasscodeAllowFaceID : @(1),
  53. kVLCSettingPasscodeAllowTouchID : @(1),
  54. kVLCSettingContinueAudioInBackgroundKey : @(YES),
  55. kVLCSettingStretchAudio : @(NO),
  56. kVLCSettingTextEncoding : kVLCSettingTextEncodingDefaultValue,
  57. kVLCSettingSkipLoopFilter : kVLCSettingSkipLoopFilterNonRef,
  58. kVLCSettingSubtitlesFont : kVLCSettingSubtitlesFontDefaultValue,
  59. kVLCSettingSubtitlesFontColor : kVLCSettingSubtitlesFontColorDefaultValue,
  60. kVLCSettingSubtitlesFontSize : kVLCSettingSubtitlesFontSizeDefaultValue,
  61. kVLCSettingSubtitlesBoldFont: kVLCSettingSubtitlesBoldFontDefaultValue,
  62. kVLCSettingDeinterlace : kVLCSettingDeinterlaceDefaultValue,
  63. kVLCSettingHardwareDecoding : kVLCSettingHardwareDecodingDefault,
  64. kVLCSettingNetworkCaching : kVLCSettingNetworkCachingDefaultValue,
  65. kVLCSettingVolumeGesture : @(YES),
  66. kVLCSettingPlayPauseGesture : @(YES),
  67. kVLCSettingBrightnessGesture : @(YES),
  68. kVLCSettingSeekGesture : @(YES),
  69. kVLCSettingCloseGesture : @(YES),
  70. kVLCSettingVariableJumpDuration : @(NO),
  71. kVLCSettingVideoFullscreenPlayback : @(YES),
  72. kVLCSettingContinuePlayback : @(1),
  73. kVLCSettingContinueAudioPlayback : @(1),
  74. kVLCSettingFTPTextEncoding : kVLCSettingFTPTextEncodingDefaultValue,
  75. kVLCSettingWiFiSharingIPv6 : kVLCSettingWiFiSharingIPv6DefaultValue,
  76. kVLCSettingEqualizerProfile : kVLCSettingEqualizerProfileDefaultValue,
  77. kVLCSettingPlaybackForwardSkipLength : kVLCSettingPlaybackForwardSkipLengthDefaultValue,
  78. kVLCSettingPlaybackBackwardSkipLength : kVLCSettingPlaybackBackwardSkipLengthDefaultValue,
  79. kVLCSettingOpenAppForPlayback : kVLCSettingOpenAppForPlaybackDefaultValue,
  80. kVLCAutomaticallyPlayNextItem : @(YES)};
  81. [defaults registerDefaults:appDefaults];
  82. }
  83. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  84. {
  85. BITHockeyManager *hockeyManager = [BITHockeyManager sharedHockeyManager];
  86. [hockeyManager configureWithBetaIdentifier:@"0114ca8e265244ce588d2ebd035c3577"
  87. liveIdentifier:@"c95f4227dff96c61f8b3a46a25edc584"
  88. delegate:nil];
  89. [hockeyManager startManager];
  90. // Configure Dropbox
  91. [DBClientsManager setupWithAppKey:kVLCDropboxAppKey];
  92. [VLCApperanceManager setupAppearanceWithTheme:PresentationTheme.current];
  93. // Init the HTTP Server and clean its cache
  94. [[VLCHTTPUploaderController sharedInstance] cleanCache];
  95. self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  96. rootViewController = [UITabBarController new];
  97. self.window.rootViewController = rootViewController;
  98. [self.window makeKeyAndVisible];
  99. // enable crash preventer
  100. void (^setupBlock)() = ^{
  101. void (^setupLibraryBlock)() = ^{
  102. appCoordinator = [[AppCoordinator alloc] initWithTabBarController:rootViewController];
  103. [appCoordinator start];
  104. };
  105. [self validatePasscodeIfNeededWithCompletion:setupLibraryBlock];
  106. BOOL spotlightEnabled = ![VLCKeychainCoordinator passcodeLockEnabled];
  107. [[MLMediaLibrary sharedMediaLibrary] setSpotlightIndexingEnabled:spotlightEnabled];
  108. [[MLMediaLibrary sharedMediaLibrary] applicationWillStart];
  109. VLCMediaFileDiscoverer *discoverer = [VLCMediaFileDiscoverer sharedInstance];
  110. NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  111. discoverer.directoryPath = [searchPaths firstObject];
  112. [discoverer addObserver:self];
  113. [discoverer startDiscovering];
  114. };
  115. NSError *error = nil;
  116. if ([[MLMediaLibrary sharedMediaLibrary] libraryMigrationNeeded]){
  117. _isRunningMigration = YES;
  118. VLCMigrationViewController *migrationController = [[VLCMigrationViewController alloc] initWithNibName:@"VLCMigrationViewController" bundle:nil];
  119. migrationController.completionHandler = ^{
  120. //migrate
  121. setupBlock();
  122. _isRunningMigration = NO;
  123. [[MLMediaLibrary sharedMediaLibrary] updateMediaDatabase];
  124. [[VLCMediaFileDiscoverer sharedInstance] updateMediaList];
  125. };
  126. self.window.rootViewController = migrationController;
  127. [self.window makeKeyAndVisible];
  128. } else {
  129. if (error != nil) {
  130. APLog(@"removed persistentStore since it was corrupt");
  131. NSURL *storeURL = ((MLMediaLibrary *)[MLMediaLibrary sharedMediaLibrary]).persistentStoreURL;
  132. [[NSFileManager defaultManager] removeItemAtURL:storeURL error:&error];
  133. }
  134. setupBlock();
  135. }
  136. /* add our static shortcut items the dynamic way to ease l10n and dynamic elements to be introduced later */
  137. if (@available(iOS 9, *)) {
  138. if (application.shortcutItems == nil || application.shortcutItems.count < 4) {
  139. UIApplicationShortcutItem *localLibraryItem = [[UIApplicationShortcutItem alloc] initWithType:kVLCApplicationShortcutLocalLibrary
  140. localizedTitle:NSLocalizedString(@"SECTION_HEADER_LIBRARY",nil)
  141. localizedSubtitle:nil
  142. icon:[UIApplicationShortcutIcon iconWithTemplateImageName:@"AllFiles"]
  143. userInfo:nil];
  144. UIApplicationShortcutItem *localServerItem = [[UIApplicationShortcutItem alloc] initWithType:kVLCApplicationShortcutLocalServers
  145. localizedTitle:NSLocalizedString(@"LOCAL_NETWORK",nil)
  146. localizedSubtitle:nil
  147. icon:[UIApplicationShortcutIcon iconWithTemplateImageName:@"Local"]
  148. userInfo:nil];
  149. UIApplicationShortcutItem *openNetworkStreamItem = [[UIApplicationShortcutItem alloc] initWithType:kVLCApplicationShortcutOpenNetworkStream
  150. localizedTitle:NSLocalizedString(@"OPEN_NETWORK",nil)
  151. localizedSubtitle:nil
  152. icon:[UIApplicationShortcutIcon iconWithTemplateImageName:@"OpenNetStream"]
  153. userInfo:nil];
  154. UIApplicationShortcutItem *cloudsItem = [[UIApplicationShortcutItem alloc] initWithType:kVLCApplicationShortcutClouds
  155. localizedTitle:NSLocalizedString(@"CLOUD_SERVICES",nil)
  156. localizedSubtitle:nil
  157. icon:[UIApplicationShortcutIcon iconWithTemplateImageName:@"iCloudIcon"]
  158. userInfo:nil];
  159. application.shortcutItems = @[localLibraryItem, localServerItem, openNetworkStreamItem, cloudsItem];
  160. }
  161. }
  162. return YES;
  163. }
  164. #pragma mark - Handoff
  165. - (BOOL)application:(UIApplication *)application willContinueUserActivityWithType:(NSString *)userActivityType
  166. {
  167. if ([userActivityType isEqualToString:kVLCUserActivityLibraryMode] ||
  168. [userActivityType isEqualToString:kVLCUserActivityPlaying] ||
  169. [userActivityType isEqualToString:kVLCUserActivityLibrarySelection])
  170. return YES;
  171. return NO;
  172. }
  173. - (BOOL)application:(UIApplication *)application
  174. continueUserActivity:(NSUserActivity *)userActivity
  175. restorationHandler:(void (^)(NSArray *))restorationHandler
  176. {
  177. NSString *userActivityType = userActivity.activityType;
  178. NSDictionary *dict = userActivity.userInfo;
  179. if([userActivityType isEqualToString:kVLCUserActivityLibraryMode] ||
  180. [userActivityType isEqualToString:kVLCUserActivityLibrarySelection]) {
  181. //TODO: Add restoreUserActivityState to the mediaviewcontroller
  182. _isComingFromHandoff = YES;
  183. return YES;
  184. } else {
  185. NSURL *uriRepresentation = nil;
  186. if ([userActivityType isEqualToString:CSSearchableItemActionType]) {
  187. uriRepresentation = [NSURL URLWithString:dict[CSSearchableItemActivityIdentifier]];
  188. } else {
  189. uriRepresentation = dict[@"playingmedia"];
  190. }
  191. if (!uriRepresentation) {
  192. return NO;
  193. }
  194. NSManagedObject *managedObject = [[MLMediaLibrary sharedMediaLibrary] objectForURIRepresentation:uriRepresentation];
  195. if (managedObject == nil) {
  196. APLog(@"%s file not found: %@",__PRETTY_FUNCTION__,userActivity);
  197. return NO;
  198. }
  199. [[VLCPlaybackController sharedInstance] openMediaLibraryObject:managedObject];
  200. return YES;
  201. }
  202. return NO;
  203. }
  204. - (void)application:(UIApplication *)application
  205. didFailToContinueUserActivityWithType:(NSString *)userActivityType
  206. error:(NSError *)error
  207. {
  208. if (error.code != NSUserCancelledError){
  209. //TODO: present alert
  210. }
  211. }
  212. - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
  213. {
  214. //Handles Dropbox Authorization flow.
  215. DBOAuthResult *authResult = [DBClientsManager handleRedirectURL:url];
  216. if (authResult != nil) {
  217. if ([authResult isSuccess]) {
  218. return YES;
  219. }
  220. }
  221. //Handles Google Authorization flow.
  222. if ([_currentGoogleAuthorizationFlow resumeAuthorizationFlowWithURL:url]) {
  223. _currentGoogleAuthorizationFlow = nil;
  224. return YES;
  225. }
  226. //TODO: we need a model of URLHandlers that registers with the VLCAppdelegate
  227. // then we can go through the list of handlers ask if they can handle the url and the first to say yes handles the call.
  228. // that way internal if elses get encapsulated
  229. /*
  230. protocol VLCURLHandler {
  231. func canHandleOpen(url: URL, options:[UIApplicationOpenURLOptionsKey:AnyObject]=[:]()) -> bool
  232. func performOpen(url: URL, options:[UIApplicationOpenURLOptionsKey:AnyObject]=[:]()) -> bool
  233. } */
  234. // if (_libraryViewController && url != nil) {
  235. // APLog(@"%@ requested %@ to be opened", sourceApplication, url);
  236. //
  237. // if (url.isFileURL) {
  238. // NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  239. // NSString *directoryPath = searchPaths[0];
  240. // NSURL *destinationURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@", directoryPath, url.lastPathComponent]];
  241. // NSError *theError;
  242. // [[NSFileManager defaultManager] moveItemAtURL:url toURL:destinationURL error:&theError];
  243. // if (theError.code != noErr)
  244. // APLog(@"saving the file failed (%li): %@", (long)theError.code, theError.localizedDescription);
  245. //
  246. // [[VLCMediaFileDiscoverer sharedInstance] updateMediaList];
  247. // } else if ([url.scheme isEqualToString:@"vlc-x-callback"] || [url.host isEqualToString:@"x-callback-url"]) {
  248. // // URL confirmes to the x-callback-url specification
  249. // // vlc-x-callback://x-callback-url/action?param=value&x-success=callback
  250. // APLog(@"x-callback-url with host '%@' path '%@' parameters '%@'", url.host, url.path, url.query);
  251. // NSString *action = [url.path stringByReplacingOccurrencesOfString:@"/" withString:@""];
  252. // NSURL *movieURL;
  253. // NSURL *successCallback;
  254. // NSURL *errorCallback;
  255. // NSString *fileName;
  256. // for (NSString *entry in [url.query componentsSeparatedByString:@"&"]) {
  257. // NSArray *keyvalue = [entry componentsSeparatedByString:@"="];
  258. // if (keyvalue.count < 2) continue;
  259. // NSString *key = keyvalue[0];
  260. // NSString *value = [keyvalue[1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  261. //
  262. // if ([key isEqualToString:@"url"])
  263. // movieURL = [NSURL URLWithString:value];
  264. // else if ([key isEqualToString:@"filename"])
  265. // fileName = value;
  266. // else if ([key isEqualToString:@"x-success"])
  267. // successCallback = [NSURL URLWithString:value];
  268. // else if ([key isEqualToString:@"x-error"])
  269. // errorCallback = [NSURL URLWithString:value];
  270. // }
  271. // if ([action isEqualToString:@"stream"] && movieURL) {
  272. // VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
  273. // vpc.fullscreenSessionRequested = YES;
  274. //
  275. // VLCMediaList *medialist = [[VLCMediaList alloc] init];
  276. // [medialist addMedia:[VLCMedia mediaWithURL:movieURL]];
  277. // vpc.successCallback = successCallback;
  278. // vpc.errorCallback = errorCallback;
  279. // [vpc playMediaList:medialist firstIndex:0 subtitlesFilePath:nil];
  280. //
  281. // }
  282. // else if ([action isEqualToString:@"download"] && movieURL) {
  283. // [self downloadMovieFromURL:movieURL fileNameOfMedia:fileName];
  284. // }
  285. // } else {
  286. // NSString *receivedUrl = [url absoluteString];
  287. // if ([receivedUrl length] > 6) {
  288. // NSString *verifyVlcUrl = [receivedUrl substringToIndex:6];
  289. // if ([verifyVlcUrl isEqualToString:@"vlc://"]) {
  290. // NSString *parsedString = [receivedUrl substringFromIndex:6];
  291. // NSUInteger location = [parsedString rangeOfString:@"//"].location;
  292. //
  293. // /* Safari & al mangle vlc://http:// so fix this */
  294. // if (location != NSNotFound && [parsedString characterAtIndex:location - 1] != 0x3a) { // :
  295. // parsedString = [NSString stringWithFormat:@"%@://%@", [parsedString substringToIndex:location], [parsedString substringFromIndex:location+2]];
  296. // } else {
  297. // parsedString = [receivedUrl substringFromIndex:6];
  298. // if (![parsedString hasPrefix:@"http://"] && ![parsedString hasPrefix:@"https://"] && ![parsedString hasPrefix:@"ftp://"]) {
  299. // parsedString = [@"http://" stringByAppendingString:[receivedUrl substringFromIndex:6]];
  300. // }
  301. // }
  302. // url = [NSURL URLWithString:parsedString];
  303. // }
  304. // }
  305. // [[VLCSidebarController sharedInstance] selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]
  306. // scrollPosition:UITableViewScrollPositionNone];
  307. //
  308. // NSString *scheme = url.scheme;
  309. // if ([scheme isEqualToString:@"http"] || [scheme isEqualToString:@"https"] || [scheme isEqualToString:@"ftp"]) {
  310. // VLCAlertView *alert = [[VLCAlertView alloc] initWithTitle:NSLocalizedString(@"OPEN_STREAM_OR_DOWNLOAD", nil) message:url.absoluteString cancelButtonTitle:NSLocalizedString(@"BUTTON_DOWNLOAD", nil) otherButtonTitles:@[NSLocalizedString(@"PLAY_BUTTON", nil)]];
  311. // alert.completion = ^(BOOL cancelled, NSInteger buttonIndex) {
  312. // if (cancelled)
  313. // [self downloadMovieFromURL:url fileNameOfMedia:nil];
  314. // else {
  315. // VLCMedia *media = [VLCMedia mediaWithURL:url];
  316. // VLCMediaList *medialist = [[VLCMediaList alloc] init];
  317. // [medialist addMedia:media];
  318. // [[VLCPlaybackController sharedInstance] playMediaList:medialist firstIndex:0 subtitlesFilePath:nil];
  319. // }
  320. // };
  321. // [alert show];
  322. // } else {
  323. // VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
  324. // vpc.fullscreenSessionRequested = YES;
  325. // VLCMediaList *medialist = [[VLCMediaList alloc] init];
  326. // [medialist addMedia:[VLCMedia mediaWithURL:url]];
  327. // [vpc playMediaList:medialist firstIndex:0 subtitlesFilePath:nil];
  328. // }
  329. // }
  330. // return YES;
  331. // }
  332. return NO;
  333. }
  334. - (void)applicationWillEnterForeground:(UIApplication *)application
  335. {
  336. [[MLMediaLibrary sharedMediaLibrary] applicationWillStart];
  337. }
  338. - (void)applicationWillResignActive:(UIApplication *)application
  339. {
  340. //Touch ID is shown
  341. if ([_window.rootViewController.presentedViewController isKindOfClass:[UINavigationController class]]){
  342. UINavigationController *navCon = (UINavigationController *)_window.rootViewController.presentedViewController;
  343. if ([navCon.topViewController isKindOfClass:[PAPasscodeViewController class]]){
  344. return;
  345. }
  346. }
  347. [self validatePasscodeIfNeededWithCompletion:^{
  348. //TODO: handle updating the videoview and
  349. if ([VLCPlaybackController sharedInstance].isPlaying){
  350. //TODO: push playback
  351. }
  352. }];
  353. [[MLMediaLibrary sharedMediaLibrary] applicationWillExit];
  354. }
  355. - (void)applicationDidBecomeActive:(UIApplication *)application
  356. {
  357. if (!_isRunningMigration && !_isComingFromHandoff) {
  358. [[MLMediaLibrary sharedMediaLibrary] updateMediaDatabase];
  359. // [[VLCMediaFileDiscoverer sharedInstance] updateMediaList];
  360. [[VLCPlaybackController sharedInstance] recoverDisplayedMetadata];
  361. } else if(_isComingFromHandoff) {
  362. _isComingFromHandoff = NO;
  363. }
  364. }
  365. - (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler
  366. {
  367. //TODO: shortcutItem should be implemented
  368. }
  369. #pragma mark - media discovering
  370. - (void)mediaFileAdded:(NSString *)fileName loading:(BOOL)isLoading
  371. {
  372. if (!isLoading) {
  373. MLMediaLibrary *sharedLibrary = [MLMediaLibrary sharedMediaLibrary];
  374. [sharedLibrary addFilePaths:@[fileName]];
  375. /* exclude media files from backup (QA1719) */
  376. NSURL *excludeURL = [NSURL fileURLWithPath:fileName];
  377. [excludeURL setResourceValue:@YES forKey:NSURLIsExcludedFromBackupKey error:nil];
  378. // TODO Should we update media db after adding new files?
  379. [sharedLibrary updateMediaDatabase];
  380. // TODO: update the VideoViewController
  381. }
  382. }
  383. - (void)mediaFileDeleted:(NSString *)name
  384. {
  385. [[MLMediaLibrary sharedMediaLibrary] updateMediaDatabase];
  386. // TODO: update the VideoViewController
  387. }
  388. - (void)mediaFilesFoundRequiringAdditionToStorageBackend:(NSArray<NSString *> *)foundFiles
  389. {
  390. [[MLMediaLibrary sharedMediaLibrary] addFilePaths:foundFiles];
  391. // TODO: update the VideoViewController
  392. }
  393. #pragma mark - pass code validation
  394. - (VLCKeychainCoordinator *)keychainCoordinator
  395. {
  396. if (!_keychainCoordinator) {
  397. _keychainCoordinator = [[VLCKeychainCoordinator alloc] init];
  398. }
  399. return _keychainCoordinator;
  400. }
  401. - (void)validatePasscodeIfNeededWithCompletion:(void(^)(void))completion
  402. {
  403. if ([VLCKeychainCoordinator passcodeLockEnabled]) {
  404. //TODO: Dimiss playback
  405. [self.keychainCoordinator validatePasscodeWithCompletion:completion];
  406. } else {
  407. completion();
  408. }
  409. }
  410. #pragma mark - download handling
  411. - (void)downloadMovieFromURL:(NSURL *)url
  412. fileNameOfMedia:(NSString *)fileName
  413. {
  414. [[VLCDownloadViewController sharedInstance] addURLToDownloadList:url fileNameOfMedia:fileName];
  415. //TODO: open DownloadViewController
  416. }
  417. #pragma mark - playback
  418. - (void)playWithURL:(NSURL *)url successCallback:(NSURL *)successCallback errorCallback:(NSURL *)errorCallback
  419. {
  420. VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
  421. vpc.fullscreenSessionRequested = YES;
  422. vpc.successCallback = successCallback;
  423. vpc.errorCallback = errorCallback;
  424. VLCMediaList *mediaList = [[VLCMediaList alloc] initWithArray:@[[VLCMedia mediaWithURL:url]]];
  425. [vpc playMediaList:mediaList firstIndex:0 subtitlesFilePath:nil];
  426. }
  427. @end