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: 
tim_beynart
Channel Surfer

RAF and the Back Button... Focus Problems

I'm struggling with RAF, SSAI, and the back button.  I will be the first to admit that I am confused by how SG handles remote events (for example, why does RAF steal focus and not trigger onKeyPress observers upstream?).
I have implemented stitchedAdhandledEvent in an event loop, inside of a task.
Problem 1:
During an ad, if I click the back button I see this debug info:

rafrndr-onKeyEvent() - key: back
rafrndr-onkeyevent() - keycode: 0

and I can see that RAF reports the adexited:true
RAF cur ad >    <Component: roAssociativeArray> =
{
    adcompleted: false
    adexited: true
    adindex: 1
    adpodindex: 1
    evthandled: true
}


However, I must hit the back button again for my home scene to detect the keypress and close the video. I assume I am supposed to hack an observer upstream to close the video player manually using the information provided by RAF?

Problem 2:
During content, The back button is swallowed completely by RAF. No debug info, nothing. The content just keeps playing as if the button was never pressed. The stitchedAdHandledEvent logs this
RAF cur ad >    <Component: roInvalid>


Attempts to fix:
So far I have tried to force focus on the video node using m.videoplayer.setFocus(true) inside of the RAF event loop, but this does not work as expected. The video does indeed close and my logic runs to show the previous screen, but focus is not assigned as expected to some buttons on this screen.
Can anyone provide an RAF SSAI example in SeneGraph that illustrates how to make the back button work as expected?
0 Kudos
5 REPLIES 5
tim_beynart
Channel Surfer

Re: RAF and the Back Button... Focus Problems

Is there an official working example of SceneGraph RAF using SSAI anywhere?
0 Kudos
tim_beynart
Channel Surfer

Re: RAF and the Back Button... Focus Problems

I sort of figured it out, in case anyone stumbles on this thread.
My home scene monitors the video state, and will hide the video node and show the details screen when state="stopped", so the following event loop for RAF works for my needs:
m.playing = true
    while m.playing
      msg = wait(0, port)
      ? "RAF  >",type(msg),msg.getField(),msg.getData()
      curAd = invalid
      curAd = m.raf.stitchedAdHandledEvent(msg, {sgNode:m.videoplayer,port : port})
      if curAd <> invalid
        'detect ad exit and nuke loop
        if curAd.adExited
          ? "ad exited"
          m.videoplayer.control="STOP"
          m.playing = false
          exit while
        end if
      else if msg.getField()="keypressed" and msg.getData()=0
      ? "BACK BUTTON PRESSED"
        m.playing = false
        m.videoplayer.control="STOP"
        exit while
      end if
    end while
0 Kudos
NB_
Roku Guru

Re: RAF and the Back Button... Focus Problems

In your "if curAd <> Invalid" branch, make sure to add
           if curAd.adCompleted:
               ' ad rendering may reset focus, make sure focus is set properly when not rendering an ad '
               video.setFocus(true)
           end if
0 Kudos
tim_beynart
Channel Surfer

Re: RAF and the Back Button... Focus Problems

Thanks RokuNB. I think I finally got my head around this. I am a little confused as to why RAF swallows the back button entirely, that seems like an event that would bubble. Is this behavior necessary to support interactive ads (e.g. Brightline)?
0 Kudos
NB_
Roku Guru

Re: RAF and the Back Button... Focus Problems

"tim_beynart" wrote:
I am a little confused as to why RAF swallows the back button entirely, that seems like an event that would bubble. Is this behavior necessary to support interactive ads (e.g. Brightline)?

Because all your keys are belong to us? 8-)
All remote input during an ad run are consumed by RAF, not only Back. And yes, interactive ads are part of the picture.
It would be more intuitive in CSAI case, re SSAI I understand the flummox. It's one of those edge cases that can be argued either way.
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.