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

Oof! I am a noob.

I can manipulate php, some SQL, and xml, but the Brightscript is really tough for me to wrap my head around.

As I understand, starting with some of the example channels can be sort of overly-complicated, so I was hoping someone here can tell me where to start.

Specifically, I don't know where (or how) to define and parse my xml "fields" in brightscript. Such as <category>, <title>, <preview>, etc. What should that BS file be called? What should be included in it.

I have a million other questions / issues at the moment, but if I could at least get some of the front-end and design elements in place, I would feel much better. Hope I'm not being a bother.

I am trying to decipher the documentation and examples, but it is SO MUCH information to take in, that I fear I may be over complicating the issues.

Thank you in advance.
0 Kudos
7 REPLIES 7

Re: Oof! I am a noob.

Which version of the SDK are you using? That will be helpful in calling out certain pages of the documents.
Also what type of channel are you trying to create? There are quite a few options (screensaver, video, photo, music) and each has a different approach and different demos to look through.

I'd strongly recommend starting with the Channel Packaging and Publishing guide and doing a very simple Hello, World script. It's not directly related to coding, but understanding the process of taking a channel from a folder of asset files and .brs scripts to something that shows up on your Roku via the channel store is a good groundwork to build from.
0 Kudos
stitch1z
Visitor

Re: Oof! I am a noob.

Thank you for the response!

I am using v2.9 SDK

I am creating a ppv video channel (like Amazon, EZTakes).

I have the XML feeds set up, but like I said, I have no idea where to start on the brightscript. Checking out the packaging documents now.

Any other advice based on that info? Thanks again!
0 Kudos
stitch1z
Visitor

Re: Oof! I am a noob.

I am checking out the videoplayer source code since it is the closest to what I need...

Okay, correct me if I'm wrong, but the xml feed "fields" for each video are defined in the "showfeed.brs" file, correct?

Would I add a "preview" field here:
Function init_show_feed_item() As Object
o = CreateObject("roAssociativeArray")

o.ContentId = ""
o.Title = ""
o.ContentType = ""
o.ContentQuality = ""
o.Synopsis = ""
o.Genre = ""
o.Runtime = ""
o.StreamQualities = CreateObject("roArray", 5, true)
o.StreamBitrates = CreateObject("roArray", 5, true)
o.StreamUrls = CreateObject("roArray", 5, true)

return o
End Function


or here?

Function parse_show_feed(xml As Object, feed As Object) As Void

showCount = 0
showList = xml.GetChildElements()

for each curShow in showList

'for now, don't process meta info about the feed size
if curShow.GetName() = "resultLength" or curShow.GetName() = "endIndex" then
goto skipitem
endif

item = init_show_feed_item()

'fetch all values from the xml for the current show
item.hdImg = validstr(curShow@hdImg)
item.sdImg = validstr(curShow@sdImg)
item.ContentId = validstr(curShow.contentId.GetText())
item.Title = validstr(curShow.title.GetText())
item.Description = validstr(curShow.description.GetText())
item.ContentType = validstr(curShow.contentType.GetText())
item.ContentQuality = validstr(curShow.contentQuality.GetText())
item.Synopsis = validstr(curShow.synopsis.GetText())
item.Genre = validstr(curShow.genres.GetText())
item.Runtime = validstr(curShow.runtime.GetText())
item.HDBifUrl = validstr(curShow.hdBifUrl.GetText())
item.SDBifUrl = validstr(curShow.sdBifUrl.GetText())
item.StreamFormat = validstr(curShow.streamFormat.GetText())
if item.StreamFormat = "" then 'set default streamFormat to mp4 if doesn't exist in xml
item.StreamFormat = "mp4"
endif

'map xml attributes into screen specific variables
item.ShortDescriptionLine1 = item.Title
item.ShortDescriptionLine2 = item.Description
item.HDPosterUrl = item.hdImg
item.SDPosterUrl = item.sdImg

