With the release of the TiVO Home Media Engine SDK, the TiVO isn't simply a standalone digital video recorder any more, it's a gateway to a massive convergence of information and multimedia.

WEBINAR:

On-Demand

Enhancing the Application Using the HME
The sample application makes a good start, but it is a little basic. But you can take the code you've already seen as a foundation and use it to generate a portfolio grid of many stocks on the screen, updating them every few seconds. You can see the finished version (available in the downloadable code) in Figure 5.

Figure 5. Multiple Stock Quotes: The figure shows the multiple stock quote application running in the TiVO simulator listing five stocks that update every five seconds.

To do this, the first thing you need to do is to make your class runnable, by having its declaration specify implements Runnable like this:

public class StockQuote extends Application
implements Runnable

Next, you will need to use HME "views" to specify the areas of the screen where you want to put the information. Earlier you used root.SetResource to write to the screen, but that method just writes to the root screen object. If you have a number of objects that you want to write to, you define a content view that overlays the root, and then have panels that divide the screen upin this case into the five colored areas that you see in Figure 5. This application is hard coded for five stocks, but changing that number or making it dynamic should not be a big deal. Finally, the code adds views to these panels that will hold the text. The code from the init() function shown below handles all this.

The constants that you see (SAFE_ACTION_H, etc.) are part of the SDK. Check the documentation for more details. The last line of the preceding code starts a new thread, which runs the application, causing the run() function to be called. Run() is the workhorse of the app; it uses the SOAP code you saw earlier to get a quote for each of the five stock tickers hard-coded into this sample app. It then updates each of the views with the appropriate text, as shown in the code fragment below.

The flush() function triggers a redraw of the TiVO screen. The run() function code is pretty straightforward, as you can see. Every time it runs, it loops through the tickers and gets the quote using getQuote(strTickers[lp]) where strTickers is the array of pre-defined ticker strings. It passes the returned value to the update function, which you'll see in just a moment. After it's done with this, it calls flush() again to make sure that the screen is updated with the new values before going into a five-second (5,000 millisecond) wait cycle. At the end of this cycle, it runs again.

The update() function is a helper function that takes the string value and the reference to the view (the five views are stored in an array), and sets its text to the string value. It also randomly changes the background of the panel on which the view resides, causing a color shifting effect in the banded colors. See Figure 6 and Figure 7 to see the different colors. The function sets the view's text using view.setResource in much the same way as you called root.setResource in the earlier example. Here's the code:

The TiVO HME SDK is a very cool piece of software. Just imagine, you can write custom Java applications that run on your computer, communicate with an embedded device, and render on your TV! Not only that, but you can connect your TiVO to the Internet and use it to consume Web services as discussed in this article. This is really the beginning of a massive convergence of information and multimedia.

This article showed you how to get your TiVO to connect to a Web service using manually generated and parsed SOAP packets, and then to display the information on your TV showing the delayed values of some stocks with a color changing background, which you could run as a useful screensaver! With the emergence of Web services, and with outlets such as Amazon and eBay opening their data centers via Web services, the stage is set for a whole new way to access informationthrough your TV set. The promise has been around for some time (remember WebTV?), but now, TiVO appears to be much closer to delivering on that promisebringing the information highway into the living room. What you've seen here isn't all the SDK can do; it also lets you build applications for home media such as MP3s and your digital pictures. Finally, when TiVO opens the SDK up so it can access the program guide and interact with digital recordings on your TiVOor live TVa whole new wealth of application development opportunities will arise. And the best part is that you don't even need a TiVO to begin playing with them. Be forewarned thoughafter you start building to the emulator, you'll probably want to try it out on the real thing!

Laurence Moroney is a freelance enterprise architect who specializes in designing and implementing service-oriented applications and environments using .NET, J2EE, or (preferably) both. He has authored books on .NET and Web services security, and more than 30 professional articles. A former Wall Street architect, and security analyst, he also dabbles in journalism, reporting for professional sports. You can find his blog at http://www.philotic.com/blog.

Advertiser Disclosure:
Some of the products that appear on this site are from companies from which QuinStreet receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. QuinStreet does not include all companies or all types of products available in the marketplace.

Thanks for your registration, follow us on our social networks to keep up-to-date