add mixWithOthers prop

This commit is contained in:
Harrison Mendonça 2020-04-20 17:25:59 -03:00
parent 1ecb09acc4
commit b4582c681b
2 changed files with 30 additions and 3 deletions

View File

@ -67,6 +67,7 @@ static int const RCTVideoUnset = -1;
BOOL _playWhenInactive; BOOL _playWhenInactive;
BOOL _pictureInPicture; BOOL _pictureInPicture;
NSString * _ignoreSilentSwitch; NSString * _ignoreSilentSwitch;
NSString * _mixWithOthers;
NSString * _resizeMode; NSString * _resizeMode;
BOOL _fullscreen; BOOL _fullscreen;
BOOL _fullscreenAutorotate; BOOL _fullscreenAutorotate;
@ -108,6 +109,7 @@ static int const RCTVideoUnset = -1;
_playWhenInactive = false; _playWhenInactive = false;
_pictureInPicture = false; _pictureInPicture = false;
_ignoreSilentSwitch = @"inherit"; // inherit, ignore, obey _ignoreSilentSwitch = @"inherit"; // inherit, ignore, obey
_mixWithOthers = @"inherit"; // inherit, mix, duck
#if TARGET_OS_IOS #if TARGET_OS_IOS
_restoreUserInterfaceForPIPStopCompletionHandler = NULL; _restoreUserInterfaceForPIPStopCompletionHandler = NULL;
#endif #endif
@ -857,18 +859,42 @@ static int const RCTVideoUnset = -1;
[self applyModifiers]; [self applyModifiers];
} }
- (void)setMixWithOthers:(NSString *)mixWithOthers
{
_mixWithOthers = mixWithOthers;
[self applyModifiers];
}
- (void)setPaused:(BOOL)paused - (void)setPaused:(BOOL)paused
{ {
if (paused) { if (paused) {
[_player pause]; [_player pause];
[_player setRate:0.0]; [_player setRate:0.0];
} else { } else {
AVAudioSession *session = [AVAudioSession sharedInstance];
AVAudioSessionCategory category = nil;
AVAudioSessionCategoryOptions options = nil;
if([_ignoreSilentSwitch isEqualToString:@"ignore"]) { if([_ignoreSilentSwitch isEqualToString:@"ignore"]) {
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil]; category = AVAudioSessionCategoryPlayback;
} else if([_ignoreSilentSwitch isEqualToString:@"obey"]) { } else if([_ignoreSilentSwitch isEqualToString:@"obey"]) {
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:nil]; category = AVAudioSessionCategoryAmbient;
} }
if([_mixWithOthers isEqualToString:@"mix"]) {
options = AVAudioSessionCategoryOptionMixWithOthers;
} else if([_mixWithOthers isEqualToString:@"duck"]) {
options = AVAudioSessionCategoryOptionDuckOthers;
}
if (category != nil && options != nil) {
[session setCategory:category withOptions:options error:nil];
} else if (category != nil && options == nil) {
[session setCategory:category error:nil];
} else if (category == nil && options != nil) {
[session setCategory:session.category withOptions:options error:nil];
}
if (@available(iOS 10.0, *) && !_automaticallyWaitsToMinimizeStalling) { if (@available(iOS 10.0, *) && !_automaticallyWaitsToMinimizeStalling) {
[_player playImmediatelyAtRate:_rate]; [_player playImmediatelyAtRate:_rate];
} else { } else {

View File

@ -35,6 +35,7 @@ RCT_EXPORT_VIEW_PROPERTY(playInBackground, BOOL);
RCT_EXPORT_VIEW_PROPERTY(playWhenInactive, BOOL); RCT_EXPORT_VIEW_PROPERTY(playWhenInactive, BOOL);
RCT_EXPORT_VIEW_PROPERTY(pictureInPicture, BOOL); RCT_EXPORT_VIEW_PROPERTY(pictureInPicture, BOOL);
RCT_EXPORT_VIEW_PROPERTY(ignoreSilentSwitch, NSString); RCT_EXPORT_VIEW_PROPERTY(ignoreSilentSwitch, NSString);
RCT_EXPORT_VIEW_PROPERTY(mixWithOthers, NSString);
RCT_EXPORT_VIEW_PROPERTY(rate, float); RCT_EXPORT_VIEW_PROPERTY(rate, float);
RCT_EXPORT_VIEW_PROPERTY(seek, NSDictionary); RCT_EXPORT_VIEW_PROPERTY(seek, NSDictionary);
RCT_EXPORT_VIEW_PROPERTY(currentTime, float); RCT_EXPORT_VIEW_PROPERTY(currentTime, float);