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: 
tmat1075
Visitor

How to create a playlist?

I'm trying to make a playlist as referenced here: https://sdkdocs.roku.com/display/sdkdoc/Playing+Videos#PlayingVideos-MediaPlaylists
I'm using the hero-grid template, but I'm stuck with how to make this work.
Here's the code that creates the row

function createRow(list as object, num as Integer)
  print "Parser.brs - [createRow]"
  Parent = createObject("RoSGNode", "ContentNode")
  row = createObject("RoSGNode", "ContentNode")
  row.Title = list[num].Title
  for each itemAA in list[num].ContentList
    item = createObject("RoSGNode","ContentNode")
    AddAndSetFields(item, itemAA)
    row.appendChild(item)
  end for
  Parent.appendChild(row)
  return Parent
end function


And I'm assuming the current "item" ContentNode just needs to be updated to have a "content" field that has an array of other ContentNodes? Maybe after "AddAndSetFields" have another loop that creates another array of ContetnNodes, then "item.content = {array of ContentNode}" ?  The things I've been trying don't seem to work.

Any help would much appreciated.
0 Kudos
10 REPLIES 10
tmat1075
Visitor

Re: How to create a playlist?

Trying this, and it doesn't do anything


function createRow(list as object, num as Integer)
  print "Parser.brs - [createRow]"
  Parent = createObject("RoSGNode", "ContentNode")
  row = createObject("RoSGNode", "ContentNode")
  row.Title = list[num].Title

  fullRow = []
  for each itemAA2 in list[num].ContentList
    item2 = createObject("RoSGNode","ContentNode")
    AddAndSetFields(item2, itemAA2)
    fullRow.push(item2)
  end for

  for each itemAA in list[num].ContentList
    item = createObject("RoSGNode","ContentNode")
    AddAndSetFields(item, itemAA)
    for each childRow in fullRow
      item.appendChild(childRow)
    end for
    row.appendChild(item)
  end for

  Parent.appendChild(row)
  return Parent
end function


and then in the details screen: 


<Video
      id="VideoPlayer"
      visible="false"
      translation="[0, 0]"
      width="1920"
      height="1080"
      contentIsPlaylist="true"
      />


and the play button doesn't work.  it throws an error saying "No streams were provided for playback", but i'm sure a video uri is being passed in.
0 Kudos
destruk
Binge Watcher

Re: How to create a playlist?

The docs aren't as clear as they could be - so you'll need to try a few things.
I would suggest it works like populating the new rowlist screen - so try setting
Parent.contentIsPlaylist="true"
After you create the parent, but before you do the for each append for the children to it.
As far as the streams go - each content item you are sending over needs to have at least one valid http or https url.
0 Kudos
tmat1075
Visitor

Re: How to create a playlist?

Thanks for the suggestion.  Though, I wasn't able to get it to work.
The part I'm most confused about is this:

1. Set the content field to a ContentNode node containing a child ContentNode node for each media item in the playlist.
2. Set the contentIsPlaylist field to true.

So looking at the code I posted about, "Parent" is the entire scene, "row" is each individual row, and each "item" is each video in the row.  So then does the "child ContentNode node for each media item in the playlist" contain the full TITLE, DESCRIPTION, etc... and that gets added to "item.content"? And do I have to do anything with the 'nextContentIndex" and "contentIndex" values?

So confused...
0 Kudos
tmat1075
Visitor

Re: How to create a playlist?

So I was able to get this to work

function createRow(list as object, num as Integer)
  print "Parser.brs - [createRow]"
  Parent = createObject("RoSGNode", "ContentNode")
  row = createObject("RoSGNode", "ContentNode")
  row.Title = list[num].Title

  fullContentList = list[num].ContentList

  for each itemAA in fullContentList
    Playlist = createObject("RoSGNode", "ContentNode")
    Playlist.title = itemAA.title
    Playlist.description = itemAA.description
    Playlist.hdposterurl = itemAA.hdposterurl
    Playlist.sdposterurl = itemAA.sdposterurl
    Playlist.hdBackgroundImageUrl = itemAA.hdBackgroundImageUrl
    for each itemAA2 in fullContentList
      item2 = createObject("RoSGNode","ContentNode")
      AddAndSetFields(item2, itemAA2)
      Playlist.appendChild(item2)
    end for
    row.appendChild(Playlist)
  end for

  Parent.appendChild(row)
  return Parent
end function


The only problem now is each row only has one icon in it. Ideally, if there are 5 videos in a row, I'd like to show each of them... and when you click "play" is plays the list using the one you clicked as the first in the playlist. 

Also, I'm not seeing any events being fired between each playlist video. Am I missing something?
0 Kudos
destruk
Binge Watcher

Re: How to create a playlist?

It's great you got something to work, but I'm not exactly sure how to do what you want.  Could you not just recreate the playlist with 5 different start points if you created the 5 thumbnails?
0 Kudos
tmat1075
Visitor

Re: How to create a playlist?

Thanks @destruk .

Honestly, I thought the way I was doing it would work.  I'm looping through the list and creating a node... then inside THAT loop, looping to create the playlist. I assumed it would take each video and create a separate playlist for each one, but I guess not. My initial thought is that there's a variable being passed-by-reference some where?  Or maybe putting the "contentIsPlaylist" parameter on the Video node is affecting something? 
0 Kudos
tmat1075
Visitor

Re: How to create a playlist?

I know I'm mostly talking to myself here, but here's the solution I came up with  😄


'Create a row of content '
function createRow(list as object, num as Integer)
  print "Parser.brs - [createRow]"
  Parent = createObject("RoSGNode", "ContentNode")
  row = createObject("RoSGNode", "ContentNode")
  row.Title = list[num].Title

  fullContentList = list[num].ContentList

  ' Clone the content list '
  copyContentList = []
  for each thingToClone in fullContentList
    copyContentList.push(thingToClone)
  end for

  ' Loop through the content list to create a single video node '
  for each itemAA in fullContentList
    Playlist = createObject("RoSGNode", "ContentNode")
    Playlist.title = itemAA.title
    Playlist.description = itemAA.description
    Playlist.hdposterurl = itemAA.hdposterurl
    Playlist.sdposterurl = itemAA.sdposterurl
    Playlist.hdBackgroundImageUrl = itemAA.hdBackgroundImageUrl
    ' Loop  through the cloned content list, to create the playlist of other vids in the category '
    for each itemAA2 in copyContentList
      item2 = createObject("RoSGNode","ContentNode")
      item2.url = itemAA2.url
      Playlist.appendChild(item2)
    end for

    ' Remove the first item in the list and put it at the end. '
    ' This makes the 1st video in the playlist the one thats showing its title '
    shiftedItem = copyContentList.shift()
    copyContentList.push(shiftedItem)

    row.appendChild(Playlist)
  end for

  Parent.appendChild(row)
  return Parent
end function



The issue I had was the objects are passed by reference, as I suspected. So I cloned the object (is there a built-in function that does that?) and did a shift() and push() to reorder the playlist. This seems pretty clunky to me, so if anyone runs across this and has a better idea, please let me know!
0 Kudos
destruk
Binge Watcher

Re: How to create a playlist?

Good work!
0 Kudos
SECHIN_SUNNY
Visitor

Re: How to create a playlist?

Hiii , i am trying to create a playlist , will this solution work if i implement on the channel in which i am working .I am first creating a homepage having rowlist , clicking on a row item will lead the user to videoplayer , after which the video will play in a loop .
Thanks
Regards
Sechin Sunny
0 Kudos