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: 

Stack Not Working, Exits App

My attempt here is to create a player with a live video stream and confirm the viewer is still watching after a predetermined time. Currently I have the video playing and a confirmation dialog pop up. If a viewer confirms they are still watching then the timer loop resets and repeats as necessary.

The issue I'm running into is that if the viewer does not confirm they are still watching or clicks no, then the app completely exits back to the main Roku screen. From my understanding, since I am creating the paragraph screen before the video screen, then the screens are stacked and if the video screen is closed, then in theory it should return to the previous screen in the stack. But it's not doing this.

Am I misunderstanding the use of stacked screens or is there something wrong with my code?

Thanks.

Function Main()
Console_Log("Creating the global variables")
m.popup_time = 10000
m.close_time = 30000

m.port = CreateObject("roMessagePort")

Show_Main_Screen()

video = CreateObject("roVideoScreen")
video.SetContent({
Title: "Test Video For Timer Functionality"
StreamFormat: "mp4"
Stream: { URL: "http://video.mp4"}
})
video.Show()
Console_Log("Video Screen Shown")

Main_Timer()
End Function







Function Show_Main_Screen()
screen = CreateObject("roParagraphScreen")
screen.SetMessagePort(m.port) ' instruct screen to send events to port

screen.AddParagraph("Just a test screen for a timer function")

screen.Show()
Console_Log("Main Screen Shown")
End Function







Function Show_Popup() as Boolean
Console_Log("Starting Popup Function")
newport = CreateObject("roMessagePort")
popup = CreateObject("roMessageDialog")
popup.SetMessagePort(newport) ' instruct screen to send events to port

popup.SetTitle("Viewer")
popup.SetText("Are you still watching?")

popup.AddButton(0, "Yes")
popup.AddButton(1, "No")

popup.Show()
Console_Log("Popup Shown")

timer=createObject("rotimespan")
timer.Mark()

while true
msg = wait(5000, popup.GetMessagePort())
if type(msg) = "roMessageDialogEvent"
if msg.isButtonPressed()
if msg.GetIndex() = 0
popup.Close()
return true
exit while
else if msg.GetIndex() = 1
popup.Close()
exit while
end if
end if
end if
return false
end while

End Function







Function Main_Timer()
Console_Log("Main Timer Started")
timer=createObject("rotimespan")
port = CreateObject("roMessagePort")

timer.Mark()

while true
event = port.GetMessage()

if(event = invalid)
ticks = timer.TotalMilliseconds()

if(ticks > m.popup_time AND ticks < (m.popup_time+2000))
print Stri(m.popup_time+2000)
response = Show_Popup()
if (response = true)
Console_Log("Yes Button Was Pressed")
timer.Mark()
else if (response = false)
Console_Log("No Button Was Pressed")
exit while
end if
end if
end if
end while
End Function







Function Console_Log(Message)
print Message
End Function
שלום חבר

Dean at the School of Truth: a part of Autodidact University.

"A programmer is just a tool which converts caffeine into code"
Temet nosce
Vi Veri Veniversum Vivus Vici
Si vis pacem, para bellum
0 Kudos
4 Replies
TheEndless
Level 7

Re: Stack Not Working, Exits App

Your screen in Show_Main_Screen() is locally scoped, so it's going to close automatically when that function exits. The easiest fix would probably be to return the screen from that function and keep it alive in Main().
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

Re: Stack Not Working, Exits App

I made some modifications based off your suggestion, but it's still not working. Here are the modifications I made

Function Main()
....
temp = Show_Main_Screen()
temp.Show()
....
End Function

Function Show_Main_Screen() as Object
....
return screen
End Function


Function Main()
Console_Log("Creating the global variables")
m.popup_time = 10000
m.close_time = 30000

m.port = CreateObject("roMessagePort")

temp = Show_Main_Screen()
temp.Show()

video = CreateObject("roVideoScreen")
video.SetContent({
Title: "Test Video For Timer Functionality"
StreamFormat: "mp4"
Stream: { URL: "http://video.mp4"}
})
video.Show()
Console_Log("Video Screen Shown")

Main_Timer()
End Function







Function Show_Main_Screen() as Object
screen = CreateObject("roParagraphScreen")
screen.SetMessagePort(m.port) ' instruct screen to send events to port

screen.AddParagraph("Just a test screen for a timer function")

Console_Log("Main Screen Shown")
return screen
End Function
שלום חבר

Dean at the School of Truth: a part of Autodidact University.

"A programmer is just a tool which converts caffeine into code"
Temet nosce
Vi Veri Veniversum Vivus Vici
Si vis pacem, para bellum
0 Kudos
arifkhan
Level 7

Re: Stack Not Working, Exits App

Hi DukeOfMarshall, You must show video screen first and then paragraph screen as bellow

Show_Main_Screen()

