VLCAppDelegate.m 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. [_playlistViewController openMovieFromURL:url];
  27. return YES;
  28. }
  29. return NO;
  30. }
  31. - (void)applicationWillResignActive:(UIApplication *)application
  32. {
  33. [[MLMediaLibrary sharedMediaLibrary] applicationWillExit];
  34. }
  35. - (void)applicationDidEnterBackground:(UIApplication *)application
  36. {
  37. // 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.
  38. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
  39. }
  40. - (void)applicationWillEnterForeground:(UIApplication *)application
  41. {
  42. // 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.
  43. }
  44. - (void)applicationDidBecomeActive:(UIApplication *)application
  45. {
  46. [self updateMediaList];
  47. }
  48. - (void)applicationWillTerminate:(UIApplication *)application
  49. {
  50. // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
  51. }
  52. - (void)updateMediaList
  53. {
  54. #define LOCAL_PLAYBACK_HACK 1
  55. #if LOCAL_PLAYBACK_HACK && TARGET_IPHONE_SIMULATOR
  56. NSString *directoryPath = @"/Users/fkuehne/Desktop/VideoLAN docs/Clips/sel/";
  57. #else
  58. NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  59. NSString *directoryPath = [searchPaths objectAtIndex:0];
  60. #endif
  61. NSArray *foundFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:directoryPath error:nil];
  62. NSMutableArray *filePaths = [NSMutableArray arrayWithCapacity:[foundFiles count]];
  63. NSURL *fileURL;
  64. for (NSString *fileName in foundFiles) {
  65. if ([fileName rangeOfString:@"\\.(3gp|3gp|3gp2|3gpp|amv|asf|avi|divx|dv|flv|f4v|gvi|gxf|m1v|m2p|m2t|m2ts|m2v|m4v|mkv|moov|mov|mp2v|mp4|mpeg|mpeg1|mpeg2|mpeg4|mpg|mpv|mt2s|mts|mxf|oga|ogm|ogv|ogx|spx|ps|qt|rm|rmvb|ts|tts|vob|webm|wm|wmv)$" options:NSRegularExpressionSearch|NSCaseInsensitiveSearch].length != 0) {
  66. [filePaths addObject:[directoryPath stringByAppendingPathComponent:fileName]];
  67. /* exclude media files from backup (QA1719) */
  68. fileURL = [NSURL URLWithString:fileName];
  69. [fileURL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:nil];
  70. }
  71. }
  72. [[MLMediaLibrary sharedMediaLibrary] addFilePaths:filePaths];
  73. [_playlistViewController updateViewContents];
  74. }
  75. @end