Radiant Media Player

Closed captions and subtitles documentation



Documentation sections


Scope of support

Radiant Media Player supports multi-languages closed captions (or subtitles) in the following formats:

  • Side-loaded WebVTT closed captions files for on-demand video. WebVTT files are passed to the player through the ccFiles player settings. This use-case is supported for HLS, DASH & progressive download
  • In-manifest/in-band closed captions for live and on-demand video:
    • HLS: WebVTT & CEA 608/708
    • DASH: WebVTT & TTML

Captions can be customised with CSS or player settings to better fit your project requirements.

Casting and managing captions is also supported with Google Cast.


Side-loaded WebVTT closed captions files

Player settings

This section refers to the side-loading of WebVTT files that can be fed to the player through the ccFiles player settings. As of player version 4.7.1, 2 VTT parsers are available: vtt.js and native browser rendering. For vtt.js, all WebVTT files are ajax-loaded and as such appropriate CORS settings are expected for retrieval of WebVTT files.

ccFiles: Array

This setting holds WebVTT closed captions files location to be displayed along the video within the player. Default: []. Multi-language WebVTT closed captions can be added to the player. Example:

var ccFiles = [
  ['en', 'English', 'https://www.radiantmediaplayer.com/media/cc.vtt'],
  ['fr', 'Français', 'https://www.radiantmediaplayer.com/media/cc-fr.vtt']
];
ccFiles[i]: Array

ccFiles[i][0] is the ISO 639-1 (two-letter) code for the closed captions language
ccFiles[i][1] is the human-readable label for the closed captions language (this information will be displayed within the player captions menu)
ccFiles[i][2] is the WebVTT closed captions file location for player.

It is possible to set a default attribute to a specific caption track. This will cause the related caption track to be activated by default when player starts. Example:

var ccFiles = [
  ['en', 'English', 'https://www.radiantmediaplayer.com/media/cc.vtt'],
  ['fr', 'Français', 'https://www.radiantmediaplayer.com/media/cc-fr.vtt', 'default']
];
ccParser: String

The player provides 2 parsers when displaying side-loaded VTT captions. The default option is vtt.js, which works on the vast majority of devices but is not available in iOS. The other option is using the native browser/WebView parser, which is less flexible and offers less customisation options. Available values are: 'vtt.js' or 'native'. 'native' is always used on iOS. Default: 'vtt.js'.

Styling WebVTT closed captions through player settings

The following player settings are available to style WebVTT closed captions when rendered with vtt.js. Captions style will be ported to Google Cast when casting is available.

  • ccFontSize: the captions font size in pixels - Number, default to -1 which means auto-guess
  • ccFSFontSize: the captions font size in pixels when in full screen mode - Number, default to -1 which means auto-guess
  • ccTextColor the captions text color - Hex code as String, default to 'FFFFFF'
  • ccBackgroundColor the captions background color - Hex code as String, default to '000000'
  • ccBackgroundAlpha the captions background opacity - Number, default to 0.85

Styling WebVTT closed captions through embedded WebVTT data

The player shall honor any standard-compliant styling & positioning information that are held within the WebVTT file (position, line, italic or bold tags ...).

Styling WebVTT closed captions with CSS

In HTML5 video captions are rendered above the video tag. This is the CSS layout structure when using vtt.js parser:

.rmp-container > .rmp-content > .rmp-cc-area > .rmp-cc-container > .rmp-cc-display > .rmp-cc-cue

Refer to the CSS information in the self-hosted player files package for further details on CSS applied for each section.

In iOS where captions are not rendered with vtt.js but with the native HTML5 track tag the CSS rules being applied are different. See the bottom of cc.less source file for more information.

Player example

Player code for the above example:

<!-- Include Radiant Media Player JavaScript file in your <body> or <head> -->
<script src="https://cdn.radiantmediatechs.com/rmp/5.0.6/js/rmp-vttjs-hlsjs.min.js"></script>
<!-- Player container element -->
<div id="rmpPlayer"></div>
<script>
var src = {
  hls: 'https://your-hls-url.m3u8'
};
// Your WebVTT closed captions
var ccFiles = [
  ['en', 'English', 'https://www.radiantmediaplayer.com/media/cc.vtt'],
  ['fr', 'Français', 'https://www.radiantmediaplayer.com/media/cc-fr.vtt']
];
// Your player settings
var settings = {
  licenseKey: 'your-license-key',
  src: src,
  width: 640,
  height: 360,
  ccFiles: ccFiles,
  crossorigin: 'anonymous', // On iOS (or when using ccParser: 'native') this is required for loading cross-origin VTT files
  poster: 'https://your-poster-url.jpg'
};
var elementID = 'rmpPlayer';
var rmp = new RadiantMP(elementID);
rmp.init(settings);
</script>

HLS & DASH in-manifest/in-band closed captions for live & on-demand video

Supported closed captions type

We support in-stream multi-language closed captions with HLS & DASH for the following caption types. Language information for the captions are directly read from the HLS or DASH manifest and automatically displayed on the player when detected. Note that in this case captions may be rendered with the native HTML5 track tag and as such browser support and styling options may vary.

  • HLS: WebVTT (in-manifest) & CEA 608/708 (in-band)
  • DASH: WebVTT & TTML (in-manifest)

