VLCAppDelegate.m 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. //
  2. // VLCAppDelegate.m
  3. // AspenProject
  4. //
  5. // Created by Felix Paul Kühne on 27.02.13.
  6. // Copyright (c) 2013 VideoLAN. All rights reserved.
  7. //
  8. #import "VLCAppDelegate.h"
  9. #import "VLCPlaylistViewController.h"
  10. #import "VLCMovieViewController.h"
  11. @implementation VLCAppDelegate
  12. + (void)initialize
  13. {
  14. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  15. NSDictionary *appDefaults = @{@"Passcode" : @"", @"PasscodeProtection" : @0};
  16. [defaults registerDefaults:appDefaults];
  17. }
  18. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  19. {
  20. self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  21. _playlistViewController = [[VLCPlaylistViewController alloc] initWithNibName:@"VLCPlaylistViewController" bundle:nil];
  22. self.navigationController = [[UINavigationController alloc] initWithRootViewController:_playlistViewController];
  23. self.window.rootViewController = self.navigationController;
  24. self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
  25. [self.window makeKeyAndVisible];
  26. return YES;
  27. }
  28. - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
  29. {
  30. if (_playlistViewController && url != nil) {
  31. APLog(@"%@ requested %@ to be opened", sourceApplication, url);
  32. if (url.isFileURL) {
  33. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"SAVE_FILE", @"") message:[NSString stringWithFormat:NSLocalizedString(@"SAVE_FILE_LONG", @""), url.lastPathComponent] delegate:self cancelButtonTitle:NSLocalizedString(@"BUTTON_CANCEL", @"") otherButtonTitles:NSLocalizedString(@"BUTTON_SAVE", @""), nil];
  34. _tempURL = url;
  35. [alert show];
  36. } else
  37. [_playlistViewController openMovieFromURL:url];
  38. return YES;
  39. }
  40. return NO;
  41. }
  42. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  43. {
  44. if (buttonIndex == 1) {
  45. NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  46. NSString *directoryPath = [searchPaths objectAtIndex:0];
  47. NSURL *destinationURL = [NSURL URLWithString:[NSString stringWithFormat:@"file://%@/%@", directoryPath, _tempURL.lastPathComponent]];
  48. NSError *theError;
  49. [[NSFileManager defaultManager] copyItemAtURL:_tempURL toURL:destinationURL error:&theError];
  50. [self updateMediaList];
  51. }
  52. [_playlistViewController openMovieFromURL:_tempURL];
  53. }
  54. - (void)applicationWillResignActive:(UIApplication *)application
  55. {
  56. [[MLMediaLibrary sharedMediaLibrary] applicationWillExit];
  57. }
  58. - (void)applicationWillEnterForeground:(UIApplication *)application
  59. {
  60. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  61. if (![[defaults objectForKey:@"Passcode"] isEqualToString:@""])
  62. self.playlistViewController.passcodeValidated = NO;
  63. else
  64. self.playlistViewController.passcodeValidated = YES;
  65. NSLog(@"applicationWillEnterForeground: %i", self.playlistViewController.passcodeValidated);
  66. }
  67. - (void)applicationDidBecomeActive:(UIApplication *)application
  68. {
  69. [self updateMediaList];
  70. }
  71. - (void)applicationWillTerminate:(UIApplication *)application
  72. {
  73. // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
  74. }
  75. - (void)updateMediaList
  76. {
  77. #define LOCAL_PLAYBACK_HACK 1
  78. #if LOCAL_PLAYBACK_HACK && TARGET_IPHONE_SIMULATOR
  79. NSString *directoryPath = @"/Users/fkuehne/Desktop/VideoLAN docs/Clips/sel/";
  80. #else
  81. NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  82. NSString *directoryPath = [searchPaths objectAtIndex:0];
  83. #endif
  84. NSArray *foundFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:directoryPath error:nil];
  85. NSMutableArray *filePaths = [NSMutableArray arrayWithCapacity:[foundFiles count]];
  86. NSURL *fileURL;
  87. for (NSString *fileName in foundFiles) {
  88. if ([fileName rangeOfString:@"\\.(3gp|3gp|3gp2|3gpp|amv|asf|avi|axv|divx|dv|flv|f4v|gvi|gxf|m1v|m2p|m2t|m2ts|m2v|m4v|mks|mkv|moov|mov|mp2v|mp4|mpeg|mpeg1|mpeg2|mpeg4|mpg|mpv|mt2s|mts|mxf|nsv|nuv|oga|ogg|ogm|ogv|ogx|spx|ps|qt|rar|rec|rm|rmvb|tod|ts|tts|vob|vro|webm|wm|wmv|wtv|xesc)$" options:NSRegularExpressionSearch|NSCaseInsensitiveSearch].length != 0) {
  89. [filePaths addObject:[directoryPath stringByAppendingPathComponent:fileName]];
  90. /* exclude media files from backup (QA1719) */
  91. fileURL = [NSURL URLWithString:[NSString stringWithFormat:@"file://%@/%@", directoryPath, fileName]];
  92. [fileURL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:nil];
  93. }
  94. }
  95. [[MLMediaLibrary sharedMediaLibrary] addFilePaths:filePaths];
  96. [_playlistViewController updateViewContents];
  97. }
  98. @end