remove tracks that are not valid from textTracks; and default to system if selectedTextTrack unavailable

This commit is contained in:
Ash Mishra 2018-07-31 16:56:19 -07:00
parent 352bad21c4
commit fa30fb3e43

View File

@ -411,6 +411,7 @@ static int const RCTVideoUnset = -1;
atTime:kCMTimeZero
error:nil];
NSMutableArray* validTextTracks = [NSMutableArray array];
for (int i = 0; i < _textTracks.count; ++i) {
AVURLAsset *textURLAsset;
NSString *textUri = [_textTracks objectAtIndex:i][@"uri"];
@ -420,6 +421,8 @@ static int const RCTVideoUnset = -1;
textURLAsset = [AVURLAsset URLAssetWithURL:[self urlFilePath:textUri] options:nil];
}
AVAssetTrack *textTrackAsset = [textURLAsset tracksWithMediaType:AVMediaTypeText].firstObject;
if (!textTrackAsset) continue; // fix when there's no textTrackAsset
[validTextTracks addObject:[_textTracks objectAtIndex:i]];
AVMutableCompositionTrack *textCompTrack = [mixComposition
addMutableTrackWithMediaType:AVMediaTypeText
preferredTrackID:kCMPersistentTrackID_Invalid];
@ -428,6 +431,9 @@ static int const RCTVideoUnset = -1;
atTime:kCMTimeZero
error:nil];
}
if (validTextTracks.count != _textTracks.count) {
[self setTextTracks:validTextTracks];
}
return [AVPlayerItem playerItemWithAsset:mixComposition];
}
@ -848,7 +854,10 @@ static int const RCTVideoUnset = -1;
selectedTrackIndex = index;
}
}
} else { // type "system"
}
// in the situation that a selected text track is not available (eg. specifies a textTrack not available)
if (![type isEqualToString:@"disabled"] && selectedTrackIndex == RCTVideoUnset) {
CFArrayRef captioningMediaCharacteristics = MACaptionAppearanceCopyPreferredCaptioningMediaCharacteristics(kMACaptionAppearanceDomainUser);
NSArray *captionSettings = (__bridge NSArray*)captioningMediaCharacteristics;
if ([captionSettings containsObject:AVMediaCharacteristicTranscribesSpokenDialogForAccessibility]) {