VLCAppDelegate.m 22.6 KB
Newer Older
1 2 3 4
/*****************************************************************************
 * VLCAppDelegate.m
 * VLC for iOS
 *****************************************************************************
Felix Paul Kühne's avatar
Felix Paul Kühne committed
5
 * Copyright (c) 2013-2014 VideoLAN. All rights reserved.
6 7 8 9 10 11 12
 * $Id$
 *
 * Authors: Felix Paul Kühne <fkuehne # videolan.org>
 *          Gleb Pinigin <gpinigin # gmail.com>
 *          Jean-Romain Prévost <jr # 3on.fr>
 *          Luis Fernandes <zipleen # gmail.com>
 *          Carola Nitz <nitz.carola # googlemail.com>
13
 *          Tamas Timar <ttimar.vlc # gmail.com>
14 15 16
 *
 * Refer to the COPYING file of the official project for license.
 *****************************************************************************/
Felix Paul Kühne's avatar
Felix Paul Kühne committed
17 18

#import "VLCAppDelegate.h"
19
#import "VLCMediaFileDiscoverer.h"
20
#import "NSString+SupportedMedia.h"
21
#import "UIDevice+SpeedCategory.h"
Felix Paul Kühne's avatar
Felix Paul Kühne committed
22 23

#import "VLCPlaylistViewController.h"
24
#import "VLCMovieViewController.h"
25
#import "VLCPlaybackNavigationController.h"
26
#import "PAPasscodeViewController.h"
27
#import "UINavigationController+Theme.h"
28
#import "VLCHTTPUploaderController.h"
29
#import "VLCMenuTableViewController.h"
30
#import "BWQuincyManager.h"
31
#import "VLCAlertView.h"
Carola Nitz's avatar
Carola Nitz committed
32
#import <BoxSDK/BoxSDK.h>
33

34
@interface VLCAppDelegate () <PAPasscodeViewControllerDelegate, VLCMediaFileDiscovererDelegate, BWQuincyManagerDelegate> {
Gleb Pinigin's avatar
Gleb Pinigin committed
35
    PAPasscodeViewController *_passcodeLockController;
36
    VLCDropboxTableViewController *_dropboxTableViewController;
Carola Nitz's avatar
Carola Nitz committed
37
    VLCGoogleDriveTableViewController *_googleDriveTableViewController;
38
    VLCOneDriveTableViewController *_oneDriveTableViewController;
Carola Nitz's avatar
Carola Nitz committed
39
    VLCBoxTableViewController *_boxTableViewController;
40
    VLCDownloadViewController *_downloadViewController;
41
    VLCDocumentPickerController *_documentPickerController;
42
    int _idleCounter;
43
    int _networkActivityCounter;
44
    VLCMovieViewController *_movieViewController;
45
    BOOL _passcodeValidated;
Gleb Pinigin's avatar
Gleb Pinigin committed
46
}
47 48

@end
Felix Paul Kühne's avatar
Felix Paul Kühne committed
49 50 51

@implementation VLCAppDelegate

52 53 54 55
+ (void)initialize
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

56 57 58 59 60
    NSNumber *skipLoopFilterDefaultValue;
    int deviceSpeedCategory = [[UIDevice currentDevice] speedCategory];
    if (deviceSpeedCategory < 3)
        skipLoopFilterDefaultValue = kVLCSettingSkipLoopFilterNonKey;
    else
61
        skipLoopFilterDefaultValue = kVLCSettingSkipLoopFilterNonRef;
62

63
    NSDictionary *appDefaults = @{kVLCSettingPasscodeKey : @"", kVLCSettingPasscodeOnKey : @(NO), kVLCSettingContinueAudioInBackgroundKey : @(YES), kVLCSettingStretchAudio : @(NO), kVLCSettingTextEncoding : kVLCSettingTextEncodingDefaultValue, kVLCSettingSkipLoopFilter : skipLoopFilterDefaultValue, kVLCSettingSubtitlesFont : kVLCSettingSubtitlesFontDefaultValue, kVLCSettingSubtitlesFontColor : kVLCSettingSubtitlesFontColorDefaultValue, kVLCSettingSubtitlesFontSize : kVLCSettingSubtitlesFontSizeDefaultValue, kVLCSettingSubtitlesBoldFont: kVLCSettingSubtitlesBoldFontDefaulValue, kVLCSettingDeinterlace : kVLCSettingDeinterlaceDefaultValue, kVLCSettingNetworkCaching : kVLCSettingNetworkCachingDefaultValue, kVLCSettingPlaybackGestures : [NSNumber numberWithBool:YES], kVLCSettingFTPTextEncoding : kVLCSettingFTPTextEncodingDefaultValue };
