【问题标题】:Making a Get request in brightscript for roku channel not working在 brightscript 中为 roku 频道发出 Get 请求不起作用
【发布时间】:2023-02-07 19:45:43
【问题描述】:

我正在建立一个 Roku 电视频道,我已经显示了一个键盘以便用户可以键入,并且有两个按钮可以搜索,我在这些按钮上做了一个观察者,当按下按钮时,我想发出一个获取请求来获取结果,但是 API 调用在与 components/keyboard.xml 链接的 components/keyboard.brs 中没有成功,但是如果我在顶部调用 source/main.brs,则相同的 API 调用会成功。

无法理解这一点,如果您对此有所了解,或者我可以在哪里找到这些东西的任何资源,请告诉我。 提前致谢。

【问题讨论】:

    标签: xml roku brightscript scenegraph


    【解决方案1】:

    所有http请求都需要在task thread上执行。

    您可以在 Roku 的 github 示例存储库 here 上看到这方面的一个工作示例。

    这是该示例中任务代码的 sn-p:

    <?xml version = "1.0" encoding = "utf-8" ?>
    
    <!--********** Copyright 2016 Roku Corp.  All Rights Reserved. **********-->
    
    <component name = "ContentReader" extends = "Task" >
    
      <interface>
        <field id = "contenturi" type = "uri" />
        <field id = "content" type = "node" />
      </interface>
    
      <script type = "text/brightscript" >
    
        <![CDATA[
    
        sub init()
          m.top.functionName = "getcontent"
        end sub
    
        sub getcontent()
          content = createObject("roSGNode", "ContentNode")
    
          contentxml = createObject("roXMLElement")
    
          readInternet = createObject("roUrlTransfer")
          readInternet.setUrl(m.top.contenturi)
          contentxml.parse(readInternet.GetToString())
    
          if contentxml.getName()="Content"
            for each item in contentxml.GetNamedElements("item")
              itemcontent = content.createChild("ContentNode")
              itemcontent.setFields(item.getAttributes())
            end for
          end if
    
          m.top.content = content
        end sub
    
        ]]>
    
      </script>
    
    </component>
    

    这就是您创建和启动任务的方式:

    m.readXMLContentTask = createObject("roSGNode", "ContentReader")
    m.readXMLContentTask.observeField("content", "setcontent")
    m.readXMLContentTask.contenturi = "http://www.sdktestinglab.com/Tutorial/content/xmlcontent.xml"
    m.readXMLContentTask.control = "RUN"
    
    
    

    您可以在 RokuCommunity sample-projects repo 的任务中看到一个稍微复杂的 http 请求示例:https://github.com/rokucommunity/sample-projects/tree/master/standard-with-task

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-20
      • 1970-01-01
      • 2017-07-04
      • 1970-01-01
      相关资源
      最近更新 更多