From c84e059543e3b60cebe3839e2b5327ea4ad79c66 Mon Sep 17 00:00:00 2001 From: Hampton Maxwell Date: Sun, 29 Jul 2018 17:42:09 -0700 Subject: [PATCH 1/3] Only look for text tracks matching system language when the "system" type is set --- ios/RCTVideo.m | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/ios/RCTVideo.m b/ios/RCTVideo.m index 2c2097d0..00b3ceb1 100644 --- a/ios/RCTVideo.m +++ b/ios/RCTVideo.m @@ -13,6 +13,8 @@ static NSString *const readyForDisplayKeyPath = @"readyForDisplay"; static NSString *const playbackRate = @"rate"; static NSString *const timedMetadata = @"timedMetadata"; +static int const RCTVideoUnset = -1; + @implementation RCTVideo { AVPlayer *_player; @@ -807,7 +809,7 @@ static NSString *const timedMetadata = @"timedMetadata"; - (void) setSideloadedText { NSString *type = _selectedTextTrack[@"type"]; - NSArray* textTracks = [self getTextTrackInfo]; + NSArray *textTracks = [self getTextTrackInfo]; // The first few tracks will be audio & video track int firstTextIndex = 0; @@ -817,7 +819,7 @@ static NSString *const timedMetadata = @"timedMetadata"; } } - int selectedTrackIndex = -1; + int selectedTrackIndex = RCTVideoUnset; if ([type isEqualToString:@"disabled"]) { // Do nothing. We want to ensure option is nil @@ -846,29 +848,27 @@ static NSString *const timedMetadata = @"timedMetadata"; selectedTrackIndex = index; } } - } - - // user's selected language might not be available, or system defaults have captions enabled - if (selectedTrackIndex == -1 || [type isEqualToString:@"default"]) { - CFArrayRef captioningMediaCharacteristics = MACaptionAppearanceCopyPreferredCaptioningMediaCharacteristics(kMACaptionAppearanceDomainUser); - NSArray *captionSettings = (__bridge NSArray*)captioningMediaCharacteristics; - if ([captionSettings containsObject: AVMediaCharacteristicTranscribesSpokenDialogForAccessibility]) { - // iterate through the textTracks to find a matching option, or default to the first object. - selectedTrackIndex = 0; - - NSString * systemLanguage = [[NSLocale preferredLanguages] firstObject]; - for (int i = 0; i < textTracks.count; ++i) { - NSDictionary *currentTextTrack = [textTracks objectAtIndex:i]; - if ([systemLanguage isEqualToString:currentTextTrack[@"language"]]) { - selectedTrackIndex = i; - break; - } + } else { // type "system" + CFArrayRef captioningMediaCharacteristics = MACaptionAppearanceCopyPreferredCaptioningMediaCharacteristics(kMACaptionAppearanceDomainUser); + NSArray *captionSettings = (__bridge NSArray*)captioningMediaCharacteristics; + if ([captionSettings containsObject:AVMediaCharacteristicTranscribesSpokenDialogForAccessibility]) { + selectedTrackIndex = 0; // If we can't find a match, use the first available track + NSString *systemLanguage = [[NSLocale preferredLanguages] firstObject]; + for (int i = 0; i < textTracks.count; ++i) { + NSDictionary *currentTextTrack = [textTracks objectAtIndex:i]; + if ([systemLanguage isEqualToString:currentTextTrack[@"language"]]) { + selectedTrackIndex = i; + break; } } + } } - + for (int i = firstTextIndex; i < _player.currentItem.tracks.count; ++i) { - BOOL isEnabled = i == selectedTrackIndex + firstTextIndex; + BOOL isEnabled = NO; + if (selectedTrackIndex != RCTVideoUnset) { + isEnabled = i == selectedTrackIndex + firstTextIndex; + } [_player.currentItem.tracks[i] setEnabled:isEnabled]; } } From efb1fc7723bcb31e209e206172c21272fa0c8bea Mon Sep 17 00:00:00 2001 From: Hampton Maxwell Date: Tue, 31 Jul 2018 11:25:17 -0700 Subject: [PATCH 2/3] Update react-native link instructions with module name Just calling react-native link is risky, it can cause double linking --- README.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ed6ffae9..826bc033 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ yarn add react-native-video
iOS -Run `react-native link` to link the react-native-video library. +Run `react-native link react-native-video` to link the react-native-video library. If you would like to allow other apps to play music over your video component, add: @@ -53,9 +53,7 @@ Note: you can also use the `ignoreSilentSwitch` prop, shown below.
tvOS -Run `react-native link` to link the react-native-video library. - -`react-native link` doesn’t work properly with the tvOS target so we need to add the library manually. +`react-native link-video` doesn’t work properly with the tvOS target so we need to add the library manually. First select your project in Xcode. @@ -77,7 +75,7 @@ Select RCTVideo-tvOS
Android -Run `react-native link` to link the react-native-video library. +Run `react-native link react-native-video` to link the react-native-video library. Or if you have trouble, make the following additions to the given files manually: From b710b690254311ab99a2d3428db7973e9f1a04fc Mon Sep 17 00:00:00 2001 From: Hampton Maxwell Date: Tue, 31 Jul 2018 11:26:09 -0700 Subject: [PATCH 3/3] Fix typo in tvOS instructions --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 826bc033..1894c613 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ Note: you can also use the `ignoreSilentSwitch` prop, shown below.
tvOS -`react-native link-video` doesn’t work properly with the tvOS target so we need to add the library manually. +`react-native link react-native-video` doesn’t work properly with the tvOS target so we need to add the library manually. First select your project in Xcode.