Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
rikkrokker
Level 7

Reloading buttons in Audio Player

Hi all,

I'm pulling my hair out and need some help. I'm trying to update my previously working audio player app to allow for refresh of the player buttons based on playstate. I keep getting errors on the 'function reloadbuttons (screen as object, isplaying as boolean, ispaused as boolean)' line, saying that 'screen' is uninitialized. What am I missing (while I still have hair on my head)...




Function showAudioSpringboardScreen(item as object)
screen = CreateObject("roSpringboardScreen")
port = screen.getmessageport()
busydialog=CreateObject("roOneLineDialog") ' creates a dialog box
print "showAudioSpringboardScreen"
print item
print item.title


busydialog.SetMessagePort(port)
screen.AllowUpdates(false)
screen.SetBreadcrumbText("Live Audio Stream","")
screen.SetBreadcrumbEnabled(true)
screen.SetContent(item)
screen.Show()
audio=createobject("roaudioplayer")
isplaying=false
ispaused=false
reloadbuttons(screen,playing,paused)

screen.SetDescriptionStyle("audio") 'audio, movie, video, generic
' generic+episode=4x3,

screen.SetStaticRatingEnabled(false)
screen.AllowUpdates(true)
screen.setadurl("http://crntalk.com/podcast/roku/app/images/adbanner_hd.png","http://crntalk.com/podcast/roku/app/images/adbanner_sd.png")
screen.setAdSelectable(true)


downKey=3
selectKey=6

while true
msg = wait(0, aud.GetMessagePort())


'*******************
if type(msg)="roAudioPlayerEvent"
print msg.getmessage()
if msg.isStatusMessage() and msg.GetMessage() = "startup progress" then
busydialog.SetMessagePort(aud.GetmessagePort()) 'sets a message port for the dialog box
busydialog.SetTitle("Your CRN Live Stream will begin momentarily. ") 'displays a line of text for the dialog box title
busydialog.ShowBusyAnimation() ' enables a spinning animation
busydialog.Show() ' makes the dialog box and busy animation display

else if msg.isStatusMessage() and msg.GetMessage() = "start of play" then
busydialog.Close()

else if msg.isStatusMessage() and msg.GetMessage() = "end of playlist" then
busydialog.Close()
busydialog=CreateObject("roOneLineDialog") ' creates a dialog box
busydialog.SetMessagePort(aud.GetmessagePort()) 'sets a message port for the dialog box
busydialog.SetTitle("The Connection Timed Out.") 'displays a line of text for the dialog box title
busydialog.Show() ' makes the dialog box

busydialog.Close()
endif

'*******************

else if type(msg) = "roSpringboardScreenEvent"
if msg.isScreenClosed()
print "Screen closed"
exit while

else if msg.isadselected() then
print "Ad Selected"
showParagraphScreen(true)

else if msg.isButtonPressed()
print "Button pressed: "; msg.GetIndex(); " " msg.GetData()
if msg.GetIndex() = 0 then
print "Audio Player Selected"
audio.SetMessagePort (port)

if item <> invalid and type(m) = "roAssociativeArray"
print "Array OK"
print item.url
Print "Getting Stream"
audio.stop()
audio.addContent(item)
audio.play()
isplaying=false
ispaused=false
reloadbuttons(screen,isplaying,ispaused)

Else if isplaying and not ispaused then

Audio.pause()
isplaying=true
ispaused=false
reloadbuttons(screen,isplaying,ispaused)

else if isplaying and ispaused then

audio.resume()
isplaying=true
ispaused=true
reloadbuttons(screen,isplaying,ispaused)



else print "invalid"
'return -1
end if

else if msg.GetIndex() = 1
print "Audio Stop"
audio.stop()
islaying=false
ispaused=false
reloadbuttons(screen,isplaying,ispaused)

else if msg.GetIndex() = 2 then
if item.title = "CRN1" then
Schedule1(true)
print "Show Schedule"
else if item.title = "CRN2" then
Schedule2(true)
print "Show Schedule"
else if item.title = "CRN3" then
Schedule3(true)
print "Show Schedule"
else if item.title = "CRN4" then
Schedule4(true)
print "Show Schedule"
else if item.title = "CRN5" then
Schedule5(true)
print "Show Schedule"
else if item.title = "CRN6" then
Schedule6(true)
print "Show Schedule"
else if item.title = "CRN7" then
Schedule7(true)
print "Show Schedule"
else print "No Schedule Loaded"
end if
else if msg.GetIndex() = 3
showParagraphScreen(true)
else if msg.GetIndex() = 4
return true
endif
else
print "Unknown event: "; msg.GetType(); " msg: "; msg.GetMessage()
endif
else
print "wrong type.... type=";msg.GetType(); " msg: "; msg.GetMessage()
endif
end while


