【问题标题】:Roku Brightscript How to refresh image with Poster objectRoku Brightscript 如何使用海报对象刷新图像
【发布时间】:2021-08-26 03:52:07
【问题描述】:

我有 1 个 http 地址来加载随时间戳变化的图像。

例如 xxx.com?time=192186577

我可以使用海报对象来实时刷新图像内容吗? 如果海报不支持,我可以使用其他对象吗? 请给我一些帮助。

我正在实现海报组件的代码

<?xml version="1.0" encoding="utf-8" ?> 
<component name="posterScene" extends="Scene" >

<script type="text/brightscript" >



<!-- m.poster.ObserveField("loadStatus", "changetext") -->
        

<![CDATA[

sub init()

    m.timer = m.top.findNode("exampleTimer")
    m.timer.ObserveField("fire", "changetexta")
    m.timer.control = "start"

    m.mirrorUrl = "http://192.168.11.6:4998/screenmirroring" 

    m.poster = m.top.findNode("channelbugPoster")

    m.top.setFocus(true)
end sub

sub changetexta()
    time = CreateObject("roDateTime")
    second = time.AsSeconds()
    milisecond = time.GetMilliseconds()
    timestampString = second.ToStr() + milisecond.ToStr()
    mirrorUrl=m.mirrorUrl+"?ts="+timestampString
    print(mirrorUrl)
    m.poster.uri = mirrorUrl
    
end sub

]]>
</script>

<children>
    <Poster
        id="channelbugPoster"
    uri="http://192.168.11.6:4998/screenmirroring?ts=1627150215328"
    width="1080"
    height="720"
    translation="[0,0]" />

    <Timer 
      id = "exampleTimer" 
      repeat = "true" 
      duration = "0.03" />

</children>

</component>


Main.brs

'********** Copyright 2015 Roku Corp.  All Rights Reserved. **********

sub Main()
    showChannelSGScreen()
end sub

sub showChannelSGScreen()
    print "in showChannelSGScreen"
    screen = CreateObject("roSGScreen")
    m.port = CreateObject("roMessagePort")
    screen.setMessagePort(m.port)
    scene = screen.CreateScene("posterScene")
    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

【问题讨论】:

  • 渲染图片时不能直接把当前时间戳传给Poster的url吗?
  • 感谢您的建议。我也尝试过使用 Poster 对象,但似乎 Poster 仅支持捆绑中的本地 url。使用 http 格式的 url,我仍然无法加载自动刷新图像。在这种情况下,你能给我更多的建议吗?
  • 您能说明您是如何尝试在海报组件中设置uri 字段的吗?
  • @juliomalves 我正在为这样的海报设置 uri。 ``` lang-js 192.168.11.3:4998/demo?ts=1627150215328" width="1080" height="720" translation= "[0,0]" /> ```我需要调用repeat来重新设置poster的uri吗?
  • @juliomalves 我曾尝试使用 Timer,但在加载设备上显示的图像时,更改海报的 uri 时出现黑色闪烁。这是我要测试的源代码。你能给我更多的建议吗?

标签: roku brightscript


【解决方案1】:

您可以通过在海报图片的 url 字符串中添加一个参数来做到这一点。在 roku 上,生成时间戳并将其添加到 url。

dt=createobject("roDateTime") value=dt.AsSeconds() transferstringurl=transferstringurl+"?ts="+value.toStr()

即-http://myservername.com/images/myposter.jpg?ts=1494302631

或者您可以修改标头 - (不确定它是否适用于 roku 的客户端,但可以在服务器端设置) Cache-Control: no-cache, no-store, must-revalidate Pragma: no-cache Expires: 0

每次您希望海报更改时,您都需要更新项目的 hdposterurl 和 sdposterurl,并且无论屏幕是否可见,您都需要使用新数据更新所有显示的内容列表,以便确保它将新图像传播到所有东西(为了安全起见) - 或者您可能不会依赖于代码的设置方式。

这实际上解决了我的问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-26
    • 1970-01-01
    • 2013-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多