diff --git a/ios/RCTVideo.m b/ios/RCTVideo.m index 00b3ceb1..c1a1bc9a 100644 --- a/ios/RCTVideo.m +++ b/ios/RCTVideo.m @@ -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]) {