Fix for textTracks not being set before selectedTextTrack (bug found on iOS 9.3)

This commit is contained in:
Ash Mishra 2018-07-06 16:38:24 -07:00
parent 05d4be2d9c
commit fa63a9ef87

View File

@ -350,7 +350,7 @@ static NSString *const timedMetadata = @"timedMetadata";
bool isNetwork = [RCTConvert BOOL:[source objectForKey:@"isNetwork"]];
bool isAsset = [RCTConvert BOOL:[source objectForKey:@"isAsset"]];
NSString *uri = [source objectForKey:@"uri"];
NSString *subtitleUri = _selectedTextTrack[@"uri"];
NSString *subtitleUri = self.selectedTextTrack[@"uri"];
NSString *type = [source objectForKey:@"type"];
NSDictionary *headers = [source objectForKey:@"requestHeaders"];
@ -381,7 +381,7 @@ static NSString *const timedMetadata = @"timedMetadata";
asset = [AVURLAsset URLAssetWithURL:[[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:uri ofType:type]] options:nil];
}
if (!_textTracks || !_selectedTextTrack) return [AVPlayerItem playerItemWithAsset:asset];
if (!_textTracks || !self.selectedTextTrack) return [AVPlayerItem playerItemWithAsset:asset];
// otherwise sideload text tracks
AVAssetTrack *videoAsset = [asset tracksWithMediaType:AVMediaTypeVideo].firstObject;
@ -721,19 +721,20 @@ static NSString *const timedMetadata = @"timedMetadata";
_repeat = repeat;
}
- (NSDictionary*) selectedTextTrack {
if (_textTracks) {
[self setSideloadedTextTrack];
}
else [self setStreamingTextTrack];
return _selectedTextTrack;
}
- (void)setSelectedTextTrack:(NSDictionary *)selectedTextTrack {
_selectedTextTrack = selectedTextTrack;
// when textTracks exist, we set side-loaded subtitles
if (_textTracks) {
[self setSideloadedTextTrack];
return;
}
// otherwise check for subtitles in the streaming asset (.m3u8)
[self setStreamingTextTrack];
}
- (void)setSideloadedTextTrack {