VLCAppDelegate.m 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 = @{kVLCSettingPasscodeKey : @"", kVLCSettingPasscodeOnKey : @0, kVLCSettingContinueAudioInBackgroundKey : @1, kVLCSettingStretchAudio : kVLCSettingStretchAudioDefaultValue, kVLCSettingVerboseOutput : kVLCSettingVerboseOutputDefaultValue, kVLCSettingTextEncoding : kVLCSettingTextEncodingDefaultValue};
  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[0];
  47. NSURL *destinationURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@", directoryPath, _tempURL.lastPathComponent]];
  48. NSError *theError;
  49. [[NSFileManager defaultManager] copyItemAtURL:_tempURL toURL:destinationURL error:&theError];
  50. if (theError.code != noErr)
  51. APLog(@"saving the file failed (%i): %@", theError.code, theError.localizedDescription);
  52. [self updateMediaList];
  53. } else
  54. [_playlistViewController openMovieFromURL:_tempURL];
  55. }
  56. - (void)applicationWillResignActive:(UIApplication *)application
  57. {
  58. [[MLMediaLibrary sharedMediaLibrary] applicationWillExit];
  59. }
  60. - (void)applicationWillEnterForeground:(UIApplication *)application
  61. {
  62. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  63. if (![[defaults objectForKey:@"Passcode"] isEqualToString:@""])
  64. self.playlistViewController.passcodeValidated = NO;
  65. else
  66. self.playlistViewController.passcodeValidated = YES;
  67. NSLog(@"applicationWillEnterForeground: %i", self.playlistViewController.passcodeValidated);
  68. }
  69. - (void)applicationDidBecomeActive:(UIApplication *)application
  70. {
  71. [self updateMediaList];
  72. }
  73. - (void)applicationWillTerminate:(UIApplication *)application
  74. {
  75. // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
  76. }
  77. - (void)updateMediaList
  78. {
  79. #define LOCAL_PLAYBACK_HACK 1
  80. #if LOCAL_PLAYBACK_HACK && TARGET_IPHONE_SIMULATOR
  81. NSString *directoryPath = @"/Users/fkuehne/Desktop/VideoLAN docs/Clips/sel/";
  82. #else
  83. NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  84. NSString *directoryPath = searchPaths[0];
  85. #endif
  86. NSArray *foundFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:directoryPath error:nil];
  87. NSMutableArray *filePaths = [NSMutableArray arrayWithCapacity:[foundFiles count]];
  88. NSURL *fileURL;
  89. for (NSString *fileName in foundFiles) {
  90. 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) {
  91. [filePaths addObject:[directoryPath stringByAppendingPathComponent:fileName]];
  92. /* exclude media files from backup (QA1719) */
  93. fileURL = [NSURL URLWithString:[NSString stringWithFormat:@"file://%@/%@", directoryPath, fileName]];
  94. [fileURL setResourceValue:@YES forKey:NSURLIsExcludedFromBackupKey error:nil];
  95. }
  96. }
  97. [[MLMediaLibrary sharedMediaLibrary] addFilePaths:filePaths];
  98. [_playlistViewController updateViewContents];
  99. }
  100. @end