From f79782b4470f74c64926eff80db511596b07a05b Mon Sep 17 00:00:00 2001 From: Cameron Perry Date: Thu, 19 Nov 2020 16:18:31 -0800 Subject: [PATCH 1/2] =?UTF-8?q?Resolved=20an=20issue=20where=20setting=20a?= =?UTF-8?q?=20video=20to=20paused=20would=20ignore=20the=20=E2=80=9Csilent?= =?UTF-8?q?=20switch=E2=80=9D=20setting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ios/Video/RCTVideo.m | 51 +++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/ios/Video/RCTVideo.m b/ios/Video/RCTVideo.m index 8780f48f..a4702cee 100644 --- a/ios/Video/RCTVideo.m +++ b/ios/Video/RCTVideo.m @@ -915,6 +915,7 @@ static int const RCTVideoUnset = -1; - (void)setIgnoreSilentSwitch:(NSString *)ignoreSilentSwitch { _ignoreSilentSwitch = ignoreSilentSwitch; + [self configureAudio]; [self applyModifiers]; } @@ -930,29 +931,8 @@ static int const RCTVideoUnset = -1; [_player pause]; [_player setRate:0.0]; } else { - AVAudioSession *session = [AVAudioSession sharedInstance]; - AVAudioSessionCategory category = nil; - AVAudioSessionCategoryOptions options = nil; - if([_ignoreSilentSwitch isEqualToString:@"ignore"]) { - category = AVAudioSessionCategoryPlayback; - } else if([_ignoreSilentSwitch isEqualToString:@"obey"]) { - 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]; - } + [self configureAudio]; if (@available(iOS 10.0, *) && !_automaticallyWaitsToMinimizeStalling) { [_player playImmediatelyAtRate:_rate]; @@ -1086,6 +1066,33 @@ static int const RCTVideoUnset = -1; [self setAllowsExternalPlayback:_allowsExternalPlayback]; } +- (void)configureAudio +{ + AVAudioSession *session = [AVAudioSession sharedInstance]; + AVAudioSessionCategory category = nil; + AVAudioSessionCategoryOptions options = nil; + + if([_ignoreSilentSwitch isEqualToString:@"ignore"]) { + category = AVAudioSessionCategoryPlayback; + } else if([_ignoreSilentSwitch isEqualToString:@"obey"]) { + 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]; + } +} + - (void)setRepeat:(BOOL)repeat { _repeat = repeat; } From a42240d5543cbc9f7c11a0692c05d625d345457a Mon Sep 17 00:00:00 2001 From: Shane Mckenna Date: Mon, 23 Aug 2021 11:59:53 -0700 Subject: [PATCH 2/2] Fix for tvOS native audio menu language selector --- ios/Video/RCTVideo.m | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/ios/Video/RCTVideo.m b/ios/Video/RCTVideo.m index a4702cee..5021f95e 100644 --- a/ios/Video/RCTVideo.m +++ b/ios/Video/RCTVideo.m @@ -1134,12 +1134,20 @@ static int const RCTVideoUnset = -1; } } } else { // default. invalid type or "system" - [_player.currentItem selectMediaOptionAutomaticallyInMediaSelectionGroup:group]; - return; + #if TARGET_OS_TV + // Do noting. Fix for tvOS native audio menu language selector + #else + [_player.currentItem selectMediaOptionAutomaticallyInMediaSelectionGroup:group]; + return; + #endif } - - // If a match isn't found, option will be nil and text tracks will be disabled - [_player.currentItem selectMediaOption:mediaOption inMediaSelectionGroup:group]; + + #if TARGET_OS_TV + // Do noting. Fix for tvOS native audio menu language selector + #else + // If a match isn't found, option will be nil and text tracks will be disabled + [_player.currentItem selectMediaOption:mediaOption inMediaSelectionGroup:group]; + #endif } - (void)setSelectedAudioTrack:(NSDictionary *)selectedAudioTrack {