Commit 39443ae3 authored by Tobias Hasselrot's avatar Tobias Hasselrot
Browse files

Fixed background playback behind notification center.

parent 848e6632
Loading
Loading
Loading
Loading
+13 −3
Changes for RCTVideo.m: 13 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -63,6 +63,11 @@ static NSString *const playbackBufferEmptyKeyPath = @"playbackBufferEmpty";
                                                 name:UIApplicationWillResignActiveNotification
                                               object:nil];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(applicationDidEnterBackground:)
                                                 name:UIApplicationDidEnterBackgroundNotification
                                               object:nil];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(applicationWillEnterForeground:)
                                                 name:UIApplicationWillEnterForegroundNotification
@@ -118,13 +123,18 @@ static NSString *const playbackBufferEmptyKeyPath = @"playbackBufferEmpty";
#pragma mark - App lifecycle handlers

- (void)applicationWillResignActive:(NSNotification *)notification
{
  if (!_paused && !_playInBackground) {
    [_player pause];
    [_player setRate:0.0];
  }
}

- (void)applicationDidEnterBackground:(NSNotification *)notification
{
    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];
    }
}