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: 
bosborne
Visitor

Check if screen has been closed?

I'm wondering if it's possible to detect if a screen has been closed?

In one function, it's possible that a screen I'm working with would have been closed. Once that method exits, additional code runs that may need to execute a different path depending on if that screen was closed or not. In this case, I can't simply go by the return value of that first method.

I tried checking that object to see if it is = invalid, but that doesn't work.

Any ideas? Thanks
0 Kudos
6 REPLIES 6
RokuJoel
Binge Watcher

Re: Check if screen has been closed?

You need to check for the msg.isScreenClosed() event:

while true
msg=wait(0,port)
if lcase(type(msg))=lcase("name of screentypemessage goes here") then
if msg.isScreenClosed() then
return "Screen Closed"
else if <some other condition> then
print "do something else"
end if
end if
end while
0 Kudos
bosborne
Visitor

Re: Check if screen has been closed?

Can you confirm that during a connection loss, there's nothing I can do to prevent the Roku from kicking back to the main screen?
0 Kudos
RokuJoel
Binge Watcher

Re: Check if screen has been closed?

If your channel is kicking back to the main screen, that means that some value is not what is expected in your code. You can check if the value is the correct type or is invalid before doing a comparison or using a variable, for example if you are expecting an roXMLElement you can check first:

if myvar <> invalid and lcase(type(myvar))="roxmlelement" then
doSomeProcess(myvar)
else
handleTheError(myvar)
end if


otherwise, your channel will probably crash when the value is not what is expected, and in a published channel, a crash takes you back to the main screen.

- Joel
0 Kudos
bosborne
Visitor

Re: Check if screen has been closed?

I wouldn't necessarily say this is a crash - as Roku pops up a message indicating there was a network connectivity loss, and prompts to being me into the network settings. If it was just a normal crash, I don't think that would happen. I tried by playing a VOD HLS stream and disconnecting the ethernet cable. Then it played out all it had, and I assume when it reached the end and couldn't download anymore it triggered something in the Roku to do that.

Do you have any recommends for debugging this - normally I telnet into the Roku to see debug output. However during a network loss I lose the telnet session and debug output.
0 Kudos
RokuJoel
Binge Watcher

Re: Check if screen has been closed?

Ah, that. No there isn't any way to detect that in your channel.

Do you know why you are losing your network connection, or is it somehow triggered from within your channel? If it is, can you reproduce the situation where it occurs?

- Joel
0 Kudos
bosborne
Visitor

Re: Check if screen has been closed?

Thanks. I'm doing it on purpose to see how the app reacts to a loss of network connectivity. I was experimenting with creating an app that could stream something 24/7 and "restart" itself in case of a network failure. I suppose that is not possible.
0 Kudos