Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
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.
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.
0 Kudos