[vlc-devel] [PATCH] VLCKit: pause playback when application resigns active (fixes #8139)

Gleb Pinigin gpinigin at gmail.com
Sat Feb 9 16:34:15 CET 2013


---
 Sources/VLCMediaPlayer.m | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/Sources/VLCMediaPlayer.m b/Sources/VLCMediaPlayer.m
index bfab357..8c51416 100644
--- a/Sources/VLCMediaPlayer.m
+++ b/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"];
-- 
1.7.12.4 (Apple Git-37)




More information about the vlc-devel mailing list