Fundamental Closed Caption Functions on iOS

A simple programming example shows the basic functions on iOS to get and set the closed caption (CC) language.

Note: Be sure you have setup the required DFXP (now TTML) files for all your videos, as detailed Required Closed Caption Setup in Backlot. This simple example shows some of the basic function calls for programming with closed captions on iOS:
  • Shown first here is a check for the OOOoyalaPlayerCurrentItemChangedNotification event, which in this context indicates that the video and its associated DFXP (now TTML) file have been loaded. (Event programming is not required for working with closed captions, but is shown here only as a useful feature. If you are interested in more details about event programming, see Working with Events.)
  • To find out what languages are available for the video, use the availableClosedCaptionsLanguages function, which returns an array named availableLanguages in this example.
  • Then, with the closedCaptionsLanguage function you can actually set the desired language. This example checks if English ("en") is available and sets the captions to that language.
 - (void) notificationReceived:(NSNotification*)notification {
  if ([ isEqualToString:OOOoyalaPlayerCurrentItemChangedNotification]) {
    NSArray* availableLanaguegs = [ooyalaPlayerViewController.player availableClosedCaptionsLanguages];
    for (NSString *language in availableLanaguegs) {
      if ([language isEqualToString:@"en"]) {
      [ooyalaPlayerViewController.player OOOoyalaPlayerViewController *oopvc = ...;
        oopvc. closedCaptionsLanguage = @"en";];

Was this article helpful?