video = CreateObject("roVideoScreen")
video.SetContent({
Title: "Test Video For Timer Functionality"
StreamFormat: "mp4"
Stream: { URL: "http://video.mp4"}
})
video.Show()
Console_Log("Video Screen Shown")


or you can use event loop as following

Function Main()
Console_Log("Creating the global variables")
m.popup_time = 10000
m.close_time = 30000

m.port = CreateObject("roMessagePort")

temp = Show_Main_Screen()
temp.Show()
Show_Video_Screen()
Main_Timer()
while true
msg = wait(0, temp.GetMessagePort())
if type(msg) = "roParagraphScreenEvent"
if msg.isScreenClosed()
exit while
'if you want to play again
'else if msg.isButtonPressed()
'Show_Video_Screen()
end if
end if
end while
End Function

Function Show_Main_Screen() as Object
screen = CreateObject("roParagraphScreen")
screen.SetMessagePort(m.port) ' instruct screen to send events to port

screen.AddParagraph("Just a test screen for a timer function")

Console_Log("Main Screen Shown")
return screen
End Function

Function Show_Video_Screen()
video = CreateObject("roVideoScreen")
video.SetContent({
Title: "Test Video For Timer Functionality"
StreamFormat: "mp4"
Stream: { URL: "http://video.mp4"}
})
video.Show()
Console_Log("Video Screen Shown")
End Function
0 Kudos

Re: Stack Not Working, Exits App

Thanks for the help and the suggestion, but that still didn't work for me. Your suggestion caused the app to exit from the video screen not long after the loading animation appeared and then the pop up would show up over the main screen instead of the playing video.

However, I was able to keep playing around with it and below is the code that I now have working. I think I may be completely misunderstanding the stack concept, but I completely left that behind and took a more object oriented approach to the situation. Now I have a working model that I can build on.

Thanks to everyone for their help and suggestions through this.

Sub Main()
Console_Log("Creating the global variables")
m.popup_time = 10000
m.close_time = 30000

m.port = CreateObject("roMessagePort")

temp = Show_Main_Screen()
temp.Show()

video = Show_Video_Screen()

Main_Timer(video)

while true
msg = wait(0, temp.GetMessagePort())
if type(msg) = "roParagraphScreenEvent"
if msg.isScreenClosed()
exit while
'if you want to play again
else if msg.isButtonPressed()
if msg.GetIndex() = 0
video = Show_Video_Screen()
Main_Timer(video)
else if msg.GetIndex() = 1
temp.Close()
exit while
end if
end if
end if
end while
End Sub







Function Show_Main_Screen() As Object
screen = CreateObject("roParagraphScreen")
screen.SetMessagePort(m.port) ' instruct screen to send events to port

screen.AddParagraph("Just a test screen for a timer function")

screen.AddButton(0, "Play Again")
screen.AddButton(1, "Exit")

Console_Log("Main Screen Shown")
return screen
End Function







Function Show_Video_Screen() As Object
video = CreateObject("roVideoScreen")
video.SetContent({
Title: "Test Video For Timer Functionality"
StreamFormat: "mp4"
Stream: {
URL: "http://video.mp4"
}
})
Console_Log("Video Screen Shown")
return video
End Function







Function Show_Popup() as Boolean
Console_Log("Starting Popup Function")
newport = CreateObject("roMessagePort")
popup = CreateObject("roMessageDialog")
popup.SetMessagePort(newport) ' instruct screen to send events to port

popup.SetTitle("Viewer")
popup.SetText("Are you still watching?")

popup.AddButton(0, "Yes")
popup.AddButton(1, "No")

popup.Show()
Console_Log("Popup Shown")

timer=createObject("rotimespan")
timer.Mark()

while true
msg = wait(5000, popup.GetMessagePort())
if type(msg) = "roMessageDialogEvent"
if msg.isButtonPressed()
if msg.GetIndex() = 0
popup.Close()
return true
exit while
else if msg.GetIndex() = 1
popup.Close()
exit while
end if
end if
end if
return false
end while

End Function







Sub Main_Timer(video as object)
Console_Log("Main Timer Started")
timer=createObject("rotimespan")
port = CreateObject("roMessagePort")

timer.Mark()

video.Show()

while true
event = port.GetMessage()

if(event = invalid)
ticks = timer.TotalMilliseconds()

if(ticks > m.popup_time AND ticks < (m.popup_time+2000))
print Stri(m.popup_time+2000)
response = Show_Popup()
if (response = true)
Console_Log("The 'Yes' Button Was Pressed")
timer.Mark()
else if (response = false)
Console_Log("The 'No' Button Was Pressed")
video.Close()
exit while
end if
end if
end if
end while
End Sub







Function Console_Log(Message)
print Message
End Function
שלום חבר

Dean at the School of Truth: a part of Autodidact University.

"A programmer is just a tool which converts caffeine into code"
Temet nosce
Vi Veri Veniversum Vivus Vici
Si vis pacem, para bellum
0 Kudos