Skip to content

Commit 0bcb779

Browse files
committed
Remove font files from pkg
Now it downloads from the fallback folder if available. Defaults to LargeBoldSystemFont. Subtitles are displayed with an outline instead of a background rectangle TODO : take captionstyle into account
1 parent 2b56ed5 commit 0bcb779

File tree

8 files changed

+78
-27
lines changed

8 files changed

+78
-27
lines changed

components/JFVideo.brs

+4-10
Original file line numberDiff line numberDiff line change
@@ -31,32 +31,26 @@ sub init()
3131
m.top.observeField("content", "onContentChange")
3232

3333
'Captions
34-
m.captionBG = m.top.findNode("captionBG")
3534
m.captionGroup = m.top.findNode("captionGroup")
36-
35+
for i = 1 to 9
36+
m.captionGroup.appendChild(createObject("roSGNode", "LayoutGroup"))
37+
end for
3738
m.captionTask = createObject("roSGNode", "captionTask")
3839
m.captionTask.observeField("currentCaption", "updateCaption")
3940
m.top.observeField("captionVisible", "toggleCaption")
4041
m.top.observeField("currentSubtitleTrack", "loadCaption")
4142
end sub
4243

4344
sub loadCaption()
44-
' if type (m.top.currentSubtitleTrack) <> invalid then
4545
m.captionTask.url = m.top.currentSubtitleTrack
46-
' end if
4746
end sub
4847

4948
sub toggleCaption()
5049
m.captionGroup.visible = m.top.captionVisible
51-
m.captionBG.visible = m.top.captionVisible
5250
end sub
5351

5452
sub updateCaption ()
55-
while m.captionGroup.removeChildIndex(0)
56-
end while
57-
m.captionGroup.appendChildren(m.captionTask.currentCaption)
58-
m.captionBG.height = m.captionGroup.BoundingRect().height
59-
m.captionBG.width = m.captionGroup.BoundingRect().width
53+
m.captionGroup.replaceChildren(m.captionTask.currentCaption, 0)
6054
end sub
6155

6256
' Event handler for when video content field changes

components/JFVideo.xml

+1-5
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,7 @@
3232
<script type="text/brightscript" uri="pkg:/source/roku_modules/api/api.brs" />
3333

3434
<children>
35-
36-
<LayoutGroup horizAlignment="center" vertAlignment="center" translation="[960,980]">
37-
<Rectangle id="captionBG" color="#323232BF" height="0" width="0" />
38-
</LayoutGroup>
39-
<LayoutGroup id="captionGroup" horizAlignment="center" vertAlignment="center" translation="[960,980]"></LayoutGroup>
35+
<Group id="captionGroup" translation="[960,1020]"></Group>
4036

4137
<timer id="playbackTimer" repeat="true" duration="30" />
4238
<timer id="bufferCheckTimer" repeat="true" />

components/captionTask.brs

+71-12
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,43 @@
11
sub init()
22
m.top.observeField("url", "fetchCaption")
3-
m.top.currentCaption = []
3+
m.top.currentCaption = CreateObject("roArray", 9, true)
44
m.top.currentPos = 0
55

66
m.captionTimer = m.top.findNode("captionTimer")
77
m.captionTimer.ObserveField("fire", "updateCaption")
88

99
m.captionList = []
1010
m.reader = createObject("roUrlTransfer")
11-
1211
m.font = CreateObject("roSGNode", "Font")
13-
m.font.uri = "pkg:/components/fonts/noto.otf"
14-
m.font.size = 50
15-
' m.font = "font:LargeSystemFont"
12+
fetchFont()
1613
end sub
1714

