Hello, I've created a program using screengraph, and I'm running into trouble getting notifications from urlEvent when using AsyncGetToFile. I've created a task that looks like this:
<component name="DownloadAssets" extends="Task">
<interface>
<field id = "downloadRequestID" type = "string" />
<field id = "downloadStatus" type = "string" />
</interface>
<script type="text/brightscript">
<![CDATA[
sub init()
m.top.functionName = "go"
m.pendingXfers = {}
m.top.downloadStatus = "start"
end sub
sub go()
Print "Downloading Assets"
m.top.downloadStatus = "start"
downloadURL = "http://www.something.com/video.mp4"
xfer = CreateObject("roUrlTransfer")
xfer.SetUrl (downloadURL)
xfer.AsyncGetToFile("tmp:/video.mp4")
requestId = xfer.GetIdentity().ToStr()
m.top.downloadRequestID = requestId
m.pendingXfers[requestId] = xfer
end sub
Function HandleUrlEvent(event as Object)
requestId = event.GetSourceIdentity().ToStr()
xfer = m.pendingXfers[requestId]
if xfer <> invalid then
m.top.downloadStatus = "done"
end if
End Function
]]>
</script>
</component>
I'm able to trigger the task, and I have an observer on the downloadStatus field which works (from testing by setting manually at the end of the go sub) but I never get a notification that the download completes. I'm not sure where I should put my handler for the urlEvent, if it needs to be in the task, or in the screen's brs file.