Developers

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Photovor
Visitor

Screengraph and AsyncGetToFile

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.
Tags (1)
0 Kudos
1 REPLY 1
renojim
Community Streaming Expert

Re: Screengraph and AsyncGetToFile

I can't say what may or may not be wrong with what you're doing, but see tim_beynart's excellent tutorial (especially Lesson 3) for an example of async requests in a task.

-JT
Roku Community Streaming Expert

Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.

I am not a Roku employee.
Tags (1)
0 Kudos
Community is Being Upgraded!

We’re upgrading Roku Community to bring you a faster, more mobile-friendly experience. You may notice limited functionality or read-only access during this time. Read more here.

Planned Downtime:
Community will be unavailable for up to 24–48 hours during the upgrade window during the week of May 19th and you may notice reduced functionality. In the meantime, for additional assistance, visit our Support Site.

We're sorry for this disruption — we’re excited to share what’s next!