Hello, sorry if the title might be misleading, as I don't know how to phrase it in regards to my problem
I just started recently onto Roku dev and I have made a file in 'source/rokuPlayer.brs', which contains the code below, which basically a wrapper of the roVideoScreen
[size=85][font=Monaco][color=#3629d2][/color][/font][/size]
function createRokuVideoPlayer(rokuPlaybackItem as Object) as Object
obj = {
rokuPlaybackItem : rokuPlaybackItem
playerName : "RokuVideoPlayer"
port : invalid
player : invalid
prepare : function() as Boolean
m.initializePlayerPrepare()
return true
end function
play : function() as Boolean
m.player.resume()
return true
end function
pause : function() as Boolean
m.player.pause()
return true
end function
close : sub()
m.initiatePlayerShutdown()
end sub
seek : function(millisecond as Integer) as Boolean
m.player.seek(milliseconds)
return true
end function
initializePlayerPrepare : sub()
m.logger.logDebug(LINE_NUM, "Preparing Player ...")
m.completePlayerPrepare()
end sub
completePlayerPrepare : sub()
m.port = createObject("roMessagePort")
m.player = createObject("roVideoScreen")
m.player.setMessagePort(m.port)
m.player.setPositionNotificationPeriod(1)
m.player.setContent(m.rokuPlaybackItem)
m.displayPlayer()
end sub
initiatePlayerShutdown: sub()
'TODO: do cleanup and shutdown of player
m.player.close()
end sub
displayPlayer : sub()
m.player.show()
while true
msg = wait(1, m.port)
if type(msg) = "roVideoScreenEvent" then
print "showHomeScreen | msg = "; msg.getMessage() " | index = "; msg.GetIndex()
if msg.isScreenClosed()
print "Screen closed"
exit while
else
print "Unexpected event type: "; msg.GetType()
end if
else
print "Unexpected message class: "; type(msg)
end if
end while
end sub
}
end function
Once that's done, I then create an Scene Graph XML file on 'components/Homescreen.xml', that contains this code, which is a UI screen composed of a list of items that when selected, should show up the roku player
<?xml version="1.0" encoding="UTF-8"?>
<component name="HomeScreen" extends="Scene" initialFocus = "builtinList">
<interface>
<!-- Specifies the content for the GridPannel -->
<field id="rokuContents" type="array" onChange="onRokuContentsUpdated"/>
<field id="rowItemSelected" type="int" alwaysnotify="true" alias="builtinList.itemSelected"/>
</interface>
<!-- main handler -->
<script type="text/brightscript">
<![CDATA[
sub init()
m.list = m.top.FindNode("builtinList")
m.top.observeField("rowItemSelected", "OnItemSelected")
m.content = createObject("RoSGNode","ContentNode")
addSection("BuiltIn Content")
addItem("Loading contents")
m.list.content = m.content
m.top.setFocus(false)
end sub
sub addSection(sectiontext as string)
m.sectionContent = m.content.createChild("ContentNode")
m.sectionContent.CONTENTTYPE = "SECTION"
m.sectionContent.TITLE = sectiontext
end sub
sub addItem(itemtext as string)
item = m.sectionContent.createChild("ContentNode")
item.title = itemtext
end sub
' Row item selected handler
Sub OnItemSelected()
? "[HomeScreen] OnRowItemSelected"
if m.top.rokuContents <> invalid
focusedIndex = m.list.itemFocused
rokuItem = m.top.rokuContents[focusedIndex]
? "Selected Index " + focusedIndex.toStr()
rokuPlayer = createRokuVideoPlayer(rokuItem)
rokuPlayer.prepare()
end if
End Sub
' If jsonContent is set, focus on the LabelList
sub onRokuContentsUpdated()
? "onJsonContentUpdated"
m.content = createObject("RoSGNode","ContentNode")
addSection("BuiltIn Content")
if m.top.rokuContents = invalid
addItem("No Built-in Contents")
else
for each rokuItem in m.top.rokuContents
addItem(rokuItem.title)
end for
end if
m.list.content = m.content
m.list.setFocus(true)
end sub
]]>
</script>
<children>
<LabelList
id = "builtinList"
textHorizAlign="left"
numRows="10"
itemSize = "[700,48]"
translation = "[160,92]"
/>
</children>
</component>
[color=#4e9192][size=85][font=Monaco][color=#009193][/color][/font][/size][/color]
However, when I compiled this onto Roku, I got this error when I selected an item
Function Call Operator ( ) attempted on non-function. (runtime error &he0) in pkg:/components/HomeScreen.xml(46)
[color=#000000][size=85][font=Menlo]046: rokuPlayer = createRokuVideoPlayer(rokuItem)[/font][/size][/color]
Backtrace:
I was under the impression that the global function I made should be applicable on the scene graph but I was wrong. I did some research and I found this
link and this
link. It talks about registering this 'Global scope' from a component script to a non-component script but its not the other way around, so those did not fix my problem.
I'm not looking for a workaround or code conversion her, such as converting the video player to use the video node in the scene graph. I'm just asking if it is possible to use any codes I made over the 'source' folder onto the XML files for Scene Graph