Forum Discussion

squirreltown's avatar
squirreltown
Roku Guru
13 years ago

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.

3 Replies

  • 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
  • "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.
  • 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