From d94920d136c9eba58d3029fdaacb6347e1bdea11 Mon Sep 17 00:00:00 2001 From: bbcallen Date: Thu, 27 Feb 2014 17:31:25 +0800 Subject: [PATCH] ios: observe applicationDidEnterBackgroundNotification for pausing --- .../IJKMediaPlayer/IJKFFMoviePlayerController.m | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ios/IJKMediaPlayer/IJKMediaPlayer/IJKFFMoviePlayerController.m b/ios/IJKMediaPlayer/IJKMediaPlayer/IJKFFMoviePlayerController.m index a60ccbdf..91ee8672 100644 --- a/ios/IJKMediaPlayer/IJKMediaPlayer/IJKFFMoviePlayerController.m +++ b/ios/IJKMediaPlayer/IJKMediaPlayer/IJKFFMoviePlayerController.m @@ -101,6 +101,11 @@ ijkmp_ios_set_glview(_mediaPlayer, glView); ijkmp_set_overlay_format(_mediaPlayer, chroma); + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(applicationDidEnterBackgroundNotification) + name:UIApplicationDidEnterBackgroundNotification + object:nil]; + [options applyTo:_mediaPlayer]; _keepScreenOnWhilePlaying = YES; @@ -110,6 +115,13 @@ return self; } +- (void)applicationDidEnterBackgroundNotification +{ + dispatch_async(dispatch_get_main_queue(), ^{ + [self pause]; + }); +} + - (void)setScreenOn: (BOOL)on { [UIApplication sharedApplication].idleTimerDisabled = on; @@ -118,6 +130,10 @@ - (void)dealloc { [_ffMrl removeTempFiles]; + + [[NSNotificationCenter defaultCenter] removeObserver:self + name:UIApplicationDidEnterBackgroundNotification + object:nil]; } - (void)prepareToPlay -- GitLab