Player code example

Following is a player code example for a DASH stream with embedded multi-language WebVTT captions.

<!-- Include Radiant Media Player JavaScript file in your <body> or <head> -->
<script src="https://cdn.radiantmediatechs.com/rmp/5.0.6/js/rmp.min.js"></script>
<!-- Player container element -->
<div id="rmpPlayer"></div>
<script>
// This sample DASH stream has multi-language VTT tracks referenced in its manifest
// The player will automatically pick them up and display the captions UI
var src = {
  dash: '//storage.googleapis.com/shaka-demo-assets/angel-one/dash.mpd' 
};
var settings = {
  licenseKey: 'your-license-key',
  src: src,
  width: 640,
  height: 360,
  poster: 'https://your-poster-url.jpg'
};
var elementID = 'rmpPlayer';
var rmp = new RadiantMP(elementID);
rmp.init(settings);
</script>

Captions API

Since Radiant Media Player 4.5.13 we provide a unified captions API allowing to programatically control captions being displayed by the player. This unified captions API works for HLS & DASH in-manifest/in-band closed captions and side-loaded WebVTT closed captions files. Refer to our player API documentation for guidance on using the player API.

Captions API events

texttrackchanged: this event fires each time a caption track change happens in the player. Note that this event also fires when all caption tracks become hidden ('off' state).

Captions API methods

showCaptions(lng)

When invoked, this method will display closed captions for the queried language passed as an input parameter. The input language parameter must be a 2 digit ISO 639-1 (two-letter) String for side-loaded WebVTT closed captions files. For HLS & DASH in-manifest/in-band captions you need to adhere to the language format provided in the manifest which may not be 2 digit ISO 639-1.

rmp.showCaptions('en');
hideCaptions()

When invoked, this method will hide all closed captions tracks.

rmp.hideCaptions();
getCCVisibleLanguage()

This method will return String representing the language code for the currently displayed caption track. For side-loaded WebVTT closed captions files this will be a 2 digit ISO 639-1 string. For HLS & DASH in-manifest/in-band captions this will be the format presented in the manifest which may not be 2 digit ISO 639-1. If no caption is displayed (meaning all captions tracks are hidden) 'off' is returned.

rmp.getCCVisibleLanguage();

The following API methods/events are only available when using side-loaded WebVTT captions through the ccFiles setting.

Captions API events

texttrackloaded: this event fires each time a text track is successfully loaded.

texttrackloaderror: this event fires each time a text track fails to load.

alltexttracksloaded: this event fires when all text tracks have been loaded. One text track must at least successfully load for this event to fire.

Captions API methods

getCaptionsData()

This method will return (Array|null) representing the raw data for the currently loaded captions track. Each item in the array is an Object representing a cue with the following properties available:

{
  align: String,
  endTime: Number,
  line: String,
  position: String,
  startTime: Number,
  text: String
}

This method should be invoked immediately after the texttrackchanged event has fired to get the raw data for the newly loaded captions track.

getCaptionsList()

This method will return (Array of Array|null) representing the successfully loaded text tracks. Tracks that fail to load will not be listed. This method becomes available when alltexttracksloaded event fires. Each track in the tracks list is an Array with the following ordered data (the following is an example or returned value):

[
  "en",
  "English",
  "Raw VTT text",
  "default"
]

For each track: index 0 shows the language code for the track - index 1 shows the human readable language for the track - index 2 shows the raw text parsed from the VTT files (on iOS this is not available, instead the URL to the VTT file is shown) - index 3 shows '' or 'default' depending on whether or not the track is set as default. All items from the list are String.

setCaptionsList(newCCFiles)

This method will update the available captions for the player when using side-loaded VTT captions (e.g. ccFiles setting).

var newCCFiles = [
  ['de', 'Deutsch', 'https://www.radiantmediaplayer.com/media/cc-de.vtt'],
  ['w3c', 'w3c', 'https://www.radiantmediaplayer.com/media/w3c.vtt']
];
rmp.setCaptionsList(newCCFiles);

Updating captions when changing player source

If you want to use update closed captions in the player several options are available:

  • Side-loaded VTT captions (preferred method)
    • Call setSrc with your new content source
    • When srcchanged event fires call setCaptionsList with your new list of captions
  • In-manifest VTT for HLS/DASH: when calling setSrc the player will attempt to update the available CC list, support for this feature varies depending on device/streaming engine
    • Shaka player: full support for DASH and HLS updates of VTT & TTML captions
    • hls.js: partial support for updates of VTT captions (updates of CEA* captions not supported) - feedback is welcomed to improve support
    • Native HLS (mainly for iOS): updates of captions depends on the native player capabilities to provide this feature - on iOS this means captions menu selector will only be available in fullscreen but will support changes in VTT captions when player source is changed
  • Destroy player instance and replace player from DOM: yet a more taxing method than using setSrc but that will allow to update the captions list reliably
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 3.0 License.