浏览代码

use VLCPlaybackController for playback control only present VLCMoviewViewController when the app is active DRY app delegate by moving VLCMovieViewController initialization and presentation to methods

Tobias Conradi 10 年之前
父节点
当前提交
1b2bf10bd4
共有 3 个文件被更改,包括 34 次插入40 次删除
  1. 34 32
      Sources/VLCAppDelegate.m
  2. 0 2
      Sources/VLCMovieViewController.h
  3. 0 6
      Sources/VLCMovieViewController.m

+ 34 - 32
Sources/VLCAppDelegate.m

@@ -46,12 +46,13 @@
     VLCDropboxTableViewController *_dropboxTableViewController;
     int _idleCounter;
     int _networkActivityCounter;
-    VLCMovieViewController *_movieViewController;
     BOOL _passcodeValidated;
     BOOL _isRunningMigration;
     BOOL _isComingFromHandoff;
 }
 
+@property (nonatomic, strong) VLCMovieViewController *movieViewController;
+
 @end
 
 @implementation VLCAppDelegate
@@ -361,6 +362,10 @@
     } else if(_isComingFromHandoff) {
         _isComingFromHandoff = NO;
     }
+
+    if ([VLCPlaybackController sharedInstance].isPlaying && !self.movieViewController.presentingViewController) {
+        [self presentMovieViewController];
+    }
 }
 
 - (void)applicationWillTerminate:(UIApplication *)application
@@ -390,6 +395,15 @@
     return _downloadViewController;
 }
 
+- (VLCMovieViewController *)movieViewController
+{
+    if (!_movieViewController) {
+        _movieViewController = [[VLCMovieViewController alloc] initWithNibName:nil bundle:nil];
+        [VLCPlaybackController sharedInstance].delegate = _movieViewController;
+    }
+    return _movieViewController;
+}
+
 #pragma mark - media discovering
 
 - (void)mediaFileAdded:(NSString *)fileName loading:(BOOL)isLoading
@@ -569,11 +583,19 @@
 
 #pragma mark - playback view handling
 
-- (void)openMediaFromManagedObject:(NSManagedObject *)mediaObject
+- (void)presentMovieViewController
 {
-    if (!_movieViewController)
-        _movieViewController = [[VLCMovieViewController alloc] initWithNibName:nil bundle:nil];
+    if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive) {
+        return;
+    }
+
+    UINavigationController *navCon = [[VLCPlaybackNavigationController alloc] initWithRootViewController:self.movieViewController];
+    navCon.modalPresentationStyle = UIModalPresentationFullScreen;
+    [self.window.rootViewController presentViewController:navCon animated:YES completion:nil];
+}
 
+- (void)openMediaFromManagedObject:(NSManagedObject *)mediaObject
+{
     VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
 
     if ([mediaObject isKindOfClass:[MLFile class]])
@@ -583,11 +605,8 @@
     else if ([mediaObject isKindOfClass:[MLShowEpisode class]])
         vpc.fileFromMediaLibrary = [(MLShowEpisode*)mediaObject files].anyObject;
     [(MLFile *)vpc.fileFromMediaLibrary setUnread:@(NO)];
-    vpc.delegate = _movieViewController;
 
-    UINavigationController *navCon = [[VLCPlaybackNavigationController alloc] initWithRootViewController:_movieViewController];
-    navCon.modalPresentationStyle = UIModalPresentationFullScreen;
-    [self.window.rootViewController presentViewController:navCon animated:YES completion:nil];
+    [self presentMovieViewController];
 
     [vpc startPlayback];
 }
@@ -596,19 +615,14 @@
          successCallback:(NSURL *)successCallback
            errorCallback:(NSURL *)errorCallback
 {
-    if (!_movieViewController)
-        _movieViewController = [[VLCMovieViewController alloc] initWithNibName:nil bundle:nil];
 
     VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
 
     vpc.url = url;
     vpc.successCallback = successCallback;
     vpc.errorCallback = errorCallback;
-    vpc.delegate = _movieViewController;
 
-    UINavigationController *navCon = [[VLCPlaybackNavigationController alloc] initWithRootViewController:_movieViewController];
-    navCon.modalPresentationStyle = UIModalPresentationFullScreen;
-    [self.window.rootViewController presentViewController:navCon animated:YES completion:nil];
+    [self presentMovieViewController];
 
     [vpc startPlayback];
 }
