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: 
squirreltown
Roku Guru

function button

I can't even imaging how to start with this so I'll ask - I would like to make a button so the user can turn on/off a function - in my case a custom screen saver. I've seen the theEndless has a "function" button or what looks like it in the Instant Watch app. I know i'll have to get into saving the choice in the box-persistence wise but i'll worry about that later, just want to work out the function on/off thing now - Know its some kind of if/else statement, if someone can direct me where to start that would be great.

Thanks
Kinetics Screensavers
0 Kudos
10 REPLIES 10
RokuJoel
Binge Watcher

Re: function button

you would probably write a value into the registry (persistent memory) for example "screensaver" key with the value "on"
Then your screensaver would check that value when it launches and if the value is not "on" then it will exit. The result should be that the system screensaver runs instead of your custom screensaver - the flashing roku on older devices, bouncing roku on Roku3.

- Joel
0 Kudos
squirreltown
Roku Guru

Re: function button

Great - Thank You Joel. I'll need to have my button check for the state also, so it can either show on or off depending what the state is. At least by now I've learned it won't be as simple as i think it is, but I'll get it eventually. thanks again.
Kinetics Screensavers
0 Kudos
RokuJoel
Binge Watcher

Re: function button

take a look at the regread / regwrite function in GeneralUtils.brs in your SDK (in the videoplayer example), it's pretty simple, just:

regwrite("screensaver","on","mychannel")

keyname, value, section name.

- Joel
0 Kudos
squirreltown
Roku Guru

Re: function button

Thanks Joel, this actually was pretty simple, you steered me just right. I am able to write On/off values into the registry, and have the buttons worked out. The only problem, and this is a little off-thread - is that the message dialog wont update when I change the state of the key value. ClearButtons/AddButtons doesn't seem to work on the MessageDialog and just .Show doesn't seem to refresh it. I can just close the dialog, but this one button would be good not to.
thanks for your help.

anything wrong here (tried the .show inside and out side the if statement)

if msg.isbuttonpressed()
button = msg.getindex()
print "Info Button ";button;" pressed"
if button = 9
SetSSstateOn("")
sleep(100)
infomenu.Show()
end if
end if
Kinetics Screensavers
0 Kudos
squirreltown
Roku Guru

Re: function button

Ok i found one other problem, which is that when i have the custom screensaver turned OFF, the screensaver that comes on is the default Roku logo, but i have it set to the digital clock in settings. Really not sure how to get around this. here is the RunScreensaver sub (its a modified audioapp one)

Sub RunScreenSaver()
sec = CreateObject("roRegistrySection", "phcom")
m.filesystem = CreateObject("roFileSystem")
m.dev = CreateObject("roDeviceInfo")
m.art_urls = CreateObject("roArray",10,true)
if (not IsMainAppRunning()) then
print "Main app not running. Exiting."
return
end if
if (GetSavedCoverArtUrl() = "") then
print "No cover art available. Exiting."
return
end if
if sec.Read("screensaver") = "on"
DisplayScreenSaver()
else
return
end if
End Sub
Kinetics Screensavers
0 Kudos
TheEndless
Channel Surfer

Re: function button

"squirreltown" wrote:
Thanks Joel, this actually was pretty simple, you steered me just right. I am able to write On/off values into the registry, and have the buttons worked out. The only problem, and this is a little off-thread - is that the message dialog wont update when I change the state of the key value. ClearButtons/AddButtons doesn't seem to work on the MessageDialog and just .Show doesn't seem to refresh it. I can just close the dialog, but this one button would be good not to.

The only way to refresh buttons on a message dialog is to redraw the dialog completely. You can show a new one before you close the old one, so it gives the appearance (for the most part) of updating the same dialog.

"squirreltown" wrote:
Ok i found one other problem, which is that when i have the custom screensaver turned OFF, the screensaver that comes on is the default Roku logo, but i have it set to the digital clock in settings. Really not sure how to get around this.

There's no way around that one, either. If your channel's screensaver exits, it reverts to the default bouncing Roku logo. There's no way to get it to revert to the user's selected screensaver.
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
squirreltown
Roku Guru

Re: function button

Thank you Endless, I sort of suspected that. Sometimes I think i've read a post to that effect, but then cant find it again.
It does sort of negate the whole turning off the screensaver thing, you might as well leave it on, since turning it off doesn't give the results you expect. I wonder what the actual mechanism is, the existence of a screensaver.brs file or RunScreensaver function?

And the component reference says very clearly that .Show() is to "Display or refresh the screen after creation or state changes"
I wonder what they meant by that. Wishful thinking it seems..

Thanks theEndless.
Kinetics Screensavers
0 Kudos
squirreltown
Roku Guru

Re: function button

OK i answered my own question, changing RunScreenSaver() to xRunScreenSaver() gets the users screensaver selection back, so there is the mechanism. So - any way to get the Roku OS to use a screensaver NOT named that? Roku engineers - tell me theres some "undocumented" thing that you've got on the bench somewhere.
I suppose if i could build my own digital clock (my personal choice) I could build that in but it wouldn't help others. If I knew how to hack, i'd be hacking now. I'm only a character away...
Kinetics Screensavers
0 Kudos
TheEndless
Channel Surfer

Re: function button

"squirreltown" wrote:
OK i answered my own question, changing RunScreenSaver() to xRunScreenSaver() gets the users screensaver selection back, so there is the mechanism. So - any way to get the Roku OS to use a screensaver NOT named that? Roku engineers - tell me theres some "undocumented" thing that you've got on the bench somewhere.
I suppose if i could build my own digital clock (my personal choice) I could build that in but it wouldn't help others. If I knew how to hack, i'd be hacking now. I'm only a character away...

You could always develop your screensaver as a separate channel and let users install it separately if they want it.
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