item.Length = strtoi(item.Runtime)
item.Categories = CreateObject("roArray", 5, true)
item.Categories.Push(item.Genre)
item.Actors = CreateObject("roArray", 5, true)
item.Actors.Push(item.Genre)
item.Description = item.Synopsis

'Set Default screen values for items not in feed
item.HDBranded = false
item.IsHD = false
item.StarRating = "90"
item.ContentType = "episode"

'media may be at multiple bitrates, so parse an build arrays
for idx = 0 to 4
e = curShow.media[idx]
if e <> invalid then
item.StreamBitrates.Push(strtoi(validstr(e.streamBitrate.GetText())))
item.StreamQualities.Push(validstr(e.streamQuality.GetText()))
item.StreamUrls.Push(validstr(e.streamUrl.GetText()))
endif
next idx

showCount = showCount + 1
feed.Push(item)

skipitem:

next


And if the latter, where exactly?

Also, If I were offering the same video in three different bitrates, how would I need to define those here?

Thanks again. Sorry I suck.
0 Kudos
stitch1z
Visitor

Re: Oof! I am a noob.

To specify, I'm not talking about adding in the built-in 2 minute preview of a video, but an actual trailer of the film.

Thanks again!
0 Kudos
stitch1z
Visitor

Re: Oof! I am a noob.

Bumpety bump
0 Kudos

Re: Oof! I am a noob.

init_show_feed_item() is just creating a simple object to use in your BrightScript. It's a storage container for the data you are pulling from the XML. It doesn't actually define the XML file, you do that by altering the structure of the XML file directly, adding nodes and attributes. Note, your parse function will need to know what to expect in terms of the structure, so if you modify the XML, also modify the parse function to accomodate.

parse_show_feed() is what parses the XML files and pulls the data into the roAssociativeArray. Check the xml folder of the videoplayer example to see how the XML is structured, then follow along in the parse_show_feed function. If you want a quick shorthand: @ references an attribute, . references a child node, and GetText() returns the contents of a node. Section 4.5 of the BrightScript Reference Manual covers XML support in BrightScript.

If you wanted to add additional info for each video item, you would probably want to do that in all three places.
1. The XML File - Add additional element nodes or attributes to each <item></item>
2. The init_show_feed_item function - Add additional properties in your roAssociativeArray
3. The parse_show_feed function - Read the xml nodes or attributes from the xml file and store them your roAssociativeArray

As an example, your XML might look like this after adding a previewUrl item:

<item sdImg="http://rokudev.roku.com/rokudev/examples/videoplayer/images/ElizabethGilbert.jpg" hdImg="http://rokudev.roku.com/rokudev/examples/videoplayer/images/ElizabethGilbert.jpg">
<title>Elizabeth Gilbert on nurturing creativity</title>
<contentId>10051</contentId>
<contentType>Talk</contentType>
<contentQuality>SD</contentQuality>
<streamFormat>mp4</streamFormat>
<media>
<streamQuality>SD</streamQuality>
<streamBitrate>1500</streamBitrate>
<streamUrl>http://video.ted.com/talks/podcast/ElizabethGilbert_2009_480.mp4</streamUrl>
<previewUrl>http://video.ted.com/talks/podcast/ElizabethGilbert_2009_480.mp4</previewUrl>
</media>
<synopsis>Elizabeth Gilbert muses on the impossible things we expect from artists and geniuses -- and shares the radical idea that, instead of the rare person 'being' a genius, all of us 'have' a genius. It's a funny, personal and surprisingly moving talk.</synopsis>
<genres>Creativity</genres>
<runtime>1172</runtime>
</item>

Note the new previewUrl node inside the media node.

Once you have the information pulled into your roAssociative array, you'll probably have to write your own solution to determine when to play different bit rate files and preview files. Hopefully someone with more experience on the video end of things can chime in with some suggestions there.

Hope this was at least a little clarifying. 🙂
0 Kudos
stitch1z
Visitor

Re: Oof! I am a noob.

Thank you Ryan, that helps a lot!
0 Kudos