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

Videoplayer fails with Welcome and Registration screens

Hi Guys,

I am building an application based on the Videoplayer example. As a part of this application, I need to have a Welcome screen and a Registration Screen. So I added two function calls in the Main function of appMain.brs like this:

Sub Main()

'initialize theme attributes like titles, logos and overhang color
initTheme()

'prepare the screen for display and get ready to begin
screen=preShowHomeScreen("", "")
if screen=invalid then
print "unexpected error in preShowHomeScreen"
return
end if

showWelcomeScreen()

showRegScreen()

'set to go, time to get started
showHomeScreen(screen)

End Sub


Please find the function definitions below.

Function showWelcomeScreen() As Void

port = CreateObject("roMessagePort")
screen = CreateObject("roParagraphScreen")
screen.SetMessagePort(port)

screen.AddHeaderText("XYZ Channel")
screen.AddParagraph("blah")
screen.AddParagraph("blah blah")
screen.AddButton(1, "next")
screen.Show()

while true
msg = wait(0, screen.GetMessagePort())
if type(msg) = "roParagraphScreenEvent" then
if msg.isButtonPressed() then
exit while
end if
end if
end while

screen.Close()

End Function

Function showRegScreen() As Void

port = CreateObject("roMessagePort")
screen = CreateObject("roCodeRegistrationScreen")
screen.SetMessagePort(port)

screen.AddParagraph("blah")
screen.AddFocalText(" ", "spacing-dense")
screen.AddFocalText("From your computer,", "spacing-dense")
screen.AddFocalText("go to www.xyz.com/roku", "spacing-dense")
screen.AddFocalText("and enter this code:", "spacing-dense")
screen.AddFocalText(" ", "spacing-dense")
screen.SetRegistrationCode("retrieving code..")
screen.AddParagraph("This screen will automatically update once your Roku player has been linked.")
screen.AddButton(0, "get a new code")
screen.AddButton(1, "back")
screen.Show()

sleep(10000)
screen.SetRegistrationCode("ABC7TG")
screen.Show()

while true
msg = wait(0, screen.GetMessagePort())
if type(msg) = "roCodeRegistrationScreenEvent" then
exit while
end if
end while

screen.Close()

End Function


The registration screen should show as if the code is being fetched from the web server. Thats why, the 10s delay! Now, the problem here is when I run the application the Welcome screen appears and when I press the next button, the registration screen flashes and the application terminates and returns to the Main roku screen. I was wondering if anyone else is facing this problem or is it something in my code? I would really appreciate any comments on this and sorry for the long post!
0 Kudos
11 REPLIES 11
RokuKevin
Visitor

Re: Videoplayer fails with Welcome and Registration screens

I don't see anything wrong with the code you posted.... Maybe there's something wrong in some of the unposted functions....

Anyway I used your showWelcomeScreen() and showRegScreen() in a quick sample app that displays a poster screen when hitting the showRegScreen() back button....

Maybe that will get you going?



Sub Main()

'initialize theme attributes like titles, logos and overhang color
initTheme()

'display a fake screen while the real one initializes. this screen
'has to live for the duration of the whole app to prevent flashing
'back to the roku home screen.
screenFacade = CreateObject("roPosterScreen")
screenFacade.show()

showWelcomeScreen()
showRegScreen()

Items = [ {ContentType:"episode"
SDPosterUrl:"file://pkg:/images/DanGilbert.jpg"
HDPosterUrl:"file://pkg:/images/DanGilbert.jpg"
IsHD:true
HDBranded:true
ShortDescriptionLine1:"Dan Gilbert asks, Why are we happy?"
ShortDescriptionLine2:""
Description:"Harvard psychologist Dan Gilbert says our beliefs about what will make us happy are often wrong -- a premise he supports with intriguing research, and explains in his accessible and unexpectedly funny book, Stumbling on Happiness."
Rating:"NR"
StarRating:"80"
Length:1280
Categories:["Technology","Talk"]
Title:"Dan Gilbert asks, Why are we happy?"
},
{ContentType:"episode"
SDPosterUrl:"file://pkg:/images/DanGilbert.jpg"
HDPosterUrl:"file://pkg:/images/DanGilbert.jpg"
IsHD:true
HDBranded:true
ShortDescriptionLine1:"Dan Gilbert asks, Why are we happy?"
ShortDescriptionLine2:""
Description:"Harvard psychologist Dan Gilbert says our beliefs about what will make us happy are often wrong -- a premise he supports with intriguing research, and explains in his accessible and unexpectedly funny book, Stumbling on Happiness."
Rating:"NR"
StarRating:"80"
Length:1280
Categories:["Technology","Talk"]
Title:"Dan Gilbert asks, Why are we happy?"
}
]