64 65 66 67

    [defaults registerDefaults:appDefaults];
}

Felix Paul Kühne's avatar
Felix Paul Kühne committed
68 69
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
70
    if (SYSTEM_RUNS_IOS7_OR_LATER) {
71
        // Change the keyboard for UISearchBar
72
        [[UITextField appearance] setKeyboardAppearance:UIKeyboardAppearanceDark];
73 74 75 76 77 78
        // For the cursor
        [[UITextField appearance] setTintColor:[UIColor VLCOrangeTintColor]];
        // Don't override the 'Cancel' button color in the search bar with the previous UITextField call. Use the default blue color
        [[UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor colorWithRed:0.0 green:122.0/255.0 blue:1.0 alpha:1.0]} forState:UIControlStateNormal];
        // For the edit selection indicators
        [[UITableView appearance] setTintColor:[UIColor VLCOrangeTintColor]];
79 80
    }

81 82
    [[UISwitch appearance] setOnTintColor:[UIColor VLCOrangeTintColor]];

83 84 85 86
    BWQuincyManager *quincyManager = [BWQuincyManager sharedQuincyManager];
    [quincyManager setSubmissionURL:@"http://crash.videolan.org/crash_v200.php"];
    [quincyManager setDelegate:self];
    [quincyManager setShowAlwaysButton:YES];
87
    [quincyManager startManager];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
88

89
    /* clean caches on launch (since those are used for wifi upload only) */
90
    [self cleanCache];
91

92 93 94
    // Init the HTTP Server
    self.uploadController = [[VLCHTTPUploaderController alloc] init];

95 96 97
    // enable crash preventer
    [[MLMediaLibrary sharedMediaLibrary] applicationWillStart];

Felix Paul Kühne's avatar
Felix Paul Kühne committed
98
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
99

100
    _playlistViewController = [[VLCPlaylistViewController alloc] init];
101 102
    UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:_playlistViewController];
    [navCon loadTheme];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
103

104
    _revealController = [[GHRevealViewController alloc] initWithNibName:nil bundle:nil];
105
    _revealController.wantsFullScreenLayout = YES;
106 107
    _menuViewController = [[VLCMenuTableViewController alloc] initWithNibName:nil bundle:nil];
    _revealController.sidebarViewController = _menuViewController;
108
    _revealController.contentViewController = navCon;
109

110
    self.window.rootViewController = self.revealController;
111
    // necessary to avoid navbar blinking in VLCOpenNetworkStreamViewController & VLCDownloadViewController
112
    _revealController.contentViewController.view.backgroundColor = [UIColor VLCDarkBackgroundColor];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
113
    [self.window makeKeyAndVisible];
114

115 116 117
    VLCMediaFileDiscoverer *discoverer = [VLCMediaFileDiscoverer sharedInstance];
    [discoverer addObserver:self];
    [discoverer startDiscovering:[self directoryPath]];
118

119
    [self validatePasscode];
120

Felix Paul Kühne's avatar
Felix Paul Kühne committed
121 122 123
    return YES;
}

124 125
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
126 127 128 129
    if ([[DBSession sharedSession] handleOpenURL:url]) {
        [self.dropboxTableViewController updateViewAfterSessionChange];
        return YES;
    }
Carola Nitz's avatar
Carola Nitz committed
130
    [[BoxSDK sharedSDK].OAuth2Session performAuthorizationCodeGrantWithReceivedURL:url];
