Skip to content

Commit 56fa288

Browse files
committed
Merge branch 'dev' into release/5.3.0
2 parents 48de6d2 + ed39edf commit 56fa288

File tree

8 files changed

+513
-0
lines changed

8 files changed

+513
-0
lines changed

docs/_sidebar.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
- Plugins
44
- [Accessibility](/plugins/accessibility.md)
5+
- [App](/plugins/app.md)
56
- [Utils](/plugins/utils.md)
67
- [Storage](/plugins/storage.md)
78
- [Settings](/plugins/settings.md)

docs/plugins/app.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# App
2+
3+
SDK provides various methods that can be used within the application.
4+
5+
## Available Methods
6+
7+
### overRideKeyMap
8+
9+
This method can be used to merge and override the existing keymap (coming from `settings.json`) by using a custom keymap in runtime. The method will merge all key mappings by overriding the existing key mappings with the new ones when a key is defined in both keymaps.
10+
11+
`keepDuplicates` flag is set to `false` by default, which means duplicated values (like two different keys trigger the `Back` action) will be removed from the final keymap. If `keepDuplicates` is set to `true`, duplicated **values** will be kept in the final keymap.
12+
13+
#### Usage
14+
15+
```js
16+
const customKeyMap = {
17+
13: "Enter",
18+
83: "Search"
19+
}
20+
21+
this.application.overRideKeyMap(customKeyMap) // keepDuplicates = false
22+
```
23+
24+
or
25+
26+
```js
27+
this.application.overRideKeyMap(customKeyMap, true) // keepDuplicates = true
28+
```
29+
30+
#### Parameters
31+
32+
- `customKeyMap` : keymap object
33+
- `keepDuplicates`: flag to keep duplicated values in the final keymap or not. The default value is `false`.

docs/plugins/subtitles.md

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
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+
```

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,4 @@ export { default as TV } from './src/TV'
4343
export { default as Utils } from './src/Utils'
4444
export { default as VideoPlayer } from './src/VideoPlayer'
4545
export { default as Metadata } from './src/Metadata'
46+
export { default as Subtitles } from './src/Subtitles'

src/Application/index.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,32 @@ export default function(App, appData, platformSettings) {
119119
Accessibility.colorshift(this, type, config)
120120
}
121121

122+
get keymapping() {
123+
return this.stage.application.config.keys
124+
}
125+
126+
/**
127+
* This function overides the default keymap with the latest keymap.
128+
* @param customKeymap
129+
* @param keepDuplicates
130+
*/
131+
overRideKeyMap(customKeymap, keepDuplicates = false) {
132+
const baseKeymap = this.stage.application.config.keys
133+
Object.keys(customKeymap).reduce((keymapping, key) => {
134+
// prevent duplicate values to exist in final keymapping (i.e. 2 keys triggering 'Back')
135+
if (!keepDuplicates) {
136+
Object.keys(baseKeymap).forEach(baseKey => {
137+
if (baseKey != key && baseKeymap[baseKey] == customKeymap[key]) {
138+
delete keymapping[baseKey]
139+
}
140+
})
141+
}
142+
keymapping[key] = customKeymap[key]
143+
return keymapping
144+
}, baseKeymap)
145+
return baseKeymap
146+
}
147+
122148
_setup() {
123149
Promise.all([
124150
this.loadFonts((App.config && App.config.fonts) || (App.getFonts && App.getFonts()) || []),

0 commit comments

Comments
 (0)