Forum Discussion
belltown
9 years agoRoku Guru
Here's a very simplified example that illustrates the concept. Note that I don't include the Video node as a field in the Task node as you've done. That just seems weird to me. It makes more sense to keep the Video node contained within the Render thread and communicate any state changes that the Task needs to know about via an interface field on the Task node that only contains the information the Task needs to know (i.e. the video state in this case). The Task just prints out any changes to the Video state by observing its interface field. You can add your own code to use your roUrlTransfer object to send that data where it needs to go.
Test.xml:
Test.brs:
TaskServer.xml:
TaskServer.brs:
Test.xml:
<?xml version="1.0" encoding="UTF-8"?>
<component name="Test" extends="Scene">
<script type="text/brightscript" uri="pkg:/components/Test.brs" />
<children>
<Video id="videoNode">
<ContentNode role="content"
url="https://archive.org/download/Plan9FromOuterSpace1958/Plan-9-from-Outer-Space.mp4"
title="Test Video" />
</Video>
<TaskServer id="taskServerNode" />
</children>
</component>
Test.brs:
sub init()
m.taskServerNode = m.top.findNode("taskServerNode")
m.taskServerNode.ObserveField("stateOutput", "onTaskStateOutput")
m.videoNode = m.top.findNode("videoNode")
m.videoNode.SetFocus(true)
m.videoNode.ObserveField("state", "onVideoState")
m.videoNode.control = "play"
end sub
sub onVideoState()
m.taskServerNode.stateInput = m.videoNode.state
end sub
sub onTaskStateOutput()
print "Task state: "; m.taskServerNode.stateOutput
end sub
function onKeyEvent(key as string, press as boolean) as boolean
handled = false
if press
if key = "play"
if m.videoNode.state = "playing"
m.videoNode.control = "pause"
else if m.videoNode.state = "paused"
m.videoNode.control = "resume"
else if m.videoNode.state = "stopped"
m.videoNode.control = "play"
end if
handled = true
end if
end if
return handled
end function
TaskServer.xml:
<?xml version="1.0" encoding="UTF-8"?>
<component name="TaskServer" extends="Task">
<script type="text/brightscript" uri="pkg:/components/TaskServer.brs" />
<interface>
<field id="stateInput" type="string" alwaysNotify="true" />
<field id="stateOutput" type="string" alwaysNotify="true" />
</interface>
</component>
TaskServer.brs:
sub init()
m.top.functionName = "taskRun"
m.top.control = "RUN"
end sub
function taskRun() as void
port = CreateObject("roMessagePort")
m.top.ObserveField("stateInput", port)
while true
msg = Wait(0, port)
if Type(msg) = "roSGNodeEvent"
field = msg.GetField()
state = msg.GetData()
if field = "stateInput"
print "stateInput: "; state
m.top.stateOutput = state
end if
end if
end while
end function