Skip to content

Commit

Permalink
Remove font files from pkg
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jkim2492 committed Feb 1, 2023
1 parent 2b56ed5 commit 0bcb779
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 27 deletions.
14 changes: 4 additions & 10 deletions components/JFVideo.brs
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,26 @@ sub init()
m.top.observeField("content", "onContentChange")

'Captions
m.captionBG = m.top.findNode("captionBG")
m.captionGroup = m.top.findNode("captionGroup")

for i = 1 to 9
m.captionGroup.appendChild(createObject("roSGNode", "LayoutGroup"))
end for
m.captionTask = createObject("roSGNode", "captionTask")
m.captionTask.observeField("currentCaption", "updateCaption")
m.top.observeField("captionVisible", "toggleCaption")
m.top.observeField("currentSubtitleTrack", "loadCaption")
end sub

sub loadCaption()
' if type (m.top.currentSubtitleTrack) <> invalid then
m.captionTask.url = m.top.currentSubtitleTrack
' end if
end sub

sub toggleCaption()
m.captionGroup.visible = m.top.captionVisible
m.captionBG.visible = m.top.captionVisible
end sub

sub updateCaption ()
while m.captionGroup.removeChildIndex(0)
end while
m.captionGroup.appendChildren(m.captionTask.currentCaption)
m.captionBG.height = m.captionGroup.BoundingRect().height
m.captionBG.width = m.captionGroup.BoundingRect().width
m.captionGroup.replaceChildren(m.captionTask.currentCaption, 0)
end sub

' Event handler for when video content field changes
Expand Down
6 changes: 1 addition & 5 deletions components/JFVideo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@
<script type="text/brightscript" uri="pkg:/source/roku_modules/api/api.brs" />

<children>

<LayoutGroup horizAlignment="center" vertAlignment="center" translation="[960,980]">
<Rectangle id="captionBG" color="#323232BF" height="0" width="0" />
</LayoutGroup>
<LayoutGroup id="captionGroup" horizAlignment="center" vertAlignment="center" translation="[960,980]"></LayoutGroup>
<Group id="captionGroup" translation="[960,1020]"></Group>

<timer id="playbackTimer" repeat="true" duration="30" />
<timer id="bufferCheckTimer" repeat="true" />
Expand Down
83 changes: 71 additions & 12 deletions components/captionTask.brs
Original file line number Diff line number Diff line change
@@ -1,20 +1,43 @@
sub init()
m.top.observeField("url", "fetchCaption")
m.top.currentCaption = []
m.top.currentCaption = CreateObject("roArray", 9, true)
m.top.currentPos = 0

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

m.captionList = []
m.reader = createObject("roUrlTransfer")

m.font = CreateObject("roSGNode", "Font")
m.font.uri = "pkg:/components/fonts/noto.otf"
m.font.size = 50
' m.font = "font:LargeSystemFont"
fetchFont()
end sub


sub fetchFont()
fs = CreateObject("roFileSystem")
fontlist = fs.Find("tmp:/", ".*\.(otf|ttf)")
if fontlist.count() = 0
re = CreateObject("roRegex", "Name.:.(.*?).,.Size", "s")
m.filename = APIRequest("FallbackFont/Fonts").GetToString()
m.filename = re.match(m.filename)
if m.filename.count() <> 0
m.filename = m.filename[1]
APIRequest("FallbackFont/Fonts/" + m.filename).gettofile("tmp:/" + m.filename)
m.font.uri = "tmp:/" + m.filename
m.font.size = 60
else
m.font = "font:LargeBoldSystemFont"
end if
else
?"font exists"
m.font.uri = fontlist[0]
?m.font.uri
m.font.size = 60
end if
end sub



sub fetchCaption()
re = CreateObject("roRegex", "(http.*?\.vtt)", "s")
url = re.match(m.top.url)[0]
Expand All @@ -28,22 +51,58 @@ sub fetchCaption()
end if
end sub

function newlabel(txt):
label = CreateObject("roSGNode", "Label")
label.text = txt
label.font = m.font
label.color = &H000000FF
label.height = 108
return label
end function

function newlayout(labels)
invis = CreateObject("roSGNode", "Label")
invis.visible = False
l = labels.count()
newlg = CreateObject("roSGNode", "LayoutGroup")
for i = 0 to 7 - l
newlg.appendchild(invis.clone(True))
end for
newlg.appendchildren(labels)
newlg.horizalignment = "center"
newlg.vertalignment = "bottom"

return newlg
end function


sub updateCaption ()
' Stop updating captions if the video isn't playing
if m.top.playerState = "playing"
m.top.currentPos = m.top.currentPos + 100
tmp = []
texts = []
for each entry in m.captionList
if entry["start"] <= m.top.currentPos and m.top.currentPos <= entry["end"]
label = CreateObject("roSGNode", "Label")
label.text = entry["text"]
label.font = m.font
tmp.push(label)
texts.push(entry["text"])
end if
end for
m.top.currentCaption = tmp
labels = []
for each text in texts
labels.push(newlabel (text))
end for
lg = newlayout(labels)
lglist = []
coords = [[-1, -1], [-1, 0], [-1, 1], [0, -1], [0, 1], [1, -1], [1, 0], [1, 1], [0, 0]]
for p = 0 to 8
lgg = lg.clone(True)
lgg.translation = [coords[p][0] * 5, coords[p][1] * 5]
lglist.push(lgg)
end for
for q = 0 to 7
lglist[8].getchild(q).color = &HFFFFFFFF
end for
m.top.currentCaption = lglist
end if
' end if
end sub

function ms(t) as integer
Expand Down
2 changes: 2 additions & 0 deletions components/captionTask.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<field id="currentPos" type="int" />
</interface>
<script type="text/brightscript" uri="captionTask.brs" />
<script type="text/brightscript" uri="pkg:/source/utils/config.brs" />
<script type="text/brightscript" uri="pkg:/source/api/baserequest.brs" />
<children>
<timer id="captionTimer" repeat="true" duration="0.1" />
</children>
Expand Down
Binary file removed components/fonts/noto.otf
Binary file not shown.
Binary file removed components/fonts/notoB.otf
Binary file not shown.
Binary file removed fonts/noto.otf
Binary file not shown.
Binary file removed fonts/notoB.otf
Binary file not shown.

0 comments on commit 0bcb779

Please sign in to comment.