Developing a Roku channel is fun!
I recently treated myself to a Roku LT which is an inexpensive little gadget (currently retailing for about £40) that streams content from the Internet to your TV. Roku has got a lot right with this device. It is simple to use, the user interface is consistent, and it is compact - the unit is about the size of a hockey puck. A software development kit is also available so you can develop your own apps, or channels in Roku-speak. So I set myself the challenge of writing a new channel to see what developing for a Roku box is like.
The Software Development Kit is really easy to get your hands on. Just visit http://www.roku.com/developer and register. You will then have a new link on your account page for the developer site. Channels are developed using a language called BrightScript. As you might have guessed this is a Roku specific language, but is based on BASIC so if you have any familiarity with languages like Visual Basic for Applications you will be off to a flying start. I think it is fair to say that BrightScript has a slightly retro feel, it reminds me slightly of writing macros for Excel 97, but it gets the job done and I found the Roku to be quite straightforward and fun to program.
Channels can be developed using the tools in the SDK download and a text editor or through an Eclipse plug in. Comprehensive documentation is included in the SDK (and also online). Roku also run a developer blog and have a developer section on their forum . The SDK can be used on Linux, Mac and Windows. One thing to note though is that you will need an actual Roku device as well, an emulator is not part of the SDK, instead you first add the developer features to your Roku (through a remote control sequence explained in the docs) and connecting to it from your computer using telnet (the Eclipse plug in takes care of discovering and connecting to Roku boxes on your network).
Getting started on your new channel is pretty easy. The SDK and Eclipse plugin contain several examples covering major use cases such as audio and video players. A debugger is available on the Roku box itself. You can't do things like set breakpoints in Eclipse but you can press Ctrl+C while your app is running and use a text mode debugger in the telnet session to examine the contents of variables etc. which is very handy. The video player example is especially useful as it contains code that shows you how to parse an XML file which is great if you are using an RSS feed as the source of your data. A JSON parser is also available. Parsing XML is quite straightforward as you get an object that you can access properties on to get the contents of an element. E.g. xml.channels would get you all of the channel elements, something like item.title.getText() would get you the text in the <title> element of an <item> element. One handy thing to know though is that you have to use a slightly different notation for elements with a namespace, e.g. if you had a <dc:creator> element inside an <item> element you would need to have a line like this:
creator = item.GetNamedElements("dc:creator").GetText()
This tripped me up at first!
My little channel delivers podcasts from the CCMixter website to the Roku. I ran into an issue that many developers might face - that the feed of data was not quite as simple as I would have liked. To get the information I needed it was necessary to do a bit of text processing to extract some of what I needed from the feed. Fortunately regular expressions are supported on the Roku so you can write some pretty sophisticated text parsing routines, although ideally it is better to generate a cleaner feed on the server side. I started with the audio example channel from the SDK and built on the feed processing code in the video player sample. The code for my channel can be found here: https://github.com/liamgh/roku-ccmixter. All of this feed processing might take a few seconds so it is a good idea to add a splash screen for when your channel starts. Fortunately this is very easy, just specify the locations of SD and HD versions of your splash screen graphic file in the manifest file in your project.
The Roku platform has a bit more of a standardised look and feel than some other TV Internet environments. Standard screens can display lists of items to select or information about a media file currently playing. This is great as it means you do not have to worry too much about the design (although you still will need some graphics and a colour scheme). You can build these standard UI screen elements and pass information to populate them. For example you can build a screen to play an item, you would pass the title, author, length and these get displayed in standard places. You also add buttons which you can then get to control playback. The code has a main event loop where such things as button press events can be trapped and implemented.
One odd thing that I found was that the screen has a progress bar for how far through an audio track you are, however this does not need to automatically updated. You will need to keep updating this in your main event loop. The platform does not give you any meta data either about remote files that it is playing, so if you need to know the length of a track for example this will have to come from your feed. This caused me a bit of an issue as not every item in my feed had a length, so I had to implement extra code to not show a progress bar in this case. This also becomes a bit of an issue when implementing the fast forward and rewind buttons. I found I had to implement a timing variable and work out where to move to in the file manually, taking care to fast forward past the end of a track!
When you are ready to try out your code the Eclipse plug in takes care of packaging it and putting it onto the Roku device. You can only have one development channel loaded at once on the box, so if you work on another project and run it this will replace any development channel that is already there. When you are happy with your creation you can either submit it to Roku for inclusion in their channel store (subject to approval) or make it available as a "private channel". In the latter case the channel does not get reviewed by Roku or appear in the channel store, but you can send people a link that they can use to install the app via the Roku web site. This works really well. For example my channel can be installed with this link: http://owner.roku.com/add/ccmixter.
I am planning on experimenting more with Roku channel development. The platform has many interesting features, one I am keep to explore is the capability to pass data to a channel through a URL. This might be an interesting way to experiment with ideas around integrating TV and tablet devices on the same network. It did not take long to develop a channel for the Roku which was quite a refreshing change from some of the more complex platforms.