15+
16+
sub fetchFont()
17+
fs = CreateObject("roFileSystem")
18+
fontlist = fs.Find("tmp:/", ".*\.(otf|ttf)")
19+
if fontlist.count() = 0
20+
re = CreateObject("roRegex", "Name.:.(.*?).,.Size", "s")
21+
m.filename = APIRequest("FallbackFont/Fonts").GetToString()
22+
m.filename = re.match(m.filename)
23+
if m.filename.count() <> 0
24+
m.filename = m.filename[1]
25+
APIRequest("FallbackFont/Fonts/" + m.filename).gettofile("tmp:/" + m.filename)
26+
m.font.uri = "tmp:/" + m.filename
27+
m.font.size = 60
28+
else
29+
m.font = "font:LargeBoldSystemFont"
30+
end if
31+
else
32+
?"font exists"
33+
m.font.uri = fontlist[0]
34+
?m.font.uri
35+
m.font.size = 60
36+
end if
37+
end sub
38+
39+
40+
1841
sub fetchCaption()
1942
re = CreateObject("roRegex", "(http.*?\.vtt)", "s")
2043
url = re.match(m.top.url)[0]
@@ -28,22 +51,58 @@ sub fetchCaption()
2851
end if
2952
end sub
3053

54+
function newlabel(txt):
55+
label = CreateObject("roSGNode", "Label")
56+
label.text = txt
57+
label.font = m.font
58+
label.color = &H000000FF
59+
label.height = 108
60+
return label
61+
end function
62+
63+
function newlayout(labels)
64+
invis = CreateObject("roSGNode", "Label")
65+
invis.visible = False
66+
l = labels.count()
67+
newlg = CreateObject("roSGNode", "LayoutGroup")
68+
for i = 0 to 7 - l
69+
newlg.appendchild(invis.clone(True))
70+
end for
71+
newlg.appendchildren(labels)
72+
newlg.horizalignment = "center"
73+
newlg.vertalignment = "bottom"
74+
75+
return newlg
76+
end function
77+
78+
3179
sub updateCaption ()
3280
' Stop updating captions if the video isn't playing
3381
if m.top.playerState = "playing"
3482
m.top.currentPos = m.top.currentPos + 100
35-
tmp = []
83+
texts = []
3684
for each entry in m.captionList
3785
if entry["start"] <= m.top.currentPos and m.top.currentPos <= entry["end"]
38-
label = CreateObject("roSGNode", "Label")
39-
label.text = entry["text"]
40-
label.font = m.font
41-
tmp.push(label)
86+
texts.push(entry["text"])
4287
end if
4388
end for
44-
m.top.currentCaption = tmp
89+
labels = []
90+
for each text in texts
91+
labels.push(newlabel (text))
92+
end for
93+
lg = newlayout(labels)
94+
lglist = []
95+
coords = [[-1, -1], [-1, 0], [-1, 1], [0, -1], [0, 1], [1, -1], [1, 0], [1, 1], [0, 0]]
96+
for p = 0 to 8
97+
lgg = lg.clone(True)
98+
lgg.translation = [coords[p][0] * 5, coords[p][1] * 5]
99+
lglist.push(lgg)
100+
end for
101+
for q = 0 to 7
102+
lglist[8].getchild(q).color = &HFFFFFFFF
103+
end for
104+
m.top.currentCaption = lglist
45105
end if
46-
' end if
47106
end sub
48107

49108
function ms(t) as integer

components/captionTask.xml

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
<field id="currentPos" type="int" />
88
</interface>
99
<script type="text/brightscript" uri="captionTask.brs" />
10+
<script type="text/brightscript" uri="pkg:/source/utils/config.brs" />
11+
<script type="text/brightscript" uri="pkg:/source/api/baserequest.brs" />
1012
<children>
1113
<timer id="captionTimer" repeat="true" duration="0.1" />
1214
</children>

components/fonts/noto.otf

-4.52 MB
Binary file not shown.

components/fonts/notoB.otf

-4.68 MB
Binary file not shown.

fonts/noto.otf

-4.52 MB
Binary file not shown.

fonts/notoB.otf

-4.68 MB
Binary file not shown.

0 commit comments

Comments
 (0)