Subtitles
Subtitle selection can be performed with the SDK via the player controller native interface. Currently, the SDK subclass AVPlayer allows only for the activation and deactivation of subtitles.
Prerequisites
A clear stream with subtitles is available for testing.
Example code
The following code sample shows how to select subtitles.
- (void)onTrackChanged
{
NSArray* subtitlesArray = [_playerController getTrackInfo];
if (subtitlesArray) {
[subtitlesArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
NMPTrackInfo* trackInfo = subtitlesArray[idx];
NMPCLog(@"Subtitle track %d: type is %d, language is %@", idx, trackInfo.type, trackInfo.language);
// Current SDK only returns one track.
NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults];
bool subtitleEnabled = [userDefaults boolForKey:@"subtitleSwitch"];
if (subtitleEnabled) {
[_playerController selectTrack:0];
}
}];
}
}
See the NMPAVPla
See the NMPAVPlayer class reference for details of the API calls used above.