|
| 1 | +# Subtitles |
| 2 | + |
| 3 | +You can use the *Subtitles* plugin to easily display Subtitles (or Closed Captions) in your App. |
| 4 | + |
| 5 | +The plugin comes with some basic styling of Subtitles and offers the option to customize them, such as font size, colors, and positioning. |
| 6 | + |
| 7 | +> The Subtitles plugins in the Lightning-SDK only offers an API for displaying Subtitles. |
| 8 | +
|
| 9 | +> Retrieving subtitles from a video stream or a remote API is not part of the Plugin's functionality as it's very App and / or Platform specific. |
| 10 | +
|
| 11 | +## Usage |
| 12 | + |
| 13 | +If you want to display Subtitles in your App, first import the Subtitles plugin from the Lightning SDK: |
| 14 | + |
| 15 | +```js |
| 16 | +import { Subtitles } from '@lightningjs/sdk' |
| 17 | +``` |
| 18 | + |
| 19 | +## Available Methods |
| 20 | + |
| 21 | +### show |
| 22 | + |
| 23 | +Sets the visibility of Subtitles to `true`, to display Subtitles. |
| 24 | + |
| 25 | +```js |
| 26 | +Subtitles.show() |
| 27 | +``` |
| 28 | + |
| 29 | +### hide |
| 30 | + |
| 31 | +Sets the visibility of Subtitles to `false`, to hide Subtitles. |
| 32 | + |
| 33 | +```js |
| 34 | +Subtitles.hide() |
| 35 | +``` |
| 36 | + |
| 37 | +### text |
| 38 | + |
| 39 | +Sets the text of the Subtitles text. |
| 40 | + |
| 41 | +```js |
| 42 | +Subtitles.text('Subtitle Text') |
| 43 | +``` |
| 44 | + |
| 45 | +### clear |
| 46 | + |
| 47 | +Clears the text of the Subtitles text. |
| 48 | + |
| 49 | +```js |
| 50 | +Subtitles.clear() |
| 51 | +``` |
| 52 | + |
| 53 | +### styles |
| 54 | + |
| 55 | +Sets the styles of the Subtitles text. This is a short hand method for setting the following styles: `fontFamily`, `fontSize`, `fontColor`, `backgroundColor`, `textAlign`. If any of these styles are not set, the default values will be used. |
| 56 | + |
| 57 | +```js |
| 58 | +Subtitles.styles({ |
| 59 | + fontFamily: 'sans-serif', |
| 60 | + fontSize: 45, |
| 61 | + fontColor: 0xffffffff, |
| 62 | + backgroundColor: 0x90000000, |
| 63 | + textAlign: 'center', |
| 64 | +}) |
| 65 | +``` |
| 66 | +### fontFamily |
| 67 | + |
| 68 | +Sets the `fontFamily` style of the Subtitles text. |
| 69 | + |
| 70 | +```js |
| 71 | +Subtitles.fontFamily('sans-serif') |
| 72 | +``` |
| 73 | + |
| 74 | +### fontSize |
| 75 | + |
| 76 | +Sets the `fontSize` style of the Subtitles text. |
| 77 | + |
| 78 | +```js |
| 79 | +Subtitles.fontSize(50) |
| 80 | +``` |
| 81 | + |
| 82 | +### fontColor |
| 83 | + |
| 84 | +Sets the `fontColor` style of the Subtitles text |
| 85 | + |
| 86 | +```js |
| 87 | +Subtitles.fontColor(0xffffffff) |
| 88 | +``` |
| 89 | + |
| 90 | +### backgroundColor |
| 91 | + |
| 92 | +Sets the `backgroundColor` style of the Subtitles text |
| 93 | + |
| 94 | +```js |
| 95 | +Subtitles.backgroundColor(0x90000000) |
| 96 | +``` |
| 97 | + |
| 98 | +### textAlign |
| 99 | + |
| 100 | +Sets the `textAlign` style of the Subtitles text |
| 101 | + |
| 102 | +```js |
| 103 | +Subtitles.textAlign('center') |
| 104 | +``` |
| 105 | + |
| 106 | +### position |
| 107 | + |
| 108 | +Sets the x and y positions of the Subtitles text. |
| 109 | + |
| 110 | +`x` value must be either a number or one of the following options: `'left'`, `'center'`, `'right'`. The default value for `x` is `'center'`. |
| 111 | + |
| 112 | +`y` value must be either a number or one of the following options: `'top'`, `'center'`, `'bottom'`. The default value for `y` is 'bottom'. |
| 113 | + |
| 114 | +```js |
| 115 | +Subtitles.position('center', 'top') |
| 116 | +Subtitles.position(100, 100) |
| 117 | +``` |
| 118 | + |
| 119 | +### viewport |
| 120 | + |
| 121 | +Sets the width and height for the viewport of the Subtitles text. The viewport is the area in which the Subtitles text will be displayed. By default, Subtitles assumes the viewport is the same size as the App. If your video player is smaller, you can set the viewport to match the size of the video player to correctly position the Subtitles text. |
| 122 | + |
| 123 | +The first argument is the width of the viewport, the second argument is the height of the viewport. |
| 124 | + |
| 125 | + |
| 126 | +```js |
| 127 | +Subtitles.viewport(854, 480) |
| 128 | +``` |
| 129 | + |
| 130 | +### maxWidth |
| 131 | + |
| 132 | +Sets the maximum width of the Subtitles text. |
| 133 | + |
| 134 | +```js |
| 135 | +Subtitles.maxWidth(1200) |
| 136 | +``` |
| 137 | + |
| 138 | +### maxLines |
| 139 | + |
| 140 | +Sets the maximum number of lines for the Subtitles text. |
| 141 | + |
| 142 | +```js |
| 143 | +Subtitles.maxLines(2) |
| 144 | +``` |
0 commit comments