Developers

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>
Tags (1)
0 Kudos
1 REPLY 1
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 !  🙂 
Tags (1)
0 Kudos
Community is Being Upgraded!

We’re upgrading Roku Community to bring you a faster, more mobile-friendly experience. You may notice limited functionality or read-only access during this time. Read more here.

Planned Downtime:
Community will be unavailable for up to 24–48 hours during the upgrade window during the week of May 19th and you may notice reduced functionality. In the meantime, for additional assistance, visit our Support Site.

We're sorry for this disruption — we’re excited to share what’s next!