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

Associate array index

well at the risk of interrupting the spammers here is my question for today
i am opening an audio springboard with the music already playing.
The playlist is an array of arrays.
I need to ask the array what is the index of the current associate array, the one that the currently playing audio is coming from.

the array is m.item

So, variable = m.item [ ? ]

Is it possible to create a if statement somehow? like

looking for value of X
IF m.item[x) =Y then..

thanks
Kinetics Screensavers
0 Kudos
10 REPLIES 10
destruk
Streaming Star

Re: Associate array index

If you are tracking what the index is already, then there isn't a need to query what is playing.
If you are searching for a match in an existing array (because you have no idea what you told it to play) then you can do it with a loop.

found=0 'initialize flag variable for search
for x=0 to m.item.count()-1 ' arrays are 0 based indexes, count returns a number starting at 1, so you want to subtract 1 so the numbers match up
if m.item.num=1 then
found=1
exit for 'exit for and end for are identical in operation - you can use whichever you prefer
end if
Next

This loop exits when the first match is located, or ends with x being equal to the number of available items, so the found flag variable is used to determine if there was actually a match.

For the search, m.item.num could be any variable of the associative array -- ie
if m.item.title="December Rain" then
if m.item.length=2000 then
etc etc etc


http://sdkdocs.roku.com/display/sdkdoc/ ... +Reference
The Brightscript programming reference is part of the sdk docs which would cover loops, arrays, searches, array access, multidimensional arrays, operators, etc that you would need to do most of this.
0 Kudos
squirreltown
Roku Guru

Re: Associate array index

Thank You destruk! That is really helpful. I know all this is referenced in the brightscript docs which i am becoming very familiar with, but a helpful person can make a lot more sense quickly, and make the docs actually useful when you are inexperienced in a particular area. This is exactly what i was looking for.
Kinetics Screensavers
0 Kudos
squirreltown
Roku Guru

Re: Associate array index

"destruk" wrote:

This loop exits when the first match is located, or ends with x being equal to the number of available items, so the found flag variable is used to determine if there was actually a match.
.

found = 0
For x=0 to m.item.count()-1
if m.item[x].num=0 then
found = x
exit for
end if
Next
m.song = found


What I'm finding with this is that it seems that it returns whatever number you put in num= above. That is its just saying - yes, there is an array entry with these conditions but it doesnt seem to relate to what the current song/array item is.

So the audio player seems to be the only thing that knows what the current index is but i cant ask it because it only returns an index on song select, and if there was a isPlaying status message i cant put a loop where i need it. You'd think syncing audio and screen info wouldnt be that big a deal but then i found a post yesterday about whats actually needed to make the progress indicator work, so i'm starting to get it.
Kinetics Screensavers
0 Kudos
RokuMarkn
Visitor

Re: Associate array index

"squirreltown" wrote:

So the audio player seems to be the only thing that knows what the current index is but i cant ask it because it only returns an index on song select, and if there was a isPlaying status message i cant put a loop where i need it.


I thought you had worked this out in an earlier thread. You just need to copy the index when you get the isListItemSelected message from the AudioPlayer. That gives you the index of the currently playing item.

--Mark
0 Kudos
squirreltown
Roku Guru

Re: Associate array index

"RokuMarkn" wrote:


I thought you had worked this out in an earlier thread. You just need to copy the index when you get the isListItemSelected message from the AudioPlayer. That gives you the index of the currently playing item.

--Mark

Thank You Mark, i really had all of this worked out a couple of days ago, except for the part where the audio track advances when you are NOT at the springboard. In that case my m.song variable remains where it was set when you left the springboard, and there seems to be no way to ask the audio player of the index of what is currently playing now. If only you could send the springboard to back like a canvas layer. It seems like the only way left is what Joel said to pass the variable to where you are going say, slideshow, increment it with status"start ofPlay" while there and then pass it back. I dont know if this will work since i have about six different places to go and return from but i"ll see if i can get it working with one first.
Kinetics Screensavers
0 Kudos
RokuMarkn
Visitor

Re: Associate array index

Well obviously I don't know the overall structure of your channel, but if you're not at the springboard, where are you? Wherever you are, the AudioPlayer still exists and is still sending messages to the port that you assigned to it. If you receive messages from that port in whatever event loop you're in and handle the AudioPlayer messages, you should be ok. I'm also not sure what you mean by "send the springboard to back" -- you should be able to put up another screen on top of the springboard if that's what you're trying to do.

--Mark
0 Kudos
squirreltown
Roku Guru

Re: Associate array index

Its a slideshow affair. The are 5 slideshows, a grid screen thats an index of all the slideshows, a paragraph screen and every one of those have info dialogs with buttons (just a button on the paragraph screen) to take you to the the audio springboard. Once you start the audio it runs until you stop it, you can go in and out of all of the above and the audio continues, plus you can return to the springboard from anywhere and change tracks, and the audio will start the new track when you press play. You have to press stop at the springboard or exit the channel to stop the audio, which makes the whole thing seem "smart" , which is why i want to get this last piece - showing the right screen info if the track has advanced when you were "somewhere else".
Kinetics Screensavers
0 Kudos
squirreltown
Roku Guru

Re: Associate array index

This is a request to Roku, as i have determined what I am trying is not possible, that is to play audio in the background, and retrieve the audio index after the function that created the audio player has closed.

The item needed is an audio status message - isPlaying with an index parameter, that works in the background, as the audio does, not only when the creating function is active.

This is needed because you allow audio to play in the background, as in the DeviantArt example in the SDK, but there is no way to sync screen info after the function that creates the roAudioplayer closes. For instance if a user wants to return to the audio page and change tracks, if the playlist has incremented since the audio screen was closed, there is no way to get the current audio index, and therefore sync proper screen info to it.

Creating an index variable in Function A (where the audioplayer is created) and passing it to Function B (say, a slideshow) and passing it back does not work because Function B will not recognize audio status messages from an audioplayer created in Function A, and therefore cannot increment the variable before passing it back.

Please consider this. Thank you.
Kinetics Screensavers
0 Kudos
RokuMarkn
Visitor

Re: Associate array index

What you're asking for already exists. The isListItemSelected status message does exactly what you're asking for. The problem you're having is due to your management of the message port(s) you're using. The audio player sends the status message to the message port that you assign to the player. You can receive messages from that port in any function you want. There are several ways to structure your code to do this. You could, for example, ignore the audio player port until you need to know the player's status, then read all the accumulated status messages. Or you could use the same message port for all your screens. Or you could periodically do a GetMessage loop from the audio player port after receiving a message from another screen. Unless you can clarify, I don't see that there's any additional mechanism necessary to support global audio players.

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