Merge pull request #1157 from react-native-community/bugfix/disable-sideload-track
Fix sideload text track issues on iOS
This commit is contained in:
commit
352bad21c4
@ -13,6 +13,8 @@ static NSString *const readyForDisplayKeyPath = @"readyForDisplay";
|
|||||||
static NSString *const playbackRate = @"rate";
|
static NSString *const playbackRate = @"rate";
|
||||||
static NSString *const timedMetadata = @"timedMetadata";
|
static NSString *const timedMetadata = @"timedMetadata";
|
||||||
|
|
||||||
|
static int const RCTVideoUnset = -1;
|
||||||
|
|
||||||
@implementation RCTVideo
|
@implementation RCTVideo
|
||||||
{
|
{
|
||||||
AVPlayer *_player;
|
AVPlayer *_player;
|
||||||
@ -807,7 +809,7 @@ static NSString *const timedMetadata = @"timedMetadata";
|
|||||||
|
|
||||||
- (void) setSideloadedText {
|
- (void) setSideloadedText {
|
||||||
NSString *type = _selectedTextTrack[@"type"];
|
NSString *type = _selectedTextTrack[@"type"];
|
||||||
NSArray* textTracks = [self getTextTrackInfo];
|
NSArray *textTracks = [self getTextTrackInfo];
|
||||||
|
|
||||||
// The first few tracks will be audio & video track
|
// The first few tracks will be audio & video track
|
||||||
int firstTextIndex = 0;
|
int firstTextIndex = 0;
|
||||||
@ -817,7 +819,7 @@ static NSString *const timedMetadata = @"timedMetadata";
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int selectedTrackIndex = -1;
|
int selectedTrackIndex = RCTVideoUnset;
|
||||||
|
|
||||||
if ([type isEqualToString:@"disabled"]) {
|
if ([type isEqualToString:@"disabled"]) {
|
||||||
// Do nothing. We want to ensure option is nil
|
// Do nothing. We want to ensure option is nil
|
||||||
@ -846,17 +848,12 @@ static NSString *const timedMetadata = @"timedMetadata";
|
|||||||
selectedTrackIndex = index;
|
selectedTrackIndex = index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else { // type "system"
|
||||||
|
|
||||||
// user's selected language might not be available, or system defaults have captions enabled
|
|
||||||
if (selectedTrackIndex == -1 || [type isEqualToString:@"default"]) {
|
|
||||||
CFArrayRef captioningMediaCharacteristics = MACaptionAppearanceCopyPreferredCaptioningMediaCharacteristics(kMACaptionAppearanceDomainUser);
|
CFArrayRef captioningMediaCharacteristics = MACaptionAppearanceCopyPreferredCaptioningMediaCharacteristics(kMACaptionAppearanceDomainUser);
|
||||||
NSArray *captionSettings = (__bridge NSArray*)captioningMediaCharacteristics;
|
NSArray *captionSettings = (__bridge NSArray*)captioningMediaCharacteristics;
|
||||||
if ([captionSettings containsObject: AVMediaCharacteristicTranscribesSpokenDialogForAccessibility]) {
|
if ([captionSettings containsObject:AVMediaCharacteristicTranscribesSpokenDialogForAccessibility]) {
|
||||||
// iterate through the textTracks to find a matching option, or default to the first object.
|
selectedTrackIndex = 0; // If we can't find a match, use the first available track
|
||||||
selectedTrackIndex = 0;
|
NSString *systemLanguage = [[NSLocale preferredLanguages] firstObject];
|
||||||
|
|
||||||
NSString * systemLanguage = [[NSLocale preferredLanguages] firstObject];
|
|
||||||
for (int i = 0; i < textTracks.count; ++i) {
|
for (int i = 0; i < textTracks.count; ++i) {
|
||||||
NSDictionary *currentTextTrack = [textTracks objectAtIndex:i];
|
NSDictionary *currentTextTrack = [textTracks objectAtIndex:i];
|
||||||
if ([systemLanguage isEqualToString:currentTextTrack[@"language"]]) {
|
if ([systemLanguage isEqualToString:currentTextTrack[@"language"]]) {
|
||||||
@ -868,7 +865,10 @@ static NSString *const timedMetadata = @"timedMetadata";
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (int i = firstTextIndex; i < _player.currentItem.tracks.count; ++i) {
|
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];
|
[_player.currentItem.tracks[i] setEnabled:isEnabled];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user