port = CreateObject("roMessagePort")
screen = CreateObject("roPosterScreen")
screen.SetMessagePort(port)

screen.SetBreadcrumbText("Roku", "FeatureTests")

Categories = [ "Category 1", "Category 2", "Category 3" ]
Categories2 = [ "Category A", "Category B", "Category C" ]
screen.SetListNames(Categories)
screen.SetContentList(Items)
screen.Show()

while true
msg = wait(0, screen.GetMessagePort())
print "Event: type: "; msg.GetType(); " Index: " ;msg.GetIndex(); " Data: " msg.GetData(); " msg: " msg.GetMessage()
if type(msg) = "roPosterScreenEvent"
if msg.isScreenClosed()
print "Screen closed"
exit while
endif
endif
end while


End Sub


'*************************************************************
'** Set the configurable theme attributes for the application
'**
'** Configure the custom overhang and Logo attributes
'*************************************************************

Sub initTheme()

app = CreateObject("roAppManager")
theme = CreateObject("roAssociativeArray")

theme.OverhangPrimaryLogoOffsetSD_X = "72"
theme.OverhangPrimaryLogoOffsetSD_Y = "15"
theme.OverhangSliceSD = "pkg:/images/Overhang_BackgroundSlice_SD43.png"
theme.OverhangPrimaryLogoSD = "pkg:/images/Logo_Overhang_SD43.png"

theme.OverhangPrimaryLogoOffsetHD_X = "123"
theme.OverhangPrimaryLogoOffsetHD_Y = "20"
theme.OverhangSliceHD = "pkg:/images/Overhang_BackgroundSlice_HD.png"
theme.OverhangPrimaryLogoHD = "pkg:/images/Logo_Overhang_HD.png"

app.SetTheme(theme)

End Sub


Function showWelcomeScreen() As Void

port = CreateObject("roMessagePort")
screen = CreateObject("roParagraphScreen")
screen.SetMessagePort(port)

screen.AddHeaderText("XYZ Channel")
screen.AddParagraph("blah")
screen.AddParagraph("blah blah")
screen.AddButton(1, "next")
screen.Show()

while true
msg = wait(0, screen.GetMessagePort())
if type(msg) = "roParagraphScreenEvent" then
if msg.isButtonPressed() then
exit while
end if
end if
end while

screen.Close()

End Function

Function showRegScreen() As Void

port = CreateObject("roMessagePort")
screen = CreateObject("roCodeRegistrationScreen")
screen.SetMessagePort(port)

screen.AddParagraph("blah")
screen.AddFocalText(" ", "spacing-dense")
screen.AddFocalText("From your computer,", "spacing-dense")
screen.AddFocalText("go to www.xyz.com/roku", "spacing-dense")
screen.AddFocalText("and enter this code:", "spacing-dense")
screen.AddFocalText(" ", "spacing-dense")
screen.SetRegistrationCode("retrieving code..")
screen.AddParagraph("This screen will automatically update once your Roku player has been linked.")
screen.AddButton(0, "get a new code")
screen.AddButton(1, "back")
screen.Show()

sleep(10000)
screen.SetRegistrationCode("ABC7TG")
screen.Show()

while true
msg = wait(0, screen.GetMessagePort())
if type(msg) = "roCodeRegistrationScreenEvent" then
exit while
end if
end while

screen.Close()

End Function
0 Kudos
asenthil
Visitor

Re: Videoplayer fails with Welcome and Registration screens

