From 848e6632a31304d0464e40877e3527122b9a1e16 Mon Sep 17 00:00:00 2001 From: Tobias Hasselrot Date: Thu, 28 Apr 2016 15:06:22 +0200 Subject: [PATCH] Sound now plays when app is in background. --- RCTVideo.m | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/RCTVideo.m b/RCTVideo.m index 11ae0798..d6bf41b4 100644 --- a/RCTVideo.m +++ b/RCTVideo.m @@ -119,7 +119,10 @@ static NSString *const playbackBufferEmptyKeyPath = @"playbackBufferEmpty"; - (void)applicationWillResignActive:(NSNotification *)notification { - if (!_paused && !_playInBackground) { + if (_playInBackground) { + // Needed to play sound in background. See https://developer.apple.com/library/ios/qa/qa1668/_index.html + [_playerLayer setPlayer:nil]; + } else if (!_paused) { [_player pause]; [_player setRate:0.0]; } @@ -128,6 +131,9 @@ static NSString *const playbackBufferEmptyKeyPath = @"playbackBufferEmpty"; - (void)applicationWillEnterForeground:(NSNotification *)notification { [self applyModifiers]; + if (_playInBackground) { + [_playerLayer setPlayer:_player]; + } } #pragma mark - Progress