From 1f901be3638d7c6c4ec8599ddd834c7d43837fb4 Mon Sep 17 00:00:00 2001 From: Brent Vatne Date: Thu, 25 Jun 2015 15:40:46 -0700 Subject: [PATCH] Pause video when the app is backgrounded --- RCTVideo.m | 26 ++++++++++++++++++++++++++ package.json | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/RCTVideo.m b/RCTVideo.m index 47aa2707..e7e288a5 100644 --- a/RCTVideo.m +++ b/RCTVideo.m @@ -54,11 +54,37 @@ static NSString *const statusKeyPath = @"status"; _pendingSeek = false; _pendingSeekTime = 0.0f; _lastSeekTime = 0.0f; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(applicationWillResignActive:) + name:UIApplicationWillResignActiveNotification + object:nil]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(applicationWillEnterForeground:) + name:UIApplicationWillEnterForegroundNotification + object:nil]; } return self; } +#pragma mark - App lifecycle handlers + +- (void)applicationWillResignActive:(NSNotification *)notification +{ + if (!_paused) { + [self stopProgressTimer]; + [_player pause]; + } +} + +- (void)applicationWillEnterForeground:(NSNotification *)notification +{ + [self startProgressTimer]; + [self applyModifiers]; +} + #pragma mark - Progress - (void)sendProgressUpdate diff --git a/package.json b/package.json index b4c2f52f..679d0c4d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-video", - "version": "0.4.7", + "version": "0.4.8", "description": "A