Stop audio

Trying to stop the audio from playing by pressing a remote key in the DeviantArt example in the SDK

original:

audio = CreateObject("roAudioPlayer")
	item = CreateObject("roAssociativeArray")
	item.Url = "http://www.xxxxx.com/roku/songs/Nightfall.mp3"
      item.StreamFormat = "mp3"
	audio.AddContent(item)
	audio.SetLoop(false)
	audio.Play()

changed to:

audio = CreateObject("roAudioPlayer")
	port=CreateObject("roMessagePort")
	audio.SetMessagePort(port)
	item = CreateObject("roAssociativeArray")
	item.Url = "http://www.xxxxx.com/roku/songs/Nightfall.mp3"
      item.StreamFormat = "mp3"
	audio.AddContent(item)
	audio.SetLoop(false)
	audio.Play()
	
	While True
	msg = Wait (0, port)
 	if msg.isRemoteKeyPressed()
	index = msg.GetIndex()
	print "Remote button pressed: " + index.tostr()
	if index = 10  then'<INFO>
	audio.Pause()
	end if
	end if
	end while

It compiles and doesn’t error but doesnt do anything. Am i even close? where to look for an example?
thanks

That will only work if you press the “*” button on the remote, but it should work as far as I can tell by looking at it.

Hey thank you TheEndless, I’ve read enough posts to know you know your stuff, The “*” key is the one I want.

  1. I’m shocked if I actually wrote it correctly.
  2. It still doesn’t work - Arrgh!
  3. I’m going to stare at it until it does

thanks

“squirreltown” wrote:
Hey thank you TheEndless, I’ve read enough posts to know you know your stuff, The “*” key is the one I want.

  1. I’m shocked if I actually wrote it correctly.
  2. It still doesn’t work - Arrgh!
  3. I’m going to stare at it until it does

thanks
I see the problem. You’re listening for the keypress on the roAudioPlayer’s message port. roAudioPlayer doesn’t receive isRemoteKeyPressed events. You need to share that port with the screen you’re displaying at the time. Depending on the screen type, it should either receive an isRemoteKeyPressed event or an isButtonInfo event (in some cases both).

You could also try using the UniversalControlEvent. (if it’s sharing the port with the screen, then it should work)
else if type(msg) = “roUniversalControlEvent” then
If msg.GetInt()=10
end if
end if

What would be really cool would be if eventually roku combined all these methods into a single interface for the remote control instead of having 4 or 5 ways to use it depending on the screen. Maybe the UniversalControlEvent is actually universal, to be used everywhere? :slightly_smiling_face:

“destruk” wrote:
You could also try using the UniversalControlEvent. (if it’s sharing the port with the screen, then it should work)
else if type(msg) = “roUniversalControlEvent” then
If msg.GetInt()=10
end if
end if

What would be really cool would be if eventually roku combined all these methods into a single interface for the remote control instead of having 4 or 5 ways to use it depending on the screen. Maybe the UniversalControlEvent is actually universal, to be used everywhere? :slightly_smiling_face:
I’m pretty sure only the roScreen component receives roUniversalControlEvents.

You are correct Endless. I still think it would be nice if it was universal - would combine the isbuttoninfo, remotekeypressed, islistiteminfo, and however many others I forgot.
Maybe it’s not as big a problem as I thought it was - but I still get hung up on the “SetMessagePort” and “SetPort” compatibility issue too.
In the 3.1 firmware which runs on legacy Roku devices, the SetMessagePort method is not supported on the roScreen and roUrlTransfer components. For compatibility with these devices, your channels should call SetPort on these components instead.
Maybe a future firmware update will add both methods for 3.1 firmware (which would be 3.2 firmware, HA)

You need to share that port with the screen you’re displaying at the time. Depending on the screen type, it should either receive an isRemoteKeyPressed event or an isButtonInfo event (in some cases both).

I have looked at the audioapp example in the SDK, it says its an example of " … Using one shared msgport for multiple event types."

1.) I am not able to see where this sharing is taking place. if someone could point to the right section it would be great.

2.) I’m working with the DeviantArt example -slideshow and audio - there are no references to any kind of “screen” anywhere Ro or otherwise. Is the slideshow considered a “screen”? It seems like it would have to be If I’m going to share its msgport with the audio, but its totally not obvious to me.

thanks

  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.

  2. The deviantart example starts with a poster screen. It’s created in uitkPreShowPosterMenu. When the roSlideShow starts, it effectively acts as a screen, receiving button presses, etc.

–Mark

Thank you Mark!

“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

“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.

“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

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.

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.

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.