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

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.  😞


<?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 2
Tyler_Smith
Binge Watcher

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
0 Kudos
kane2931
Channel Surfer

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 !  🙂 
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.