如何将main.brs函数调用到其他.brs文件中? 你们能帮我吗?由于我是Roku中的新手。 我已经在customscreen.xml中给出了main.brs文件的路径,但是通过这种方法它不起作用 我有一个将状态设为0,1的API URL和另一个随机代码。我在main.brs中创建了一个函数,并在main本身中调用它们以在0和1状态以及custom.brs中显示不同的场景已经做了一个屏幕显示方法,所以现在我想要那个随机代码,以便我可以在屏幕上显示该随机代码 这是main.brs和自定义brs文件的代码
main.brs '**********版权所有2016 Roku Corp.保留所有权利。 **********
sub RunUserInterface()
screen = CreateObject("roSGScreen")
port = CreateObject("roMessagePort")
screen.SetMessagePort(port)
res=getauth()
response = parseJSON(res)
' print "what we got:"response
'
' print response.valid
' print response.atuh
' chck=status.valid
' print chck
status=response.valid
if status = "1" then
scene = screen.CreateScene("HomeScene")
screen.Show()
else
scene = screen.CreateScene("MessageScreen")
screen.Show()
while (true)
msg = wait(10, m.port)
msgType = type(msg)
endwhile
endif
oneRow = GetApiArray()
list = [
{
Title:"First row"
ContentList : oneRow
}
{
Title:"Second row"
ContentList : oneRow
}
]
scene.gridContent = ParseXMLContent(list)
while true
msg = wait(0, port)
print "------------------"
print "msg = "; msg
end while
if screen <> invalid then
screen.Close()
screen = invalid
end if
end sub
Function ParseXMLContent(list As Object)
RowItems = createObject("RoSGNode","ContentNode")
for each rowAA in list
row = createObject("RoSGNode","ContentNode")
row.Title = rowAA.Title
for each itemAA in rowAA.ContentList
item = createObject("RoSGNode","ContentNode")
' We don't use item.setFields(itemAA) as doesn't cast streamFormat to proper value
for each key in itemAA
item[key] = itemAA[key]
end for
row.appendChild(item)
end for
RowItems.appendChild(row)
end for
return RowItems
End Function
Function GetApiArray()
url = CreateObject("roUrlTransfer")
url.SetUrl("http://api.delvenetworks.com/rest/organizations/59021fabe3b645968e382ac726cd6c7b/channels/1cfd09ab38e54f48be8498e0249f5c83/media.rss")
rsp = url.GetToString()
responseXML = ParseXML(rsp)
responseXML = responseXML.GetChildElements()
responseArray = responseXML.GetChildElements()
result = []
for each xmlItem in responseArray
if xmlItem.getName() = "item"
itemAA = xmlItem.GetChildElements()
if itemAA <> invalid
item = {}
for each xmlItem in itemAA
item[xmlItem.getName()] = xmlItem.getText()
if xmlItem.getName() = "media:content"
item.stream = {url : xmlItem.url}
item.url = xmlItem.getAttributes().url
item.streamFormat = "mp4"
mediaContent = xmlItem.GetChildElements()
for each mediaContentItem in mediaContent
if mediaContentItem.getName() = "media:thumbnail"
item.HDPosterUrl = mediaContentItem.getattributes().url
item.hdBackgroundImageUrl = mediaContentItem.getattributes().url
end if
end for
end if
end for
result.push(item)
end if
end if
end for
return result
End Function
Function ParseXML(str As String) As dynamic
if str = invalid return invalid
xml = CreateObject("roXMLElement")
if not xml.Parse(str) return invalid
return xml
End Function
function getauth() As string
url = CreateObject("roUrlTransfer")
url.SetUrl("http://demo8592579.mockable.io/rokuTest/auth")
rsp = url.GetToString()
return rsp
end function
function GetCode() As string
url = CreateObject("roUrlTransfer")
url.SetUrl("http://demo8592579.mockable.io/rokuTest/auth")
rsp = url.GetToString()
response=parseJSON(rsp)
return response
end function
MessageScreen.brs
function init()
m.top.setFocus(true)
m.myLabel = m.top.findNode("myLabel")
m.myLabel.text = "HOW"
m.myLabel.font.size=92
'
' 'Set the color to light blue
m.myLabel.color="0x72D7EEFF"
end function
现在我想在Messagescreen.brs中显示随机代码。你们可以帮我吗?
答案 0 :(得分:1)
如果要获取GetCode()函数对场景的响应,请将GetCode()函数放在TASK中,然后例如在Scene init()函数中运行TASK,一旦TASK得到您的代码,您将获得代码。 API的响应。 您似乎不知道此选项,因此请在开始之前阅读以下内容: https://sdkdocs.roku.com/display/sdkdoc/Task。
如果您需要有关如何使用任务的真实示例,还可以查看我的仓库: https://github.com/umitic/Roku-Custom-Audio-Player