131 132
    if (_playlistViewController && url != nil) {
        APLog(@"%@ requested %@ to be opened", sourceApplication, url);
133

134
        if (url.isFileURL) {
135 136 137 138 139 140
            NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
            NSString *directoryPath = searchPaths[0];
            NSURL *destinationURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@", directoryPath, url.lastPathComponent]];
            NSError *theError;
            [[NSFileManager defaultManager] moveItemAtURL:url toURL:destinationURL error:&theError];
            if (theError.code != noErr)
141
                APLog(@"saving the file failed (%li): %@", (long)theError.code, theError.localizedDescription);
142 143

            [self updateMediaList];
144 145 146 147 148 149 150
        } else if ([url.scheme isEqualToString:@"vlc-x-callback"] || [url.host isEqualToString:@"x-callback-url"]) {
            // URL confirmes to the x-callback-url specification
            // vlc-x-callback://x-callback-url/action?param=value&x-success=callback
            APLog(@"x-callback-url with host '%@' path '%@' parameters '%@'", url.host, url.path, url.query);
            NSString *action = [url.path stringByReplacingOccurrencesOfString:@"/" withString:@""];
            NSURL *movieURL = nil;
            NSURL *successCallback = nil;
151
            NSString *fileName = nil;
152 153 154 155 156 157 158 159
            for (NSString *entry in [url.query componentsSeparatedByString:@"&"]) {
                NSArray *keyvalue = [entry componentsSeparatedByString:@"="];
                if (keyvalue.count < 2) continue;
                NSString *key = keyvalue[0];
                NSString *value = [keyvalue[1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                if ([key isEqualToString:@"url"]) {
                    movieURL = [NSURL URLWithString:value];
                }
160 161 162
                else if ([key isEqualToString:@"filename"]) {
                    fileName = value;
                }
163 164 165 166 167 168 169
                else if ([key isEqualToString:@"x-success"]) {
                    successCallback = [NSURL URLWithString:value];
                }
            }
            if ([action isEqualToString:@"stream"] && movieURL) {
                [self openMovieFromURL:movieURL successCallback:successCallback];
            }
170 171 172
            else if ([action isEqualToString:@"download"] && movieURL) {
                [self downloadMovieFromURL:movieURL fileNameOfMedia:fileName];
            }
Luis's avatar
Luis committed
173
        } else {
174 175 176 177 178 179 180 181 182 183
            NSString *receivedUrl = [url absoluteString];
            if ([receivedUrl length] > 6) {
                NSString *verifyVlcUrl = [receivedUrl substringToIndex:6];
                if ([verifyVlcUrl isEqualToString:@"vlc://"]) {
                    NSString *parsedString = [receivedUrl substringFromIndex:6];
                    NSUInteger location = [parsedString rangeOfString:@"//"].location;

                    /* Safari & al mangle vlc://http:// so fix this */
                    if (location != NSNotFound && [parsedString characterAtIndex:location - 1] != 0x3a) { // :
                            parsedString = [NSString stringWithFormat:@"%@://%@", [parsedString substringToIndex:location], [parsedString substringFromIndex:location+2]];
184 185 186 187 188 189
                    } else {
                        parsedString = [receivedUrl substringFromIndex:6];
                        if (![parsedString hasPrefix:@"http://"] && ![parsedString hasPrefix:@"https://"] && ![parsedString hasPrefix:@"ftp://"]) {
                            parsedString = [@"http://" stringByAppendingString:[receivedUrl substringFromIndex:6]];
                        }
                    }
190 191 192
                    url = [NSURL URLWithString:parsedString];
                }
            }
193
            [self.menuViewController selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:UITableViewScrollPositionNone];
194 195 196

            NSString *scheme = url.scheme;
            if ([scheme isEqualToString:@"http"] || [scheme isEqualToString:@"https"] || [scheme isEqualToString:@"ftp"]) {
197
                VLCAlertView *alert = [[VLCAlertView alloc] initWithTitle:NSLocalizedString(@"OPEN_STREAM_OR_DOWNLOAD", nil) message:url.absoluteString cancelButtonTitle:NSLocalizedString(@"BUTTON_DOWNLOAD", nil) otherButtonTitles:@[NSLocalizedString(@"BUTTON_PLAY", nil)]];
198 199
                alert.completion = ^(BOOL cancelled, NSInteger buttonIndex) {
                    if (cancelled)
200
                        [self downloadMovieFromURL:url fileNameOfMedia:nil];
201 202 203 204 205 206
                    else
                        [self openMovieFromURL:url];
                };
                [alert show];
            } else
                [self openMovieFromURL:url];
Luis's avatar
Luis committed
207
        }
208 209 210 211 212
        return YES;
    }
    return NO;
}

213 214 215 216 217
- (void)applicationWillEnterForeground:(UIApplication *)application
{
    [[MLMediaLibrary sharedMediaLibrary] applicationWillStart];
}

Felix Paul Kühne's avatar
Felix Paul Kühne committed
218 219
- (void)applicationWillResignActive:(UIApplication *)application
{
220
    _passcodeValidated = NO;
221
    [self validatePasscode];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
222 223 224 225 226
    [[MLMediaLibrary sharedMediaLibrary] applicationWillExit];
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
227
    [[MLMediaLibrary sharedMediaLibrary] updateMediaDatabase];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
228 229 230
    [self updateMediaList];
}

231 232
- (void)applicationWillTerminate:(UIApplication *)application
{
233
    _passcodeValidated = NO;
234 235 236
    [[NSUserDefaults standardUserDefaults] synchronize];
}

237 238 239 240
#pragma mark - properties

- (VLCDropboxTableViewController *)dropboxTableViewController
{
Felix Paul Kühne's avatar
Felix Paul Kühne committed
241
    if (_dropboxTableViewController == nil)
242
        _dropboxTableViewController = [[VLCDropboxTableViewController alloc] initWithNibName:@"VLCCloudStorageTableViewController" bundle:nil];
243 244 245 246

    return _dropboxTableViewController;
}

Carola Nitz's avatar
Carola Nitz committed
247 248
- (VLCGoogleDriveTableViewController *)googleDriveTableViewController
{
Felix Paul Kühne's avatar
Felix Paul Kühne committed
249
    if (_googleDriveTableViewController == nil)
250
        _googleDriveTableViewController = [[VLCGoogleDriveTableViewController alloc] initWithNibName:@"VLCCloudStorageTableViewController" bundle:nil];
Carola Nitz's avatar
Carola Nitz committed
251 252 253 254

    return _googleDriveTableViewController;
}

255 256 257 258 259 260 261
- (VLCOneDriveTableViewController *)oneDriveTableViewController
{
    if (_oneDriveTableViewController == nil)
        _oneDriveTableViewController = [[VLCOneDriveTableViewController alloc] initWithNibName:@"VLCCloudStorageTableViewController" bundle:nil];

    return _oneDriveTableViewController;
}
Carola Nitz's avatar
Carola Nitz committed
262

Carola Nitz's avatar
Carola Nitz committed
263 264 265 266 267 268 269 270
- (VLCBoxTableViewController *)boxTableViewController
{
    if (_boxTableViewController == nil)
        _boxTableViewController = [[VLCBoxTableViewController alloc] initWithNibName:@"VLCCloudStorageTableViewController" bundle:nil];

    return _boxTableViewController;
}

271 272
- (VLCDownloadViewController *)downloadViewController
{
273 274 275 276 277 278
    if (_downloadViewController == nil) {
        if (SYSTEM_RUNS_IOS7_OR_LATER)
            _downloadViewController = [[VLCDownloadViewController alloc] initWithNibName:@"VLCFutureDownloadViewController" bundle:nil];
        else
            _downloadViewController = [[VLCDownloadViewController alloc] initWithNibName:@"VLCDownloadViewController" bundle:nil];
    }
279 280 281 282

    return _downloadViewController;
}

283 284 285 286 287 288 289 290
- (VLCDocumentPickerController *)documentPickerController
{
    if (_documentPickerController == nil)
        _documentPickerController = [[VLCDocumentPickerController alloc] init];

    return _documentPickerController;
}

291
#pragma mark - media discovering
292

293 294
- (void)mediaFileAdded:(NSString *)fileName loading:(BOOL)isLoading
{
295 296 297
    if (!isLoading) {
        MLMediaLibrary *sharedLibrary = [MLMediaLibrary sharedMediaLibrary];
        [sharedLibrary addFilePaths:@[fileName]];
298

299 300 301
        /* exclude media files from backup (QA1719) */
        NSURL *excludeURL = [NSURL fileURLWithPath:fileName];
        [excludeURL setResourceValue:@YES forKey:NSURLIsExcludedFromBackupKey error:nil];
302

303 304
        // TODO Should we update media db after adding new files?
        [sharedLibrary updateMediaDatabase];
305
        [_playlistViewController updateViewContents];
306 307 308
    }
}

309 310
- (void)mediaFileDeleted:(NSString *)name
{
311 312 313 314
    [[MLMediaLibrary sharedMediaLibrary] updateMediaDatabase];
    [_playlistViewController updateViewContents];
}

315 316
- (void)cleanCache
{
317 318 319
    if ([self haveNetworkActivity])
        return;

320 321 322 323 324 325 326
    NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
    NSString* uploadDirPath = [searchPaths[0] stringByAppendingPathComponent:@"Upload"];
    NSFileManager *fileManager = [NSFileManager defaultManager];
    if ([fileManager fileExistsAtPath:uploadDirPath])
        [fileManager removeItemAtPath:uploadDirPath error:nil];
}

327 328 329
#pragma mark - media list methods

- (NSString *)directoryPath
Felix Paul Kühne's avatar
Felix Paul Kühne committed
330
{
331
    NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
Felix Paul Kühne's avatar
Felix Paul Kühne committed
332
    NSString *directoryPath = searchPaths[0];
333 334 335 336 337 338
    return directoryPath;
}

- (void)updateMediaList
{
    NSString *directoryPath = [self directoryPath];
339 340
    NSMutableArray *foundFiles = [NSMutableArray arrayWithObject:@""];
    NSMutableArray *filePaths = [NSMutableArray array];
341
    NSURL *fileURL;
342 343 344 345 346
    while (foundFiles.count) {
        NSString *fileName = foundFiles.firstObject;
        NSString *filePath = [directoryPath stringByAppendingPathComponent:fileName];
        [foundFiles removeObject:fileName];

347
        if ([fileName isSupportedMediaFormat] || [fileName isSupportedAudioMediaFormat]) {
348
            [filePaths addObject:filePath];
349 350

            /* exclude media files from backup (QA1719) */
351
            fileURL = [NSURL fileURLWithPath:filePath];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
352
            [fileURL setResourceValue:@YES forKey:NSURLIsExcludedFromBackupKey error:nil];
353 354 355
        } else {
            BOOL isDirectory = NO;
            BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:filePath isDirectory:&isDirectory];
356

357 358
            // add folders
            if (exists && isDirectory) {
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
                NSArray *files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:filePath error:nil];
                for (NSString* file in files) {
                    NSString *fullFilePath = [directoryPath stringByAppendingPathComponent:file];
                    isDirectory = NO;
                    exists = [[NSFileManager defaultManager] fileExistsAtPath:fullFilePath isDirectory:&isDirectory];
                    //only add folders or files in folders
                    if ((exists && isDirectory) || ![filePath.lastPathComponent isEqualToString:@"Documents"]) {
                        NSString *folderpath = [filePath stringByReplacingOccurrencesOfString:directoryPath withString:@""];
                        if (![folderpath isEqualToString:@""]) {
                            folderpath = [folderpath stringByAppendingString:@"/"];
                        }
                        NSString *path = [folderpath stringByAppendingString:file];
                        [foundFiles addObject:path];
                    }
                }
374
            }
Felix Paul Kühne's avatar
Felix Paul Kühne committed
375 376 377
        }
    }
    [[MLMediaLibrary sharedMediaLibrary] addFilePaths:filePaths];
