Selaa lähdekoodia

VLCMediaPlayer: implement native player behavior on iOS

Signed-off-by: Felix Paul Kühne <fkuehne@videolan.org>
Gleb Pinigin 12 vuotta sitten
vanhempi
commit
4b32714352
2 muutettua tiedostoa jossa 22 lisäystä ja 2 poistoa
  1. 1 0
      Headers/Public/VLCMediaPlayer.h
  2. 21 2
      Sources/VLCMediaPlayer.m

+ 1 - 0
Headers/Public/VLCMediaPlayer.h

@@ -95,6 +95,7 @@ extern NSString * VLCMediaPlayerStateToString(VLCMediaPlayerState state);
     float position;                     //< The position of the media being played
     id drawable;                        //< The drawable associated to this media player
     VLCAudio *audio;
+    BOOL shouldResumePlaying;           //< resume playing on iOS
 }
 
 #if !TARGET_OS_IPHONE

+ 21 - 2
Sources/VLCMediaPlayer.m

@@ -840,8 +840,13 @@ static const VLCMediaPlayerState libvlc_to_local_state[] =
 
         [self registerObservers];
 #if TARGET_OS_IPHONE
-        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillResignActive:)
-                                                     name:UIApplicationWillResignActiveNotification object:nil];
+        NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
+        [center addObserver:self selector:@selector(applicationWillResignActive:)
+                       name:UIApplicationWillResignActiveNotification object:nil];
+        [center addObserver:self selector:@selector(applicationDidBecomeActive:)
+                       name:UIApplicationDidBecomeActiveNotification object:nil];
+        [center addObserver:self selector:@selector(applicationDidEnterBackground:)
+                       name:UIApplicationDidEnterBackgroundNotification object:nil];
 #endif
 
         [self setDrawable:aDrawable];
@@ -884,8 +889,22 @@ static const VLCMediaPlayerState libvlc_to_local_state[] =
 #if TARGET_OS_IPHONE
 - (void)applicationWillResignActive:(NSNotification *)notification
 {
+    shouldResumePlaying = YES;
     [self pause];
 }
+
+- (void)applicationDidEnterBackground:(NSNotification *)notification
+{
+    shouldResumePlaying = NO;
+}
+
+- (void)applicationDidBecomeActive:(NSNotification *)notification
+{
+    if (shouldResumePlaying) {
+        shouldResumePlaying = NO;
+        [self play];
+    }
+}
 #endif
 
 - (void)mediaPlayerTimeChanged:(NSNumber *)newTime