JavaTV is an API to build interactive applications for Digital TV. It is relatively well documented and, well, it is Java, so it is part of a well known and reliable platform. A software for Digital TV runs on a set top box, which is a hardware with a smaller set of resources than regular desktops, but still powerful. A TV application is a kind of JavaME application, and is called, and is called Xlet. It is, in a very simplistic view, an interface you have to implement to have a JavaTV application.
You can use any IDE you like to develop JavaTV applications, but I don't know anyone which has real support for that (like JavaME support, or web development support). This is not a problem, since you will see it is very simple to work with this API. You will need to download Xletview, that is a tool that emulates a TV. You can include xletview.jar in you application, so you will be able to use some of libraries it comes with.
I am going to show you a very simple xlet that comes from InteractiveTvWeb. I liked it because it is very didactic. As you will see, it does actually....nothing. But it does compile and it shows you how any xlet should looks like. Don't be disappointed, because I will post more sophisticated xlets in the next posts. For now, just believe me this is a nice and powerful API and you will have fun with it.
P.S.: If you wanna more fun now, I sugest you to make this code implement a KeyListener, write a System.out.println() to show you something about the key you pressed, compile it, put it into a jar and open it in Xletview. It works just like any Java application.
package javatv;
/**
* The simplest Xlet that you will ever write. This Xlet
* does absolutely nothing, not even print a message.
* However, it is a complete skeleton Xlet that will
* compile, even if it does nothing useful once it's been
* compiled.
*
* This Xlet implements the Javax.tv.xlet.Xlet interface,
* in order to be the main class for an Xlet. All methods
* are inherited from javax.tv.xlet.Xlet
*/
public class MyFirstExampleXlet
implements javax.tv.xlet.Xlet {
/**
* Every Xlet should have a default constructor that
* takes no arguments. No other constructor will get
* called.
*/
public MyFirstExampleXlet() {
// The constructor should contain nothing. Any
// initialisation should be done in the initXlet()
// method, or in the startXlet method if it's time-
// or resource-intensive. That way, the MHP
// middleware can control when the initialisation
// happens in a much more predictable way
}
/**
* Initialise the Xlet. The context for this Xlet
* will get passed in to this method, and a reference
* to it should be stored in case it's needed later.
*
* This is the place where any initialisation should
* be done, unless it takes a lot of time or resources.
* If something goes wrong, then an
* XletStateChangeException should get thrown to let
* the runtime system know that the Xlet can't be
* initialised.
*/
public void initXlet(javax.tv.xlet.XletContext context)
throws javax.tv.xlet.XletStateChangeException {
// Do nothing for now
}
/**
* Start the Xlet. At this point the Xlet can display
* itself on the screen and start interacting with the
* user, or do any resource-intensive tasks. These
* kinds of function should be kept in startXlet(),
* and should *not* be done in initXlet().
*
* As with initXlet(), if there is any problem this
* method should throw an XletStateChangeException to
* tell the runtime system that it can't start.
*
* One of the common pitfalls is that the startXlet()
* method must return to its caller. This means that
* the main functions of the Xlet should be done in
* another thread. The startXlet() method should
* really just create that thread and start it, then
* return.
*/
public void startXlet()
throws javax.tv.xlet.XletStateChangeException {
// Do nothing for now
}
/**
* Pause the Xlet. Unfortunately, it's not clear to
* anyone (including the folks who wrote the MHP
* specification) what this means. Generally, it means
* that the Xlet should free any scarce resources that
* it's using, stop any unnecessary threads, and remove
* itself from the screen.
*
* Unlike the other methods, pauseXlet() can't throw an
* exception to indicate a problem with changing state.
* When the Xlet is told to pause itself, it must do so.
*/
public void pauseXlet() {
// Do nothing for now
}
/**
* Stop the Xlet. The boolean parameter tells the method
* whether the Xlet has to obey this request. If the
* value of the parameter is true, the Xlet must
* terminate and the runtime system will assume that
* when the method returns, the Xlet has terminated. If
* the value of the parameter is false, the Xlet can
* request that it not be killed, by throwing an
* XletStateChangeException. If the MHP middleware
* still wants to kill the Xlet, it should call
* destroyXlet() again with the parameter set to true.
*/
public void destroyXlet(boolean unconditional)
throws javax.tv.xlet.XletStateChangeException {
// Do nothing for now
}
}
2 comments:
Very good. I will study more about it.
Hey, DiDiVp,
Thanks for your comment. This is a very good area to go deeper into. I intend to post more about that. Keep in touch!
Post a Comment