Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
kane2931
Level 7

Audio Node

I try to get the audio keeps playing when the user scroll up and down in a list (of radio stations), i am using AudioExemple template.  What i would like to be able to do, is scrubbing the listing, then when the user press ok (for selecting a new station), it stops the current (station) and start playing the new one.
Now every time the user touch the remote, audio stops.  Smiley Sad


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

<!--********** Copyright 2016 Roku Corp.  All Rights Reserved. **********-->

<component name = "AudioScene" extends = "Scene" >

  <script type = "text/brightscript" >
    <![CDATA[

    sub init()
      m.top.backgroundURI = "pkg:/images/rsgetbg.png"

      m.audiolist = m.top.findNode("audioLabelList")
      m.audioposter = m.top.findNode("audioPoster")


      m.audiolist.observeField("itemFocused","setaudio")
      m.audiolist.observeField("itemSelected","playaudio")

      m.audio = createObject("RoSGNode","Audio")

      m.audio.observeField("state","controlaudioplay")

      m.readAudioContentTask = createObject("RoSGNode","AudioContentReader")
      m.readAudioContentTask.observeField("audiocontent","showaudiolist")
      m.readAudioContentTask.audiocontenturi = "pkg:/server/audiocontent.xml"
      m.readAudioContentTask.control = "RUN" 
    end sub

    sub showaudiolist()
      m.audiolist.content = m.readAudioContentTask.audiocontent
      m.audiolist.setFocus(true)
    end sub

    sub setaudio()
      audiocontent = m.audiolist.content.getChild(m.audiolist.itemFocused)
      m.audioposter.uri = audiocontent.hdposterurl
      m.audio.content = audiocontent
    end sub

    sub playaudio()
      m.audio.control = "stop"
      m.audio.control = "none"
      m.audio.control = "play"
    end sub

    sub controlaudioplay()
      if (m.audio.state = "finished") 
        m.audio.control = "stop"
        m.audio.control = "none"
      end if
    end sub

    function onKeyEvent(key as String,press as Boolean) as Boolean
      if press then
        if key = "back"
          if (m.audio.state = "playing")
            m.audio.control = "stop"

            return true
          end if
        end if
      end if

      return false
    end function

    ]]>
  </script>

  <children>

    <Group >

      <LabelList 
        id = "audioLabelList"
        color="0x000000"
        itemSize = "[ 360, 60 ]"
        translation = "[ 90, 60 ]">
        <Font
            role = "font"
            uri = "pkg:/fonts/avenirltstd-light-webfont.ttf"
            id = "avenir-light"
            size = "26"/>
          </LabelList>

      <Poster
        id = "audioPoster"
        translation = "[ 844, 150 ]"
        width = "300"
        height = "300" />
      

    </Group>

  </children>

</component>
0 Kudos
2 Replies
Tyler_Smith
Level 7

Re: Audio Node

Remove m.audiolist.observeField("itemFocused","setaudio") and combine your setAudio and playAudio subroutines like I have below.

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

<!--********** Copyright 2016 Roku Corp.  All Rights Reserved. **********-->

