[vlc-devel] [PATCH] VLCMediaPlayer: implement native player behavior on iOS
Gleb Pinigin
gpinigin at gmail.com
Sat Mar 23 12:31:55 CET 2013
---
Headers/Public/VLCMediaPlayer.h | 1 +
Sources/VLCMediaPlayer.m | 23 +++++++++++++++++++++--
2 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/Headers/Public/VLCMediaPlayer.h b/Headers/Public/VLCMediaPlayer.h
index eda8d37..e3f7df3 100644
--- a/Headers/Public/VLCMediaPlayer.h
+++ b/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
diff --git a/Sources/VLCMediaPlayer.m b/Sources/VLCMediaPlayer.m
index e533d93..7ea2e33 100644
--- a/Sources/VLCMediaPlayer.m
+++ b/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
--
1.7.12.4 (Apple Git-37)
More information about the vlc-devel
mailing list