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

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
Kinetics Screensavers
0 Kudos
15 REPLIES 15
TheEndless
Channel Surfer

Re: Stop audio

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.
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
squirreltown
Roku Guru

Re: Stop audio

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
Kinetics Screensavers
0 Kudos
TheEndless
Channel Surfer

Re: Stop audio

"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).
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
destruk
Binge Watcher

Re: Stop audio

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? 🙂
0 Kudos
TheEndless
Channel Surfer

Re: Stop audio

"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? 🙂

I'm pretty sure only the roScreen component receives roUniversalControlEvents.
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
destruk
Binge Watcher

Re: Stop audio

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)
0 Kudos
squirreltown
Roku Guru

Re: Stop audio


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
Kinetics Screensavers
0 Kudos
RokuMarkn
Visitor

Re: Stop audio

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
0 Kudos
squirreltown
Roku Guru

Re: Stop audio

Thank you Mark!
Kinetics Screensavers
0 Kudos