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: 
sudo97
Visitor

Extention

When I extend Video Node, I don't want my extended node to process any key pressings but "play", so I first wrote this:

function onKeyEvent(key as String, press as Booelan) as boolean
if(key <> "play")
return true
end if
return false
end function

with this key-event, when I start playing content in my VideoE in my scene, I can press "play" and it is handled correctly, but any other key-pressings are not handled by scene(such as arrow-keys which I use for navigation).

after that I tried this function:


function onKeyEvent(key as String, press as boolean) as boolean
print key
return true
end function

this gives me no reaction of VideoE on any key even on "play" and also it isn't handled by scene.

then I tried

function onKeyEvent(key as String, press as boolean) as boolean
print key
return false
end function

with this function: my navigation on scene works only when content isn't set; after the content is set and playing, arrow-keys are handled by VideoE, which isn't allowed for me.

I need arrow-keys to be handled by scene, and VideoE to process only "play" button(fastforward and rewind are also accepted). How can I make this?

here's full xml-code

<?xml version="1.0" encoding="utf-8"?>

<component name="VideoE" extends="Video">
<interface>
<field id="showStats" type="bool" onChange="setEngineeringMode" value = "false"/>
</interface>
<script type="text/brightscript">
<![CDATA[

sub init()
m.top.observeField("focusedChild", "showFocused")
setEngineeringMode()
end sub

function onKeyEvent(key as String, press as boolean) as boolean
print key
return true
end function

sub showFocused()
if(m.top.isInFocusChain())
m.top.FindNode("FocusAnimation").control = "start"
print "Focused"
else
m.top.FindNode("UnfocusAnimation").control = "start"
print "Unfocused"
end if
print m.top.hasFocus()
end sub
]]>
</script>
<children>
<Poster
id="RectViolet"
translation = "[-5, -5]"
uri="pkg:/images/rect_violet_640_360.png"
opacity = "0" />
<Animation
id="FocusAnimation"
duration="0.7"
repeat="false"
easeFunction="linear">
<FloatFieldInterpolator
id="fadeInInterp"
key = "[0.0, 0.5, 1.0]"
keyValue = "[ 0.0, 0.5, 1.0]"
fieldToInterp="RectViolet.opacity"/>
</Animation>
<Animation
id="UnfocusAnimation"
duration="0.7"
repeat="false"
easeFunction="linear">
<FloatFieldInterpolator
id="fadeoutInterp"
key = "[0.0, 0.5, 1.0]"
keyValue = "[ 1.0, 0.5, 0.0]"
fieldToInterp="RectViolet.opacity"/>
</Animation>
</children>
</component>

0 Kudos
4 REPLIES 4
BCVatOVG
Visitor

Re: Extention

for the onKeyEvent you need to return a value from the function.

https://sdkdocs.roku.com/pages/viewpage ... Id=1608547

The onKeyEvent() function must return true if the XML component handled the event, or false if it did not handle the event. Returning false allows the event to continue bubbling up the focus chain so that ancestors of the XML component can handle the event.
0 Kudos
sudo97
Visitor

Re: Extention

I fixed it in my post, and I also tried it in code, it doesn't work
0 Kudos
BCVatOVG
Visitor

Re: Extention

It seems to work fine to me. Are you sure you are creating a VideoE component and not just a regular Video component?

Can you zip up an example app so I can see the rest of the code, or post more code so we can help identify the problem?
0 Kudos
BCVatOVG
Visitor

Re: Extention

It may also have to do with where you are setting focus to as that component will then be handling the button events. I would need to see a more complete code example to troubleshoot further. 😄
0 Kudos