378
    [_playlistViewController updateViewContents];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
379 380
}

381 382 383 384 385 386
#pragma mark - pass code validation

- (void)validatePasscode
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString *passcode = [defaults objectForKey:kVLCSettingPasscodeKey];
387
    if ([passcode isEqualToString:@""] || ![[defaults objectForKey:kVLCSettingPasscodeOnKey] boolValue]) {
388
        _passcodeValidated = YES;
389 390
        return;
    }
391

392
    if (!_passcodeValidated) {
393 394 395
        _passcodeLockController = [[PAPasscodeViewController alloc] initForAction:PasscodeActionEnter];
        _passcodeLockController.delegate = self;
        _passcodeLockController.passcode = passcode;
396 397 398 399 400 401 402

        if (self.window.rootViewController.presentedViewController)
            [self.window.rootViewController dismissViewControllerAnimated:NO completion:nil];

        UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:_passcodeLockController];
        navCon.modalPresentationStyle = UIModalPresentationFullScreen;
        [self.window.rootViewController presentViewController:navCon animated:NO completion:nil];
403 404 405 406 407
    }
}

- (void)PAPasscodeViewControllerDidEnterPasscode:(PAPasscodeViewController *)controller
{
408
    [self.window.rootViewController dismissViewControllerAnimated:YES completion:nil];
409 410 411 412
}

