Teach Your TiVO New Tricks with the HME SDK

Teach Your TiVO New Tricks with the HME SDK

f you aren’t already a DVR addict, someday you likely will be! Being able to turn on your TV, push a button, and get a menu of shows that you want to watch?without surfing through hundreds of channels of junk?is a very pleasant experience. It really is TV on demand. TiVO, pioneers and ongoing innovators of this technology have recently released an open source SDK that lets you take the next step in innovating on their platform?the Home Media Engine (HME).

The HME is an extensibility platform for the TiVO unit that allows you to build applications to enhance it. However, at present it doesn’t support the full DVR platform; unfortunately, the main missing part is the DVR functionality?meaning your applications can’t interact with live video?so no program guide or TV show access for your applications yet. However, even with that lacking, there’s still a lot left to explore.

This article is a guide to get you started in building HTM applications to run on a TiVO. This is the perfect excuse to go out and buy the hardware! Alternatively, if you don’t want to buy the hardware, or already own a competing platform, get the SDK anyway, because it comes with a complete emulator so you can try your inventions out without investing any of your hard earned cash!

Getting Started
You can download the HME from tivohme.sourceforge.net. When you do that, you get a ZIP file that you simply extract to a folder on your hard drive and unzip it. Figure 1 shows the HME directory structure created when you unzip the file.

The doc directory contains (surprise, surprise) the documentation for the SDK, which consists of a couple of PDFs containing a developers guide and a protocol guide for streaming information to and from your PC (more on this later) as well as a zip file of the javadocs for HME applications.

For this article, start in the samples directory, which contains several cool samples that will give you an idea for the kind of things that you can do with the SDK.

One caveat is that the simulator only appears to work if you are connected to a network. It doesn’t bind happily to if you are disconnected. To try out the sample applications, first make sure that you have a Java SDK installed (I used 1.4.2_07), and double click the simulator.jar file to execute the emulator. After you have done this, and the emulator is running, it will appear as shown in Figure 2.

In the ‘Samples‘ directory, you’ll see a runsamples.bat (or runsamples.sh for Linux/Unix users), which launch the sample applications. These applications will give you a good feel for the kind of things you can do with the SDK, including slide shows, music and even an excellent Connect-4 style game (seen in Figure 2).

Figure 1. The Directory Structure of the HME SDK: When you download and unzip the HME SDK, it creates this directory structure on your hard drive.
Figure 2. Running the Emulator: The figure shows the TiVO emulator running one of the sample applications, a Connect-4 game.

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(      "") + 29;   int nEnd = strSOAPPacket.indexOf("");   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).

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.

View content = new View(root, SAFE_ACTION_H,    SAFE_ACTION_V, root.width - SAFE_ACTION_H * 2,   root.height - SAFE_ACTION_V * 2);int panelHeight = content.height / views.length;for(int lp=0;lp<5;++lp){   View panel = new View(content, 0, lp * panelHeight,      content.width, panelHeight);   views[lp] = new View(panel, 0, 0, 200, 70);}new Thread(this).start();

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.

