如何从Brightscript为Roku频道调用XML代码?

时间:2017-08-10 15:40:29

标签: roku brightscript scenegraph

我正在尝试使用以下XML Roku Channel,Scenegraph代码填充标签列表。我收到了这些错误:

BRIGHTSCRIPT: ERROR: roSGScreen: creating MAIN|TASK-only component failed on RENDER thread: pkg:/components/screens/DetailsScreen/DetailsScreen.brs(101)
BRIGHTSCRIPT: ERROR: roMessagePort: Trying to construct a message port on a non-plugin thread: pkg:/components/screens/DetailsScreen/DetailsScreen.brs(102) 

调用 Brightscript 代码:

   ' on Button press handle
Sub onItemSelected()
    showChannelSGScreen()
End Sub

sub showChannelSGScreen()
  screen = CreateObject("roSGScreen")
  m.port = CreateObject("roMessagePort")
  screen.setMessagePort(m.port)
  scene = screen.CreateScene("LabelListExample")
  screen.show()

  while(true)
    msg = wait(0, m.port)
    msgType = type(msg)

    if msgType = "roSGScreenEvent"
      if msg.isScreenClosed() then return
    end if
  end while

end sub

XML 代码:

<?xml version = "1.0" encoding = "utf-8" ?>

<!--********** Copyright 2016 Roku Corp.  All Rights Reserved. **********-->

<component name = "LabelListExample" extends = "Group" initialFocus = "exampleLabelList" >

  <script type = "text/brightscript" >

    <![CDATA[

    sub init()
      examplerect = m.top.boundingRect()
      centerx = (1280 - examplerect.width) / 2
      centery = (720 - examplerect.height) / 2
      m.top.translation = [ centerx, centery ]
    end sub

    ]]>

  </script>

  <children >

    <LabelList id = "exampleLabelList" >

      <ContentNode role = "content" >
        <ContentNode title = "Renderable Nodes" />
        <ContentNode title = "Z-Order/Parent-Child" />
        <ContentNode title = "Animations" />
        <ContentNode title = "Events and Observers" />
      </ContentNode>

    </LabelList>

  </children>

</component>

我的问题是:从 Brightscript 调用 XML 的正确方法是什么?

*****完整错误消息**:

BRIGHTSCRIPT: ERROR: roSGScreen: creating MAIN|TASK-only component failed on RENDER thread: pkg:/components/screens/DetailsScreen/DetailsScreen.brs(101)
BRIGHTSCRIPT: ERROR: roMessagePort: Trying to construct a message port on a non-plugin thread: pkg:/components/screens/DetailsScreen/DetailsScreen.brs(102)

BrightScript Micro Debugger.
Enter any BrightScript statement, debug commands, or HELP.

Suspending threads...
Thread selected:  1*   ...ailsScreen/DetailsScreen.brs(103)    screen.setMessagePort(m.port)

Current Function:
100:  sub showChannelSGScreen()
101:    screen = CreateObject("roSGScreen")
102:    m.port = CreateObject("roMessagePort")
103:*   screen.setMessagePort(m.port)
104:    scene = screen.CreateScene("LabelListExample")
105:    screen.show()
106:  
107:    while(true)
'Dot' Operator attempted with invalid BrightScript Component or interface reference. (runtime error &hec) in pkg:/components/screens/DetailsScreen/DetailsScreen.brs(103)
103:   screen.setMessagePort(m.port)
Backtrace:
#1  Function showchannelsgscreen() As Void
   file/line: pkg:/components/screens/DetailsScreen/DetailsScreen.brs(103)
#0  Function onitemselected() As Void
   file/line: pkg:/components/screens/DetailsScreen/DetailsScreen.brs(95)
Local Variables:
global           Interface:ifGlobal
m                roAssociativeArray refcnt=3 count:7
screen           Invalid
scene            <uninitialized>
msg              <uninitialized>
msgtype          <uninitialized>
Threads:
ID    Location                                Source Code
 0    pkg:/source/main.brs(20)                msg = wait(0, port)
 1*   ...ailsScreen/DetailsScreen.brs(103)    screen.setMessagePort(m.port)
  *selected

Brightscript Debugger> 
Thread detached
>>> Details >> OnkeyEvent

Thread detached

3 个答案:

答案 0 :(得分:1)

只应使用场景组件作为参数调用CreateScene方法。您的案例中的 LabelListExample 组件不是场景,因为它扩展了Group。改变这一行:

<component name = "LabelListExample" extends = "Group" initialFocus = "exampleLabelList" >

对此:

<component name = "LabelListExample" extends = "Scene" initialFocus = "exampleLabelList" >

答案 1 :(得分:1)

来自您的错误消息

  

BRIGHTSCRIPT:错误:roSGScreen:在RENDER线程上创建MAIN | TASK-only组件失败:pkg:/components/screens/DetailsS​​creen/DetailsS​​creen.brs(101)

很明显,您正在渲染线程中创建一个屏幕实例。有两种可行的方法来实现屏幕导航

  1. 启动应用时通过主课程
  2. 使用Task组件创建屏幕实例并将其推送到屏幕堆栈
  3. 我建议使用第二个选项,您可以根据需要创建和推送屏幕。

    在您的情况下,您可以在任务组件内编写showChannelSGScreen函数脚本并在开始导航屏幕之前运行任务。

    一切顺利!!!

答案 2 :(得分:0)

嗨社区我正在制作一个 Roku 应用程序,我需要创建窗口实例以便可以在它之间冲浪。开发位于主要功能内,因为这是它工作的唯一方式。

此外,我还需要创建一些不依赖于主模块的模块,我一直在调查并且是节点使用和任务所必需的。

这是我的代码,我想知道您是否有一些使用节点和任务的示例

    screen = CreateObject("roSGScreen")
     m.port = CreateObject("roMessagePort")
     screen.setMessagePort(m.port)
     scene = screen.CreateScene("PlayerScreen")
     screen.show()