Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
destruk
Level 10

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?
0 Kudos
5 Replies
TheEndless
Level 9

Re: roImageCanvas Image Cancellation

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.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
destruk
Level 10

Re: roImageCanvas Image Cancellation

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.
0 Kudos
TheEndless
Level 9

Re: roImageCanvas Image Cancellation

"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.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
destruk
Level 10

Re: roImageCanvas Image Cancellation

Thanks a bunch! This is great!
0 Kudos
RokuKevin
Level 9

Re: roImageCanvas Image Cancellation

and thanks for pointing out the doc bug. I'll remedy that in the next SDK release.

--Kevin
0 Kudos