VLCAppDelegate.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  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)(void) = ^{
  101. void (^setupLibraryBlock)(void) = ^{
  102. self->appCoordinator = [[AppCoordinator alloc] initWithTabBarController:self->rootViewController];
  103. [self->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. self->_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", url);
  236. //
  237. // if (url.isFileURL) {
  238. // NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  239. // NSString *directoryPath = searchPaths.firstObject;
  240. // NSURL *destinationURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@", directoryPath, url.lastPathComponent]];
  241. // NSError *theError;
  242. // NSFileManager *manager = [NSFileManager defaultManager];
  243. // [[NSFileManager defaultManager] moveItemAtURL:url toURL:destinationURL error:&theError];
  244. // if (theError.code != noErr)
  245. // APLog(@"saving the file failed (%li): %@", (long)theError.code, theError.localizedDescription);
  246. //
  247. // [[VLCMediaFileDiscoverer sharedInstance] updateMediaList];
  248. //
  249. // NSURLRelationship relationship;
  250. // [manager getRelationship:&relationship ofDirectoryAtURL:[NSURL fileURLWithPath:directoryPath] toItemAtURL:url error:&theError];
  251. // if (relationship == NSURLRelationshipContains) {
  252. // [self playWithURL:url completion:nil];
  253. // }
  254. // } else if ([url.scheme isEqualToString:@"vlc-x-callback"] || [url.host isEqualToString:@"x-callback-url"]) {
  255. // // URL confirmes to the x-callback-url specification
  256. // // vlc-x-callback://x-callback-url/action?param=value&x-success=callback
  257. // APLog(@"x-callback-url with host '%@' path '%@' parameters '%@'", url.host, url.path, url.query);
  258. // NSString *action = [url.path stringByReplacingOccurrencesOfString:@"/" withString:@""];
  259. // NSURL *movieURL;
  260. // NSURL *successCallback;
  261. // NSURL *errorCallback;
  262. // NSString *fileName;
  263. // for (NSString *entry in [url.query componentsSeparatedByString:@"&"]) {
  264. // NSArray *keyvalue = [entry componentsSeparatedByString:@"="];
  265. // if (keyvalue.count < 2) continue;
  266. // NSString *key = keyvalue[0];
  267. // NSString *value = [keyvalue[1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  268. //
  269. // if ([key isEqualToString:@"url"])
  270. // movieURL = [NSURL URLWithString:value];
  271. // else if ([key isEqualToString:@"filename"])
  272. // fileName = value;
  273. // else if ([key isEqualToString:@"x-success"])
  274. // successCallback = [NSURL URLWithString:value];
  275. // else if ([key isEqualToString:@"x-error"])
  276. // errorCallback = [NSURL URLWithString:value];
  277. // }
  278. // if ([action isEqualToString:@"stream"] && movieURL) {
  279. // [self playWithURL:movieURL completion:^(BOOL success) {
  280. // NSURL *callback = success ? successCallback : errorCallback;
  281. // if (@available(iOS 10, *)) {
  282. // [[UIApplication sharedApplication] openURL:callback options:@{} completionHandler:nil];
  283. // } else {
  284. //#pragma clang diagnostic push
  285. //#pragma clang diagnostic ignored "-Wdeprecated-declarations"
  286. // /* UIApplication's replacement calls require iOS 10 or later, which we can't enforce as of yet */
  287. // [[UIApplication sharedApplication] openURL:callback];
  288. //#pragma clang diagnostic pop
  289. // }
  290. // }];
  291. // }
  292. // else if ([action isEqualToString:@"download"] && movieURL) {
  293. // [self downloadMovieFromURL:movieURL fileNameOfMedia:fileName];
  294. // }
  295. // } else {
  296. // NSString *receivedUrl = [url absoluteString];
  297. // if ([receivedUrl length] > 6) {
  298. // NSString *verifyVlcUrl = [receivedUrl substringToIndex:6];
  299. // if ([verifyVlcUrl isEqualToString:@"vlc://"]) {
  300. // NSString *parsedString = [receivedUrl substringFromIndex:6];
  301. // NSUInteger location = [parsedString rangeOfString:@"//"].location;
  302. //
  303. // /* Safari & al mangle vlc://http:// so fix this */
  304. // if (location != NSNotFound && [parsedString characterAtIndex:location - 1] != 0x3a) { // :
  305. // parsedString = [NSString stringWithFormat:@"%@://%@", [parsedString substringToIndex:location], [parsedString substringFromIndex:location+2]];
  306. // } else {
  307. // parsedString = [receivedUrl substringFromIndex:6];
  308. // if (![parsedString hasPrefix:@"http://"] && ![parsedString hasPrefix:@"https://"] && ![parsedString hasPrefix:@"ftp://"]) {
  309. // parsedString = [@"http://" stringByAppendingString:[receivedUrl substringFromIndex:6]];
  310. // }
  311. // }
  312. // url = [NSURL URLWithString:parsedString];
  313. // }
  314. // }
  315. // [[VLCSidebarController sharedInstance] selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]
  316. // scrollPosition:UITableViewScrollPositionNone];
  317. //
  318. // NSString *scheme = url.scheme;
  319. // if ([scheme isEqualToString:@"http"] || [scheme isEqualToString:@"https"] || [scheme isEqualToString:@"ftp"]) {
  320. // VLCAlertView *alert = [[VLCAlertView alloc] initWithTitle:NSLocalizedString(@"OPEN_STREAM_OR_DOWNLOAD", nil) message:url.absoluteString cancelButtonTitle:NSLocalizedString(@"BUTTON_DOWNLOAD", nil) otherButtonTitles:@[NSLocalizedString(@"PLAY_BUTTON", nil)]];
  321. // alert.completion = ^(BOOL cancelled, NSInteger buttonIndex) {
  322. // if (cancelled)
  323. // [self downloadMovieFromURL:url fileNameOfMedia:nil];
  324. // else {
  325. // [self playWithURL:url completion:nil];
  326. // }
  327. // };
  328. // [alert show];
  329. // } else {
  330. // [self playWithURL:url completion:nil];
  331. // }
  332. // }
  333. // return YES;
  334. // }
  335. return NO;
  336. }
  337. - (void)applicationWillEnterForeground:(UIApplication *)application
  338. {
  339. [[MLMediaLibrary sharedMediaLibrary] applicationWillStart];
  340. }
  341. - (void)applicationWillResignActive:(UIApplication *)application
  342. {
  343. //Touch ID is shown
  344. if ([_window.rootViewController.presentedViewController isKindOfClass:[UINavigationController class]]){
  345. UINavigationController *navCon = (UINavigationController *)_window.rootViewController.presentedViewController;
  346. if ([navCon.topViewController isKindOfClass:[PAPasscodeViewController class]]){
  347. return;
  348. }
  349. }
  350. [self validatePasscodeIfNeededWithCompletion:^{
  351. //TODO: handle updating the videoview and
  352. if ([VLCPlaybackController sharedInstance].isPlaying){
  353. //TODO: push playback
  354. }
  355. }];
  356. [[MLMediaLibrary sharedMediaLibrary] applicationWillExit];
  357. }
  358. - (void)applicationDidBecomeActive:(UIApplication *)application
  359. {
  360. if (!_isRunningMigration && !_isComingFromHandoff) {
  361. [[MLMediaLibrary sharedMediaLibrary] updateMediaDatabase];
  362. // [[VLCMediaFileDiscoverer sharedInstance] updateMediaList];
  363. [[VLCPlaybackController sharedInstance] recoverDisplayedMetadata];
  364. } else if(_isComingFromHandoff) {
  365. _isComingFromHandoff = NO;
  366. }
  367. }
  368. - (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler
  369. {
  370. //TODO: shortcutItem should be implemented
  371. }
  372. #pragma mark - media discovering
  373. - (void)mediaFileAdded:(NSString *)fileName loading:(BOOL)isLoading
  374. {
  375. if (!isLoading) {
  376. MLMediaLibrary *sharedLibrary = [MLMediaLibrary sharedMediaLibrary];
  377. [sharedLibrary addFilePaths:@[fileName]];
  378. /* exclude media files from backup (QA1719) */
  379. NSURL *excludeURL = [NSURL fileURLWithPath:fileName];
  380. [excludeURL setResourceValue:@YES forKey:NSURLIsExcludedFromBackupKey error:nil];
  381. // TODO Should we update media db after adding new files?
  382. [sharedLibrary updateMediaDatabase];
  383. // TODO: update the VideoViewController
  384. }
  385. }
  386. - (void)mediaFileDeleted:(NSString *)name
  387. {
  388. [[MLMediaLibrary sharedMediaLibrary] updateMediaDatabase];
  389. // TODO: update the VideoViewController
  390. }
  391. - (void)mediaFilesFoundRequiringAdditionToStorageBackend:(NSArray<NSString *> *)foundFiles
  392. {
  393. [[MLMediaLibrary sharedMediaLibrary] addFilePaths:foundFiles];
  394. // TODO: update the VideoViewController
  395. }
  396. #pragma mark - pass code validation
  397. - (VLCKeychainCoordinator *)keychainCoordinator
  398. {
  399. if (!_keychainCoordinator) {
  400. _keychainCoordinator = [[VLCKeychainCoordinator alloc] init];
  401. }
  402. return _keychainCoordinator;
  403. }
  404. - (void)validatePasscodeIfNeededWithCompletion:(void(^)(void))completion
  405. {
  406. if ([VLCKeychainCoordinator passcodeLockEnabled]) {
  407. //TODO: Dimiss playback
  408. [self.keychainCoordinator validatePasscodeWithCompletion:completion];
  409. } else {
  410. completion();
  411. }
  412. }
  413. #pragma mark - download handling
  414. - (void)downloadMovieFromURL:(NSURL *)url
  415. fileNameOfMedia:(NSString *)fileName
  416. {
  417. [[VLCDownloadViewController sharedInstance] addURLToDownloadList:url fileNameOfMedia:fileName];
  418. //TODO: open DownloadViewController
  419. }
  420. #pragma mark - playback
  421. - (void)playWithURL:(NSURL *)url completion:(void (^ __nullable)(BOOL success))completion
  422. {
  423. VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
  424. vpc.fullscreenSessionRequested = YES;
  425. VLCMediaList *mediaList = [[VLCMediaList alloc] initWithArray:@[[VLCMedia mediaWithURL:url]]];
  426. [vpc playMediaList:mediaList firstIndex:0 subtitlesFilePath:nil completion:completion];
  427. }
  428. @end