As I become more and more comfortable with programming the Roku DVP, I am slowly amassing a small mountain of notes on common pitfalls. These are the little mistakes that I make over and over and need a quick reminder of what I’m doing wrong.
Here’s a big one. Often times, I will attempt to play a video on the Roku DVP, but when I activate the roVideoSrreen, nothing happens. The roVideoScreen appears on screen, the title of my video appears in the center of the screen, and an empty progress bar appears at the bottom of the screen. Then, nothing happens. The progress indicator never gets populated and no error is logged to the debug terminal. Fixing this situation is usually pretty simple, but the solution is something I need to be reminded of occasionally because it is not included in the Roku SDK documentation.
For any piece of content you want to play on the Roku DVP, you must construct a data structure called a content-meta-data that tells the box how to present your content. The content-meta-data is nothing more than an associative array and building it is fairly straight forward. One of the items in this associative array must have a key of “StreamURLs” (plural). The value of the StreamURLs item must be an array of URLs to video streams. Why an array rather than just one stream URL? Because the Roku DVP is able to intelligently choose between multiple content streams based on the bandwidth available to it at any given moment. Simple enough, right?
In order for the Roku DVP to make the appropriate stream choice from the list of StreamURLs, your content-meta-data must also contain an item with a key of “StreamBitrates”. The value of the StreamBitrates item must be an array of integers. The first integer in that array represents the bitrate of the first stream in the StreamURLs item, the second integer represents the bitrate of the second stream, and so on.
In many cases, the data a developer is using to populate their content-meta-data structure is coming from an XML file. It’s tempting to simply populate the StreamBitrates array with the strings parsed out of your XML. This is a mistake, the items in the StreamBitrates array must be integers. This is what causes the DOA roVideoScreen, a StreamBitrates array populated with non-integers.
How do you turn a string into an integer with BrightScript? A quick glance through the BrightScript Reference Manual isn’t much help. There is not a documented function that takes a string as an argument and returns an integer. There is a function Val(s As String) that takes a string and returns a float, but that is no help. Populating the StreamBitrates array with the results of the Val function yields the same DOA roVideoScreen with an empty progress bar that never gets populated. We need integers, but how do we get them?
The solution to this little issue is an apparently undocumented function that I have only found by digging through the example code distributed with the Roku SDK. The function StrToI(s As String) takes a string as an argument and returns an integer with the value represented by that string. Populating the StreamBitrates array with the results of the StrToI function solves the problem and makes the roVideoScreen behave properly.
Why the StrToI function is not documented in the BrightScript Reference manual is a mystery, especially given its importance to the process of building a working channel.