return screen
End Function

Function reloadButtons(screen as object, isplaying as Boolean, ispaused as Boolean)

screen.clearbuttons()
If not isplaying then
screen.addbutton(0,"Play")
Else if isplaying and not ispaused then
screen.addbutton(0,"Pause")
screen.addbutton(1,"Stop")

Else if isplaying and ispaused then
screen.addbutton(0,"Resume")
screen.addbutton(1,"Stop")
End if

'now add any non-conditional buttons

screen.AddButton(2,"Network Schedule")
screen.AddButton(3,"About CRN")
screen.AddButton(4,"Go Back")

End function
0 Kudos
6 Replies
Highlighted
Roku Employee
Roku Employee

Re: Reloading buttons in Audio Player

Are you sure it's screen that's not initialized and not one of the other paramters? These lines look like they may be a problem...

   isplaying=false
ispaused=false
reloadbuttons(screen,playing,paused)


You initialize 2 variables named isplaying and ispaused, then pass two different variable names to reloadbuttons()

When a crash happens, the BrightScript console will show you a list of all variables currently in scope and their values. It will also show you a trace with line numbers so you can see which call to the function caused the problem.
0 Kudos
Highlighted
rikkrokker
Level 7

Re: Reloading buttons in Audio Player

Thanks Chris,

I noticed a few typos in there after your reply. I guess sometimes an extra set of eyes is all I need. Working on this and will post my results.

Erik
0 Kudos
Highlighted
rikkrokker
Level 7

Re: Reloading buttons in Audio Player

OK,

So after the typo fixes, my screen shows the buttons but seems to stop the event loop after the 'reloadbuttons' call and hang on the screen. How do I handle the reloadbuttons call and return to the event loop?

Here's the updated code:

Function showAudioSpringboardScreen(item as object)
screen = CreateObject("roSpringboardScreen")
port = screen.getmessageport()
busydialog=CreateObject("roOneLineDialog") ' creates a dialog box
print "showAudioSpringboardScreen"
print item
print item.title
busydialog.SetMessagePort(port)

screen.SetDescriptionStyle("audio") 'audio, movie, video, generic
screen.SetStaticRatingEnabled(false)
screen.AllowUpdates(true)
screen.setadurl("http://crntalk.com/podcast/roku/app/images/adbanner_hd.png","http://crntalk.com/podcast/roku/app/images/adbanner_sd.png")
screen.setAdSelectable(true)
screen.AllowUpdates(false)
screen.SetBreadcrumbText("Live Audio Stream","")
screen.SetBreadcrumbEnabled(true)
screen.SetContent(item)
screen.Show()

audio=createobject("roaudioplayer")
isplaying=false
ispaused=false
reloadbuttons(screen,isplaying,ispaused)

downKey=3
selectKey=6



while true
msg = wait(0, screen.GetMessagePort())


'**Busy Dialog Box**
if type(msg)="roAudioPlayerEvent"
print msg.getmessage()
if msg.isStatusMessage() and msg.GetMessage() = "startup progress" then
busydialog.SetMessagePort(screen.GetmessagePort()) 'sets a message port for the dialog box
busydialog.SetTitle("Your CRN Live Stream will begin momentarily. ") 'displays a line of text for the dialog box title
busydialog.ShowBusyAnimation() ' enables a spinning animation
busydialog.Show() ' makes the dialog box and busy animation display

else if msg.isStatusMessage() and msg.GetMessage() = "start of play" then
busydialog.Close()

else if msg.isStatusMessage() and msg.GetMessage() = "end of playlist" then
busydialog.Close()
busydialog=CreateObject("roOneLineDialog") ' creates a dialog box
busydialog.SetMessagePort(screen.GetmessagePort()) 'sets a message port for the dialog box
busydialog.SetTitle("The Connection Timed Out.") 'displays a line of text for the dialog box title
busydialog.Show() ' makes the dialog box

busydialog.Close()
endif

'*******************

else if type(msg) = "roSpringboardScreenEvent"
if msg.isScreenClosed()
print "Screen closed"
exit while

else if msg.isadselected() then
print "Ad Selected"
showParagraphScreen(true)

