Explorar o código

VLCKit: pause playback when application resigns active (fixes #8139)

Signed-off-by: Felix Paul Kühne <fkuehne@videolan.org>
Gleb Pinigin %!s(int64=12) %!d(string=hai) anos
pai
achega
8ac9f4b86c
Modificáronse 1 ficheiros con 8 adicións e 0 borrados
  1. 8 0
      Sources/VLCMediaPlayer.m

+ 8 - 0
Sources/VLCMediaPlayer.m

@@ -206,6 +206,7 @@ static void HandleMediaPlayerMediaChanged(const libvlc_event_t * event, void * s
 
     [self unregisterObservers];
     [[VLCEventManager sharedManager] cancelCallToObject:self];
+    [[NSNotificationCenter defaultCenter] removeObserver:self];
 
     // Always get rid of the delegate first so we can stop sending messages to it
     // TODO: Should we tell the delegate that we're shutting down?
@@ -727,6 +728,8 @@ static const VLCMediaPlayerState libvlc_to_local_state[] =
         instance = libvlc_media_player_new([VLCLibrary sharedInstance]);
 
         [self registerObservers];
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillResignActive:)
+                                                     name:UIApplicationWillResignActiveNotification object:nil];
 
         [self setDrawable:aDrawable];
     }
@@ -765,6 +768,11 @@ static const VLCMediaPlayerState libvlc_to_local_state[] =
     libvlc_event_detach(p_em, libvlc_MediaPlayerMediaChanged,     HandleMediaPlayerMediaChanged,   self);
 }
 
+- (void)applicationWillResignActive:(NSNotification *)notification
+{
+    [self pause];
+}
+
 - (void)mediaPlayerTimeChanged:(NSNumber *)newTime
 {
     [self willChangeValueForKey:@"time"];