From eb313378374db00e2940881ee808f343a734145c Mon Sep 17 00:00:00 2001 From: tobias Date: Fri, 29 Apr 2016 13:55:34 +0200 Subject: [PATCH] Added play when inactive to support playing while showing notification center. --- RCTVideo.m | 15 +++++++++++---- Video.ios.js | 1 + Video.js | 1 + 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/RCTVideo.m b/RCTVideo.m index 28b25bb9..6664532b 100644 --- a/RCTVideo.m +++ b/RCTVideo.m @@ -37,6 +37,7 @@ static NSString *const playbackBufferEmptyKeyPath = @"playbackBufferEmpty"; BOOL _paused; BOOL _repeat; BOOL _playInBackground; + BOOL _playWhenInactive; NSString * _resizeMode; BOOL _fullscreenPlayerPresented; UIViewController * _presentingViewController; @@ -57,6 +58,7 @@ static NSString *const playbackBufferEmptyKeyPath = @"playbackBufferEmpty"; _controls = NO; _playerBufferEmpty = YES; _playInBackground = false; + _playWhenInactive = false; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillResignActive:) @@ -124,10 +126,10 @@ static NSString *const playbackBufferEmptyKeyPath = @"playbackBufferEmpty"; - (void)applicationWillResignActive:(NSNotification *)notification { - if (!_paused && !_playInBackground) { - [_player pause]; - [_player setRate:0.0]; - } + if (_playInBackground || _playWhenInactive || _paused) return; + + [_player pause]; + [_player setRate:0.0]; } - (void)applicationDidEnterBackground:(NSNotification *)notification @@ -371,6 +373,11 @@ static NSString *const playbackBufferEmptyKeyPath = @"playbackBufferEmpty"; _playInBackground = playInBackground; } +- (void)setPlayWhenInactive:(BOOL)playWhenInactive +{ + _playWhenInactive = playWhenInactive; +} + - (void)setPaused:(BOOL)paused { if (paused) { diff --git a/Video.ios.js b/Video.ios.js index d9f16633..f75fbc3d 100644 --- a/Video.ios.js +++ b/Video.ios.js @@ -21,6 +21,7 @@ var Video = React.createClass({ volume: PropTypes.number, rate: PropTypes.number, playInBackground: PropTypes.bool, + playWhenInactive: PropTypes.bool, onLoadStart: PropTypes.func, onLoad: PropTypes.func, onError: PropTypes.func, diff --git a/Video.js b/Video.js index 466c3223..1447eee4 100644 --- a/Video.js +++ b/Video.js @@ -187,6 +187,7 @@ Video.propTypes = { volume: PropTypes.number, rate: PropTypes.number, playInBackground: PropTypes.bool, + playWhenInactive: PropTypes.bool, controls: PropTypes.bool, currentTime: PropTypes.number, onLoadStart: PropTypes.func,