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

Re: Stop audio

"RokuMarkn" wrote:
1. In the audioapp sample, AudioInit creates a MessagePort and stores it in o.port. It calls roAudioPlayer.SetMessagePort using that port, and then later Show_Audio_Screen calls create_springboard which calls roSpringboardScreen.SetMessagePort using the same port. Thus messages for both the roAudioPlayer and the roSpringboardScreen will be sent to the same port.


Ok so i've tried a whole bunch of things that don't work. My question is if the roAudioPlayer doesn't receive isRemoteKeyPressed events, how does sharing the port with some other component that does receive isRemoteKeyPressed events change things - I'm still trying to talk to the roAudioPlayer not the screen I'm on.

I've added an info paragraph (from the simpleinfo example) which has the ability to have a button on it. Would it be easier to have a "stop Audio" button there? The sharing port thing isn't going to happen, its just beyond me.

Thanks
Kinetics Screensavers
0 Kudos
RokuChris
Roku Employee
Roku Employee

Re: Stop audio

"squirreltown" wrote:
Ok so i've tried a whole bunch of things that don't work. My question is if the roAudioPlayer doesn't receive isRemoteKeyPressed events, how does sharing the port with some other component that does receive isRemoteKeyPressed events change things - I'm still trying to talk to the roAudioPlayer not the screen I'm on.


Message ports don't have anything to do with which components you can talk to, it's about which components you can listen to. You need to be listening to the port that raises the event you're interested in. In your case that's an isRemoteKeyPressed raised by the screen that's currently displayed, so you need to be listening to the port assigned to that screen. When you receive the event, you can then issue commands to any component you want, like your roAudioPlayer object.

"squirreltown" wrote:
I've added an info paragraph (from the simpleinfo example) which has the ability to have a button on it. Would it be easier to have a "stop Audio" button there? The sharing port thing isn't going to happen, its just beyond me.


Generally, best practice is to use a roSpringboardScreen as an audio UI. You could certainly add one or more on-screen buttons there to control playback. Take a look at Live365, Amazon Cloud Player, Pandora as examples.
0 Kudos
squirreltown
Roku Guru

Re: Stop audio

"RokuChris" wrote:

Generally, best practice is to use a roSpringboardScreen as an audio UI. You could certainly add one or more on-screen buttons there to control playback. Take a look at Live365, Amazon Cloud Player, Pandora as examples.


Thank you Chris. I have added a springboard for the audio, and made the buttons work as I'd like.
Now I added the audio springboard code into the DisplayInfomenu(infotype) function so the springboard gets called by a button on the info page. I see no errors in the debugger. All seems fine until you go back to the slideshow where the OK and * buttons dont work anymore. Left Right and Up still do. So you can start the music, go back to the slideshow but OK wont trigger it. If you just go to the info page and out -no problem. If you go info-then audio springboard and DONT start the audio, you get the problem so its loading the springboard which seems cause the issue. I did try to make the audio springboard a function and call it from a button on the info page but in addition to the above problems it stops the audio when you go back to the slideshow so thats no good.

hope someone can see or recognize this problem
thanks


Function DisplayInfomenu(infotype)
infomenu = createobject("romessagedialog")
infomenu.setmessageport(createobject("romessageport"))
infomenu.enableoverlay(true)
if (infotype = 0)
infomenu.setTitle("xxx")
infomenu.settext("xxx")
'infomenu.addbutton(1,"Play Music")
infomenu.addbutton(4,"done")
'infomenu.setfocusedmenuitem(1) ' 2nd button
elseif (infotype = 1)
infomenu.setTitle("xxx")
infomenu.settext("xxx")
'infomenu.addbutton(1,"Play Music")
infomenu.addbutton(4,"done")
'infomenu.setfocusedmenuitem(1) ' 2nd button
elseif (infotype = 2)
infomenu.setTitle("xxx")
infomenu.settext("xxx")
infomenu.addbutton(3,"Show Music Controls")
infomenu.addbutton(4,"done")
'infomenu.setfocusedmenuitem(1) ' 2nd button
elseif (infotype = 3)
infomenu.setTitle("xxx")
infomenu.settext("xxx")
'infomenu.addbutton(1,"Play Music")
infomenu.addbutton(4,"done")
'infomenu.setfocusedmenuitem(1) ' 2nd button
else
infomenu.setTitle("xxx")
infomenu.settext("xxx")
'infomenu.addbutton(1,"Play Music")
infomenu.addbutton(4,"done")
'infomenu.setfocusedmenuitem(1) ' 2nd button
endif
infomenu.show()
while true
msg = wait(0,infomenu.getmessageport())
if msg.isscreenclosed() return 0
if msg.isButtonInfo() return 0 ' Info pressed again, dismiss the info overlay
if msg.isbuttonpressed()
button = msg.getindex()
print "Info Button ";button;" pressed"
if button = 4
return button
endif
if msg.isbuttonpressed()
button = msg.getindex()
print "Info Button ";button;" pressed"
if button = 3

