From b4582c681b72ea9c0f5b890b97e539d78d6707c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Harrison=20Mendon=C3=A7a?= Date: Mon, 20 Apr 2020 17:25:59 -0300 Subject: [PATCH] add mixWithOthers prop --- ios/Video/RCTVideo.m | 32 +++++++++++++++++++++++++++++--- ios/Video/RCTVideoManager.m | 1 + 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/ios/Video/RCTVideo.m b/ios/Video/RCTVideo.m index dde0dcb6..0181b28f 100644 --- a/ios/Video/RCTVideo.m +++ b/ios/Video/RCTVideo.m @@ -67,6 +67,7 @@ static int const RCTVideoUnset = -1; BOOL _playWhenInactive; BOOL _pictureInPicture; NSString * _ignoreSilentSwitch; + NSString * _mixWithOthers; NSString * _resizeMode; BOOL _fullscreen; BOOL _fullscreenAutorotate; @@ -108,6 +109,7 @@ static int const RCTVideoUnset = -1; _playWhenInactive = false; _pictureInPicture = false; _ignoreSilentSwitch = @"inherit"; // inherit, ignore, obey + _mixWithOthers = @"inherit"; // inherit, mix, duck #if TARGET_OS_IOS _restoreUserInterfaceForPIPStopCompletionHandler = NULL; #endif @@ -857,18 +859,42 @@ static int const RCTVideoUnset = -1; [self applyModifiers]; } +- (void)setMixWithOthers:(NSString *)mixWithOthers +{ + _mixWithOthers = mixWithOthers; + [self applyModifiers]; +} + - (void)setPaused:(BOOL)paused { if (paused) { [_player pause]; [_player setRate:0.0]; } else { + AVAudioSession *session = [AVAudioSession sharedInstance]; + AVAudioSessionCategory category = nil; + AVAudioSessionCategoryOptions options = nil; + if([_ignoreSilentSwitch isEqualToString:@"ignore"]) { - [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil]; + category = AVAudioSessionCategoryPlayback; } 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) { [_player playImmediatelyAtRate:_rate]; } else { diff --git a/ios/Video/RCTVideoManager.m b/ios/Video/RCTVideoManager.m index 7233646f..e8bda250 100644 --- a/ios/Video/RCTVideoManager.m +++ b/ios/Video/RCTVideoManager.m @@ -35,6 +35,7 @@ RCT_EXPORT_VIEW_PROPERTY(playInBackground, BOOL); RCT_EXPORT_VIEW_PROPERTY(playWhenInactive, BOOL); RCT_EXPORT_VIEW_PROPERTY(pictureInPicture, BOOL); RCT_EXPORT_VIEW_PROPERTY(ignoreSilentSwitch, NSString); +RCT_EXPORT_VIEW_PROPERTY(mixWithOthers, NSString); RCT_EXPORT_VIEW_PROPERTY(rate, float); RCT_EXPORT_VIEW_PROPERTY(seek, NSDictionary); RCT_EXPORT_VIEW_PROPERTY(currentTime, float);