Forum Discussion

devnullpointer's avatar
devnullpointer
Streaming Star
4 years ago

onKeyEvent stops receiving events when audio starts

In my Roku application I'm using scenegraph timegrid view and another custom view for audio content. I have an onkeyevent in the main.brs and additional ones in each of the main views (timegrid and audio content). The onkeyevents get propagated properly up the chain in the timegrid view as I'm overriding the "options" key to show a custom menu dialog to allow the user to switch between views. When in the audio content view, the onkeyevents are propagating properly from within RowLists and Groups up the chain. Only when I start an audio stream does the "options" key event seem to no be delivered to the onkeyevent as I have put logging statements to see the keys triggered. 

So all other keyevents I listen for such as dpad movements and OK are being captured but the onkeyevent in the audio view but the "options" key is bringing up the standard roku options menu instead of being thrown up the chain to where it should be caught by the onkeyevent in the main. This only happens when I start the audio. Can someone explain to me what I'm doing wrong? Focus is not on the audio component as the Rowlist and other components get focus because i catch the focus events. 

Thanks.

Edit:

I just checked if the audio is in the focus chain after I set the control to 'play' and its not.

print "Chain " + booltostr(m.audioPlayer.isInFocuschain())
 
OK pressed.
Playing station.
stopped
Chain false
OK
11-12 19:12:47.916 [beacon.signal] |LiveStartInitiate ---------> TimeBase(22828 ms)
11-12 19:12:47.916 [beacon.signal] |LiveStartComplete ---------> Duration(3766 ms)

