VLCAppDelegate.m 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 <MediaLibraryKit/MLMediaLibrary.h>
  10. #import "VLCPlaylistViewController.h"
  11. #import "VLCDetailViewController.h"
  12. @implementation VLCAppDelegate
  13. - (void)dealloc
  14. {
  15. [_playlistViewController release];
  16. [_window release];
  17. [_navigationController release];
  18. [_splitViewController release];
  19. [super dealloc];
  20. }
  21. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  22. {
  23. self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
  24. // Override point for customization after application launch.
  25. if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
  26. _playlistViewController = [[VLCPlaylistViewController alloc] initWithNibName:@"VLCPlaylistViewController_iPhone" bundle:nil];
  27. self.navigationController = [[[UINavigationController alloc] initWithRootViewController:_playlistViewController] autorelease];
  28. self.window.rootViewController = self.navigationController;
  29. } else {
  30. _playlistViewController = [[VLCPlaylistViewController alloc] initWithNibName:@"VLCPlaylistViewController_iPad" bundle:nil];
  31. UINavigationController *masterNavigationController = [[[UINavigationController alloc] initWithRootViewController:_playlistViewController] autorelease];
  32. VLCDetailViewController *detailViewController = [[[VLCDetailViewController alloc] initWithNibName:@"VLCDetailViewController_iPad" bundle:nil] autorelease];
  33. UINavigationController *detailNavigationController = [[[UINavigationController alloc] initWithRootViewController:detailViewController] autorelease];
  34. _playlistViewController.detailViewController = detailViewController;
  35. self.splitViewController = [[[UISplitViewController alloc] init] autorelease];
  36. self.splitViewController.delegate = detailViewController;
  37. self.splitViewController.viewControllers = @[masterNavigationController, detailNavigationController];
  38. self.window.rootViewController = self.splitViewController;
  39. }
  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(NSUserDomainMask, NSDocumentDirectory, YES);
  71. NSString *directoryPath = [paths 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