Forum Discussion

destruk's avatar
destruk
Streaming Star
15 years ago

roImageCanvas Image Cancellation

When I download an image to set as the background, is there any way to abort the download of the image file before the download completes without closing the screen? To programatically interrupt the download of the image file?
Maybe I'd need to set the canvas component to "nothing", then run the garbage collector, and then create a new roImageCanvas object? Would that cancel the transfer of the file in progress?

5 Replies

  • Assuming a call to ClearLayer doesn't cancel the transfer, you could potentially use the AsyncGetToFile method of the roUrlTransfer component to download it to a tmp: location prior to setting the layer on the image canvas. Since it won't display until it's fully downloaded anyway, it shouldn't incur any additional performance penalties, and gives you the ability to cancel the transfer without having to recreate the canvas.
  • destruk's avatar
    destruk
    Streaming Star
    Thanks! I hadn't thought about clearlayer. How would you cancel a file transfer in progress? I see your answer to copy the file to tmp, and then display it if it 'hasn't been cancelled' by the user, but the file that way would still be transferred taking up the bandwidth to get the whole file. I'd like to cancel it partway, before it's done transferring - if it's possible. If not, that's ok - just not preferred.
  • "destruk" wrote:
    Thanks! I hadn't thought about clearlayer. How would you cancel a file transfer in progress? I see your answer to copy the file to tmp, and then display it if it 'hasn't been cancelled' by the user, but the file that way would still be transferred taking up the bandwidth to get the whole file. I'd like to cancel it partway, before it's done transferring - if it's possible. If not, that's ok - just not preferred.

    If you use AsyncGetToFile, you can call AsyncCancel to cancel the transfer. Oddly enough, I don't see AsyncCancel documented in the component reference, but you can see it in use in the urlUtils.brs file in the videoplayer example.
  • and thanks for pointing out the doc bug. I'll remedy that in the next SDK release.

    --Kevin