Browse DevX
Sign up for e-mail newsletters from DevX


Teach Your TiVO New Tricks with the HME SDK : Page 2

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.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

How HME Applications Work
HME applications actually run on your PC, sending commands to your TiVO box to get it to lay out and paint objects on the screen based on how you develop the application. In turn, the TiVO triggers events, such as a response to a remote control command, and sends event notifications back across the network to your application, which handles them, and generally issues commands back to the TiVO in response.

This isn't as constraining as it might sound—and in many ways it is quite flexible, because it abstracts the TiVO box (an embedded system which is difficult to update and maintain) through the network protocol, using the PC as workhorse (a non-embedded system which is easy to update and maintain), so that you don't have to reflash or otherwise update the embedded systems in your TiVO box every time the SDK changes. Abstracting the process through the network protocol, means that even if you do update the SDK platform, the TiVO will still work as long as you code to the same protocol spec.

Figure 3. Architecture of an HME SDK Application: Your application sends commands through the network to the TiVO, which responds to events and sends notifications back, which your application can handle.
Building Your First Application
For the rest of this article you'll step through building a simple application that uses SOAP to communicate to the xmethods.net delayed stock quote sample site. For the sake of deployment simplicity the sample application doesn't use any XML or SOAP libraries, and it creates the SOAP documents itself in hard code. I did this by generating a SOAP client using Oracle JDeveloper, used that to call the Web service, and then 'sniffed' the HTTP line to get the document format. Finally, I hard coded the result into the Java code in the sample application. So, if you want to consume a different Web service, and run it on your TiVO, you can either follow the same methodology, or if you prefer, use a SOAP client and deploy its dependencies to your TiVO. This SOAP client is adapted from the one at IBM developerWorks.

The initial application is very straightforward. When building TiVO applications, your Java should extend Application, and have an init() function. In your init function you place the following:

protected void init(Context context) { String strVal = "IBM Stock is trading at " + getQuote("IBM"); root.setResource(createText("default-36-bold.font", Color.white,strVal)); }

The init() method calls the getQuote helper function to get the stock quote for (in this case) IBM. It then sets an HME resource with the text "IBM Stock is trading at xxx" where xxx is the price returned from the xmethods.net delayed stock quote service.

The getQuote helper function calls the getSOAPQuote helper function that does all the dirty work of creating the SOAP envelope, calling the Web service, and reading the reply. It then takes the SOAP document that is returned from this Web service and slices out the return value, putting it into a string and returning it to the caller (in this case init). Here's the getQuote method.

public String getQuote(String strTicker) { String strReturn = ""; String strSOAPPacket = getSOAPQuote(strTicker); //strReturn = strSOAPPacket; //String strTest = cli.getQuote("IBM"); int nStart = strSOAPPacket.indexOf( "<Result xsi:type='xsd:float'>") + 29; int nEnd = strSOAPPacket.indexOf("</Result>"); strReturn = strSOAPPacket.substring(nStart,nEnd); return strReturn; }

Listing 1 shows the getSOAPQuote method.

Figure 4. Running Your First Application: The figure shows the sample stock quote application showing a delayed quote obtained via the Web service displayed on the TiVO simulator.
To run this application on the Emulator, you have to jump through a couple of hoops. First, you need to deploy it to a .jar file. I used the package com.devx.tivo.SoapClient, and called the class StockQuote. You'll see all this in the download. Next, you need to create a batch file, similar to the one used to run the samples. This batch file will contain a single line:

java -cp ..\hme.jar;SoapClient.jar com.tivo.hme.sdk.Factory -launcher stock.txt

If you want to see debug messages, you can use the –d option too, like this:

java -cp ..\hme.jar;SoapClient.jar com.tivo.hme.sdk.Factory –d -launcher stock.txt

The SoapClient.jar reference in the preceding code is the .jar file mentioned in the last paragraph, and stock.txt is a set of instructions that the launcher needs. For this sample, create a stock.txt file containing the following:


To explore and understand more of these launcher-instruction files, check out the ones that the samples use (runsamples.bat and launcher.txt respectively).

When you run this application you'll get a basic TIVO screen containing a delayed quote for IBM (see Figure 4).

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



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