port = CreateObject("roMessagePort")
audio = CreateObject("roAudioPlayer")
audio.SetMessagePort(port)
item = CreateObject("roAssociativeArray")
item.Url = "http://www.xxx.com/roku/songs/Nightfall.mp3"
item.Artist = "xxx"
item.Title = "NightFall"
item.Album = "Alls Well That Ends Well"
item.HDPosterUrl = "pkg:/images/albumcover_hd.png"
item.SDPosterUrl = "pkg:/images/albumcover_sd.png"
item.StreamFormat = "mp3"
audio.AddContent(item)
audio.SetLoop(0)
audio.SetNext(0)


scr = CreateObject("roSpringboardScreen")
scr.SetDescriptionStyle("audio")
ContentType = "audio"
scr.SetMessagePort(port)
scr.SetStaticRatingEnabled(false)
scr.SetContent(item)
scr.AddButton(1, "Play Music")
scr.AddButton(5, "Done")
scr.SetPosterStyle("rounded-square-generic")
scr.Show()

while true
msg = wait(0, port)
if type (msg) = "roSpringboardScreenEvent"
if msg.isScreenClosed()
exit while
else if msg.isButtonPressed()
button = msg.GetIndex ()
if button = 1 ' Play Button
audio.Play()
scr.ClearButtons()
scr.AddButton(2, "Pause")
scr.AddButton(4, "Stop")
scr.AddButton(5, "Done")
else if button = 2 ' Pause Button
audio.Pause()
scr.ClearButtons()
scr.AddButton(3, "Resume")
scr.AddButton(4, "Stop")
scr.AddButton(5, "Done")
else if button = 3 ' Resume Button
audio.Resume()
scr.ClearButtons()
scr.AddButton(2, "Pause")
scr.AddButton(4, "Stop")
scr.AddButton(5, "Done")
else if button = 4 ' Stop Button
audio.Stop()
scr.ClearButtons()
scr.AddButton(1, "Play Music")
scr.AddButton(5, "Done")
else if button = 5 ' Done Button
scr.Close()

endif

end if
else if type (msg) = "roAudioPlayerEvent"
' Do nothing
end if
end while

endif
end if
endif
end while

end function
Kinetics Screensavers
0 Kudos
squirreltown
Roku Guru

Re: Stop audio

Just wanted to add that now the audio pauses for a few seconds randomly and then starts again, so it feels like the box is choking on something but its not showing in the debugger so I have no clue what.
Kinetics Screensavers
0 Kudos
squirreltown
Roku Guru

Re: Stop audio

Still trying to give the user some control over music playing under a slideshow.

I have audioplayer/springboard code that works fine.

I have put that code in a function, or in a separate file and it doesnt seem to matter.

If I call the function from a button on the info page, it causes the controls not to work when going back to the slideshow screen.

If i put the code (not as a function) at the beginning of Main.brs it works fine and doesnt screw up the slideshow controls but its the first thing to show in the app and since its a ancillary thing to the slideshow that doesnt make sense from a user perspective. It needs to be hidden until the user wants it.

If I call the function with the "*" key (replacing the info page) it doesnt screw up the slideshow controls, but stops the music when exiting the springboard, and i lose my info page.

I see that others have had this problem and have gotten advice like this "but make sure the audioplayer component itself is passed back, or saved globally" and I understand that the port needs to be shared and thought i was doing that by making the springboard function.

Maybe someone could point an example of how to do this:"audioplayer component itself is passed back, or saved globally" or tell me how this should be organized, should the springboard code be in a function or not? it seems each approach requires different solutions and I'm too inexperienced to even know which is the right way to start looking.

thanks

EDIT: have found the problem with the info page button screwing up the slideshow controls, but still need to "save the audio globally" to keep it from stopping when leaving the springboard.
Kinetics Screensavers
0 Kudos
squirreltown
Roku Guru

Re: Stop audio

Have found the solution to keeping the audio playing.
changed all references to

audio
to m.audio.

Only thing left is that bringing up the springboard while audio is playing stops the audio. Will try to find a way to stop that.
Kinetics Screensavers
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.