Merge pull request #1162 from nfb-onf/master

Fix for #1150 and improvements for #1143
This commit is contained in:
Hampton Maxwell 2018-08-01 13:45:02 -07:00 committed by GitHub
commit bf5974242c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -347,8 +347,12 @@ static int const RCTVideoUnset = -1;
} }
- (NSURL*) urlFilePath:(NSString*) filepath { - (NSURL*) urlFilePath:(NSString*) filepath {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); if ([filepath containsString:@"file://"]) {
return [NSURL URLWithString:filepath];
}
// code to support local caching
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* relativeFilePath = [filepath lastPathComponent]; NSString* relativeFilePath = [filepath lastPathComponent];
// the file may be multiple levels below the documents directory // the file may be multiple levels below the documents directory
NSArray* fileComponents = [filepath componentsSeparatedByString:@"Documents/"]; NSArray* fileComponents = [filepath componentsSeparatedByString:@"Documents/"];
@ -384,7 +388,7 @@ static int const RCTVideoUnset = -1;
NSArray *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]; NSArray *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies];
[assetOptions setObject:cookies forKey:AVURLAssetHTTPCookiesKey]; [assetOptions setObject:cookies forKey:AVURLAssetHTTPCookiesKey];
asset = [AVURLAsset URLAssetWithURL:[NSURL URLWithString:uri] options:assetOptions]; asset = [AVURLAsset URLAssetWithURL:[NSURL URLWithString:uri] options:assetOptions];
} else if (isAsset) { // assets on iOS have to be in the Documents folder } else if (isAsset) { // assets on iOS can be in the Bundle or Documents folder
asset = [AVURLAsset URLAssetWithURL:[self urlFilePath:uri] options:nil]; asset = [AVURLAsset URLAssetWithURL:[self urlFilePath:uri] options:nil];
} else { // file passed in through JS, or an asset in the Xcode project } else { // file passed in through JS, or an asset in the Xcode project
asset = [AVURLAsset URLAssetWithURL:[[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:uri ofType:type]] options:nil]; asset = [AVURLAsset URLAssetWithURL:[[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:uri ofType:type]] options:nil];
@ -411,6 +415,7 @@ static int const RCTVideoUnset = -1;
atTime:kCMTimeZero atTime:kCMTimeZero
error:nil]; error:nil];
NSMutableArray* validTextTracks = [NSMutableArray array];
for (int i = 0; i < _textTracks.count; ++i) { for (int i = 0; i < _textTracks.count; ++i) {
AVURLAsset *textURLAsset; AVURLAsset *textURLAsset;
NSString *textUri = [_textTracks objectAtIndex:i][@"uri"]; NSString *textUri = [_textTracks objectAtIndex:i][@"uri"];
@ -420,6 +425,8 @@ static int const RCTVideoUnset = -1;
textURLAsset = [AVURLAsset URLAssetWithURL:[self urlFilePath:textUri] options:nil]; textURLAsset = [AVURLAsset URLAssetWithURL:[self urlFilePath:textUri] options:nil];
} }
AVAssetTrack *textTrackAsset = [textURLAsset tracksWithMediaType:AVMediaTypeText].firstObject; AVAssetTrack *textTrackAsset = [textURLAsset tracksWithMediaType:AVMediaTypeText].firstObject;
if (!textTrackAsset) continue; // fix when there's no textTrackAsset
[validTextTracks addObject:[_textTracks objectAtIndex:i]];
AVMutableCompositionTrack *textCompTrack = [mixComposition AVMutableCompositionTrack *textCompTrack = [mixComposition
addMutableTrackWithMediaType:AVMediaTypeText addMutableTrackWithMediaType:AVMediaTypeText
preferredTrackID:kCMPersistentTrackID_Invalid]; preferredTrackID:kCMPersistentTrackID_Invalid];
@ -428,6 +435,9 @@ static int const RCTVideoUnset = -1;
atTime:kCMTimeZero atTime:kCMTimeZero
error:nil]; error:nil];
} }
if (validTextTracks.count != _textTracks.count) {
[self setTextTracks:validTextTracks];
}
return [AVPlayerItem playerItemWithAsset:mixComposition]; return [AVPlayerItem playerItemWithAsset:mixComposition];
} }
@ -848,7 +858,10 @@ static int const RCTVideoUnset = -1;
selectedTrackIndex = index; 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); CFArrayRef captioningMediaCharacteristics = MACaptionAppearanceCopyPreferredCaptioningMediaCharacteristics(kMACaptionAppearanceDomainUser);
NSArray *captionSettings = (__bridge NSArray*)captioningMediaCharacteristics; NSArray *captionSettings = (__bridge NSArray*)captioningMediaCharacteristics;
if ([captionSettings containsObject:AVMediaCharacteristicTranscribesSpokenDialogForAccessibility]) { if ([captionSettings containsObject:AVMediaCharacteristicTranscribesSpokenDialogForAccessibility]) {