VLCAppDelegate.m 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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)dealloc
  13. {
  14. [_playlistViewController release];
  15. [_window release];
  16. [_navigationController release];
  17. [_splitViewController release];
  18. [super dealloc];
  19. }
  20. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  21. {
  22. self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
  23. // Override point for customization after application launch.
  24. _playlistViewController = [[VLCPlaylistViewController alloc] initWithNibName:@"VLCPlaylistViewController" bundle:nil];
  25. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  26. self.navigationController = [[[UINavigationController alloc] initWithRootViewController:_playlistViewController] autorelease];
  27. self.window.rootViewController = self.navigationController;
  28. } else {
  29. _playlistViewController = [[VLCPlaylistViewController alloc] initWithNibName:@"VLCPlaylistViewController" bundle:nil];
  30. UINavigationController *masterNavigationController = [[[UINavigationController alloc] initWithRootViewController:_playlistViewController] autorelease];
  31. VLCMovieViewController *movieViewController = [[[VLCMovieViewController alloc] initWithNibName:@"VLCMovieViewController" bundle:nil] autorelease];
  32. UINavigationController *movieNavigationController = [[[UINavigationController alloc] initWithRootViewController:movieViewController] autorelease];
  33. _playlistViewController.movieViewController = movieViewController;
  34. self.splitViewController = [[[UISplitViewController alloc] init] autorelease];
  35. self.splitViewController.delegate = movieViewController;
  36. self.splitViewController.viewControllers = @[masterNavigationController, movieNavigationController];
  37. self.window.rootViewController = self.splitViewController;
  38. }
  39. UINavigationBar *navbar = self.navigationController.navigationBar;
  40. navbar.barStyle = UIBarStyleBlack;
  41. navbar.translucent = YES;
  42. navbar.tintColor = [UIColor colorWithWhite:.15 alpha:1.];
  43. [self.window makeKeyAndVisible];
  44. return YES;
  45. }
  46. - (void)applicationWillResignActive:(UIApplication *)application
  47. {
  48. [[MLMediaLibrary sharedMediaLibrary] applicationWillExit];
  49. }
  50. - (void)applicationDidEnterBackground:(UIApplication *)application
  51. {
  52. // 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.
  53. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
  54. }
  55. - (void)applicationWillEnterForeground:(UIApplication *)application
  56. {
  57. // 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.
  58. }
  59. - (void)applicationDidBecomeActive:(UIApplication *)application
  60. {
  61. [self updateMediaList];
  62. }
  63. - (void)applicationWillTerminate:(UIApplication *)application
  64. {
  65. // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
  66. }
  67. - (void)updateMediaList
  68. {
  69. #define LOCAL_PLAYBACK_HACK 1
  70. #if LOCAL_PLAYBACK_HACK && TARGET_IPHONE_SIMULATOR
  71. NSString *directoryPath = @"/Users/fkuehne/Desktop/VideoLAN docs/Clips/sel/";
  72. #else
  73. NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  74. NSString *directoryPath = [searchPaths objectAtIndex:0];
  75. #endif
  76. NSArray *foundFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:directoryPath error:nil];
  77. NSMutableArray *filePaths = [NSMutableArray arrayWithCapacity:[foundFiles count]];
  78. for (NSString * fileName in foundFiles) {
  79. 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) {
  80. [filePaths addObject:[directoryPath stringByAppendingPathComponent:fileName]];
  81. }
  82. }
  83. [[MLMediaLibrary sharedMediaLibrary] addFilePaths:filePaths];
  84. [_playlistViewController updateViewContents];
  85. }
  86. @end