else if msg.isButtonPressed()
print "Button pressed: "; msg.GetIndex(); " " msg.GetData()
if msg.GetIndex() = 0 then
print "Audio Player Selected"
audio.SetMessagePort (port)

if item <> invalid and type(m) = "roAssociativeArray"
print "Array OK"
print item.url
Print "Getting Stream"
audio.stop()
audio.addContent(item)
audio.play()
isplaying=false
ispaused=false
reloadbuttons(screen,isplaying,ispaused)

else if isplaying and not ispaused then

Audio.pause()
isplaying=true
ispaused=false
reloadbuttons(screen,isplaying,ispaused)

else if isplaying and ispaused then

audio.resume()
isplaying=true
ispaused=true
reloadbuttons(screen,isplaying,ispaused)



else print "invalid"
return -1
end if

else if msg.GetIndex() = 1
print "Audio Stop"
audio.stop()
islaying=false
ispaused=false
reloadbuttons(screen,isplaying,ispaused)

else if msg.GetIndex() = 2 then
if item.title = "CRN1" then
Schedule1(true)
print "Show Schedule"
else if item.title = "CRN2" then
Schedule2(true)
print "Show Schedule"
else if item.title = "CRN3" then
Schedule3(true)
print "Show Schedule"
else if item.title = "CRN4" then
Schedule4(true)
print "Show Schedule"
else if item.title = "CRN5" then
Schedule5(true)
print "Show Schedule"
else if item.title = "CRN6" then
Schedule6(true)
print "Show Schedule"
else if item.title = "CRN7" then
Schedule7(true)
print "Show Schedule"
else print "No Schedule Loaded"
end if
else if msg.GetIndex() = 3
showParagraphScreen(true)
else if msg.GetIndex() = 4
return true
endif
else
print "Unknown event: "; msg.GetType(); " msg: "; msg.GetMessage()
endif
'else
'print "wrong type.... type="; msg.GetType(); " msg: "; msg.GetMessage()
endif
end while


return true
End Function

Function reloadButtons(screen as object, isplaying as Boolean, ispaused as Boolean)

screen.clearbuttons()
If not isplaying then
screen.addbutton(0,"Play")
Else if isplaying and not ispaused then
screen.addbutton(0,"Pause")
screen.addbutton(1,"Stop")

Else if isplaying and ispaused then
screen.addbutton(0,"Resume")
screen.addbutton(1,"Stop")
End if

'now add any non-conditional buttons

screen.AddButton(2,"Network Schedule")
screen.AddButton(3,"About CRN")
screen.AddButton(4,"Go Back")

End function
0 Kudos
Highlighted
Roku Employee
Roku Employee

Re: Reloading buttons in Audio Player

You aren't setting a message port on your springboard screen, so your Wait() never gets a roSpringboardScreenEvent. And you're setting the message port on your audio player in your roSpringboardScreenEvent handler, so that never happens either.
0 Kudos
rikkrokker
Level 7

Re: Reloading buttons in Audio Player

So I cleaned up the MSG port oversight and some other housekeeping, but the app still hangs after the reloadbuttons function. Telnet shows no errors, the app just stops reponding with no buttons on screen. The graphic elements are there, but no buttons. The event loop seems to stop.

Function showAudioSpringboardScreen(item as object)
screen = CreateObject("roSpringboardScreen")
port = screen.getmessageport()
busydialog=CreateObject("roOneLineDialog") ' creates a dialog box
print "showAudioSpringboardScreen"
print item
print item.title
'busydialog.SetMessagePort(port)

screen.SetMessagePort(port)
screen.SetDescriptionStyle("audio") 'audio, movie, video, generic
screen.SetStaticRatingEnabled(false)
screen.AllowUpdates(true)
screen.setadurl("http://crntalk.com/podcast/roku/app/images/adbanner_hd.png","http://crntalk.com/podcast/roku/app/images/adbanner_sd.png")
screen.setAdSelectable(true)
screen.AllowUpdates(false)
screen.SetBreadcrumbText("Live Audio Stream","")
screen.SetBreadcrumbEnabled(true)
screen.SetContent(item)
screen.Show()

audio=createobject("roaudioplayer")
audio.SetMessagePort (screen.GetMessagePort())
isplaying=false
ispaused=false
reloadbuttons(screen,isplaying,ispaused)

downKey=3
selectKey=6



while true
msg = wait(0, screen.GetMessagePort())


