I created task and Ran it (to get the video details) when user presses watch button on the video asset. I am able to run the task and get the playback details from server. After getting play details, I need to ran a timer for every 30 sec, and once the timer is fired, I need to run another task to update the heartbeat to the server. After receiving the response for heartbeat, I need to update one field of the playback details with a value of response for heartbeat. Even though I changed the value of field using addReplace(), the value is not getting changed.
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
In didReceiveHeartbeatContent(), I am trying to change the streamToken value in playbackDetails with streamToken of heartbeatContent. But the value is not getting changed.
playbackDetails and heartbeatContent are roAssociativeArrays I defined in XML files and setting values as below.
<?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>
Can any one please suggest me how to change the value of a filed in the playbackDetails?
Associative arrays as node fields are immutable, meaning that their contents cannot be changed.
You'll have to override the entire object:
playbackDetails = m.livePlaybackNode.playbackDetails
playbackDetails.streamToken = m.heartbeatNode.heartbeatContent.streamToken
m.livePlaybackNode.playbackDetails = playbackDetails
Or you could use Nodes instead of Associative arrays.