- (void)PAPasscodeViewController:(PAPasscodeViewController *)controller didFailToEnterPasscode:(NSInteger)attempts
{
413
    // FIXME: handle countless failed passcode attempts
414 415
}

416 417 418 419 420 421 422 423 424 425 426 427 428 429 430
#pragma mark - idle timer preventer
- (void)disableIdleTimer
{
    _idleCounter++;
    if ([UIApplication sharedApplication].idleTimerDisabled == NO)
        [UIApplication sharedApplication].idleTimerDisabled = YES;
}

- (void)activateIdleTimer
{
    _idleCounter--;
    if (_idleCounter < 1)
        [UIApplication sharedApplication].idleTimerDisabled = NO;
}

431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449
- (void)networkActivityStarted
{
    _networkActivityCounter++;
    if ([UIApplication sharedApplication].networkActivityIndicatorVisible == NO)
        [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
}

- (BOOL)haveNetworkActivity
{
    return _networkActivityCounter >= 1;
}

- (void)networkActivityStopped
{
    _networkActivityCounter--;
    if (_networkActivityCounter < 1)
        [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}

450 451 452 453 454 455 456 457 458 459 460
#pragma mark - download handling

- (void)downloadMovieFromURL:(NSURL *)url
             fileNameOfMedia:(NSString *)fileName
{
    [self.downloadViewController addURLToDownloadList:url fileNameOfMedia:fileName];

    // select Downloads menu item and reveal corresponding viewcontroller
    [self.menuViewController selectRowAtIndexPath:[NSIndexPath indexPathForRow:2 inSection:1] animated:NO scrollPosition:UITableViewScrollPositionNone];
}

461 462 463 464 465 466 467 468
#pragma mark - playback view handling

- (void)openMediaFromManagedObject:(NSManagedObject *)mediaObject
{
    if (!_movieViewController)
        _movieViewController = [[VLCMovieViewController alloc] initWithNibName:nil bundle:nil];

    if ([mediaObject isKindOfClass:[MLFile class]])
469
        _movieViewController.fileFromMediaLibrary = (MLFile *)mediaObject;
470
    else if ([mediaObject isKindOfClass:[MLAlbumTrack class]])
471
        _movieViewController.fileFromMediaLibrary = [(MLAlbumTrack*)mediaObject files].anyObject;
472
    else if ([mediaObject isKindOfClass:[MLShowEpisode class]])
473 474
        _movieViewController.fileFromMediaLibrary = [(MLShowEpisode*)mediaObject files].anyObject;
    [(MLFile *)_movieViewController.fileFromMediaLibrary setUnread:@(NO)];
475

476
    UINavigationController *navCon = [[VLCPlaybackNavigationController alloc] initWithRootViewController:_movieViewController];
477 478 479 480 481
    navCon.modalPresentationStyle = UIModalPresentationFullScreen;
    [self.window.rootViewController presentViewController:navCon animated:YES completion:nil];
}

- (void)openMovieFromURL:(NSURL *)url
482
         successCallback:(NSURL *)successCallback
483 484 485 486 487
{
    if (!_movieViewController)
        _movieViewController = [[VLCMovieViewController alloc] initWithNibName:nil bundle:nil];

    _movieViewController.url = url;
488
    _movieViewController.successCallback = successCallback;
489

490
    UINavigationController *navCon = [[VLCPlaybackNavigationController alloc] initWithRootViewController:_movieViewController];
491 492 493 494
    navCon.modalPresentationStyle = UIModalPresentationFullScreen;
    [self.window.rootViewController presentViewController:navCon animated:YES completion:nil];
}

495 496 497 498 499
- (void)openMovieFromURL:(NSURL *)url
{
    [self openMovieFromURL:url successCallback:nil];
}

500
- (void)openMediaList:(VLCMediaList *)list atIndex:(int)index
501 502 503 504 505 506
{
    if (!_movieViewController)
        _movieViewController = [[VLCMovieViewController alloc] initWithNibName:nil bundle:nil];

    _movieViewController.mediaList = list;
    _movieViewController.itemInMediaListToBePlayedFirst = index;
507
    _movieViewController.pathToExternalSubtitlesFile = nil;
508

509
    UINavigationController *navCon = [[VLCPlaybackNavigationController alloc] initWithRootViewController:_movieViewController];
510 511 512 513 514 515 516 517 518 519
    navCon.modalPresentationStyle = UIModalPresentationFullScreen;
    [self.window.rootViewController presentViewController:navCon animated:YES completion:nil];
}

- (void)openMovieWithExternalSubtitleFromURL:(NSURL *)url externalSubURL:(NSString *)SubtitlePath
{
    if (!_movieViewController)
        _movieViewController = [[VLCMovieViewController alloc] initWithNibName:nil bundle:nil];

    _movieViewController.url = url;
520
    _movieViewController.pathToExternalSubtitlesFile = SubtitlePath;
521

522
    UINavigationController *navCon = [[VLCPlaybackNavigationController alloc] initWithRootViewController:_movieViewController];
523 524 525 526
    navCon.modalPresentationStyle = UIModalPresentationFullScreen;
    [self.window.rootViewController presentViewController:navCon animated:YES completion:nil];
}

Felix Paul Kühne's avatar
Felix Paul Kühne committed
527
@end