'**Busy Dialog Box**
if type(msg)="roAudioPlayerEvent"
print msg.getmessage()
if msg.isStatusMessage() and msg.GetMessage() = "startup progress" then
busydialog.SetMessagePort(screen.GetmessagePort()) 'sets a message port for the dialog box
busydialog.SetTitle("Your CRN Live Stream will begin momentarily. ") 'displays a line of text for the dialog box title
busydialog.ShowBusyAnimation() ' enables a spinning animation
busydialog.Show() ' makes the dialog box and busy animation display

else if msg.isStatusMessage() and msg.GetMessage() = "start of play" then
busydialog.Close()

else if msg.isStatusMessage() and msg.GetMessage() = "end of playlist" then
busydialog.Close()
busydialog=CreateObject("roOneLineDialog") ' creates a dialog box
busydialog.SetMessagePort(screen.GetmessagePort()) 'sets a message port for the dialog box
busydialog.SetTitle("The Connection Timed Out.") 'displays a line of text for the dialog box title
busydialog.Show() ' makes the dialog box

busydialog.Close()
endif

'*******************


else if type(msg) = "roSpringboardScreenEvent"
if msg.isScreenClosed()
print "Screen closed"
exit while

else if msg.isadselected() then
print "Ad Selected"
showParagraphScreen(true)

else if msg.isButtonPressed()
print "Button pressed: "; msg.GetIndex(); " " msg.GetData()
if msg.GetIndex() = 0 then
if not isplaying and not ispaused then
print "Audio Player Selected"

if item <> invalid and type(m) = "roAssociativeArray"
print "Array OK"
print item.url
Print "Getting Stream"
audio.stop()
audio.addContent(item)
audio.play()
isplaying=false
ispaused=false
reloadbuttons(screen,isplaying,ispaused)
else print "invalid"
return -1
end if



else if isplaying and not ispaused then

Audio.pause()
isplaying=true
ispaused=false
reloadbuttons(screen,isplaying,ispaused)

else if isplaying and ispaused then

audio.resume()
isplaying=true
ispaused=true
reloadbuttons(screen,isplaying,ispaused)

end if


else if msg.GetIndex() = 1
print "Audio Stop"
audio.stop()
islaying=false
ispaused=false
reloadbuttons(screen,isplaying,ispaused)

else if msg.GetIndex() = 2 then
if item.title = "CRN1" then
Schedule1(true)
print "Show Schedule"
else if item.title = "CRN2" then
Schedule2(true)
print "Show Schedule"
else if item.title = "CRN3" then
Schedule3(true)
print "Show Schedule"
else if item.title = "CRN4" then
Schedule4(true)
print "Show Schedule"
else if item.title = "CRN5" then
Schedule5(true)
print "Show Schedule"
else if item.title = "CRN6" then
Schedule6(true)
print "Show Schedule"
else if item.title = "CRN7" then
Schedule7(true)
print "Show Schedule"
else print "No Schedule Loaded"
end if
else if msg.GetIndex() = 3
showParagraphScreen(true)
else if msg.GetIndex() = 4
return true
endif
else
print "Unknown event: "; msg.GetType(); " msg: "; msg.GetMessage()
endif
'else
'print "wrong type.... type="; msg.GetType(); " msg: "; msg.GetMessage()
endif

end while


'return true
End Function

Function reloadButtons(screen as object, isplaying as Boolean, ispaused as Boolean)

screen.clearbuttons()

If not isplaying then
screen.addbutton(0,"Play")

Else if isplaying and not ispaused then
screen.addbutton(0,"Pause")
screen.addbutton(1,"Stop")

Else if isplaying and ispaused then
screen.addbutton(0,"Resume")
screen.addbutton(1,"Stop")
End if

'now add any non-conditional buttons

screen.AddButton(2,"Network Schedule")
screen.AddButton(3,"About CRN")
screen.AddButton(4,"Go Back")


End function
0 Kudos
Highlighted
Roku Employee
Roku Employee

Re: Reloading buttons in Audio Player

I don't think you've fixed the message port issue and your event loop isn't doing anything because it isn't getting any events.

You're doing this:

port = screen.getmessageport()
screen.SetMessagePort(port)


Calling GetMessagePort() on a screen that doesn't have a message port will return invalid. So port is invalid when you pass it to SetMessagePort() and no message port is set on your screen. An easy way to see that is to print the type of port to the console:

screen = CreateObject("roSpringboardScreen")
port = screen.GetMessagePort()
? type(port)


You need to create a roMessagePort object and pass that to SetMessagePort()

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


You can also see what kind of events (if any) your Wait() is returning with the same technique:

msg = Wait(0, port)
? type(msg)
0 Kudos