VLCAppDelegate.m 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
  40. [self.window makeKeyAndVisible];
  41. return YES;
  42. }
  43. - (void)applicationWillResignActive:(UIApplication *)application
  44. {
  45. [[MLMediaLibrary sharedMediaLibrary] applicationWillExit];
  46. }
  47. - (void)applicationDidEnterBackground:(UIApplication *)application
  48. {
  49. // 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.
  50. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
  51. }
  52. - (void)applicationWillEnterForeground:(UIApplication *)application
  53. {
  54. // 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.
  55. }
  56. - (void)applicationDidBecomeActive:(UIApplication *)application
  57. {
  58. [self updateMediaList];
  59. }
  60. - (void)applicationWillTerminate:(UIApplication *)application
  61. {
  62. // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
  63. }
  64. - (void)updateMediaList
  65. {
  66. #define LOCAL_PLAYBACK_HACK 1
  67. #if LOCAL_PLAYBACK_HACK && TARGET_IPHONE_SIMULATOR
  68. NSString *directoryPath = @"/Users/fkuehne/Desktop/VideoLAN docs/Clips/sel/";
  69. #else
  70. NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  71. NSString *directoryPath = [searchPaths objectAtIndex:0];
  72. #endif
  73. NSArray *foundFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:directoryPath error:nil];
  74. NSMutableArray *filePaths = [NSMutableArray arrayWithCapacity:[foundFiles count]];
  75. for (NSString *fileName in foundFiles) {
  76. 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) {
  77. [filePaths addObject:[directoryPath stringByAppendingPathComponent:fileName]];
  78. }
  79. }
  80. [[MLMediaLibrary sharedMediaLibrary] addFilePaths:filePaths];
  81. [_playlistViewController updateViewContents];
  82. }
  83. @end