Browse Source

make sure video output doesn't get lost in background mode

Felix Paul Kühne 10 years ago
parent
commit
98bb898077

+ 3 - 2
Sources/VLCAppDelegate.m

@@ -567,11 +567,12 @@ continueUserActivity:(NSUserActivity *)userActivity
 - (void)openMediaFromManagedObject:(NSManagedObject *)mediaObject
 {
     BOOL retainFullscreenPlayback = false;
-    if (self.movieViewController.presentingViewController)
-        retainFullscreenPlayback = YES;
 
     VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
 
+    if (vpc.presentingMovieViewController)
+        retainFullscreenPlayback = YES;
+
     if ([mediaObject isKindOfClass:[MLFile class]])
         vpc.fileFromMediaLibrary = (MLFile *)mediaObject;
     else if ([mediaObject isKindOfClass:[MLAlbumTrack class]])

+ 7 - 1
Sources/VLCMiniPlaybackView.m

@@ -144,9 +144,15 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom
             _videoView = nil;
         }
     } else {
+        if (_videoView) {
+            [_videoView removeFromSuperview];
+            _videoView = nil;
+        }
         _videoView = [[UIView alloc] initWithFrame:_artworkView.frame];
         [self addSubview:_videoView];
-        controller.videoOutputView = _videoView;
+
+        if (!controller.presentingMovieViewController)
+            controller.videoOutputView = _videoView;
     }
 
     NSString *metaDataString;

+ 6 - 2
Sources/VLCMovieViewController.m

@@ -435,8 +435,8 @@ typedef NS_ENUM(NSInteger, VLCPanType) {
     }
 
     VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
-    vpc.videoOutputView = self.movieView;
     vpc.delegate = self;
+    vpc.presentingMovieViewController = YES;
     [vpc recoverPlaybackState];
 
     [self setControlsHidden:NO animated:YES];
@@ -449,6 +449,8 @@ typedef NS_ENUM(NSInteger, VLCPanType) {
 
     VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
     [vpc recoverDisplayedMetadata];
+    vpc.videoOutputView = nil;
+    vpc.videoOutputView = self.movieView;
 }
 
 - (void)viewWillLayoutSubviews
@@ -493,7 +495,9 @@ typedef NS_ENUM(NSInteger, VLCPanType) {
 
 - (void)viewWillDisappear:(BOOL)animated
 {
-    [VLCPlaybackController sharedInstance].videoOutputView = nil;
+    VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
+    vpc.videoOutputView = nil;
+    vpc.presentingMovieViewController = NO;
 
     _viewAppeared = NO;
     if (_idleTimer) {

+ 1 - 0
Sources/VLCPlaybackController.h

@@ -66,6 +66,7 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom
 @property (nonatomic, readonly) BOOL currentMediaHasTrackToChooseFrom;
 @property (nonatomic, readonly) BOOL activePlaybackSession;
 @property (nonatomic, readonly) BOOL audioOnlyPlaybackSession;
+@property (nonatomic, readwrite) BOOL presentingMovieViewController;
 
 + (VLCPlaybackController *)sharedInstance;
 

+ 3 - 0
Sources/VLCPlaybackController.m

@@ -589,6 +589,9 @@
         [_actualVideoOutputView layoutSubviews];
         [_actualVideoOutputView updateConstraints];
 
+        if (_mediaPlayer.currentVideoTrackIndex == -1)
+            _mediaPlayer.currentVideoTrackIndex = 0;
+
         [videoOutputView addSubview:_actualVideoOutputView];
     } else
         [_actualVideoOutputView removeFromSuperview];