Listener to move to other screen in roku

85 Views Asked by At

I want to listen for event when the item is selected from the PosterGrid here is my XML element posterGrid

 <PosterGrid 
            id = "videosGrid" 
            basePosterSize = "[ 312, 188 ]" 
            caption1NumLines = "1" 
            numColumns = "3" 
            numRows = "5" 
            itemSpacing = "[ 20, 25 ]" 
            translation = "[ 100, 200]"
          />

I have implemented a observer when Item is selected like this

m.videosGrid = m.top.findNode("videosGrid")

m.videosGrid.observeField("itemSelected", "playVideo")

this is successfully calling when specific video is selected, but I want to listen from the main thread, this is a specific videoScreen thread, I am opening this videoScreen from this code

sub ShowVideoGridScreen()
m.VideosGridScreen = CreateObject("roSGNode", "VideosScreen")
m.VideosGridScreen.ObserveField("selectedPosterIndex", "OnGridScreenItemSelected") observe postergrid field, when item is selected 
ShowScreen(m.VideosGridScreen) ' show GridScreen
end sub

sub OnVideoGridScreenItemSelected() ' invoked when GridScreen item is selected
    print "------- Video Item Is Selected -----------"
    ShowVideoScreen()
end sub

I want to listen here for event and show videoScreen to play video as I have displayed the grid screen. This is the code which is in the ShowVideoScreen() function to open the playVideo thread. Can't understand this, please let me know if you know something about that, or any resource where can I find these things. Thanks in advance.

2

There are 2 best solutions below

0
amit kumar On

m.VideosGridScreen = CreateObject("roSGNode", "VideosScreen") m.VideosGridScreen.ObserveField("selectedPosterIndex", "OnGridScreenItemSelected") observe postergrid field, when item is selected

Since you want to observe "selectedPosterIndex", define this field in m.VideosGridScreen xml.

<xml>
<component name="VideosScreen">
<interface>
 <field id="selectedPosterIndex" value="-1" type="integer" />
 <PosterGrid 
            id = "videosGrid" 
            basePosterSize = "[ 312, 188 ]" 
            caption1NumLines = "1" 
            numColumns = "3" 
            numRows = "5" 
            itemSpacing = "[ 20, 25 ]" 
            translation = "[ 100, 200]"
          />

</component>
</xml>

you can assign "selectedPosterIndex" field, when item is selected.

0
vbuchii On

In Roku's SceneGraph application framework, the main thread primarily serves as the entry point of the application. It's responsible for creating and displaying the initial Scene. Manipulations such as listening for item selection events and handling navigation should ideally be performed in the Render thread.

In your case, when your application launches, it should display a Scene. This Scene can then add a screen with tiles. This screen should be responsible for observing tile selection events and executing a callback function to navigate to the video screen when a tile is selected.

For more information on SceneGraph threads, you can refer to Roku's official documentation: Roku Developer Program - Core Concepts - Threads

Additionally, to gain a better understanding of Roku's application structure and event handling, you might find it helpful to review some of the sample applications provided by Roku: Roku Developer Samples on GitHub

I hope this helps clarify your question. Let me know if you need further information.