Thanks a lot Kevin! The facade screen did the magic. I did not have one in my main function and without it for some reason the app was getting killed after displaying the Welcome screen and before the registration screen could load itself. Now, it works well. Thanks again.
0 Kudos
RokuKevin
Visitor

Re: Videoplayer fails with Welcome and Registration screens

Without the screen facade there are no screens left in the display stack when the reg screen closes so the app exits....

--Kevin
0 Kudos
FML2010
Visitor

Re: Videoplayer fails with Welcome and Registration screens

I tried this example above and gave me some help thank you!

But the issues I now have are these:

1.) retrieving code takes a long time like 20 + seconds
2.) if i click on get a new code it just takes me to the categories
3,) with this example it now doesn't allow for the categories etc shown from the xml in the original videoplayer example


how can we get this to work together with the video player to grab the Xml for categories etc. Just finally got the xml to be created server side so really want to keep that working.
0 Kudos
RokuKevin
Visitor

Re: Videoplayer fails with Welcome and Registration screens

1) Note that the sleeps in my code are just to provide a simulation. Take them out when pointing to your real site!
2) This simulation doesn't wire up the "Get new Code" button... you have to do that.
3) You would replace the categories parsed from your xml where the current hardcoded Categories = [ "Category 1", "Category 2", "Category 3" ] array is.

--Kevin
0 Kudos
FML2010
Visitor

Re: Videoplayer fails with Welcome and Registration screens

Thanks Kevin but i have tried and tried but it wont work, i seem to always cut off something that will then not even show my channel .

all i am trying to do is a registration screen and then go to the appHomeScreen.brs page after a good registration.

then on a Back button just go to a alternate poster screen like simplePoster.brs -- mainly so i can see how this back button is working and sending to another page.

also is it possible to add a banner in this reg screen?
0 Kudos
RokuKevin
Visitor

Re: Videoplayer fails with Welcome and Registration screens

I suggest you start with the working example code in this post and make your modifications step by step.

There is no way to have an ad banner on the reg screen.

--Kevin
0 Kudos
FML2010
Visitor

Re: Videoplayer fails with Welcome and Registration screens

Kevin,

I have been able to use the register example and link my roku....

but when trying to get your example here working i am having a few issues.

1.) in the Register example i was able to put the url of the prelink like this:
"m.UrlGetRegCode = m.UrlBase + "/prelink.php"".

so how do we do the prelinking in this example? i tried adding the regScreen.brs from the register example i got working, but it doesnt do anything actually

is this example almost complete like i only need appMain.brs or does it need more supporting files?

could you just show a example of using the registration with the video player example? i have tried adding the whole registration example into the video player example folder. but not sure how to get them to play with each other correctly.
0 Kudos
joetesta
Roku Guru

Re: Videoplayer fails with Welcome and Registration screens

NOTE: I made this question a new topic here viewtopic.php?f=34&t=39292&p=260215#p260215
i hope that's OK!

I started with the videoplayer example, added my modified 'regScreen.brs' file to the folder, then modified 'appHomeScreen.brs', adding the line 'doRegistration()' between these two lines:
      else if msg.isListItemSelected() then
print "list item selected | index = "; msg.GetIndex()


Now the roku asks the user to register before playing the videos (YAY!)

In the example, it looks like the first part of doRegistration() is to load the reg token and if it exists, bypass the registration.

Is the token somehow associated to our channel inside the roku, or do we need to give the token a name more unique than "RegToken" (otherwise any old RegToken would grant access to our channel)?

And what if the user cancels their membership on our site, how can we deactivate their token if we don't check it? I don't think that we can, given the way this is working in the example...

I think there needs to be another script on my server that checks the unique code stored in roku's registry and tells the roku whether it is authorized, and if yes, bypass reg and give them the content, or if not, then doRegistration().

It should work similarly to the other components of registration (Brightscript sends out a call to the server including the stored unique code and handles the response; the server receives the inquiry with stored code, checks the code in the db, and returns the appropriate response)

Is this component in the register example, or something I'll need to write myself?
aspiring
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.