Text displayers

Code samples

PRESTOplay for Web Apps renders text cues with one of two displayers: the HTML displayer, which is recommended, or the browser’s native text displayer.

HTML displayer

The HTML displayer renders text cues using the HTML surface, with rich styling capabilities and consistent results across browsers. It has strong support for rendering parsed TTML, SMPTE-TT, IMSC1, WebVTT, and SRT cues.

To use it:

  1. Add the PRESTOplay default styles to your page:

    <link rel="stylesheet" href="clpp.styles.css">
    
  2. Import the HTML Cue module:

    import "@castlabs/prestoplay/cl.htmlcue";
    

The HTML text displayer is used by default once @castlabs/prestoplay/cl.htmlcue is imported. Set enableHtmlCue to false in the player configuration to change this.

<link rel="stylesheet" href="clpp.styles.css">
<video id="video" width="640" height="360" crossorigin="anonymous" controls></video>
<script type="module">
  import { clpp } from "@castlabs/prestoplay";
  import "@castlabs/prestoplay/cl.mse";
  import "@castlabs/prestoplay/cl.dash";
  import "@castlabs/prestoplay/cl.ttml";
  import "@castlabs/prestoplay/cl.vtt";
  import "@castlabs/prestoplay/cl.htmlcue";

  const player = new clpp.Player('video', {});

  player.open({
    source: '//demo.cf.castlabs.com/media/prestodash/Manifest.mpd'
  });
</script>

Styling

Styles apply in this order, from lowest to highest priority:

  1. Player styles

  2. Website styles

  3. Embedded styles

  4. Text style options

Player styles come from clpp.styles.css and are required — they provide default styles for text cues and regions.

Override the default styles with your own stylesheet by extending the .clpp-text-container, .clpp-text-cue, or .clpp-text-cue-region classes. Website styles take priority over default styles.

A text track can contain embedded styles, which take priority over website and default styles.

Text style options, set in the player configuration or through player.getTextDisplayer(), take priority over embedded, website, and default styles. Use these to let your users customize the look and feel of subtitles.

Font size

The HTML displayer adjusts a base font size to the container size for responsive design. By default, the font size is 7% of the container height. Adjust it in the player configuration:

const playerConfig = {
  // ...
  textStyle: {
    fontSizePercent: 0.03
  }
};

Native text displayer

Styling

Style text cues using text style options in the player configuration:

const playerConfig = {
  // ...
  textStyle: {
    backgroundColor: 'rgba(207, 0, 15, 0.75)',
    fontFamily: 'monospace',
    fontColor: 'blue',
    fontSize: '1.2em',
    edgeColor: 'green',
    edgeType: clpp.text.EdgeType.DROP_SHADOW
  }
}

Or style cues on the fly through a text displayer instance:

player.getTextDisplayer().setFontColor('blue');

Native text-cue styling has some constraints:

  • It requires Edge 19 or later.

  • Background color and opacity are configurable on browsers other than Safari (macOS/iPadOS/iOS) and Chrome (macOS).

Use the HTML displayer to style text cues consistently across all supported browsers.

Next topic: Thumbnails
Previous topic: Side-loaded text tracks