10 Replies

  • RokuJonathanD's avatar
    RokuJonathanD
    Community Moderator

    Hi devnullpointer,

    Are you using the Video node or Audio node for this? Also, can you provide me with a sample channel so our engineering team can further help you?

    Thanks,

    Jonathan

    • devnullpointer's avatar
      devnullpointer
      Streaming Star

      Hi RokuJonathanD ,

       

      Sorry for the late reply. I'm using an Audio node. I've inserted the code from the XML and the BRS files respectively. The primeRadio function loads the contentNode from a TaskNode to the audio player. I then make sure the Scene gets the focus not the audio player, hoping this would solve the problem. Unfortunately as long as the audio player is playing and not "stop" then the keyevent never gets propagated up the chain. I've also added the onKeyEvent function to show I don't process the "*" key.

      I'd prefer sending you full source files outside this thread to maintain source integrity, and we could update this thread with impending solution if any.

      <?xml version="1.0" encoding="UTF-8"?>
      <!-- Copyright (c) 2021 Xystra, Inc. All rights reserved. -->
      
      
      <component
          name="RadioGridView"
          extends="SGDEXComponent"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:noNamespaceSchemaLocation="https://devtools.web.roku.com/schema/RokuSceneGraph.xsd"
      >
          <interface>
              <function name="switchMode" />
          </interface>
      
          <script type="text/brightscript" uri="RadioGridView.brs" />
          <script type="text/brightscript" uri="pkg:/components/AppUtils.brs" />
          <script type="text/brightscript" uri="pkg:/components/SGDEX/Views/utils/Utils.brs" />
      
          <children>
              <!-- Background, randomly selected -->
              <Poster
                  uri="pkg:/images/background/blue.png"
                  width="1920.0"
                  height="1080.0"
                  translation="[0, 0]" 
              />
      
              <!-- Main Audio component -->
              <Audio
                  id="streamPlayer"
              />
      
              <!-- Headline -->
              <Group>
                  <Poster
                      uri="pkg:/images/logo.png"
                      width="75"
                      height="75"
                      translation="[50.0, 60.0]"
                  />
      
                  <Label
                      id="radioHeadline"
                      translation="[135, 30]"
                      maxLines="1"
                  />
                  <Label
                      id="radioMoto"
                      translation="[135, 150]"
                      horizAlign="left"
                  />
              </Group>
      
              <!-- Now Playing component -->
              <Group
                  id="nowStreaming"
                  visible="true"        
              >
                  <Poster
                      uri="pkg:/images/background/nowplaying.9.png"
                      width="801"
                      height="300"
                      translation="[1120.0, 100.0]"
                  />
                  <Poster
                      id="nowPlayingLogo"
                      width="200"
                      height="200"
                      translation="[1200, 150]"
                  />
                  <Label 
                      id="nowPlayingStation"
                      translation="[1430.0, 140.0]"
                      horizAlign="left"
                  />
                  <Label 
                      id="nowPlayingLocation"
                      translation="[1430.0, 180.0]"
                      horizAlign="left"
                  />
                  <Label 
                      id="nowPlayingRDSHeader"
                      translation="[1430.0, 230.0]"
                      horizAlign="left"
                  />
                  <Label 
                      id="nowPlayingRDS"
                      translation="[1430.0, 255.0]"
                      horizAlign="left"
                      width="420"
                      wrap="false"
                      ellipsizeOnBoundary="true"
                  />
                  <Poster
                      id="nowPlayingControl"
                      height="75"
                      width="75"
                      translation="[1480.0, 290.0]"
                  />
                  <Poster
                      id="nowPlayingFavorite"
                      height="75"
                      width="75"
                      translation="[1570.0, 290.0]"
                  />
              </Group>
      
              <!-- RowList of channels -->
              <RowList
                  id="stationList" 
                  translation="[ 100, 400 ]" 
                  itemComponentName="stationItem" 
                  numRows="4" 
                  itemSize="[ 1720, 250 ]" 
                  rowItemSize="[ [170, 170] ]" 
                  rowItemSpacing="[ [ 50, 0 ] ]"
                  showRowLabel="[ true ]" 
                  drawFocusFeedback="true"
                  focusBitmapUri="pkg:/images/background/stationfocus.9.png"
                  rowFocusAnimationStyle="floatingFocus"
              />
      
              <Timer
                  id="rdsTimer"
                  repeat="true"
                  duration="5"
              />
              
              <!-- Aux features controls -->
              <Group>
                  <Poster
                      uri="pkg:/images/star.png"
                      width="40.0"
                      height="40.0"
                      translation="[1560,10]" />
                  <Label
                      id="menuLabel"
                      translation="[1610, 15]"
                      wrap="false"
                  />
              </Group>
      
              <Group
                  id="busySpinner"
                  visible="false"
              >
                  <Poster
                      uri="pkg:/images/background/modal.png"
                      width="1920"
                      height="1080"
                      translation="[0.0,0.0]"
                  />
                  <BusySpinner
                      id="spinner"
                      translation="[960, 540]"
                  />
                  <Label
                      id="busyLoading"
                      translation="[820, 650]"
                  />
              </Group>
          </children>
      </component>
      sub primeRadio()
          print "Starting playback: " + m.playTask.stationContent.title
      
          m.current = m.playTask.stationContent
      
          m.tgRegistry.Write("lastRadio", m.current.id)
          m.tgRegistry.Flush()
          
          m.nowPlayingStation.text = m.playTask.stationContent.title
          m.nowPlayingLocation.text = m.playTask.stationContent.location
          m.nowPlayingLogo.uri = "<link to png file>"
      
          m.nowPlayingRDS.text = "Not available"
          if m.playTask.stationContent.rds then
              startRDSTimer()
          end if
      
          favsJson = m.tgRegistry.Read("radioFavorites")
          favorites = ParseJson(favsJson)
      
          m.currentIsFavorite = false
          for each fav in favorites 
              if fav.id = m.current.id then
                  m.currentIsFavorite = true
              end if
          end for
      
          if m.currentIsFavorite then
              m.nowPlayingFavorite.uri = "pkg:/images/heart-focus.png"
          else
              m.nowPlayingFavorite.uri = "pkg:/images/heart-off.png"
          end if
      
          m.nowPlayingControl.uri = "pkg:/images/pause.png"
      
          m.audioPlayer.content = m.playTask.stationContent
          m.audioPlayer.control = "play"
      
          m.top.getScene().setFocus(true)
          if not m.isSubGroup then
              ShowSpinner(false)
          end if
      end sub
      
      function onKeyEvent(_key_ as String, _press_ as Boolean) as Boolean  
          handled = false
      
          if _press_ then
              ? _key_ + " pressed."
      
              if _key_ = "down" then
                  if not m.stationList.hasFocus() then
                      m.stationList.setFocus(true)           
                      handled = True
                  end if
              end if
      
              if _key_ = "up" then
                  m.nowPlayingControl.setFocus(true)
              end if
              
              if _key_ = "left" or _key_ = "right" then
                  if not m.stationList.hasFocus() then
                      if m.nowPlayingControl.hasFocus() then
                          m.nowPlayingFavorite.setFocus(true)
                      else
                          m.nowPlayingControl.setFocus(true)
                      end if
                      handled = True
                  end if
              end if
              
              if _key_ = "OK" then
                  if m.nowPlayingControl.hasFocus() then
                      OnNowPlayingControlSelected()
                      handled = True
                  else if m.nowPlayingFavorite.hasFocus() then
                      OnNowPlayingFavoriteSelected()
                      handled = True
                  end if
              end if
      
              'keys not used in fullscreen
              if _key_ = "replay" or _key_ = "play" or _key_ = "rewind" or _key_ = "fastforward" then
                  handled = true
              end if
          end if
      
          return handled
      end function