Skip to content

Commit

Permalink
Merge pull request #1950 from cewert/fix-caption-timeout-crash
Browse files Browse the repository at this point in the history
  • Loading branch information
cewert authored Oct 6, 2024
2 parents d17a8d9 + b1809c0 commit 41c870c
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions components/captionTask.bs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import "pkg:/source/utils/config.bs"
import "pkg:/source/api/baserequest.bs"
import "pkg:/source/roku_modules/log/LogMixin.brs"

sub init()
m.log = log.Logger("captionTask")
m.top.observeField("url", "fetchCaption")
m.top.currentCaption = []
m.top.currentPos = 0
Expand Down Expand Up @@ -41,17 +43,26 @@ sub setFont()
end sub

sub fetchCaption()
m.log.debug("start fetchCaption()")
m.captionTimer.control = "stop"
re = CreateObject("roRegex", "(http.*?\.vtt)", "s")
url = re.match(m.top.url)[0]

if url <> invalid
port = createObject("roMessagePort")
m.reader.setUrl(url)
text = m.reader.GetToString()
m.captionList = parseVTT(text)
m.captionTimer.control = "start"
m.reader.setMessagePort(port)
if m.reader.AsyncGetToString()
msg = port.waitMessage(0)
if type(msg) = "roUrlEvent"
m.captionList = parseVTT(msg.GetString())
m.captionTimer.control = "start"
end if
end if
else
m.captionTimer.control = "stop"
end if
m.log.debug("end fetchCaption()", url)
end sub

function newlabel(txt)
Expand Down

0 comments on commit 41c870c

Please sign in to comment.