roku - Roku Brightscript 如何使用海报对象刷新图像
问题描述
我有 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>
主要.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
解决方案
您可以通过在海报图片的 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,并且您需要使用新数据更新所有显示的内容列表,无论它们的屏幕是否可见,以确保它传播一切的新图像(为了安全起见) - 或者你可能不会取决于你的代码是如何设置的。
这实际上解决了我的问题
推荐阅读
- rest - REST API - 加入其他资源/映射资源的资源
- spring-mvc - HTTP 状态 500 - 处理 JSP 页面 il 选择表单时发生异常:表单
- python - 在 Matplotlib 中使用日期时间数据绘制矩形
- css - CSS 过渡:如何“闪现”进出课堂
- botframework - 通过付费渠道查找消息数量
- python - 从日期列中获取月份
- javascript - 如何配置 WebPack DevServer 来处理 React JS 中的 POST 请求?
- javascript - 使用 Javascript 进行 SQL 查询字符串操作
- php - 在 laravel 5.5 中创建视频缩略图
- java - 无法使用 ImageIO.read(file) 读取 25mb 图像