Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 

Create Custom Library with no UI Components

HI 

I am newbie to brightscript and ROKU. We have a situation here where in we need to develop a library for video measurement.
This do not require any UI elements. All we need to do is take some input perform some logic behind scene. 

For this , i need to create something similar to class in OO programming.  The closest i have come across is using associative arrays- through which i can assign key-value pairs for variables and methods that i require. I created a brightscript file measure.brs and added all my methods. 

During initialization of lib, we start a timer and call some particular methods every 500ms based on position we get from video play-head. We also have other methods that are called on user actions. 

The problem here : Control never comes out of Timer, So no other methods are being executed since main thread is occupied by timer. 

I have read some forms and found out about task node, which is capable of executing something asynchronously.  So i have created a timer task and tried to pass the associativeArray as object reference to task.  Inside the task i am able to access member variables but all firsthand functions are treated as invalid. so i can run timer task but cannot call methods that i intend to. 

please note the methods cannot be separated from measure.brs file..

Do i have any solution for this. 

any help is appreciated
0 Kudos
4 Replies
joetesta
Level 10

Re: Create Custom Library with no UI Components

If I'm understanding correctly, you should be able to include the brs file that has your methods by including it in the task's xml file;
<script type="text/brightscript" uri="pkg:/components/measure.brs" />

And then your task would have access to those methods.

There's also the possibility to create objects with functions defined within and pass the whole object in, not sure if it'll work with tasks this way, can't recall doing this yet with a task... but don't see any reason it shouldn't work.  Here's the general form;

function parentFunct(params = whatever) as object
 this = {}  
 this.myChildFunct = function()
     someResult = DoStuff()
    return someResult
  end function
  return this
end function
aspiring
0 Kudos

Re: Create Custom Library with no UI Components

Thanks for the tip joetesta

I ll give that a try and check.
0 Kudos

Re: Create Custom Library with no UI Components

The solution might not work in my situation.

We have two files: measure.brs and timertask.xml as our end product
Timertask is part of one of measure.brs for initiating a timer and call a method periodically. 

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco} span.s1 {color: #3f7777}

m.Timer       = m.top.findNode("timerTask")

and i am sending object to timer in following way

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; color: #3629d2} span.s1 {color: #3629d2} span.s2 {color: #3f7777} span.s3 {color: #000000}
initTimers = function()
    m.doUpdate()
    m.doSync()
    m.timer.setField("test",m)
    m.timer.control = "RUN"
    end function

and inside timer if i try to access m.top.test.doupdate() I am getting invalid -p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco}
Member function not found in BrightScript Component or interface. (runtime error &hf4) in pkg:/components/timerTask.xml(22)

I have two questions. 

Can i have a timer run in same file without help of task. Will i be able to run it in background thread (i Think No)

Is there a way we can pass member functions into task 

Thanks
Srikanth
0 Kudos
tim_beynart
Level 7

Re: Create Custom Library with no UI Components

You can use a task, I have written a couple analytics libraries that do exactly what you describe.
A task runs it it's own thread, and you can have a timer running within it or simply have it record stuff with each playhead update.  Your task can observe field changes on the player.
Shameless brag: I wrote up a tutorial on SceneGraph that might help you get familiar with tasks and stuff: https://github.com/learnroku/crash-course
0 Kudos