while (context != null) {   //update(views[1],"waiting...");   flush();   try   {      for(int lp=0;lp<5;lp++)      {         fQuotes[lp] = getQuote(strTickers[lp]);         update(views[lp],strTickers[lp] + ":" +             fQuotes[lp]);      }   }   catch(Exception e)   {      e.printStackTrace();      update(views[1],"Error : " + e);      flush();   }   flush();   // Wait 5 seconds and do it again   synchronized (this)    {      try       {         wait(5 * 1000);      }       catch (InterruptedException e)       {         return;      }   }}

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:

void update(View view, String strValue){   // Tweak the parent's background color, just for    // fun. This lets the user know that the RSS feed    // was updated.   int red   = random.nextInt(0x80);   int green = random.nextInt(0x80);   int blue  = random.nextInt(0x80);           view.parent.setResource(new Color(      red, green, blue));   // Now update the view with the new text.   view.setResource(createText("default-36.font",       Color.white, strValue));}

Figure 6 One Set of Colors: The update() function updates the views, using white text and a randomly chosen background color.
Figure 7. Colors Changed by the Update() Function: As the sample application calls update(), the background colors change.

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!



Share the Post:
Poland Energy Future

Westinghouse Builds Polish Power Plant

Westinghouse Electric Company and Bechtel have come together to establish a formal partnership in order to design and construct Poland’s inaugural nuclear power plant at

EV Labor Market

EV Industry Hurting For Skilled Labor

The United Auto Workers strike has highlighted the anticipated change towards a future dominated by electric vehicles (EVs), a shift which numerous people think will

Soaring EV Quotas

Soaring EV Quotas Spark Battle Against Time

Automakers are still expected to meet stringent electric vehicle (EV) sales quotas, despite the delayed ban on new petrol and diesel cars. Starting January 2023,

Affordable Electric Revolution

Tesla Rivals Make Bold Moves

Tesla, a name synonymous with EVs, has consistently been at the forefront of the automotive industry’s electric revolution. The products that Elon Musk has developed

Poland Energy Future

Westinghouse Builds Polish Power Plant

Westinghouse Electric Company and Bechtel have come together to establish a formal partnership in order to design and construct Poland’s inaugural nuclear power plant at the Lubiatowo-Kopalino site in Pomerania.

EV Labor Market

EV Industry Hurting For Skilled Labor

The United Auto Workers strike has highlighted the anticipated change towards a future dominated by electric vehicles (EVs), a shift which numerous people think will result in job losses. However,

Soaring EV Quotas

Soaring EV Quotas Spark Battle Against Time

Automakers are still expected to meet stringent electric vehicle (EV) sales quotas, despite the delayed ban on new petrol and diesel cars. Starting January 2023, more than one-fifth of automobiles

Affordable Electric Revolution

Tesla Rivals Make Bold Moves

Tesla, a name synonymous with EVs, has consistently been at the forefront of the automotive industry’s electric revolution. The products that Elon Musk has developed are at the forefront because

Sunsets' Technique

Inside the Climate Battle: Make Sunsets’ Technique

On February 12, 2023, Luke Iseman and Andrew Song from the solar geoengineering firm Make Sunsets showcased their technique for injecting sulfur dioxide (SO₂) into the stratosphere as a means

AI Adherence Prediction

AI Algorithm Predicts Treatment Adherence

Swoop, a prominent consumer health data company, has unveiled a cutting-edge algorithm capable of predicting adherence to treatment in people with Multiple Sclerosis (MS) and other health conditions. Utilizing artificial

Personalized UX

Here’s Why You Need to Use JavaScript and Cookies

In today’s increasingly digital world, websites often rely on JavaScript and cookies to provide users with a more seamless and personalized browsing experience. These key components allow websites to display

Geoengineering Methods

Scientists Dimming the Sun: It’s a Good Thing

Scientists at the University of Bern have been exploring geoengineering methods that could potentially slow down the melting of the West Antarctic ice sheet by reducing sunlight exposure. Among these

why startups succeed

The Top Reasons Why Startups Succeed

Everyone hears the stories. Apple was started in a garage. Musk slept in a rented office space while he was creating PayPal with his brother. Facebook was coded by a

Bold Evolution

Intel’s Bold Comeback

Intel, a leading figure in the semiconductor industry, has underperformed in the stock market over the past five years, with shares dropping by 4% as opposed to the 176% return

Semiconductor market

Semiconductor Slump: Rebound on the Horizon

In recent years, the semiconductor sector has faced a slump due to decreasing PC and smartphone sales, especially in 2022 and 2023. Nonetheless, as 2024 approaches, the industry seems to

Elevated Content Deals

Elevate Your Content Creation with Amazing Deals

The latest Tech Deals cater to creators of different levels and budgets, featuring a variety of computer accessories and tools designed specifically for content creation. Enhance your technological setup with

Learn Web Security

An Easy Way to Learn Web Security

The Web Security Academy has recently introduced new educational courses designed to offer a comprehensible and straightforward journey through the intricate realm of web security. These carefully designed learning courses

Military Drones Revolution

Military Drones: New Mobile Command Centers

The Air Force Special Operations Command (AFSOC) is currently working on a pioneering project that aims to transform MQ-9 Reaper drones into mobile command centers to better manage smaller unmanned

Tech Partnership

US and Vietnam: The Next Tech Leaders?

The US and Vietnam have entered into a series of multi-billion-dollar business deals, marking a significant leap forward in their cooperation in vital sectors like artificial intelligence (AI), semiconductors, and

Huge Savings

Score Massive Savings on Portable Gaming

This week in tech bargains, a well-known firm has considerably reduced the price of its portable gaming device, cutting costs by as much as 20 percent, which matches the lowest

Cloudfare Protection

Unbreakable: Cloudflare One Data Protection Suite

Recently, Cloudflare introduced its One Data Protection Suite, an extensive collection of sophisticated security tools designed to protect data in various environments, including web, private, and SaaS applications. The suite

Drone Revolution

Cool Drone Tech Unveiled at London Event

At the DSEI defense event in London, Israeli defense firms exhibited cutting-edge drone technology featuring vertical-takeoff-and-landing (VTOL) abilities while launching two innovative systems that have already been acquired by clients.

2D Semiconductor Revolution

Disrupting Electronics with 2D Semiconductors

The rapid development in electronic devices has created an increasing demand for advanced semiconductors. While silicon has traditionally been the go-to material for such applications, it suffers from certain limitations.

Cisco Growth

Cisco Cuts Jobs To Optimize Growth

Tech giant Cisco Systems Inc. recently unveiled plans to reduce its workforce in two Californian cities, with the goal of optimizing the company’s cost structure. The company has decided to

FAA Authorization

FAA Approves Drone Deliveries

In a significant development for the US drone industry, drone delivery company Zipline has gained Federal Aviation Administration (FAA) authorization, permitting them to operate drones beyond the visual line of

Mortgage Rate Challenges

Prop-Tech Firms Face Mortgage Rate Challenges

The surge in mortgage rates and a subsequent decrease in home buying have presented challenges for prop-tech firms like Divvy Homes, a rent-to-own start-up company. With a previous valuation of

Lighthouse Updates

Microsoft 365 Lighthouse: Powerful Updates

Microsoft has introduced a new update to Microsoft 365 Lighthouse, which includes support for alerts and notifications. This update is designed to give Managed Service Providers (MSPs) increased control and

Website Lock

Mysterious Website Blockage Sparks Concern

Recently, visitors of a well-known resource website encountered a message blocking their access, resulting in disappointment and frustration among its users. While the reason for this limitation remains uncertain, specialists