VLCAppDelegate.m 23 KB

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