Commit fa30fb3e authored by Ash Mishra's avatar Ash Mishra
Browse files

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

remove tracks that are not valid from textTracks; and default to system if selectedTextTrack unavailable
parent 352bad21
Loading
Loading
Loading
Loading
+10 −1
Changes for ios/RCTVideo.m: 10 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -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]) {