【问题标题】:Adding internal Search function to Screnegraph Brightscript Channell向 Screengraph Brightscript Channell 添加内部搜索功能
【发布时间】:2019-08-12 09:37:34
【问题描述】:

我需要在我的 Brightscript 场景脚本脚本中为 Roku 频道添加搜索功能。有没有人有一个简单的搜索示例,或者我可以用来添加到“滑动面板”Roku 频道脚本的脚本?

RoSearch 已贬值。

当前页面与滑动面板示例非常相似。

需要在我的 Roku 频道上使用搜索功能。

<component name = "minikeyboardexample" extends = "Group" initialFocus = "exampleMiniKeyboard" >

<script type="text/brightscript" >
<![CDATA[
sub init()
  m.testlabel = m.top.FindNode("testLabel")
  m.testpostergrid = m.top.FindNode("testPosterGrid")
  m.testpostergridcontent = createObject("roSGNode","ContentNode")
  m.readPosterGridTask = createObject("roSGNode","postergridCR")
  m.readPosterGridTask.setField("postergriduri","http://test-xml.xml")
  m.readPosterGridTask.observeField("gotitem","buildpostergrid")
  m.readPosterGridTask.observeField("gotcontent","showpostergrid")
  m.readPosterGridTask.control = "RUN"
  m.top.setFocus(true)
end sub

sub buildpostergrid()
  gridposter = createObject("roSGNode","ContentNode")
  gridposter.hdgridposterurl = m.readPosterGridTask.hdgridposterurl
  gridposter.hdposterurl = m.readPosterGridTask.hdposterurl
  gridposter.sdgridposterurl = m.readPosterGridTask.sdgridposterurl
  gridposter.sdposterurl = m.readPosterGridTask.sdposterurl
  gridposter.shortdescriptionline1 = m.readPosterGridTask.shortdescriptionline1
  gridposter.shortdescriptionline2 = m.readPosterGridTask.shortdescriptionline2
  gridposter.x = m.readPosterGridTask.xposterpos
  gridposter.y = m.readPosterGridTask.yposterpos
  gridposter.w = m.readPosterGridTask.wnumcols
  gridposter.h = m.readPosterGridTask.hnumrows
  m.testpostergridcontent.appendChild(gridposter)
end sub

sub showpostergrid()
  m.testlabel.text = "Here's the PosterGrid: "
  m.testpostergrid.content=m.testpostergridcontent
  m.testpostergrid.visible=true
  m.testpostergrid.setFocus(true)
end sub
]]>
</script>



  <children>

    <MiniKeyboard id = "exampleMiniKeyboard" />

    <Label id="testLabel" translation="[100,32]" text="Building PosterGrid... " />

    <PosterGrid
    id="testPosterGrid"
    translation="[100,100]"
    basePosterSize="[240,240]"
    itemSpacing="[32,32]"
    caption1NumLines="1"
    caption2NumLines="1"
    numColumns="4"
    numRows="3"
    />


  </children>

</component>

【问题讨论】:

    标签: search roku brightscript


    【解决方案1】:

    首先阅读以下想法: https://developer.roku.com/en-gb/docs/developer-program/discovery/search/implementing-search.md

    这些代码用于搜索功能。它采用静态方式。

    sub Main()
    
    
    ''Search Screen UI
    
    'REM ******************************************************
    'REM Main routine - example of search screen usage
    'REM ******************************************************
        print "start"
    
        'toggle the search suggestions vs. search history behavior
        'this allow you to generate both versions of the example below
    
        displayHistory = false
        history = CreateObject("roArray", 1, true)
    
        'prepopulate the search history with sample results
    
        history.Push("seinfeld")
        history.Push("fraiser")
        history.Push("cheers")
        port = CreateObject("roMessagePort")
        screen = CreateObject("roSearchScreen")
    
        'commenting out SetBreadcrumbText() hides breadcrumb on screen
    
        screen.SetBreadcrumbText("", "Search Channel")
        screen.SetMessagePort(port)
        if displayHistory
           screen.SetSearchTermHeaderText("Recent Searches:")
            screen.SetSearchButtonText("search") 
            screen.SetClearButtonText("clear history")
            screen.SetClearButtonEnabled(true) 'defaults to true
            screen.SetSearchTerms(history)
        else
            screen.SetSearchTermHeaderText("Suggestions:")
            screen.SetSearchButtonText("search")
            screen.SetClearButtonEnabled(false)
        endif
    
        print "Doing show screen..."
    
        screen.Show()
    
        print "Waiting for a message from the screen..."
    
        ' search screen main event loop
    
        done = false
        while done = false
            msg = wait(0, screen.GetMessagePort())
            if type(msg) = "roSearchScreenEvent"
                if msg.isScreenClosed()
                    print "screen closed"
                    done = true
                else if msg.isCleared()
                    print "search terms cleared"
                    history.Clear()
                else if msg.isPartialResult()
                    print "partial search: "; msg.GetMessage()
                    if not displayHistory                    
                         screen.SetSearchTerms(GenerateSearchSuggestions(msg.GetMessage()))
                    endif
                else if msg.isFullResult()
                    print "full search: "; msg.GetMessage()
                    history.Push(msg.GetMessage())
                    if displayHistory
                        screen.AddSearchTerm(msg.GetMessage())
                    end if
    
                   'uncomment to exit the screen after a full search result:
                    'done = true
    
                else
                    print "Unknown event: "; msg.GetType(); " msg: "; sg.GetMessage()
                endif
            endif
        endwhile
    
        print "Exiting..."
    End Sub 
    
    Function GenerateSearchSuggestions(partSearchText As String) As Object
        availableContent = [
            "ch1"
            "ch2"
            "ch3"
            "ch4"
            "ch5"
            "ch6"
            "ch7"
            "ch8"
            ]
        suggestions = []
        if partSearchText <> ""
            partSearchText = LCase(partSearchText)
            for each available in availableContent
                if available.Instr(partSearchText) >= 0
                    suggestions.Push(available)
                end if
            end for
        end if
        return suggestions
    End Function
    End sub
    

    这段代码写在 main.brs 文件中

    我希望这段代码有用。

    【讨论】:

    • Roku Document 说“此组件已弃用,将于 2019 年 1 月 1 日从 Roku OS 中删除。从 2017 年 7 月 1 日开始,任何使用此组件的新频道都将在认证期间被拒绝。开始2018 年 1 月 1 日,任何使用此组件对现有频道的更新都将在认证期间被拒绝。”
    • 感谢 dhir Pratap 提供的信息。您建议使用任何其他方式在 Roku 中动态搜索,例如 Netflix 和 Roku 的 youtube 频道。
    • 是的,正如我在 OP RoSearch 中提到的,已经贬值了。
    【解决方案2】:

    SceenGraph 中的大多数搜索屏幕都使用MiniKeyboard 与任何类型的列表或网格的组合,例如MarkupGrid。您可以将这些组件添加到您的面板或组组件中并自己管理转换。

    【讨论】:

    • 感谢您的回复。容易说,做到了。我试过了。只是无法绕过它。
    • 确实如此。请让我知道您发现的具体问题,并会尽力回答。
    • 我更新了我原来的问题,给你更多的细节。提前致谢。
    • 我看到了更新的代码,唯一缺少的是关键处理函数。请参阅此文档以获取 onKeyEvent
    猜你喜欢
    • 2016-10-16
    • 1970-01-01
    • 2016-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-02
    相关资源
    最近更新 更多