我创建了任务,并在用户按下视频资产上的观看按钮时将其运行(以获取视频详细信息)。我能够运行任务并从服务器获取播放详细信息。获取播放详细信息后,我需要每30秒运行一个计时器,并且一旦启动计时器,我需要运行另一个任务以将心跳更新到服务器。收到心跳响应后,我需要用心跳响应值更新播放详细信息的一个字段。 即使我使用addReplace()更改了字段的值,该值也没有改变。
scene.brs
sub playLive()
m.livePlaybackData = CreateObject("roSGNode", "FetchPlaybackDetails")
m.livePlaybackNode.observeField("playbackDetails", "didReceivePlaybackDetails")
m.livePlaybackNode.control = "RUN"
end sub
sub didReceivePlaybackDetails()
videoContent = createObject("RoSGNode", "ContentNode")
videoContent.url = m.livePlaybackNode.playbackDetails.pUrl
videoContent.title = "Test Video"
videoContent.streamformat = "dash"
m.video.content = videoContent
m.video.visible = true
m.video.setFocus(true)
m.video.control = "play"
m.video.observeField("state", "OnVideoPlayerStateChange")
m.playbackHeartbeatTimer.control = "start"
m.playbackHeartbeatTimer.ObserveField("fire","updateHeartbeat")
end sub
sub updateHeartbeat()
m.heartbeatNode.setField("liveStreamToken", m.livePlaybackNode.playbackDetails.streamToken)
m.heartbeatNode.observeField("heartbeatContent", "didReceiveHeartbeatContent")
m.heartbeatNode.control = "RUN"
end sub
sub didReceiveHeartbeatContent()
m.livePlaybackNode.playbackDetails.AddReplace("streamToken", m.heartbeatNode.heartbeatContent.streamToken)
?m.livePlaybackNode.playbackDetails.streamToken
end sub
在didReceiveHeartbeatContent()中,我尝试使用heartbeatContent的streamToken更改playbackDetails中的streamToken值。但是价值并没有改变。
playbackDetails和heartbeatContent是我在XML文件中定义的roAssociativeArrays,并按如下所示设置值。
<?xml version="1.0" encoding="utf-8" ?>
<component name = "FetchPlaybackDetails" extends = "Task" >
<interface>
<field id="playbackDetails" type="assocarray" />
</interface>
</component>
<?xml version="1.0" encoding="utf-8" ?>
<component name = "UpdateHeartbeat" extends = "Task" >
<interface>
<field id="liveStreamToken" type="string" />
<field id="heartbeatContent" type="assocarray" />
</interface>
</component>
有人可以建议我如何更改文件的值吗?
答案 0 :(得分:1)
作为节点字段的关联数组是不可变的,这意味着它们的内容无法更改。
您将不得不覆盖整个对象:
playbackDetails = m.livePlaybackNode.playbackDetails
playbackDetails.streamToken = m.heartbeatNode.heartbeatContent.streamToken
m.livePlaybackNode.playbackDetails = playbackDetails
或者您可以使用节点而不是关联数组。