VLCAppDelegate.m 4.41 KB
Newer Older
Felix Paul Kühne's avatar
Felix Paul Kühne committed
1 2 3 4 5 6 7 8 9 10 11 12
//
//  VLCAppDelegate.m
//  AspenProject
//
//  Created by Felix Paul Kühne on 27.02.13.
//  Copyright (c) 2013 VideoLAN. All rights reserved.
//

#import "VLCAppDelegate.h"

#import "VLCPlaylistViewController.h"

13
#import "VLCMovieViewController.h"
Felix Paul Kühne's avatar
Felix Paul Kühne committed
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29

@implementation VLCAppDelegate

- (void)dealloc
{
    [_playlistViewController release];
    [_window release];
    [_navigationController release];
    [_splitViewController release];
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
30 31 32
    _playlistViewController = [[VLCPlaylistViewController alloc] initWithNibName:@"VLCPlaylistViewController" bundle:nil];
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {

Felix Paul Kühne's avatar
Felix Paul Kühne committed
33 34 35
        self.navigationController = [[[UINavigationController alloc] initWithRootViewController:_playlistViewController] autorelease];
        self.window.rootViewController = self.navigationController;
    } else {
36
        _playlistViewController = [[VLCPlaylistViewController alloc] initWithNibName:@"VLCPlaylistViewController" bundle:nil];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
37 38
        UINavigationController *masterNavigationController = [[[UINavigationController alloc] initWithRootViewController:_playlistViewController] autorelease];

39
        VLCMovieViewController *movieViewController = [[[VLCMovieViewController alloc] initWithNibName:@"VLCMovieViewController" bundle:nil] autorelease];
40
        UINavigationController *movieNavigationController = [[[UINavigationController alloc] initWithRootViewController:movieViewController] autorelease];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
41

42
        _playlistViewController.movieViewController = movieViewController;
Felix Paul Kühne's avatar
Felix Paul Kühne committed
43 44

        self.splitViewController = [[[UISplitViewController alloc] init] autorelease];
45 46
        self.splitViewController.delegate = movieViewController;
        self.splitViewController.viewControllers = @[masterNavigationController, movieNavigationController];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
47 48 49

        self.window.rootViewController = self.splitViewController;
    }
50 51

    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
Felix Paul Kühne's avatar
Felix Paul Kühne committed
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
    [self.window makeKeyAndVisible];
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    [[MLMediaLibrary sharedMediaLibrary] applicationWillExit];
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // 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.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // 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.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    [self updateMediaList];
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

- (void)updateMediaList
{
#define LOCAL_PLAYBACK_HACK 1
#if LOCAL_PLAYBACK_HACK && TARGET_IPHONE_SIMULATOR
    NSString *directoryPath = @"/Users/fkuehne/Desktop/VideoLAN docs/Clips/sel/";
#else
88 89
    NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *directoryPath = [searchPaths objectAtIndex:0];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
90 91 92
#endif
    NSArray *foundFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:directoryPath error:nil];
    NSMutableArray *filePaths = [NSMutableArray arrayWithCapacity:[foundFiles count]];
93
    for (NSString *fileName in foundFiles) {
Felix Paul Kühne's avatar
Felix Paul Kühne committed
94 95 96 97 98
        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) {
            [filePaths addObject:[directoryPath stringByAppendingPathComponent:fileName]];
        }
    }
    [[MLMediaLibrary sharedMediaLibrary] addFilePaths:filePaths];
99
    [_playlistViewController updateViewContents];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
100 101 102
}

@end