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: 
Alexanderrk
Reel Rookie

Play next item in m.list using key up and down

Hi,

I'm using the custom-playback-channel and trying to set it up so that pressing the up and down key will play the next item in the list.

So far here's the code.

' ********** Copyright 2016 Roku Corp.  All Rights Reserved. **********

'Main Scene Initialization with menu and video.
sub init()
	m.player = m.top.FindNode("Video")
	m.list = m.top.FindNode("MenuList")
	m.listbg = m.top.FindNode("MenuBG")
	m.list.setFocus(true)

  'Set the initial video player to some content'
  content = CreateObject("roSGNode", "ContentNode")
  content.url = "http://cdnamd-hls-globecast.akamaized.net/live/ramdisk/2m_monde/hls_video_ts/2m_monde.m3u8"
  content.streamformat = "hls"
  m.itemfocused = 0
  m.player.content = content
  'Tell the video player to play the content'
  m.player.control = "play"
end sub

'Handle remote control key presses'
function onKeyEvent(key as String, press as Boolean) as boolean
  print key + ":" ; press
  if press
    if key = "OK"
      print m.list.visible
      print m.list.itemfocused
      print m.itemfocused
      if m.list.ItemFocused = m.itemfocused and m.list.visible = true
        m.list.visible = false
        m.listbg.visible = false
        m.player.setfocus(true)
      else if m.list.visible = false
        m.list.visible = true
		m.listbg.visible = true
      else if m.list.visible = true
        m.itemfocused = m.list.itemfocused
        m.player.visible = false
        m.player.control = "stop"
        selectedContent = m.list.content.getChild(m.list.itemfocused)
        content = CreateObject("roSGNode", "ContentNode")
        content.url = selectedContent.url
        content.streamformat = selectedContent.description
        m.player.content = content
        m.player.visible = true
        m.player.control = "play"
      end if
    else if key = "play"
      if m.player.control = "pause"
        m.player.control = "resume"
      else
        m.player.control = "pause"
      end if
    else if key = "up"
      if m.list.visible = false
        m.player.control = "pause"
      end if
    else if key = "down"
      if m.list.visible = false
        m.player.control = "pause"
      end if
    else if key = "back"
      if m.list.visible = true
        m.list.visible = false
		m.listbg.visible = false
        m.player.setfocus(true)
        return true
      else
        m.list.visible = true
        m.listbg.visible = true
        m.list.setfocus(true)
        return true
      end if
    else
      print key
    end if
  else
    m.list.setfocus(true)
  end if
end function

The farthest i've been able to get is to get the up and down key to react when being pressed (using pause as a placeholder).

    else if key = "up"
      if m.list.visible = false
        m.player.control = "pause"

 

I've tried searching and using the developer docs but I think i'm stuck.

I'm trying to set this app up for someone who is vision impaired so If anyone has any suggestions how to make this work, i'd by very appreciative. 

Thanks.

0 Kudos
1 REPLY 1
joetesta
Roku Guru

Re: Play next item in m.list using key up and down

So where you added the "pause" placeholder, you want to do something like this:

        if m.myIndex = invalid then m.myIndex =m.list.itemfocused
        if m.myIndex + 1 < m.list.content.getChildCount()
m.player.control = "stop"
m.myIndex++
nextContent = m.list.content.getChild(m.myIndex) content = CreateObject("roSGNode", "ContentNode") content.url = nextContent.url content.streamformat = nextContent.description m.player.content = content m.player.visible = true m.player.control = "play"
else
' no more items in playlist
end if

  

aspiring