Reputation: 5376
I need to access video player from two or three different screens (namely guide, feature) which extends Group. Initially I thought of declaring Video in all the xml files and access that in respective brs files as below
.xml
<Video id="VideoPlayer" visible="false" translation="[0, 0]" width="1920" height="1080" />
.brs
m.video = m.top.findNode("VideoPlayer")
This is working fine. But later I realized that I am creating multiple video player instances unnecessarily. I am planning to create at one place and use it in all the screens which intended to use player. But I am not able to understand how I can create the player. Can anyone please let me know whether I need to create a screen file (.xml) for Video as below to achieve this
<?xml version="1.0" encoding="UTF-8"?>
<component name="VideoPlayer" extends="Group">
<children>
<Video id="VideoPlayer" visible="false" translation="[0, 0]" width="1920" height="1080" />
</children>
<script type="text/brightscript" uri="pkg://components/Player/VideoPlayer.brs"/>
</component>
Can any one please let me know if this is the correct way.
Upvotes: 1
Views: 172
Reputation: 2350
There's more than one way to do it. Maybe the easiest would be to create the player on global and access it from anywhere.
m.global.addField("player","node", false)
m.global.player = createObject("RoSGNode","VideoPlayer")
Then in the screens you can access using m.global.player
You also could create it as a component and pass it to your subComponents (screens) as needed, by adding a field definition to each component to reference the player. In each component's interface definition:
<field id="player" type="node" />
Then when the screen is created, set the player field from above to your one player instance. Then in the screens you can access using m.top.player
Upvotes: 2