Browse Source

playback: fix vout behavior when app moves back and forth between active, background and active states (closes #14795)

(cherry picked from commit 2cfb76550c2eb2eced514956a06d853fbf21604b)
Felix Paul Kühne 10 years ago
parent
commit
713ee565c7
3 changed files with 38 additions and 17 deletions
  1. 10 6
      Sources/VLCMiniPlaybackView.m
  2. 19 1
      Sources/VLCMovieViewController.m
  3. 9 10
      Sources/VLCPlaybackController.m

+ 10 - 6
Sources/VLCMiniPlaybackView.m

@@ -217,12 +217,16 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom
             [_videoView removeFromSuperview];
             _videoView = nil;
         }
-        _videoView = [[UIView alloc] initWithFrame:_artworkView.frame];
-        [_videoView setClipsToBounds:YES];
-        [_videoView addGestureRecognizer:_artworkTapRecognizer];
-        _videoView.userInteractionEnabled = YES;
-        [self addSubview:_videoView];
-        controller.videoOutputView = _videoView;
+
+        VLCPlayerDisplayController *pdc = [(VLCAppDelegate *)[UIApplication sharedApplication].delegate playerDisplayController];
+        if (pdc.displayMode == VLCPlayerDisplayControllerDisplayModeMiniplayer) {
+            _videoView = [[UIView alloc] initWithFrame:_artworkView.frame];
+            [_videoView setClipsToBounds:YES];
+            [_videoView addGestureRecognizer:_artworkTapRecognizer];
+            _videoView.userInteractionEnabled = YES;
+            [self addSubview:_videoView];
+            controller.videoOutputView = _videoView;
+        }
     }
 
     NSString *metaDataString;

+ 19 - 1
Sources/VLCMovieViewController.m

@@ -29,7 +29,8 @@
 #import "VLCPlaybackController.h"
 #import "UIDevice+VLC.h"
 #import "VLCTimeNavigationTitleView.h"
-
+#import "VLCPlayerDisplayController.h"
+#import "VLCAppDelegate.h"
 #import "VLCStatusLabel.h"
 
 #define FORWARD_SWIPE_DURATION 30
@@ -226,6 +227,10 @@ typedef NS_ENUM(NSInteger, VLCPanType) {
                    name:UIScreenDidDisconnectNotification object:nil];
     [center addObserver:self selector:@selector(screenBrightnessChanged:)
                    name:UIScreenBrightnessDidChangeNotification object:nil];
+    [center addObserver:self
+               selector:@selector(appBecameActive:)
+                   name:UIApplicationDidBecomeActiveNotification
+                 object:nil];
 
     _playingExternallyTitle.text = NSLocalizedString(@"PLAYING_EXTERNALLY_TITLE", nil);
     _playingExternallyDescription.text = NSLocalizedString(@"PLAYING_EXTERNALLY_DESC", nil);
@@ -1536,6 +1541,19 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom
         self.brightnessSlider.value = [(UIScreen *)[[UIScreen screens] firstObject] brightness] * 2.;
 }
 
+- (void)appBecameActive:(NSNotification *)aNotification
+{
+    VLCPlayerDisplayController *pdc = [(VLCAppDelegate *)[UIApplication sharedApplication].delegate playerDisplayController];
+    if (pdc.displayMode == VLCPlayerDisplayControllerDisplayModeFullscreen) {
+        VLCPlaybackController *vpc = self.playbackController;
+        [vpc recoverDisplayedMetadata];
+        if (vpc.videoOutputView != self.movieView) {
+            vpc.videoOutputView = nil;
+            vpc.videoOutputView = self.movieView;
+        }
+    }
+}
+
 #pragma mark - playback view
 - (IBAction)playbackSliderAction:(UISlider *)sender
 {

+ 9 - 10
Sources/VLCPlaybackController.m

@@ -37,6 +37,7 @@ NSString *const VLCPlaybackControllerPlaybackDidFail = @"VLCPlaybackControllerPl
     BOOL _playerIsSetup;
     BOOL _playbackFailed;
     BOOL _shouldResumePlaying;
+    BOOL _shouldResumePlayingAfterInteruption;
     NSTimer *_sleepTimer;
 
     NSArray *_aspectRatios;
@@ -711,15 +712,15 @@ NSString *const VLCPlaybackControllerPlaybackDidFail = @"VLCPlaybackControllerPl
 {
     if ([_mediaPlayer isPlaying]) {
         [_mediaPlayer pause];
-        _shouldResumePlaying = YES;
+        _shouldResumePlayingAfterInteruption = YES;
     }
 }
 
 - (void)endInterruption
 {
-    if (_shouldResumePlaying) {
+    if (_shouldResumePlayingAfterInteruption) {
         [_mediaPlayer play];
-        _shouldResumePlaying = NO;
+        _shouldResumePlayingAfterInteruption = NO;
     }
 }
 
@@ -1114,12 +1115,6 @@ static inline NSArray * RemoteCommandCenterCommandsToHandle(MPRemoteCommandCente
 {
     [self _savePlaybackState];
 
-    _preBackgroundWrapperView = _videoOutputViewWrapper;
-    [self setVideoOutputView:nil];
-
-    if (_mediaPlayer.audioTrackIndexes.count > 0)
-        _mediaPlayer.currentVideoTrackIndex = -1;
-
     if (![[[NSUserDefaults standardUserDefaults] objectForKey:kVLCSettingContinueAudioInBackgroundKey] boolValue]) {
         if ([_mediaPlayer isPlaying]) {
             [_mediaPlayer pause];
@@ -1130,7 +1125,11 @@ static inline NSArray * RemoteCommandCenterCommandsToHandle(MPRemoteCommandCente
 
 - (void)applicationDidEnterBackground:(NSNotification *)notification
 {
-    _shouldResumePlaying = NO;
+    _preBackgroundWrapperView = _videoOutputViewWrapper;
+    [self setVideoOutputView:nil];
+
+    if (_mediaPlayer.audioTrackIndexes.count > 0)
+        _mediaPlayer.currentVideoTrackIndex = -1;
 }
 
 - (void)applicationDidBecomeActive:(NSNotification *)notification