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.
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Channel Surfer

How to start task again?

I have a problem with task. I want to get data from the server. So I have a task:
sub init() = "executeTask"
vimeoClientID = "clientId"
    vimeoClientSecret = "clientSecret+"
    blob = CreateObject("roByteArray")
    blob.FromAsciiString(vimeoClientID + ":" + vimeoClientSecret)
    m.base64Vimeo = blob.ToBase64String()
end sub

function executeTask()    
    url =
    print("In execute task function")
    request = CreateObject("roURLTransfer")
    request.AddHeader("X-Roku-Reserved-Dev-Id", "")
    request.AddHeader("Authorization","basic " + m.base64Vimeo)
    request.SetURL(url) = request.getToString() = url
end function

In mainscene I create a task in main function
sub init()
    m.requestTask = CreateObject("roSGNode", "RequestTask")    [size=85][font=Helvetica Neue, Helvetica, Arial, sans-serif]   [/font][/size]
end sub

Also there is a function to start my task.
sub makeURLRequest(props)
m.requestTask.setField("url", props.url)
m.requestTask.control = "RUN"
m.requestTask.observeField("response", props.callback)
end sub

I get data (bunch of videos) from server like this:
sub getVimeoChannelVideosPage(page, callback)
print("Making request for page: " + page.toStr())
url: "" + + "/videos?page=" + page.toStr(),
callback: callback,
end sub

sub getVimeoChannelVideos(callback)
getVimeoChannelVideosPage(1, "onGetVimeoVideosPage")
end sub

And the problem happens in callback when I get first page with videos and  want to get another one page by restarting task. But code in executeTask function  never happens.
sub onGetVimeoVideosPage()
response = m.requestTask.response
json = parseJSON(response)

videos =
nextPage =

if (nextPage <> invalid) += 1
print("Current page " +
getVimeoChannelVideosPage(, "onGetVimeoVideosPage")
end if

end sub

I highly appreciate any help or advice. Also feel so sorry for my bad english.
0 Kudos
Channel Surfer

Re: How to start task again?

I'd suggest that instead of storing a reference to the task, create a new one for each request.
With your current implementation, you could try adding a STOP but it may not work:
sub makeURLRequest(props)
 m.requestTask.control = "STOP"
 m.requestTask.setField("url", props.url)
 m.requestTask.control = "RUN"
 m.requestTask.observeField("response", props.callback)
end sub
0 Kudos
Binge Watcher

Re: How to start task again?

I am running this file in task.xml


<?xml version=“1.0” encoding=“utf-8" ?>
<!-- Copyright 2016 Roku Corp. All Rights Reserved. -->
<component name=“ContentReader” extends=“Task”>
<script type=“text/brightscript”>
sub init() = “getAPIResponse”
end sub

sub getAPIResponse()
port = CreateObject(“roMessagePort”)
request = CreateObject(“roUrlTransfer”)
jsonString = request.GetToString()
jsonParsed = ParseJson(jsonString) = jsonParsed
end sub


And Used this below function in main.brs file


sub Main()
print “in showChannelSGScreen”
m.readXMLContentTask = createObject(“roSGNode”, “ContentReader”)
m.readXMLContentTask.observeField(“content”, “setcontent”)
m.readXMLContentTask.contenturi = “”
m.readXMLContentTask.control = “RUN”
readData =
print “readData”
end sub

but this function is not executed in main.brs file
Can you please help me to execute this function from main.brs Or provide the sample examples

0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.