VLCAppDelegate.m 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  13. {
  14. self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  15. _playlistViewController = [[VLCPlaylistViewController alloc] initWithNibName:@"VLCPlaylistViewController" bundle:nil];
  16. self.navigationController = [[UINavigationController alloc] initWithRootViewController:_playlistViewController];
  17. self.window.rootViewController = self.navigationController;
  18. self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
  19. [self.window makeKeyAndVisible];
  20. return YES;
  21. }
  22. - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
  23. {
  24. if (_playlistViewController && url != nil) {
  25. APLog(@"%@ requested %@ to be opened", sourceApplication, url);
  26. if (url.isFileURL) {
  27. 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];
  28. _tempURL = url;
  29. [alert show];
  30. } else
  31. [_playlistViewController openMovieFromURL:url];
  32. return YES;
  33. }
  34. return NO;
  35. }
  36. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  37. {
  38. if (buttonIndex == 1) {
  39. NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  40. NSString *directoryPath = [searchPaths objectAtIndex:0];
  41. NSURL *destinationURL = [NSURL URLWithString:[NSString stringWithFormat:@"file://%@/%@", directoryPath, _tempURL.lastPathComponent]];
  42. NSError *theError;
  43. [[NSFileManager defaultManager] copyItemAtURL:_tempURL toURL:destinationURL error:&theError];
  44. [self updateMediaList];
  45. }
  46. [_playlistViewController openMovieFromURL:_tempURL];
  47. }
  48. - (void)applicationWillResignActive:(UIApplication *)application
  49. {
  50. [[MLMediaLibrary sharedMediaLibrary] applicationWillExit];
  51. }
  52. - (void)applicationDidEnterBackground:(UIApplication *)application
  53. {
  54. // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
  55. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
  56. }
  57. - (void)applicationWillEnterForeground:(UIApplication *)application
  58. {
  59. // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
  60. }
  61. - (void)applicationDidBecomeActive:(UIApplication *)application
  62. {
  63. [self updateMediaList];
  64. }
  65. - (void)applicationWillTerminate:(UIApplication *)application
  66. {
  67. // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
  68. }
  69. - (void)updateMediaList
  70. {
  71. #define LOCAL_PLAYBACK_HACK 1
  72. #if LOCAL_PLAYBACK_HACK && TARGET_IPHONE_SIMULATOR
  73. NSString *directoryPath = @"/Users/fkuehne/Desktop/VideoLAN docs/Clips/sel/";
  74. #else
  75. NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  76. NSString *directoryPath = [searchPaths objectAtIndex:0];
  77. #endif
  78. NSArray *foundFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:directoryPath error:nil];
  79. NSMutableArray *filePaths = [NSMutableArray arrayWithCapacity:[foundFiles count]];
  80. NSURL *fileURL;
  81. for (NSString *fileName in foundFiles) {
  82. 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) {
  83. [filePaths addObject:[directoryPath stringByAppendingPathComponent:fileName]];
  84. /* exclude media files from backup (QA1719) */
  85. fileURL = [NSURL URLWithString:[NSString stringWithFormat:@"file://%@/%@", directoryPath, fileName]];
  86. [fileURL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:nil];
  87. }
  88. }
  89. [[MLMediaLibrary sharedMediaLibrary] addFilePaths:filePaths];
  90. [_playlistViewController updateViewContents];
  91. }
  92. @end