Set closed-caption styles

You can style the closed-caption text with PSDK methods.

  1. Create a TextFormatBuilder instance.

    You can optionally provide all the closed-caption styling parameters at construction time, or set them later.

    The PSDK encapsulates closed-caption styling information inside the TextFormat interface. The TextFormatBuilder is a utility class that allows you to obtain a reference to an object that implements this interface.

    public TextFormatBuilder(
       Font font,
       Size size,
       FontEdge fontEdge,
       Color fontColor,
       Color backgroundColor,
       Color fillColor,
       Color edgeColor,
       int fontOpacity,
       int backgroundOpacity,
       int fillOpacity)
    
  2. To obtain a reference to an object that implements the TextFormat interface, you can call the TextFormatBuilder.toTextFormat public method. This returns a TextFormat object that can be applied to the media player.
    public TextFormat toTextFormat()
    
  3. To get the current closed-caption style settings, you can do either of the following:
    • Get all the settings at once with the MediaPlayer.getCCStyle getter method. The return value is an instance of the TextFormat interface.
      /**
      * @return the current closed captioning style. 
      * If no style was previously set, it returns a TextFormat object
      * with default values for each attribute.
      * @throws IllegalStateException if media player was already released.
      */
      public TextFormat getCCStyle() throws IllegalStateException;
      
    • Get the settings one at a time through the TextFormat interface getter methods.
      public Color getFontColor();
      public Color getBackgroundColor();
      public Color getFillColor(); // retrieve the font fill color
      public Color getEdgeColor(); // retrieve the font edge color
      public Size getSize(); // retrieve the font size
      public FontEdge getFontEdge(); // retrieve the font edge type
      public Font getFont(); // retrieve the font type
      public int getFontOpacity();
      public int getBackgroundOpacity();
      
  4. To change the styling settings, you can do either of the following:
    • Use the setter method MediaPlayer.setCCStyle, passing an instance of the TextFormat interface as the single input parameter.
      /**
      * Sets the closed captioning style. Used to control the closed captioning font,
      * size, color, edge and opacity. 
      *
      * This method is safe to use even if the current media stream doesn't have closed
      * captions.
      *
      * @param textFormat
      * @throws IllegalStateException
      */
      public void setCCStyle(TextFormat textFormat) throws IllegalStateException;
      
    • Use the TextFormatBuilder class, which defines individual setter methods.

      The TextFormat interface defines an immutable object: there are only getter methods and no setters. You can set the closed-caption styling parameters only when dealing with the TextFormatBuilder class.

      // set font type
      public void setFont(Font font) 
      public void setBackgroundColor(Color backgroundColor)
      public void setFillColor(Color fillColor)
      // set the font-edge color
      public void setEdgeColor(Color edgeColor) 
      // set the font size
      public void setSize(Size size) 
      // set the font edge type
      public void setFontEdge(FontEdge fontEdge) 
      public void setFontOpacity(int fontOpacity)
      public void setBackgroundOpacity(int backgroundOpacity)
      // set the font-fill opacity level
      public void setFillOpacity(int fillOpacity) 
      public void setFontColor(Color fontColor)
      
    Note: Setting the closed-caption style is an asynchronous operation and it may take up to a few seconds to see the actual changes on the screen.