<component name = "AudioScene" extends = "Scene" >

  <script type = "text/brightscript" >
    <![CDATA[

    sub init()
      m.top.backgroundURI = "pkg:/images/rsgetbg.png"

      m.audiolist = m.top.findNode("audioLabelList")
      m.audioposter = m.top.findNode("audioPoster")


      m.audiolist.observeField("itemFocused","setaudio")
      m.audiolist.observeField("itemSelected","playaudio")

      m.audio = createObject("RoSGNode","Audio")

      m.audio.observeField("state","controlaudioplay")

      m.readAudioContentTask = createObject("RoSGNode","AudioContentReader")
      m.readAudioContentTask.observeField("audiocontent","showaudiolist")
      m.readAudioContentTask.audiocontenturi = "pkg:/server/audiocontent.xml"
      m.readAudioContentTask.control = "RUN" 
    end sub

    sub showaudiolist()
      m.audiolist.content = m.readAudioContentTask.audiocontent
      m.audiolist.setFocus(true)
    end sub

    sub playaudio()
      audiocontent = m.audiolist.content.getChild(m.audiolist.itemFocused)
     m.audioposter.uri = audiocontent.hdposterurl[/font][/size]
      m.audio.content = audiocontent
      m.audio.control = "stop"
      m.audio.control = "none"
      m.audio.control = "play"
    end sub

    sub controlaudioplay()
      if (m.audio.state = "finished") 
        m.audio.control = "stop"
        m.audio.control = "none"
      end if
    end sub

    function onKeyEvent(key as String,press as Boolean) as Boolean
      if press then
        if key = "back"
          if (m.audio.state = "playing")
            m.audio.control = "stop"

            return true
          end if
        end if
      end if

      return false
    end function

    ]]>
  </script>

  <children>

    <Group >

      <LabelList 
        id = "audioLabelList"
        color="0x000000"
        itemSize = "[ 360, 60 ]"
        translation = "[ 90, 60 ]">
        <Font
            role = "font"
            uri = "pkg:/fonts/avenirltstd-light-webfont.ttf"
            id = "avenir-light"
            size = "26"/>
          </LabelList>

      <Poster
        id = "audioPoster"
        translation = "[ 844, 150 ]"
        width = "300"
        height = "300" />
      

    </Group>

  </children>

</component>
Tyler Smith
Senior Developer, REDspace
redspace.com
0 Kudos
kane2931
Level 7

Re: Audio Node

"Tyler Smith" wrote:
Remove m.audiolist.observeField("itemFocused","setaudio") and combine your setAudio and playAudio subroutines like I have below.

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

<!--********** Copyright 2016 Roku Corp.  All Rights Reserved. **********-->

<component name = "AudioScene" extends = "Scene" >

  <script type = "text/brightscript" >
    <![CDATA[

    sub init()
      m.top.backgroundURI = "pkg:/images/rsgetbg.png"

      m.audiolist = m.top.findNode("audioLabelList")
      m.audioposter = m.top.findNode("audioPoster")


      m.audiolist.observeField("itemFocused","setaudio")
      m.audiolist.observeField("itemSelected","playaudio")

      m.audio = createObject("RoSGNode","Audio")

      m.audio.observeField("state","controlaudioplay")

      m.readAudioContentTask = createObject("RoSGNode","AudioContentReader")
      m.readAudioContentTask.observeField("audiocontent","showaudiolist")
      m.readAudioContentTask.audiocontenturi = "pkg:/server/audiocontent.xml"
      m.readAudioContentTask.control = "RUN" 
    end sub

    sub showaudiolist()
      m.audiolist.content = m.readAudioContentTask.audiocontent
      m.audiolist.setFocus(true)
    end sub

    sub playaudio()
      audiocontent = m.audiolist.content.getChild(m.audiolist.itemFocused)
     m.audioposter.uri = audiocontent.hdposterurl[/font][/size]
      m.audio.content = audiocontent
      m.audio.control = "stop"
      m.audio.control = "none"
      m.audio.control = "play"
    end sub

    sub controlaudioplay()
      if (m.audio.state = "finished") 
        m.audio.control = "stop"
        m.audio.control = "none"
      end if
    end sub

    function onKeyEvent(key as String,press as Boolean) as Boolean
      if press then
        if key = "back"
          if (m.audio.state = "playing")
            m.audio.control = "stop"

            return true
          end if
        end if
      end if

      return false
    end function

    ]]>
  </script>

  <children>

    <Group >

      <LabelList 
        id = "audioLabelList"
        color="0x000000"
        itemSize = "[ 360, 60 ]"
        translation = "[ 90, 60 ]">
        <Font
            role = "font"
            uri = "pkg:/fonts/avenirltstd-light-webfont.ttf"
            id = "avenir-light"
            size = "26"/>
          </LabelList>

      <Poster
        id = "audioPoster"
        translation = "[ 844, 150 ]"
        width = "300"
        height = "300" />
      

    </Group>

  </children>

</component>


Thank you so much it worked !  Smiley Happy 
0 Kudos