@@ -620,37 +634,25 @@
 
 - (void)openMediaList:(VLCMediaList *)list atIndex:(int)index
 {
-    if (!_movieViewController)
-        _movieViewController = [[VLCMovieViewController alloc] initWithNibName:nil bundle:nil];
-
     VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
 
     vpc.mediaList = list;
     vpc.itemInMediaListToBePlayedFirst = index;
     vpc.pathToExternalSubtitlesFile = nil;
-    vpc.delegate = _movieViewController;
 
-    UINavigationController *navCon = [[VLCPlaybackNavigationController alloc] initWithRootViewController:_movieViewController];
-    navCon.modalPresentationStyle = UIModalPresentationFullScreen;
-    [self.window.rootViewController presentViewController:navCon animated:YES completion:nil];
+    [self presentMovieViewController];
 
     [vpc startPlayback];
 }
 
 - (void)openMovieWithExternalSubtitleFromURL:(NSURL *)url externalSubURL:(NSString *)SubtitlePath
 {
-    if (!_movieViewController)
-        _movieViewController = [[VLCMovieViewController alloc] initWithNibName:nil bundle:nil];
-
     VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
 
     vpc.url = url;
     vpc.pathToExternalSubtitlesFile = SubtitlePath;
-    vpc.delegate = _movieViewController;
 
-    UINavigationController *navCon = [[VLCPlaybackNavigationController alloc] initWithRootViewController:_movieViewController];
-    navCon.modalPresentationStyle = UIModalPresentationFullScreen;
-    [self.window.rootViewController presentViewController:navCon animated:YES completion:nil];
+    [self presentMovieViewController];
 
     [vpc startPlayback];
 }
@@ -669,12 +671,12 @@
     if ([userInfo[@"name"] isEqualToString:@"getNowPlayingInfo"]) {
         responseDict = [self nowPlayingResponseDict];
     } else if ([userInfo[@"name"] isEqualToString:@"playpause"]) {
-        [_movieViewController playPause];
-        responseDict = @{@"playing": @(_movieViewController.isPlaying)};
+        [[VLCPlaybackController sharedInstance] playPause];
+        responseDict = @{@"playing": @([VLCPlaybackController sharedInstance].isPlaying)};
     } else if ([userInfo[@"name"] isEqualToString:@"skipForward"]) {
-        [_movieViewController forward:nil];
+        [[VLCPlaybackController sharedInstance] forward];
     } else if ([userInfo[@"name"] isEqualToString:@"skipBackward"]) {
-        [_movieViewController backward:nil];
+        [[VLCPlaybackController sharedInstance] backward];
     } else if ([userInfo[@"name"] isEqualToString:@"playFile"]) {
         [self playFileFromWatch:userInfo[@"userInfo"]];
     } else {

+ 0 - 2
Sources/VLCMovieViewController.h

@@ -84,8 +84,6 @@
 @property (nonatomic, strong) IBOutlet UILabel *trackNameLabel;
 @property (nonatomic, strong) IBOutlet UIImageView *artworkImageView;
 
-@property (nonatomic, readonly, getter=isPlaying) BOOL playing;
-
 - (IBAction)closePlayback:(id)sender;
 
 - (IBAction)positionSliderAction:(id)sender;

+ 0 - 6
Sources/VLCMovieViewController.m

@@ -847,12 +847,6 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom
     self.videoFilterButton.hidden = audioOnly;
 }
 
-- (BOOL)isPlaying
-{
-    return [VLCPlaybackController sharedInstance].isPlaying;
-}
-
-
 - (IBAction)playPause
 {
     LOCKCHECK;