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

back button on array

audio springboard, one button plays an array of 5 items.
stopping advances the audio to the next item in the array, so easy to make a RIGHT button, which cycles through the items.
Problem I'm having is making a LEFT button to cycle the other way.
I was hoping this would work:
 else if msg.isRemoteKeyPressed()
if msg.GetIndex() = 4 ' < LEFT
scr.ClearButtons()
m.audio.SetNext(msg.GetIndex() -1)
m.audio.Play()
scr.AddButton(2, "Pause")
scr.AddButton(4, "Stop")
scr.AddButton(5, "Done")

It returns a result but not based on the current item playing in the springboard, it always returns the same result which is to play item 2 in the array as it seems to think item 3 is 0.
Kinetics Screensavers
0 Kudos
3 REPLIES 3
RokuJoel
Binge Watcher

Re: back button on array

because msg.getindex() is returning the index for which remote key is pressed and not the index value for your array. You could create an index variable to reflect current position, and increment or decrement that variable depending on which key is pressed.

Then:

     else if msg.isRemoteKeyPressed()
if msg.GetIndex() = 4 ' < LEFT
scr.ClearButtons()

if index > 0 then index=index-1
if index=0 then index=playlist.count()-1

m.audio.SetNext(msg.GetIndex() -1)
m.audio.Play()
scr.AddButton(2, "Pause")
scr.AddButton(4, "Stop")
scr.AddButton(5, "Done")


- Joel
0 Kudos
squirreltown
Roku Guru

Re: back button on array

"RokuJoel" wrote:
because msg.getindex() is returning the index for which remote key is pressed and not the index value for your array. You could create an index variable to reflect current position, and increment or decrement that variable depending on which key is pressed.


- Joel


Thank You Joel, I will try to do that if i can figure out how to get the current position of the array. Documentation seems a tad thin on this.
Kinetics Screensavers
0 Kudos
squirreltown
Roku Guru

Re: back button on array

Here are a left and right buttons on audio springboard which should increment items in an array of 5 items forward or backwards by one.
 else if msg.isRemoteKeyPressed()
if msg.GetIndex() = 4 ' < LEFT
scr.ClearButtons()

if msg.isPlaybackPosition() then
spot = msg.GetIndex()
index = playlist[spot]
if index > 0 then index=index-1
if index=0 then index=playlist.count()-1
m.audio.SetNext(msg.GetIndex() -1)
end if

m.audio.Play()
scr.AddButton(2, "Pause")
scr.AddButton(4, "Stop")
scr.AddButton(5, "Done")


else if msg.GetIndex() = 5 ' > RIGHT
scr.ClearButtons()

if msg.isPlaybackPosition() then
spot = msg.GetIndex()
index = playlist[spot]
if index > 0 then index=index+1
if index=0 then index=playlist.count()+1
m.audio.SetNext(msg.GetIndex() +1)
end if

m.audio.Play()
scr.AddButton(2, "Pause")
scr.AddButton(4, "Stop")
scr.AddButton(5, "Done")
end if

What is happening is both left and right buttons only increment one track forward, which is the same behavior as simply stopping the audio and starting it again. Does the format of the array matter? I ask because the titles on the springboard don't advance with the audio, it only shows the last items title. the array is like this:
		port = CreateObject("roMessagePort")
m.audio = CreateObject("roAudioPlayer")
m.audio.SetMessagePort(port)

item = CreateObject("roAssociativeArray")

item.Url = "http://www.xxx.com/roku/songs/dawn.mp3"
item.Artist = "xxx"
item.Title = "Dawn"
item.Album = "Alls Well That Ends Well"
item.HDPosterUrl = "pkg:/images/albumcover_hd.png"
item.SDPosterUrl = "pkg:/images/albumcover_sd.png"
item.StreamFormat = "mp3"
m.audio.AddContent(item)

item.Url = "http://www.xxx.com/roku/songs/nightfall.mp3"
item.Artist = "xxx"
item.Title = "Dusk"
item.Album = "Alls Well That Ends Well"
item.HDPosterUrl = "pkg:/images/albumcover_hd.png"
item.SDPosterUrl = "pkg:/images/albumcover_sd.png"
item.StreamFormat = "mp3"
m.audio.AddContent(item)
m.audio.SetLoop(true)
m.audio.SetNext(0)



I've seen arrays formated a bunch of ways, and since RokuJoel provided the code for the left/right buttons im looking somewhere else for the problem.
thanks
Kinetics Screensavers
0 Kudos